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.

145 lines
3.6KB

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