Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.4KB

  1. /*
  2. * Carla Plugin
  3. * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the GPL.txt file
  16. */
  17. #include "CarlaPluginGui.hpp"
  18. #ifdef Q_WS_X11
  19. # include <QtGui/QX11EmbedContainer>
  20. #endif
  21. CARLA_BACKEND_START_NAMESPACE
  22. #include "moc_CarlaPluginGui.cpp"
  23. // -------------------------------------------------------------------
  24. // CarlaPluginGUI
  25. CarlaPluginGui::CarlaPluginGui(CarlaEngine* const engine, Callback* const callback, const Options& options)
  26. : QMainWindow(nullptr),
  27. kCallback(callback),
  28. fContainer(nullptr),
  29. fOptions(options)
  30. {
  31. CARLA_ASSERT(callback != nullptr);
  32. carla_debug("CarlaPluginGui::CarlaPluginGui(%p, %p)", engine, callback);
  33. if (options.parented)
  34. {
  35. #ifdef Q_WS_X11
  36. fContainer = new QX11EmbedContainer(this);
  37. #else
  38. fContainer = new QWidget(this);
  39. #endif
  40. setCentralWidget(fContainer);
  41. }
  42. #ifdef Q_OS_WIN
  43. if (! options.resizable)
  44. setWindowFlags(windowFlags()|Qt::MSWindowsFixedSizeDialogHint);
  45. #endif
  46. setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint);
  47. connect(this, SIGNAL(setSizeSafeSignal(int,int)), SLOT(setSizeSafeSlot(int,int)));
  48. }
  49. CarlaPluginGui::~CarlaPluginGui()
  50. {
  51. carla_debug("CarlaPluginGui::~CarlaPluginGui()");
  52. if (fOptions.parented)
  53. {
  54. CARLA_ASSERT(fContainer != nullptr);
  55. #ifdef Q_WS_X11
  56. delete (QX11EmbedContainer*)fContainer;
  57. #else
  58. delete fContainer;
  59. #endif
  60. }
  61. }
  62. void CarlaPluginGui::setSize(const int width, const int height)
  63. {
  64. CARLA_ASSERT_INT(width > 0, width);
  65. CARLA_ASSERT_INT(height > 0, height);
  66. carla_debug("CarlaPluginGui::setSize(%i, %i)", width, height);
  67. if (width <= 0)
  68. return;
  69. if (height <= 0)
  70. return;
  71. emit setSizeSafeSignal(width, height);
  72. }
  73. void* CarlaPluginGui::getContainerWinId()
  74. {
  75. CARLA_ASSERT(fContainer != nullptr);
  76. carla_debug("CarlaPluginGui::getContainerWinId()");
  77. return (fContainer != nullptr) ? (void*)fContainer->winId() : nullptr;
  78. }
  79. void CarlaPluginGui::setWidget(QWidget* const widget)
  80. {
  81. CARLA_ASSERT(fContainer == nullptr);
  82. carla_debug("CarlaPluginGui::setWidget(%p)", widget);
  83. setCentralWidget(widget);
  84. widget->setParent(this);
  85. fContainer = widget;
  86. }
  87. void CarlaPluginGui::closeEvent(QCloseEvent* const event)
  88. {
  89. CARLA_ASSERT(event != nullptr);
  90. carla_debug("CarlaPluginGui::closeEvent(%p)", event);
  91. if (event == nullptr)
  92. return;
  93. if (event->spontaneous() && kCallback != nullptr)
  94. kCallback->guiClosedCallback();
  95. QMainWindow::closeEvent(event);
  96. }
  97. void CarlaPluginGui::setSizeSafeSlot(int width, int height)
  98. {
  99. carla_debug("CarlaPluginGui::setSizeSafeSlot(%i, %i)", width, height);
  100. if (fOptions.resizable)
  101. resize(width, height);
  102. else
  103. setFixedSize(width, height);
  104. }
  105. // -------------------------------------------------------------------
  106. CARLA_BACKEND_END_NAMESPACE