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.

152 lines
3.8KB

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