From 310eb5bc5549998d445fa10088592334c78a3b4e Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Sat, 2 May 2020 15:09:57 +0200 Subject: [PATCH 1/8] Allow to set arcColor in style sheets. --- src/gui/widgets/Knob.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index 167c3ecf883..ae1c51e5394 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -99,15 +99,23 @@ void Knob::initUi( const QString & _name ) // drawKnob method uses the line color to draw the lines. By assigning the palette colors // as the line colors here the knob lines will be drawn in this color unless the stylesheet // overrides that color. + + QColor col; switch (knobNum()) { case knobSmall_17: case knobBright_26: case knobDark_28: setlineColor(QApplication::palette().color( QPalette::Active, QPalette::WindowText )); + col = QColor(QApplication::palette().color( QPalette::Active, QPalette::WindowText)); + col.setAlpha( 70 ); + setarcColor( col ); break; case knobVintage_32: setlineColor(QApplication::palette().color( QPalette::Active, QPalette::Shadow )); + col = QColor(QApplication::palette().color( QPalette::Active, QPalette::Shadow)); + col.setAlpha( 70 ); + setarcColor( col ); break; default: break; @@ -440,14 +448,9 @@ void Knob::drawKnob( QPainter * _p ) const int arcLineWidth = 2; const int arcRectSize = m_knobPixmap->width() - arcLineWidth; - QColor col; - if( m_knobNum == knobVintage_32 ) - { col = QApplication::palette().color( QPalette::Active, QPalette::Shadow ); } - else - { col = QApplication::palette().color( QPalette::Active, QPalette::WindowText ); } - col.setAlpha( 70 ); - p.setPen( QPen( col, 2 ) ); + + p.setPen( QPen( arcColor(), 2 ) ); p.drawArc( mid.x() - arcRectSize/2, 1, arcRectSize, arcRectSize, 315*16, 16*m_totalAngle ); switch( m_knobNum ) From 56f0c208eb7a2b6c679e0e7cec1b4a91f52e36f0 Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Sat, 2 May 2020 15:14:53 +0200 Subject: [PATCH 2/8] Move setting of lineColors to separate function. --- src/gui/widgets/Knob.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index ae1c51e5394..cb83ed31db2 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -77,21 +77,8 @@ Knob::Knob( QWidget * _parent, const QString & _name ) : -void Knob::initUi( const QString & _name ) +void initLineColors() { - if( s_textFloat == NULL ) - { - s_textFloat = new TextFloat; - } - - setWindowTitle( _name ); - - onKnobNumUpdated(); - setTotalAngle( 270.0f ); - setInnerRadius( 1.0f ); - setOuterRadius( 10.0f ); - setFocusPolicy( Qt::ClickFocus ); - // This is a workaround to enable style sheets for knobs which are not styled knobs. // // It works as follows: the palette colors that are assigned as the line color previously @@ -120,7 +107,27 @@ void Knob::initUi( const QString & _name ) default: break; } +} + + + + +void Knob::initUi( const QString & _name ) +{ + if( s_textFloat == NULL ) + { + s_textFloat = new TextFloat; + } + + setWindowTitle( _name ); + + onKnobNumUpdated(); + setTotalAngle( 270.0f ); + setInnerRadius( 1.0f ); + setOuterRadius( 10.0f ); + setFocusPolicy( Qt::ClickFocus ); + initLineColors(); doConnections(); } From e2f660dad87a6f9e450b0c3f2375881bfce9c7b0 Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Sat, 2 May 2020 15:16:28 +0200 Subject: [PATCH 3/8] Move deletion of pixmap for the center of a button to separate function. --- src/gui/widgets/Knob.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index cb83ed31db2..e4504c5dc03 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -167,7 +167,7 @@ void Knob::onKnobNumUpdated() -Knob::~Knob() +void Knob::resetPixMap() { if( m_knobPixmap ) { @@ -178,6 +178,14 @@ Knob::~Knob() +Knob::~Knob() +{ + resetPixMap(); +} + + + + void Knob::setLabel( const QString & txt ) { m_label = txt; From b9799405c67b3aec3375c220d0f591efbebd0038 Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Sat, 2 May 2020 17:53:36 +0200 Subject: [PATCH 4/8] Enable theming of disabled knobs. --- src/gui/widgets/Knob.cpp | 88 ++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 13 deletions(-) diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index e4504c5dc03..ca8a4c14a1b 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -77,7 +77,7 @@ Knob::Knob( QWidget * _parent, const QString & _name ) : -void initLineColors() +void Knob::initLineColors() { // This is a workaround to enable style sheets for knobs which are not styled knobs. // @@ -134,6 +134,38 @@ void Knob::initUi( const QString & _name ) +void convertPixmapToGreyScale(QPixmap* pixmap) +{ + QImage temp = pixmap->toImage().convertToFormat(QImage::Format_ARGB32); + for (int i = 0; i < temp.height(); ++i) + { + for (int j = 0; j < temp.width(); ++j) + { + QColor pix; + pix = temp.pixelColor(i, j); + quint8 gscale = quint8( (11*pix.red() + 16*pix.green() + 5*pix.blue()) / 32); + QRgba64 pix_grey64; + pix_grey64 = QRgba64::fromRgba( gscale, gscale, gscale, quint8(pix.alpha()) ); + temp.setPixelColor(i, j, pix_grey64); + } + } + pixmap->convertFromImage(temp); +} + + + + +void Knob::resetPixmap() +{ + if( m_knobPixmap ) + { + delete m_knobPixmap; + } +} + + + + void Knob::onKnobNumUpdated() { if( m_knobNum != knobStyled ) @@ -158,20 +190,15 @@ void Knob::onKnobNumUpdated() } // If knobFilename is still empty here we should get the fallback pixmap of size 1x1 + resetPixmap(); m_knobPixmap = new QPixmap( embed::getIconPixmap( knobFilename.toUtf8().constData() ) ); - setFixedSize( m_knobPixmap->width(), m_knobPixmap->height() ); - } -} - - - + if ( !this->isEnabled() ) + { + convertPixmapToGreyScale( m_knobPixmap ); + } -void Knob::resetPixMap() -{ - if( m_knobPixmap ) - { - delete m_knobPixmap; + setFixedSize( m_knobPixmap->width(), m_knobPixmap->height() ); } } @@ -180,7 +207,7 @@ void Knob::resetPixMap() Knob::~Knob() { - resetPixMap(); + resetPixmap(); } @@ -857,3 +884,38 @@ void Knob::doConnections() this, SLOT( update() ) ); } } + + + + +void Knob::changeEvent( QEvent * _ev ) +{ + if ( _ev->type() == QEvent::EnabledChange) + { + setEnabledTheme( this->isEnabled() ); + } +} + + + + +void Knob::setEnabledTheme( bool enabled ) +{ + this->setProperty( "enabled", enabled ); + if ( !enabled ) + { + this->setStyle( QApplication::style() ); + } + else + { + initLineColors(); + } + onKnobNumUpdated(); + if ( !m_label.isEmpty() ) + { + setLabel(m_label); + } + m_cache = QImage(); + update(); +} + From d4ab4ade1a00bca562f9fd3d114070688adcd56f Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Sat, 2 May 2020 19:00:53 +0200 Subject: [PATCH 5/8] Enable theming of disabled knobs. --- src/gui/widgets/Knob.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index ca8a4c14a1b..d7889594697 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -134,7 +134,7 @@ void Knob::initUi( const QString & _name ) -void convertPixmapToGreyScale(QPixmap* pixmap) +void convertPixmapToGrayScale(QPixmap* pixmap) { QImage temp = pixmap->toImage().convertToFormat(QImage::Format_ARGB32); for (int i = 0; i < temp.height(); ++i) @@ -144,9 +144,9 @@ void convertPixmapToGreyScale(QPixmap* pixmap) QColor pix; pix = temp.pixelColor(i, j); quint8 gscale = quint8( (11*pix.red() + 16*pix.green() + 5*pix.blue()) / 32); - QRgba64 pix_grey64; - pix_grey64 = QRgba64::fromRgba( gscale, gscale, gscale, quint8(pix.alpha()) ); - temp.setPixelColor(i, j, pix_grey64); + QRgba64 pix_gray64; + pix_gray64 = QRgba64::fromRgba( gscale, gscale, gscale, quint8(pix.alpha()) ); + temp.setPixelColor(i, j, pix_gray64); } } pixmap->convertFromImage(temp); @@ -195,7 +195,7 @@ void Knob::onKnobNumUpdated() if ( !this->isEnabled() ) { - convertPixmapToGreyScale( m_knobPixmap ); + convertPixmapToGrayScale( m_knobPixmap ); } setFixedSize( m_knobPixmap->width(), m_knobPixmap->height() ); From 175f7023a8cbf069ee595a6ec4ff62458809c5f6 Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Sat, 2 May 2020 17:54:03 +0200 Subject: [PATCH 6/8] Enable theming of disabled knobs. --- include/Knob.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/Knob.h b/include/Knob.h index 4f806473118..2e4599af9b6 100644 --- a/include/Knob.h +++ b/include/Knob.h @@ -47,6 +47,8 @@ class LMMS_EXPORT Knob : public QWidget, public FloatModelView Q_OBJECT Q_ENUMS( knobTypes ) + Q_PROPERTY(bool enabled READ isEnabled) + Q_PROPERTY(float innerRadius READ innerRadius WRITE setInnerRadius) Q_PROPERTY(float outerRadius READ outerRadius WRITE setOuterRadius) @@ -68,7 +70,7 @@ class LMMS_EXPORT Knob : public QWidget, public FloatModelView Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) void initUi( const QString & _name ); //!< to be called by ctors - void onKnobNumUpdated(); //!< to be called when you updated @a m_knobNum + void onKnobNumUpdated(); //!< to be called when you updated @a m_knobNum public: Knob( knobTypes _knob_num, QWidget * _parent = NULL, const QString & _name = QString() ); @@ -134,6 +136,7 @@ class LMMS_EXPORT Knob : public QWidget, public FloatModelView void mouseDoubleClickEvent( QMouseEvent * _me ) override; void paintEvent( QPaintEvent * _me ) override; void wheelEvent( QWheelEvent * _me ) override; + void changeEvent( QEvent * _ev) override; virtual float getValue( const QPoint & _p ); @@ -145,6 +148,7 @@ private slots: private: QString displayValue() const; + void initLineColors(); void doConnections() override; QLineF calculateLine( const QPointF & _mid, float _radius, @@ -153,6 +157,9 @@ private slots: void drawKnob( QPainter * _p ); void setPosition( const QPoint & _p ); bool updateAngle(); + void resetPixmap(); + + void setEnabledTheme(bool); int angleFromValue( float value, float minValue, float maxValue, float totalAngle ) const { From cc54af4f7432c925c48b97ce4e10e4bbd6e41cc0 Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Sat, 2 May 2020 18:22:50 +0200 Subject: [PATCH 7/8] Enable theming of disabled knobs. --- include/Knob.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Knob.h b/include/Knob.h index 2e4599af9b6..e2f78212b5f 100644 --- a/include/Knob.h +++ b/include/Knob.h @@ -70,7 +70,7 @@ class LMMS_EXPORT Knob : public QWidget, public FloatModelView Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) void initUi( const QString & _name ); //!< to be called by ctors - void onKnobNumUpdated(); //!< to be called when you updated @a m_knobNum + void onKnobNumUpdated(); //!< to be called when you updated @a m_knobNum public: Knob( knobTypes _knob_num, QWidget * _parent = NULL, const QString & _name = QString() ); From b751f35859ea2ab0770544a469f22e875fbd33b3 Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Sat, 2 May 2020 17:54:34 +0200 Subject: [PATCH 8/8] Add example for disabled knob theming. --- data/themes/default/style.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/data/themes/default/style.css b/data/themes/default/style.css index f95469201cd..d827335914b 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -40,6 +40,11 @@ QMdiArea { background-color: #111314; } +Knob[enabled=false] { + qproperty-lineColor: rgb(120, 120, 120); + qproperty-arcColor: rgba(120, 120, 120, 70); +} + AutomationEditor { color: #ffffff; background-color: #141616;