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.

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