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.

153 lines
3.7KB

  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. else
  62. {
  63. CARLA_ASSERT(fContainer == nullptr);
  64. }
  65. }
  66. void CarlaPluginGui::setSize(const int width, const int height)
  67. {
  68. CARLA_ASSERT_INT(width > 0, width);
  69. CARLA_ASSERT_INT(height > 0, height);
  70. carla_debug("CarlaPluginGui::setSize(%i, %i)", width, height);
  71. if (width <= 0)
  72. return;
  73. if (height <= 0)
  74. return;
  75. emit setSizeSafeSignal(width, height);
  76. }
  77. void* CarlaPluginGui::getContainerWinId()
  78. {
  79. CARLA_ASSERT(fContainer != nullptr);
  80. carla_debug("CarlaPluginGui::getContainerWinId()");
  81. return (fContainer != nullptr) ? (void*)fContainer->winId() : nullptr;
  82. }
  83. void CarlaPluginGui::setWidget(QWidget* const widget)
  84. {
  85. CARLA_ASSERT(fContainer == nullptr);
  86. carla_debug("CarlaPluginGui::setWidget(%p)", widget);
  87. setCentralWidget(widget);
  88. widget->setParent(this);
  89. fContainer = widget;
  90. }
  91. void CarlaPluginGui::removeWidget()
  92. {
  93. CARLA_ASSERT(fContainer != nullptr);
  94. carla_debug("CarlaPluginGui::removeWidget()");
  95. if (fContainer == nullptr)
  96. return;
  97. fContainer->setParent(nullptr);
  98. setCentralWidget(nullptr);
  99. fContainer = nullptr;
  100. }
  101. void CarlaPluginGui::closeEvent(QCloseEvent* const event)
  102. {
  103. CARLA_ASSERT(event != nullptr);
  104. carla_debug("CarlaPluginGui::closeEvent(%p)", event);
  105. if (event == nullptr)
  106. return;
  107. if (event->spontaneous() && kCallback != nullptr)
  108. kCallback->guiClosedCallback();
  109. QMainWindow::closeEvent(event);
  110. }
  111. void CarlaPluginGui::setSizeSafeSlot(int width, int height)
  112. {
  113. carla_debug("CarlaPluginGui::setSizeSafeSlot(%i, %i)", width, height);
  114. if (fOptions.resizable)
  115. resize(width, height);
  116. else
  117. setFixedSize(width, height);
  118. }
  119. // -------------------------------------------------------------------
  120. CARLA_BACKEND_END_NAMESPACE