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.

CarlaPluginGui.cpp 3.5KB

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