diff --git a/include/LedCheckBox.h b/include/LedCheckBox.h index 95016b87f..ba1b196fa 100644 --- a/include/LedCheckBox.h +++ b/include/LedCheckBox.h @@ -48,10 +48,12 @@ public: LedCheckBox( const QString & _txt, QWidget * _parent, const QString & _name = QString(), - LedColors _color = Yellow ); + LedColors _color = Yellow, + bool legacyMode = true); LedCheckBox( QWidget * _parent, const QString & _name = QString(), - LedColors _color = Yellow ); + LedColors _color = Yellow, + bool legacyMode = true); ~LedCheckBox() override; @@ -75,8 +77,12 @@ private: QString m_text; + bool m_legacyMode; + void initUi( LedColors _color ); //!< to be called by ctors void onTextUpdated(); //!< to be called when you updated @a m_text + void paintLegacy(QPaintEvent * p); + void paintNonLegacy(QPaintEvent * p); } ; diff --git a/plugins/LadspaEffect/LadspaMatrixControlDialog.cpp b/plugins/LadspaEffect/LadspaMatrixControlDialog.cpp index e492638ba..d3015634a 100644 --- a/plugins/LadspaEffect/LadspaMatrixControlDialog.cpp +++ b/plugins/LadspaEffect/LadspaMatrixControlDialog.cpp @@ -67,7 +67,7 @@ LadspaMatrixControlDialog::LadspaMatrixControlDialog(LadspaControls * ladspaCont { mainLayout->addSpacing(3); - m_stereoLink = new LedCheckBox(tr("Link Channels"), this); + m_stereoLink = new LedCheckBox(tr("Link Channels"), this, QString(), LedCheckBox::Yellow, false); m_stereoLink->setModel(&ladspaControls->m_stereoLinkModel); mainLayout->addWidget(m_stereoLink, 0, Qt::AlignCenter); } diff --git a/plugins/LadspaEffect/LadspaWidgetFactory.cpp b/plugins/LadspaEffect/LadspaWidgetFactory.cpp index 8f09a333f..22785fa19 100644 --- a/plugins/LadspaEffect/LadspaWidgetFactory.cpp +++ b/plugins/LadspaEffect/LadspaWidgetFactory.cpp @@ -55,7 +55,7 @@ QWidget * LadspaWidgetFactory::createWidget(LadspaControl * ladspaControl, QWidg case TOGGLED: { LedCheckBox * toggle = new LedCheckBox( - name, parent, QString(), LedCheckBox::Green); + name, parent, QString(), LedCheckBox::Green, false); toggle->setModel(ladspaControl->toggledModel()); return toggle; } diff --git a/src/gui/widgets/LedCheckBox.cpp b/src/gui/widgets/LedCheckBox.cpp index 1be072815..f607171f4 100644 --- a/src/gui/widgets/LedCheckBox.cpp +++ b/src/gui/widgets/LedCheckBox.cpp @@ -44,9 +44,10 @@ static const auto names = std::array LedCheckBox::LedCheckBox( const QString & _text, QWidget * _parent, - const QString & _name, LedColors _color ) : + const QString & _name, LedColors _color, bool legacyMode ) : AutomatableButton( _parent, _name ), - m_text( _text ) + m_text( _text ), + m_legacyMode(legacyMode) { initUi( _color ); } @@ -55,8 +56,8 @@ LedCheckBox::LedCheckBox( const QString & _text, QWidget * _parent, LedCheckBox::LedCheckBox( QWidget * _parent, - const QString & _name, LedColors _color ) : - LedCheckBox( QString(), _parent, _name, _color ) + const QString & _name, LedColors _color, bool legacyMode ) : + LedCheckBox( QString(), _parent, _name, _color, legacyMode ) { } @@ -80,24 +81,16 @@ void LedCheckBox::setText( const QString &s ) -void LedCheckBox::paintEvent( QPaintEvent * ) +void LedCheckBox::paintEvent( QPaintEvent * pe ) { - QPainter p( this ); - p.setFont( pointSize<7>( font() ) ); - - if( model()->value() == true ) - { - p.drawPixmap( 0, 0, *m_ledOnPixmap ); + if (!m_legacyMode) + { + paintNonLegacy(pe); } else { - p.drawPixmap( 0, 0, *m_ledOffPixmap ); + paintLegacy(pe); } - - p.setPen( QColor( 64, 64, 64 ) ); - p.drawText( m_ledOffPixmap->width() + 4, 11, text() ); - p.setPen( QColor( 255, 255, 255 ) ); - p.drawText( m_ledOffPixmap->width() + 3, 10, text() ); } @@ -115,7 +108,11 @@ void LedCheckBox::initUi( LedColors _color ) names[_color].toUtf8().constData() ) ); m_ledOffPixmap = new QPixmap( embed::getIconPixmap( "led_off" ) ); - setFont( pointSize<7>( font() ) ); + if (m_legacyMode) + { + setFont( pointSize<7>( font() ) ); + } + setText( m_text ); } @@ -124,9 +121,54 @@ void LedCheckBox::initUi( LedColors _color ) void LedCheckBox::onTextUpdated() { - setFixedSize(m_ledOffPixmap->width() + 5 + horizontalAdvance(QFontMetrics(font()), - text()), - m_ledOffPixmap->height()); + if (m_legacyMode) + { + setFixedSize(m_ledOffPixmap->width() + 5 + horizontalAdvance(QFontMetrics(font()), + text()), + m_ledOffPixmap->height()); + } + else + { + QFontMetrics fm(font()); + + int const width = m_ledOffPixmap->width() + 5 + fm.horizontalAdvance(text()); + int const height = qMax(m_ledOffPixmap->height(), fm.height()); + + setFixedSize(width, height); + } +} + +void LedCheckBox::paintLegacy(QPaintEvent * pe) +{ + QPainter p( this ); + p.setFont( pointSize<7>( font() ) ); + + if( model()->value() == true ) + { + p.drawPixmap( 0, 0, *m_ledOnPixmap ); + } + else + { + p.drawPixmap( 0, 0, *m_ledOffPixmap ); + } + + p.setPen( QColor( 64, 64, 64 ) ); + p.drawText( m_ledOffPixmap->width() + 4, 11, text() ); + p.setPen( QColor( 255, 255, 255 ) ); + p.drawText( m_ledOffPixmap->width() + 3, 10, text() ); +} + +void LedCheckBox::paintNonLegacy(QPaintEvent * pe) +{ + QPainter p(this); + + QPixmap * drawnPixmap = model()->value() ? m_ledOnPixmap : m_ledOffPixmap; + + p.drawPixmap( 0, rect().height() / 2 - drawnPixmap->height() / 2, *drawnPixmap); + + QRect r = rect(); + r -= QMargins(m_ledOffPixmap->width() + 5, 0, 0, 0); + p.drawText(r, text()); }