3 * Copyright (C) 2011-2019 Filipe Coelho <falktx@falktx.com>
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.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "CarlaBridgeFormat.hpp"
19 #include "CarlaBridgeToolkit.hpp"
21 #include "CarlaStyle.hpp"
23 #include <QtCore/QTimerEvent>
25 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
27 # error Wrong includes for this bridge!
29 # include <QtWidgets/QApplication>
30 # include <QtWidgets/QMainWindow>
33 # error Wrong includes for this bridge!
35 # include <QtGui/QApplication>
36 # include <QtGui/QMainWindow>
38 # define USE_CUSTOM_X11_METHODS
39 # include <QtGui/QX11Info>
40 # include <X11/Xlib.h>
44 CARLA_BRIDGE_UI_START_NAMESPACE
46 // -------------------------------------------------------------------------
49 static char* qargv
[0] = {};
51 // -------------------------------------------------------------------------
53 class CarlaBridgeToolkitQt
: public QObject
,
54 public CarlaBridgeToolkit
56 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
57 # pragma clang diagnostic push
58 # pragma clang diagnostic ignored "-Winconsistent-missing-override"
61 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) && defined(__clang_major__) && __clang_major__ >= 4
62 # pragma clang diagnostic pop
66 CarlaBridgeToolkitQt(CarlaBridgeFormat
* const format
)
68 CarlaBridgeToolkit(format
),
74 carla_debug("CarlaBridgeToolkitQt::CarlaBridgeToolkitQt(%p)", format
);
77 ~CarlaBridgeToolkitQt() override
79 CARLA_SAFE_ASSERT(fApp
== nullptr);
80 CARLA_SAFE_ASSERT(fWindow
== nullptr);
81 CARLA_SAFE_ASSERT(fMsgTimer
== 0);
82 carla_debug("CarlaBridgeToolkitQt::~CarlaBridgeToolkitQt()");
85 bool init(const int /*argc*/, const char** /*argv[]*/) override
87 CARLA_SAFE_ASSERT_RETURN(fApp
== nullptr, false);
88 CARLA_SAFE_ASSERT_RETURN(fWindow
== nullptr, false);
89 CARLA_SAFE_ASSERT_RETURN(fMsgTimer
== 0, false);
90 carla_debug("CarlaBridgeToolkitQt::init()");
92 fApp
= new QApplication(qargc
, qargv
);
94 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
95 fWindow
= new QMainWindow(nullptr);
97 fWindow
= new QMainWindow(nullptr, nullptr);
99 fWindow
->resize(30, 30);
105 void exec(const bool showUI
) override
107 CARLA_SAFE_ASSERT_RETURN(fPlugin
!= nullptr,);
108 CARLA_SAFE_ASSERT_RETURN(fApp
!= nullptr,);
109 CARLA_SAFE_ASSERT_RETURN(fWindow
!= nullptr,);
110 carla_debug("CarlaBridgeToolkitQt::exec(%s)", bool2str(showUI
));
112 const CarlaBridgeFormat::Options
& options(fPlugin
->getOptions());
114 QWidget
* const widget((QWidget
*)fPlugin
->getWidget());
116 fWindow
->setCentralWidget(widget
);
117 fWindow
->adjustSize();
119 widget
->setParent(fWindow
);
122 if (! options
.isResizable
)
124 fWindow
->setFixedSize(fWindow
->width(), fWindow
->height());
126 fWindow
->setWindowFlags(fWindow
->windowFlags() | Qt::MSWindowsFixedSizeDialogHint
);
130 fWindow
->setWindowIcon(QIcon::fromTheme("carla", QIcon(":/scalable/carla.svg")));
131 fWindow
->setWindowTitle(options
.windowTitle
.buffer());
133 #ifdef USE_CUSTOM_X11_METHODS
134 if (options
.transientWindowId
!= 0)
136 XSetTransientForHint(QX11Info::display(),
137 static_cast< ::Window
>(fWindow
->winId()),
138 static_cast< ::Window
>(options
.transientWindowId
));
142 if (showUI
|| fNeedsShow
)
148 fMsgTimer
= startTimer(30);
159 CARLA_SAFE_ASSERT_RETURN(fPlugin
!= nullptr,);
160 CARLA_SAFE_ASSERT_RETURN(fApp
!= nullptr,);
161 CARLA_SAFE_ASSERT_RETURN(fWindow
!= nullptr,);
162 carla_debug("CarlaBridgeToolkitQt::quit()");
166 killTimer(fMsgTimer
);
170 if (fWindow
!= nullptr)
180 if (! fApp
->closingDown())
190 carla_debug("CarlaBridgeToolkitQt::show()");
194 if (fWindow
!= nullptr)
198 void focus() override
200 carla_debug("CarlaBridgeToolkitQt::focus()");
205 carla_debug("CarlaBridgeToolkitQt::hide()");
209 if (fWindow
!= nullptr)
213 void setChildWindow(void* const) override
{}
215 void setSize(const uint width
, const uint height
) override
217 CARLA_SAFE_ASSERT_RETURN(fPlugin
!= nullptr,);
218 CARLA_SAFE_ASSERT_RETURN(fWindow
!= nullptr,);
219 CARLA_SAFE_ASSERT_RETURN(width
> 0,);
220 CARLA_SAFE_ASSERT_RETURN(height
> 0,);
221 carla_debug("CarlaBridgeToolkitQt::resize(%i, %i)", width
, height
);
223 if (fPlugin
->getOptions().isResizable
)
224 fWindow
->resize(static_cast<int>(width
), static_cast<int>(height
));
226 fWindow
->setFixedSize(static_cast<int>(width
), static_cast<int>(height
));
229 void setTitle(const char* const title
) override
231 CARLA_SAFE_ASSERT_RETURN(fWindow
!= nullptr,);
232 CARLA_SAFE_ASSERT_RETURN(title
!= nullptr && title
[0] != '\0',);
233 carla_debug("CarlaBridgeToolkitQt::setTitle(\"%s\")", title
);
235 fWindow
->setWindowTitle(title
);
240 QMainWindow
* fWindow
;
247 CARLA_SAFE_ASSERT_RETURN(fPlugin
!= nullptr,);
249 if (fPlugin
->isPipeRunning())
256 void timerEvent(QTimerEvent
* const ev
) override
258 if (ev
->timerId() == fMsgTimer
)
261 QObject::timerEvent(ev
);
265 CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeToolkitQt
)
269 // -------------------------------------------------------------------------
271 CarlaBridgeToolkit
* CarlaBridgeToolkit::createNew(CarlaBridgeFormat
* const format
)
273 return new CarlaBridgeToolkitQt(format
);
276 // -------------------------------------------------------------------------
278 CARLA_BRIDGE_UI_END_NAMESPACE
280 // -------------------------------------------------------------------------
282 CARLA_BRIDGE_UI_USE_NAMESPACE
284 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
285 # pragma GCC diagnostic push
286 # pragma GCC diagnostic ignored "-Wmissing-declarations"
287 # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
290 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
291 # include "CarlaBridgeToolkitQt5.moc"
292 # include "resources.qt5.cpp"
294 # include "CarlaBridgeToolkitQt4.moc"
295 # include "resources.qt4.cpp"
298 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
299 # pragma GCC diagnostic pop
302 // -------------------------------------------------------------------------