Skip to content

Commit

Permalink
Fixes LMMS#6753: Lv2 help window issues (LMMS#6957)
Browse files Browse the repository at this point in the history
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 LMMS#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.
  • Loading branch information
JohannesLorenz authored Nov 12, 2023
1 parent 652b1fa commit ecc5ff8
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 4 deletions.
21 changes: 20 additions & 1 deletion include/Lv2ViewBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

class QPushButton;
class QMdiSubWindow;

class QLabel;
namespace lmms
{

Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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;
};


Expand Down
9 changes: 9 additions & 0 deletions plugins/Lv2Effect/Lv2FxControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,13 @@ void Lv2FxControlDialog::modelChanged()
}




void Lv2FxControlDialog::hideEvent(QHideEvent *event)
{
closeHelpWindow();
QWidget::hideEvent(event);
}


} // namespace lmms::gui
1 change: 1 addition & 0 deletions plugins/Lv2Effect/Lv2FxControlDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Lv2FxControlDialog : public EffectControlDialog, public Lv2ViewBase
private:
Lv2FxControls *lv2Controls();
void modelChanged() final;
void hideEvent(QHideEvent *event) override;
};


Expand Down
9 changes: 9 additions & 0 deletions plugins/Lv2Instrument/Lv2Instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ void Lv2InsView::dropEvent(QDropEvent *_de)



void Lv2InsView::hideEvent(QHideEvent *event)
{
closeHelpWindow();
QWidget::hideEvent(event);
}




void Lv2InsView::modelChanged()
{
Lv2ViewBase::modelChanged(castModel<Lv2Instrument>());
Expand Down
1 change: 1 addition & 0 deletions plugins/Lv2Instrument/Lv2Instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 40 additions & 3 deletions src/gui/Lv2ViewBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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();

Expand All @@ -203,6 +205,7 @@ Lv2ViewBase::Lv2ViewBase(QWidget* meAsWidget, Lv2ControlBase *ctrlBase)


Lv2ViewBase::~Lv2ViewBase() {
closeHelpWindow();
// TODO: hide UI if required
}

Expand All @@ -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
Expand All @@ -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

0 comments on commit ecc5ff8

Please sign in to comment.