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.

156 lines
3.9KB

  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. // Engine Helpers, defined in CarlaEngine.cpp
  25. extern QMainWindow* getEngineHostWindow(CarlaEngine* const engine);
  26. // -------------------------------------------------------------------
  27. // CarlaPluginGUI
  28. CarlaPluginGui::CarlaPluginGui(CarlaEngine* const engine, Callback* const callback, const Options& options)
  29. : QMainWindow(getEngineHostWindow(engine)),
  30. kCallback(callback),
  31. fContainer(nullptr),
  32. fOptions(options)
  33. {
  34. CARLA_ASSERT(callback != nullptr);
  35. carla_debug("CarlaPluginGui::CarlaPluginGui(%p, %p)", engine, callback);
  36. if (options.parented)
  37. {
  38. #ifdef Q_WS_X11
  39. fContainer = new QX11EmbedContainer(this);
  40. #else
  41. fContainer = new QWidget(this);
  42. #endif
  43. setCentralWidget(fContainer);
  44. }
  45. #ifdef Q_OS_WIN
  46. if (! options.resizable)
  47. setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
  48. #endif
  49. connect(this, SIGNAL(setSizeSafeSignal(int,int)), SLOT(setSizeSafeSlot(int,int)));
  50. }
  51. CarlaPluginGui::~CarlaPluginGui()
  52. {
  53. carla_debug("CarlaPluginGui::~CarlaPluginGui()");
  54. if (fOptions.parented)
  55. {
  56. CARLA_ASSERT(fContainer != nullptr);
  57. #ifdef Q_WS_X11
  58. delete (QX11EmbedContainer*)fContainer;
  59. #else
  60. delete fContainer;
  61. #endif
  62. }
  63. else
  64. {
  65. CARLA_ASSERT(fContainer == nullptr);
  66. }
  67. }
  68. void CarlaPluginGui::setSize(const int width, const int height)
  69. {
  70. CARLA_ASSERT_INT(width > 0, width);
  71. CARLA_ASSERT_INT(height > 0, height);
  72. carla_debug("CarlaPluginGui::setSize(%i, %i)", width, height);
  73. if (width <= 0)
  74. return;
  75. if (height <= 0)
  76. return;
  77. emit setSizeSafeSignal(width, height);
  78. }
  79. void* CarlaPluginGui::getContainerWinId()
  80. {
  81. CARLA_ASSERT(fContainer != nullptr);
  82. carla_debug("CarlaPluginGui::getContainerWinId()");
  83. return (fContainer != nullptr) ? (void*)fContainer->winId() : nullptr;
  84. }
  85. void CarlaPluginGui::setWidget(QWidget* const widget)
  86. {
  87. CARLA_ASSERT(fContainer == nullptr);
  88. carla_debug("CarlaPluginGui::setWidget(%p)", widget);
  89. setCentralWidget(widget);
  90. widget->setParent(this);
  91. fContainer = widget;
  92. }
  93. void CarlaPluginGui::removeWidget()
  94. {
  95. CARLA_ASSERT(fContainer != nullptr);
  96. carla_debug("CarlaPluginGui::removeWidget()");
  97. if (fContainer == nullptr)
  98. return;
  99. fContainer->setParent(nullptr);
  100. setCentralWidget(nullptr);
  101. fContainer = nullptr;
  102. }
  103. void CarlaPluginGui::closeEvent(QCloseEvent* const event)
  104. {
  105. CARLA_ASSERT(event != nullptr);
  106. carla_debug("CarlaPluginGui::closeEvent(%p)", event);
  107. if (event == nullptr)
  108. return;
  109. if (event->spontaneous() && kCallback != nullptr)
  110. kCallback->guiClosedCallback();
  111. QMainWindow::closeEvent(event);
  112. }
  113. void CarlaPluginGui::setSizeSafeSlot(int width, int height)
  114. {
  115. carla_debug("CarlaPluginGui::setSizeSafeSlot(%i, %i)", width, height);
  116. if (fOptions.resizable)
  117. resize(width, height);
  118. else
  119. setFixedSize(width, height);
  120. }
  121. // -------------------------------------------------------------------
  122. CARLA_BACKEND_END_NAMESPACE