| @@ -45,10 +45,20 @@ public: | |||
| : QMainWindow(nullptr), | |||
| kHost(host), | |||
| kPlugin(plugin), | |||
| #ifdef DISTRHO_UI_OPENGL | |||
| fWidget(this), | |||
| fUi(this, (intptr_t)fWidget.winId(), editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, uiResizeCallback) | |||
| #else | |||
| fUi(this, 0, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, uiResizeCallback) | |||
| #endif | |||
| { | |||
| #ifdef DISTRHO_UI_OPENGL | |||
| setCentralWidget(&fWidget); | |||
| #else | |||
| QtUI* const qtUi(fUi.getQtUI()); | |||
| qtUi->setParent(this); | |||
| setCentralWidget(qtUi); | |||
| #endif | |||
| setWindowTitle(QString("%1 (GUI)").arg(fUi.name())); | |||
| uiResize(fUi.width(), fUi.height()); | |||
| @@ -123,8 +133,15 @@ protected: | |||
| void uiResize(unsigned int width, unsigned int height) | |||
| { | |||
| #ifdef DISTRHO_UI_OPENGL | |||
| fWidget.setFixedSize(width, height); | |||
| setFixedSize(width, height); | |||
| #else | |||
| if (fUi.resizable()) | |||
| resize(width, height); | |||
| else | |||
| setFixedSize(width, height); | |||
| #endif | |||
| } | |||
| // --------------------------------------------- | |||
| @@ -144,8 +161,10 @@ private: | |||
| const HostDescriptor* const kHost; | |||
| PluginInternal* const kPlugin; | |||
| // Qt4 stuff | |||
| #ifdef DISTRHO_UI_OPENGL | |||
| // Qt stuff, used for GL | |||
| QWidget fWidget; | |||
| #endif | |||
| // UI | |||
| UIInternal fUi; | |||
| @@ -32,6 +32,6 @@ | |||
| #define DISTRHO_PLUGIN_URI "http://distrho.sf.net/plugins/Notes" | |||
| #define DISTRHO_UI_QT4 | |||
| #define DISTRHO_UI_QT | |||
| #endif // __DISTRHO_PLUGIN_INFO_H__ | |||
| @@ -26,7 +26,7 @@ START_NAMESPACE_DISTRHO | |||
| // ------------------------------------------------- | |||
| DistrhoUINotes::DistrhoUINotes() | |||
| : Qt4UI(), | |||
| : QtUI(), | |||
| fCurPage(1), | |||
| fSaveSizeNowChecker(-1), | |||
| fSaveTextNowChecker(-1), | |||
| @@ -61,7 +61,7 @@ DistrhoUINotes::DistrhoUINotes() | |||
| connect(&fProgressBar, SIGNAL(valueChangedFromBar(float)), SLOT(progressBarValueChanged(float))); | |||
| connect(&fTextEdit, SIGNAL(textChanged()), SLOT(textChanged())); | |||
| setFixedSize(300, 200); | |||
| setSize(300, 200); | |||
| } | |||
| DistrhoUINotes::~DistrhoUINotes() | |||
| @@ -166,14 +166,12 @@ void DistrhoUINotes::d_uiIdle() | |||
| if (fSaveTextNowChecker >= 0) | |||
| fSaveTextNowChecker++; | |||
| Qt4UI::d_uiIdle(); | |||
| } | |||
| void DistrhoUINotes::resizeEvent(QResizeEvent* event) | |||
| { | |||
| fSaveSizeNowChecker = 0; | |||
| QWidget::resizeEvent(event); | |||
| QtUI::resizeEvent(event); | |||
| } | |||
| // ------------------------------------------------- | |||
| @@ -18,7 +18,7 @@ | |||
| #ifndef __DISTRHO_UI_NOTES_HPP__ | |||
| #define __DISTRHO_UI_NOTES_HPP__ | |||
| #include "DistrhoUIQt4.hpp" | |||
| #include "DistrhoUIQt.hpp" | |||
| #include "paramspinbox.hpp" | |||
| #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |||
| @@ -40,7 +40,7 @@ START_NAMESPACE_DISTRHO | |||
| // ------------------------------------------------- | |||
| class DistrhoUINotes : public Qt4UI | |||
| class DistrhoUINotes : public QtUI | |||
| { | |||
| Q_OBJECT | |||
| @@ -26,8 +26,8 @@ | |||
| // nothing | |||
| #endif | |||
| #ifdef DISTRHO_UI_QT4 | |||
| # include "src/DistrhoUIQt4.cpp" | |||
| #ifdef DISTRHO_UI_QT | |||
| # include "src/DistrhoUIQt.cpp" | |||
| #else | |||
| # include "src/DistrhoUIOpenGL.cpp" | |||
| #endif | |||
| @@ -1,84 +0,0 @@ | |||
| /* | |||
| * DISTRHO Plugin Toolkit (DPT) | |||
| * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * This program is free software; you can redistribute it and/or | |||
| * modify it under the terms of the GNU Lesser General Public | |||
| * License as published by the Free Software Foundation. | |||
| * | |||
| * This program is distributed in the hope that it will be useful, | |||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| * GNU Lesser General Public License for more details. | |||
| * | |||
| * For a full copy of the license see the LGPL.txt file | |||
| */ | |||
| #ifndef __DISTRHO_UI_QT4_HPP__ | |||
| #define __DISTRHO_UI_QT4_HPP__ | |||
| #include "DistrhoUI.hpp" | |||
| #include <QtCore/Qt> | |||
| #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |||
| # include <QtWidgets/QWidget> | |||
| #else | |||
| # include <QtGui/QWidget> | |||
| #endif | |||
| START_NAMESPACE_DISTRHO | |||
| // ------------------------------------------------- | |||
| // Qt4 UI | |||
| class Qt4UI : public UI, | |||
| public QWidget | |||
| { | |||
| public: | |||
| Qt4UI(); | |||
| virtual ~Qt4UI(); | |||
| protected: | |||
| // --------------------------------------------- | |||
| // Information | |||
| virtual bool d_resizable() { return false; } | |||
| virtual uint d_minimumWidth() { return 100; } | |||
| virtual uint d_minimumHeight() { return 100; } | |||
| // --------------------------------------------- | |||
| // DSP Callbacks | |||
| virtual void d_parameterChanged(uint32_t index, float value) = 0; | |||
| #if DISTRHO_PLUGIN_WANT_PROGRAMS | |||
| virtual void d_programChanged(uint32_t index) = 0; | |||
| #endif | |||
| #if DISTRHO_PLUGIN_WANT_STATE | |||
| virtual void d_stateChanged(const char* key, const char* value) = 0; | |||
| #endif | |||
| #if DISTRHO_PLUGIN_IS_SYNTH | |||
| virtual void d_noteReceived(bool onOff, uint8_t channel, uint8_t note, uint8_t velocity) = 0; | |||
| #endif | |||
| // --------------------------------------------- | |||
| // UI Callbacks | |||
| virtual void d_uiIdle() {} | |||
| private: | |||
| friend class UIInternal; | |||
| // --------------------------------------------- | |||
| // Implement resize internally | |||
| void d_uiResize(unsigned int width, unsigned int height); | |||
| unsigned int d_width() const { return width(); } | |||
| unsigned int d_height() const { return height(); } | |||
| }; | |||
| // ------------------------------------------------- | |||
| END_NAMESPACE_DISTRHO | |||
| #endif // __DISTRHO_UI_QT4_HPP__ | |||
| @@ -45,8 +45,8 @@ public: | |||
| void setWindowTitle(const char* title); | |||
| App* getApp() const; | |||
| int getModifiers(); | |||
| intptr_t getWindowId(); | |||
| int getModifiers() const; | |||
| intptr_t getWindowId() const; | |||
| void addWidget(Widget* widget); | |||
| void removeWidget(Widget* widget); | |||
| @@ -284,12 +284,12 @@ public: | |||
| return kApp; | |||
| } | |||
| int getModifiers() | |||
| int getModifiers() const | |||
| { | |||
| return puglGetModifiers(kView); | |||
| } | |||
| intptr_t getWindowId() | |||
| intptr_t getWindowId() const | |||
| { | |||
| return puglGetNativeWindow(kView); | |||
| } | |||
| @@ -556,12 +556,12 @@ App* Window::getApp() const | |||
| return kPrivate->getApp(); | |||
| } | |||
| int Window::getModifiers() | |||
| int Window::getModifiers() const | |||
| { | |||
| return kPrivate->getModifiers(); | |||
| } | |||
| intptr_t Window::getWindowId() | |||
| intptr_t Window::getWindowId() const | |||
| { | |||
| return kPrivate->getWindowId(); | |||
| } | |||
| @@ -86,7 +86,7 @@ | |||
| # define USE_NAMESPACE_DISTRHO | |||
| #endif | |||
| #ifndef DISTRHO_UI_QT4 | |||
| #ifndef DISTRHO_UI_QT | |||
| # define DISTRHO_UI_OPENGL | |||
| #endif | |||
| @@ -69,8 +69,8 @@ struct PluginPrivateData { | |||
| #endif | |||
| timePos() | |||
| { | |||
| assert(d_lastBufferSize != 0); | |||
| assert(d_lastSampleRate != 0.0); | |||
| assert(bufferSize != 0); | |||
| assert(sampleRate != 0.0); | |||
| } | |||
| ~PluginPrivateData() | |||
| @@ -300,19 +300,19 @@ public: | |||
| // --------------------------------------------- | |||
| void setBufferSize(uint32_t bufferSize, bool callback = false) | |||
| void setBufferSize(uint32_t bufferSize, bool doCallback = false) | |||
| { | |||
| assert(kData != nullptr && kPlugin && bufferSize >= 2); | |||
| if (kData != nullptr) | |||
| { | |||
| if (callback && kData->bufferSize == bufferSize) | |||
| callback = false; | |||
| if (doCallback && kData->bufferSize == bufferSize) | |||
| doCallback = false; | |||
| kData->bufferSize = bufferSize; | |||
| } | |||
| if (kPlugin != nullptr && callback) | |||
| if (kPlugin != nullptr && doCallback) | |||
| { | |||
| kPlugin->d_deactivate(); | |||
| kPlugin->d_bufferSizeChanged(bufferSize); | |||
| @@ -320,19 +320,19 @@ public: | |||
| } | |||
| } | |||
| void setSampleRate(double sampleRate, bool callback = false) | |||
| void setSampleRate(double sampleRate, bool doCallback = false) | |||
| { | |||
| assert(kData != nullptr && kPlugin != nullptr && sampleRate > 0.0); | |||
| if (kData != nullptr) | |||
| { | |||
| if (callback && kData->sampleRate == sampleRate) | |||
| callback = false; | |||
| if (doCallback && kData->sampleRate == sampleRate) | |||
| doCallback = false; | |||
| kData->sampleRate = sampleRate; | |||
| } | |||
| if (kPlugin != nullptr && callback) | |||
| if (kPlugin != nullptr && doCallback) | |||
| { | |||
| kPlugin->d_deactivate(); | |||
| kPlugin->d_sampleRateChanged(sampleRate); | |||
| @@ -24,19 +24,7 @@ | |||
| # include "../dgl/App.hpp" | |||
| # include "../dgl/Window.hpp" | |||
| #else | |||
| # include "../DistrhoUIQt4.hpp" | |||
| # include <QtGui/QMouseEvent> | |||
| # include <QtGui/QResizeEvent> | |||
| # if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |||
| # include <QtWidgets/QSizeGrip> | |||
| # include <QtWidgets/QVBoxLayout> | |||
| # else | |||
| # include <QtGui/QSizeGrip> | |||
| # include <QtGui/QVBoxLayout> | |||
| # ifdef Q_WS_X11 | |||
| # include <QtGui/QX11EmbedWidget> | |||
| # endif | |||
| # endif | |||
| # include "../DistrhoUIQt.hpp" | |||
| #endif | |||
| #include <cassert> | |||
| @@ -55,23 +43,6 @@ extern double d_lastUiSampleRate; | |||
| // ------------------------------------------------- | |||
| #ifdef DISTRHO_UI_QT4 | |||
| # ifdef Q_WS_X11 | |||
| class QEmbedWidget : public QX11EmbedWidget | |||
| # else | |||
| class QEmbedWidget : public QWidget | |||
| # endif | |||
| { | |||
| public: | |||
| QEmbedWidget(WId parent); | |||
| ~QEmbedWidget(); | |||
| WId containerWinId() const; | |||
| }; | |||
| #endif | |||
| // ------------------------------------------------- | |||
| struct UIPrivateData { | |||
| // DSP | |||
| double sampleRate; | |||
| @@ -95,7 +66,7 @@ struct UIPrivateData { | |||
| uiResizeCallbackFunc(nullptr), | |||
| ptr(nullptr) | |||
| { | |||
| assert(d_lastUiSampleRate != 0.0); | |||
| assert(sampleRate != 0.0); | |||
| } | |||
| ~UIPrivateData() | |||
| @@ -135,29 +106,35 @@ struct UIPrivateData { | |||
| // ------------------------------------------------- | |||
| #ifdef DISTRHO_UI_QT4 | |||
| class UIInternal : public QObject // needed for eventFilter() | |||
| #else | |||
| class UIInternal | |||
| #endif | |||
| { | |||
| public: | |||
| UIInternal(void* ptr, intptr_t winId, editParamFunc editParamCall, setParamFunc setParamCall, setStateFunc setStateCall, sendNoteFunc sendNoteCall, uiResizeFunc uiResizeCall) | |||
| #ifdef DISTRHO_UI_QT4 | |||
| : qtGrip(nullptr), | |||
| qtWidget(nullptr), | |||
| #else | |||
| #ifdef DISTRHO_UI_OPENGL | |||
| : glApp(), | |||
| glWindow(&glApp, winId), | |||
| #else | |||
| : | |||
| #endif | |||
| kUi(createUI()), | |||
| kData((kUi != nullptr) ? kUi->pData : nullptr) | |||
| { | |||
| assert(kUi != nullptr); | |||
| if (kUi == nullptr) | |||
| return; | |||
| #ifdef DISTRHO_UI_OPENGL | |||
| assert(winId != 0); | |||
| if (kUi == nullptr || winId == 0) | |||
| if (winId == 0) | |||
| return; | |||
| #else | |||
| assert(winId == 0); | |||
| if (winId != 0) | |||
| return; | |||
| #endif | |||
| kData->ptr = ptr; | |||
| kData->editParamCallbackFunc = editParamCall; | |||
| @@ -165,21 +142,12 @@ public: | |||
| kData->setStateCallbackFunc = setStateCall; | |||
| kData->sendNoteCallbackFunc = sendNoteCall; | |||
| kData->uiResizeCallbackFunc = uiResizeCall; | |||
| #ifdef DISTRHO_UI_QT4 | |||
| createWindow(winId); | |||
| #endif | |||
| } | |||
| ~UIInternal() | |||
| { | |||
| if (kUi != nullptr) | |||
| { | |||
| #ifdef DISTRHO_UI_QT4 | |||
| destroyWindow(); | |||
| #endif | |||
| delete kUi; | |||
| } | |||
| } | |||
| // --------------------------------------------- | |||
| @@ -246,7 +214,7 @@ public: | |||
| void idle() | |||
| { | |||
| #ifdef DISTRHO_UI_QT4 | |||
| #ifdef DISTRHO_UI_QT | |||
| assert(kUi != nullptr); | |||
| if (kUi != nullptr) | |||
| @@ -256,106 +224,27 @@ public: | |||
| #endif | |||
| } | |||
| intptr_t getWinId() | |||
| #ifdef DISTRHO_UI_QT | |||
| QtUI* getQtUI() const | |||
| { | |||
| #ifdef DISTRHO_UI_QT4 | |||
| assert(qtWidget != nullptr); | |||
| return (qtWidget != nullptr) ? (intptr_t)qtWidget->winId() : 0; | |||
| #else | |||
| return glWindow.getWindowId(); | |||
| #endif | |||
| return (QtUI*)kUi; | |||
| } | |||
| // --------------------------------------------- | |||
| #ifdef DISTRHO_UI_QT4 | |||
| void createWindow(intptr_t parent) | |||
| bool resizable() const | |||
| { | |||
| assert(kUi != nullptr); | |||
| assert(kData != nullptr); | |||
| assert(qtGrip == nullptr); | |||
| assert(qtWidget == nullptr); | |||
| if (kUi == nullptr) | |||
| return; | |||
| if (kData == nullptr) | |||
| return; | |||
| if (qtGrip != nullptr) | |||
| return; | |||
| if (qtWidget != nullptr) | |||
| return; | |||
| Qt4UI* qt4Ui = (Qt4UI*)kUi; | |||
| // create embedable widget | |||
| qtWidget = new QEmbedWidget((WId)parent); | |||
| // set layout | |||
| qtWidget->setLayout(new QVBoxLayout(qtWidget)); | |||
| qtWidget->layout()->addWidget(qt4Ui); | |||
| qtWidget->layout()->setContentsMargins(0, 0, 0, 0); | |||
| qtWidget->setFixedSize(kUi->d_width(), kUi->d_height()); | |||
| // set resize grip | |||
| if (qt4Ui->d_resizable()) | |||
| { | |||
| // listen for resize on the plugin widget | |||
| qt4Ui->installEventFilter(this); | |||
| // create resize grip on bottom-right | |||
| qtGrip = new QSizeGrip(qtWidget); | |||
| qtGrip->resize(qtGrip->sizeHint()); | |||
| qtGrip->setCursor(Qt::SizeFDiagCursor); | |||
| qtGrip->move(kUi->d_width() - qtGrip->width(), kUi->d_height() - qtGrip->height()); | |||
| qtGrip->show(); | |||
| qtGrip->raise(); | |||
| qtGrip->installEventFilter(this); | |||
| } | |||
| // show it | |||
| qtWidget->show(); | |||
| return ((QtUI*)kUi)->d_resizable(); | |||
| } | |||
| void destroyWindow() | |||
| #else | |||
| intptr_t getWinId() | |||
| { | |||
| assert(kData != nullptr); | |||
| assert(qtWidget != nullptr); | |||
| if (kData == nullptr) | |||
| return; | |||
| if (qtWidget == nullptr) | |||
| return; | |||
| Qt4UI* qt4Ui = (Qt4UI*)kUi; | |||
| // remove main widget, to prevent it from being auto-deleted | |||
| qt4Ui->hide(); | |||
| qtWidget->layout()->removeWidget(qt4Ui); | |||
| qt4Ui->setParent(nullptr); | |||
| qt4Ui->close(); | |||
| qtWidget->close(); | |||
| qtWidget->removeEventFilter(this); | |||
| if (qtGrip != nullptr) | |||
| { | |||
| qtGrip->removeEventFilter(this); | |||
| delete qtGrip; | |||
| qtGrip = nullptr; | |||
| } | |||
| delete qtWidget; | |||
| qtWidget = nullptr; | |||
| return glWindow.getWindowId(); | |||
| } | |||
| #endif | |||
| // --------------------------------------------- | |||
| private: | |||
| #ifdef DISTRHO_UI_QT4 | |||
| QSizeGrip* qtGrip; | |||
| QEmbedWidget* qtWidget; | |||
| #else | |||
| #ifdef DISTRHO_UI_OPENGL | |||
| App glApp; | |||
| Window glWindow; | |||
| #endif | |||
| @@ -363,66 +252,6 @@ private: | |||
| protected: | |||
| UI* const kUi; | |||
| UIPrivateData* const kData; | |||
| #ifdef DISTRHO_UI_QT4 | |||
| bool eventFilter(QObject* obj, QEvent* event) | |||
| { | |||
| assert(kUi != nullptr); | |||
| assert(kData != nullptr); | |||
| //assert(qtGrip != nullptr); | |||
| assert(qtWidget != nullptr); | |||
| if (kUi == nullptr) | |||
| return false; | |||
| if (kData == nullptr) | |||
| return false; | |||
| if (qtGrip == nullptr) | |||
| return false; | |||
| if (qtWidget == nullptr) | |||
| return false; | |||
| Qt4UI* qt4Ui = (Qt4UI*)kUi; | |||
| if (obj == nullptr) | |||
| { | |||
| // nothing | |||
| } | |||
| else if (obj == qtGrip) | |||
| { | |||
| if (event->type() == QEvent::MouseMove) | |||
| { | |||
| QMouseEvent* mEvent = (QMouseEvent*)event; | |||
| if (mEvent->button() == Qt::LeftButton) | |||
| { | |||
| unsigned int width = qt4Ui->d_width() + mEvent->x() - qtGrip->width(); | |||
| unsigned int height = qt4Ui->d_height() + mEvent->y() - qtGrip->height(); | |||
| if (width < qt4Ui->d_minimumWidth()) | |||
| width = qt4Ui->d_minimumWidth(); | |||
| if (height < qt4Ui->d_minimumHeight()) | |||
| height = qt4Ui->d_minimumHeight(); | |||
| qt4Ui->setFixedSize(width, height); | |||
| return true; | |||
| } | |||
| } | |||
| } | |||
| else if (obj == qt4Ui && event->type() == QEvent::Resize) | |||
| { | |||
| QResizeEvent* rEvent = (QResizeEvent*)event; | |||
| const QSize& size = rEvent->size(); | |||
| qtWidget->setFixedSize(size.width(), size.height()); | |||
| qtGrip->move(size.width() - qtGrip->width(), size.height() - qtGrip->height()); | |||
| kUi->d_uiResize(size.width(), size.height()); | |||
| } | |||
| return QObject::eventFilter(obj, event); | |||
| } | |||
| #endif | |||
| }; | |||
| // ------------------------------------------------- | |||
| @@ -16,57 +16,31 @@ | |||
| #include "DistrhoUIInternal.hpp" | |||
| START_NAMESPACE_DISTRHO | |||
| // ------------------------------------------------- | |||
| // QEmbedWidget | |||
| QEmbedWidget::QEmbedWidget(WId id) | |||
| #ifdef Q_WS_X11 | |||
| : QX11EmbedWidget() | |||
| #else | |||
| : QWidget() | |||
| #endif | |||
| { | |||
| #ifdef Q_WS_X11 | |||
| embedInto(id); | |||
| #else | |||
| create(id, false, false); | |||
| #endif | |||
| } | |||
| #include <QtGui/QResizeEvent> | |||
| QEmbedWidget::~QEmbedWidget() | |||
| { | |||
| } | |||
| WId QEmbedWidget::containerWinId() const | |||
| { | |||
| #ifdef Q_WS_X11 | |||
| return QX11EmbedWidget::containerWinId(); | |||
| #else | |||
| return winId(); | |||
| #endif | |||
| } | |||
| START_NAMESPACE_DISTRHO | |||
| // ------------------------------------------------- | |||
| // Qt4UI | |||
| Qt4UI::Qt4UI() | |||
| QtUI::QtUI() | |||
| : UI(), | |||
| QWidget(nullptr) | |||
| { | |||
| } | |||
| Qt4UI::~Qt4UI() | |||
| QtUI::~QtUI() | |||
| { | |||
| } | |||
| // ------------------------------------------------- | |||
| // Implement resize internally | |||
| void Qt4UI::d_uiResize(unsigned int width, unsigned int height) | |||
| void QtUI::setSize(unsigned int width, unsigned int height) | |||
| { | |||
| UI::d_uiResize(width, height); | |||
| if (d_resizable()) | |||
| resize(width, height); | |||
| else | |||
| setFixedSize(width, height); | |||
| d_uiResize(width, height); | |||
| } | |||
| // ------------------------------------------------- | |||