From dd53bec311b18c1900f27e21a1fbe59040169f06 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sat, 10 Feb 2024 14:27:50 +0100 Subject: [PATCH] Hide the LED button for "Custom Base Velocity" (#7067) Hide the LED button for "Custom Base Velocity" as it did not have any other effect besides disabling the spinbox in the GUI. It did not affect any model which could be evaluated elsewhere. ## Technical details Add functionality to show/hide the LED button to `GroupBox`. There's also a corresponding getter called `ledButtonShown`. The latter is evaluated in the following situations: * Mouse clicks: if the LED button is hidden then the model is not toggled. * Paining: The X position of the caption changes depending on whether the LED button is shown or not. At a certain point the class `GroupBox` should be replaced by something that's implemented with layouts and which is used wherever it's possible. --- include/GroupBox.h | 15 +++++++++++++++ src/gui/instrument/InstrumentMidiIOView.cpp | 5 +---- src/gui/widgets/GroupBox.cpp | 18 +++++++++++++++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/include/GroupBox.h b/include/GroupBox.h index 6a8f424f9..fdeb31c4d 100644 --- a/include/GroupBox.h +++ b/include/GroupBox.h @@ -50,6 +50,21 @@ public: return m_led; } + /** + * @brief Returns whether the LED button is shown or not + * + * @return true LED button is shown + * @return false LED button is hidden + */ + bool ledButtonShown() const; + + /** + * @brief Sets if the LED check box is shown or not + * + * @param value Set to true to show the LED check box or to false to hide it. + */ + void setLedButtonShown(bool value); + int titleBarHeight() const { return m_titleBarHeight; diff --git a/src/gui/instrument/InstrumentMidiIOView.cpp b/src/gui/instrument/InstrumentMidiIOView.cpp index fd9d6fc54..e321d061e 100644 --- a/src/gui/instrument/InstrumentMidiIOView.cpp +++ b/src/gui/instrument/InstrumentMidiIOView.cpp @@ -145,6 +145,7 @@ InstrumentMidiIOView::InstrumentMidiIOView( QWidget* parent ) : } auto baseVelocityGroupBox = new GroupBox(tr("CUSTOM BASE VELOCITY")); + baseVelocityGroupBox->setLedButtonShown(false); layout->addWidget( baseVelocityGroupBox ); auto baseVelocityLayout = new QVBoxLayout(baseVelocityGroupBox); @@ -160,12 +161,8 @@ InstrumentMidiIOView::InstrumentMidiIOView( QWidget* parent ) : m_baseVelocitySpinBox = new LcdSpinBox( 3, baseVelocityGroupBox ); m_baseVelocitySpinBox->setLabel( tr( "BASE VELOCITY" ) ); - m_baseVelocitySpinBox->setEnabled( false ); baseVelocityLayout->addWidget( m_baseVelocitySpinBox ); - connect( baseVelocityGroupBox->ledButton(), SIGNAL(toggled(bool)), - m_baseVelocitySpinBox, SLOT(setEnabled(bool))); - layout->addStretch(); } diff --git a/src/gui/widgets/GroupBox.cpp b/src/gui/widgets/GroupBox.cpp index b5187de25..e3e71a812 100644 --- a/src/gui/widgets/GroupBox.cpp +++ b/src/gui/widgets/GroupBox.cpp @@ -72,13 +72,23 @@ void GroupBox::modelChanged() } +bool GroupBox::ledButtonShown() const +{ + return m_led->isVisible(); +} + + +void GroupBox::setLedButtonShown(bool value) +{ + m_led->setVisible(value); +} void GroupBox::mousePressEvent( QMouseEvent * _me ) { - if( _me->y() > 1 && _me->y() < 13 && _me->button() == Qt::LeftButton ) + if (ledButtonShown() && _me->y() > 1 && _me->y() < 13 && _me->button() == Qt::LeftButton) { - model()->setValue( !model()->value() ); + model()->setValue(!model()->value()); } } @@ -102,7 +112,9 @@ void GroupBox::paintEvent( QPaintEvent * pe ) // draw text p.setPen( palette().color( QPalette::Active, QPalette::Text ) ); p.setFont( pointSize<8>( font() ) ); - p.drawText( 22, m_titleBarHeight, m_caption ); + + int const captionX = ledButtonShown() ? 22 : 6; + p.drawText(captionX, m_titleBarHeight, m_caption); }