From ecc5ff8ca7b826ab22e4b68c456129782ef0eee2 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz <1042576+JohannesLorenz@users.noreply.github.com> Date: Sun, 12 Nov 2023 02:25:26 +0100 Subject: [PATCH] Fixes #6753: Lv2 help window issues (#6957) This fixes at least three issues: * Help window is not synched with window manager's `X`-button * Help window is not being closed on track destruction or on closing the plugin window * Trims help window strings and force-adds a newline, because `QLabel::sizeHint` sometimes computes too small values. Now, together with #6956, all help windows fit their strings. Some help windows are too large by one line, but this seems better than forcing the user to resize them if they are too small by one line. --- include/Lv2ViewBase.h | 21 +++++++++++- plugins/Lv2Effect/Lv2FxControlDialog.cpp | 9 +++++ plugins/Lv2Effect/Lv2FxControlDialog.h | 1 + plugins/Lv2Instrument/Lv2Instrument.cpp | 9 +++++ plugins/Lv2Instrument/Lv2Instrument.h | 1 + src/gui/Lv2ViewBase.cpp | 43 ++++++++++++++++++++++-- 6 files changed, 80 insertions(+), 4 deletions(-) diff --git a/include/Lv2ViewBase.h b/include/Lv2ViewBase.h index 3c8f1bc3faf..43086849cb6 100644 --- a/include/Lv2ViewBase.h +++ b/include/Lv2ViewBase.h @@ -37,7 +37,7 @@ class QPushButton; class QMdiSubWindow; - +class QLabel; namespace lmms { @@ -64,9 +64,25 @@ class Lv2ViewProc : public LinkedModelGroupView }; + + +class HelpWindowEventFilter : public QObject +{ + Q_OBJECT + class Lv2ViewBase* const m_viewBase; +protected: + bool eventFilter(QObject* obj, QEvent* event) override; +public: + HelpWindowEventFilter(class Lv2ViewBase* viewBase); +}; + + + + //! Base class for view for one Lv2 plugin class LMMS_EXPORT Lv2ViewBase : public LinkedModelGroupsView { + friend class HelpWindowEventFilter; protected: //! @param pluginWidget A child class which inherits QWidget Lv2ViewBase(class QWidget *pluginWidget, Lv2ControlBase *ctrlBase); @@ -79,6 +95,7 @@ class LMMS_EXPORT Lv2ViewBase : public LinkedModelGroupsView void toggleUI(); void toggleHelp(bool visible); + void closeHelpWindow(); // to be called by child virtuals //! Reconnect models if model changed @@ -94,12 +111,14 @@ class LMMS_EXPORT Lv2ViewBase : public LinkedModelGroupsView static AutoLilvNode uri(const char *uriStr); LinkedModelGroupView* getGroupView() override { return m_procView; } + void onHelpWindowClosed(); Lv2ViewProc* m_procView; //! Numbers of controls per row; must be multiple of 2 for mono effects const int m_colNum = 6; QMdiSubWindow* m_helpWindow = nullptr; + HelpWindowEventFilter m_helpWindowEventFilter; }; diff --git a/plugins/Lv2Effect/Lv2FxControlDialog.cpp b/plugins/Lv2Effect/Lv2FxControlDialog.cpp index 5265cb1813d..73890937c04 100644 --- a/plugins/Lv2Effect/Lv2FxControlDialog.cpp +++ b/plugins/Lv2Effect/Lv2FxControlDialog.cpp @@ -72,4 +72,13 @@ void Lv2FxControlDialog::modelChanged() } + + +void Lv2FxControlDialog::hideEvent(QHideEvent *event) +{ + closeHelpWindow(); + QWidget::hideEvent(event); +} + + } // namespace lmms::gui diff --git a/plugins/Lv2Effect/Lv2FxControlDialog.h b/plugins/Lv2Effect/Lv2FxControlDialog.h index 45c14c2c0f1..f38c0364bfa 100644 --- a/plugins/Lv2Effect/Lv2FxControlDialog.h +++ b/plugins/Lv2Effect/Lv2FxControlDialog.h @@ -46,6 +46,7 @@ class Lv2FxControlDialog : public EffectControlDialog, public Lv2ViewBase private: Lv2FxControls *lv2Controls(); void modelChanged() final; + void hideEvent(QHideEvent *event) override; }; diff --git a/plugins/Lv2Instrument/Lv2Instrument.cpp b/plugins/Lv2Instrument/Lv2Instrument.cpp index 32f81d23c25..841b8a89ad2 100644 --- a/plugins/Lv2Instrument/Lv2Instrument.cpp +++ b/plugins/Lv2Instrument/Lv2Instrument.cpp @@ -295,6 +295,15 @@ void Lv2InsView::dropEvent(QDropEvent *_de) +void Lv2InsView::hideEvent(QHideEvent *event) +{ + closeHelpWindow(); + QWidget::hideEvent(event); +} + + + + void Lv2InsView::modelChanged() { Lv2ViewBase::modelChanged(castModel()); diff --git a/plugins/Lv2Instrument/Lv2Instrument.h b/plugins/Lv2Instrument/Lv2Instrument.h index 2cd73632da2..5e255e0dfbe 100644 --- a/plugins/Lv2Instrument/Lv2Instrument.h +++ b/plugins/Lv2Instrument/Lv2Instrument.h @@ -124,6 +124,7 @@ Q_OBJECT protected: void dragEnterEvent(QDragEnterEvent *_dee) override; void dropEvent(QDropEvent *_de) override; + void hideEvent(QHideEvent* event) override; private: void modelChanged() override; diff --git a/src/gui/Lv2ViewBase.cpp b/src/gui/Lv2ViewBase.cpp index 830a994c8c6..77268bb9b75 100644 --- a/src/gui/Lv2ViewBase.cpp +++ b/src/gui/Lv2ViewBase.cpp @@ -137,7 +137,8 @@ AutoLilvNode Lv2ViewProc::uri(const char *uriStr) -Lv2ViewBase::Lv2ViewBase(QWidget* meAsWidget, Lv2ControlBase *ctrlBase) +Lv2ViewBase::Lv2ViewBase(QWidget* meAsWidget, Lv2ControlBase *ctrlBase) : + m_helpWindowEventFilter(this) { auto grid = new QGridLayout(meAsWidget); @@ -172,7 +173,7 @@ Lv2ViewBase::Lv2ViewBase(QWidget* meAsWidget, Lv2ControlBase *ctrlBase) LILV_FOREACH(nodes, itr, props.get()) { const LilvNode* node = lilv_nodes_get(props.get(), itr); - auto infoLabel = new QLabel(lilv_node_as_string(node)); + auto infoLabel = new QLabel(QString(lilv_node_as_string(node)).trimmed() + "\n"); infoLabel->setWordWrap(true); infoLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); @@ -181,8 +182,9 @@ Lv2ViewBase::Lv2ViewBase(QWidget* meAsWidget, Lv2ControlBase *ctrlBase) btnBox->addWidget(m_helpButton); m_helpWindow = getGUI()->mainWindow()->addWindowedWidget(infoLabel); - m_helpWindow->setSizePolicy(QSizePolicy::Minimum, + m_helpWindow->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + m_helpWindow->installEventFilter(&m_helpWindowEventFilter); m_helpWindow->setAttribute(Qt::WA_DeleteOnClose, false); m_helpWindow->hide(); @@ -203,6 +205,7 @@ Lv2ViewBase::Lv2ViewBase(QWidget* meAsWidget, Lv2ControlBase *ctrlBase) Lv2ViewBase::~Lv2ViewBase() { + closeHelpWindow(); // TODO: hide UI if required } @@ -228,6 +231,14 @@ void Lv2ViewBase::toggleHelp(bool visible) +void Lv2ViewBase::closeHelpWindow() +{ + if (m_helpWindow) { m_helpWindow->close(); } +} + + + + void Lv2ViewBase::modelChanged(Lv2ControlBase *ctrlBase) { // reconnect models @@ -248,6 +259,32 @@ AutoLilvNode Lv2ViewBase::uri(const char *uriStr) } + + +void Lv2ViewBase::onHelpWindowClosed() +{ + m_helpButton->setChecked(true); +} + + + + +HelpWindowEventFilter::HelpWindowEventFilter(Lv2ViewBase* viewBase) : + m_viewBase(viewBase) {} + + + + +bool HelpWindowEventFilter::eventFilter(QObject* , QEvent* event) +{ + if (event->type() == QEvent::Close) { + m_viewBase->m_helpButton->setChecked(false); + return true; + } + return false; +} + + } // namespace lmms::gui #endif // LMMS_HAVE_LV2