From 291d651fcd6fc8f1dada944855c1c19fdf7f3c4c Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Thu, 21 May 2020 21:34:20 +0200 Subject: [PATCH 1/8] Add example for theming of disabled knobs --- 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 feb85a612b0..fcf9d4361f4 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -40,6 +40,11 @@ QMdiArea { background-color: #111314; } +Knob { + qproperty-lineInactiveColor: rgb(120, 120, 120); + qproperty-arcInactiveColor: rgba(120, 120, 120, 70); +} + AutomationEditor { color: #ffffff; background-color: #141616; From 5c2c4f15c3afefe9cfc9cc28265031c5fc88d677 Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Thu, 21 May 2020 21:34:51 +0200 Subject: [PATCH 2/8] Add properties for theming of disabled knobs. Minor refactoring: Use smart pointer for knob picture --- include/Knob.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/include/Knob.h b/include/Knob.h index b129bc8d690..b9c3e338db7 100644 --- a/include/Knob.h +++ b/include/Knob.h @@ -26,6 +26,7 @@ #ifndef KNOB_H #define KNOB_H +#include #include #include @@ -41,6 +42,7 @@ enum knobTypes } ; +void convertPixmapToGrayScale(std::unique_ptr &pixMap); class LMMS_EXPORT Knob : public QWidget, public FloatModelView { @@ -60,6 +62,12 @@ class LMMS_EXPORT Knob : public QWidget, public FloatModelView Q_PROPERTY(QColor outerColor READ outerColor WRITE setOuterColor) Q_PROPERTY(QColor lineColor READ lineColor WRITE setlineColor) Q_PROPERTY(QColor arcColor READ arcColor WRITE setarcColor) + + Q_PROPERTY(QColor lineActiveColor MEMBER m_lineActiveColor) + Q_PROPERTY(QColor lineInactiveColor MEMBER m_lineInactiveColor) + Q_PROPERTY(QColor arcActiveColor MEMBER m_arcActiveColor) + Q_PROPERTY(QColor arcInactiveColor MEMBER m_arcInactiveColor) + mapPropertyFromModel(bool,isVolumeKnob,setVolumeKnob,m_volumeKnob); mapPropertyFromModel(float,volumeRatio,setVolumeRatio,m_volumeRatio); @@ -74,7 +82,7 @@ class LMMS_EXPORT Knob : public QWidget, public FloatModelView Knob( knobTypes _knob_num, QWidget * _parent = NULL, const QString & _name = QString() ); Knob( QWidget * _parent = NULL, const QString & _name = QString() ); //!< default ctor Knob( const Knob& other ) = delete; - virtual ~Knob(); + virtual ~Knob() {}; // TODO: remove inline void setHintText( const QString & _txt_before, @@ -134,6 +142,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 ); @@ -169,7 +178,7 @@ private slots: QString m_label; - QPixmap * m_knobPixmap; + std::unique_ptr m_knobPixmap; BoolModel m_volumeKnob; FloatModel m_volumeRatio; @@ -189,6 +198,11 @@ private slots: QColor m_outerColor; QColor m_lineColor; //!< unused yet QColor m_arcColor; //!< unused yet + + QColor m_lineActiveColor; + QColor m_lineInactiveColor; + QColor m_arcActiveColor; + QColor m_arcInactiveColor; QColor m_textColor; From ba1b2a628d034874eeb5550837db59e1f0906dc2 Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Thu, 21 May 2020 21:36:52 +0200 Subject: [PATCH 3/8] Theming of disabled knobs. Minor refactoring. --- src/gui/widgets/Knob.cpp | 83 ++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index 920c9765ddb..01496c1688b 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -22,6 +22,7 @@ * */ +#include #include #include #include @@ -57,7 +58,7 @@ Knob::Knob( knobTypes _knob_num, QWidget * _parent, const QString & _name ) : QWidget( _parent ), FloatModelView( new FloatModel( 0, 0, 0, 1, NULL, _name, true ), this ), m_label( "" ), - m_knobPixmap( NULL ), + m_knobPixmap( nullptr ), m_volumeKnob( false ), m_volumeRatio( 100.0, 0.0, 1000000.0 ), m_buttonPressed( false ), @@ -104,10 +105,16 @@ void Knob::initUi( const QString & _name ) case knobSmall_17: case knobBright_26: case knobDark_28: - setlineColor(QApplication::palette().color( QPalette::Active, QPalette::WindowText )); + m_lineActiveColor = QApplication::palette().color(QPalette::Active, QPalette::WindowText); + m_arcActiveColor = QColor(QApplication::palette().color( + QPalette::Active, QPalette::WindowText)); + m_arcActiveColor.setAlpha(70); break; case knobVintage_32: - setlineColor(QApplication::palette().color( QPalette::Active, QPalette::Shadow )); + m_lineActiveColor = QApplication::palette().color(QPalette::Active, QPalette::Shadow); + m_arcActiveColor = QColor(QApplication::palette().color( + QPalette::Active, QPalette::Shadow)); + m_arcActiveColor.setAlpha(70); break; default: break; @@ -143,8 +150,11 @@ void Knob::onKnobNumUpdated() } // If knobFilename is still empty here we should get the fallback pixmap of size 1x1 - m_knobPixmap = new QPixmap( embed::getIconPixmap( knobFilename.toUtf8().constData() ) ); - + m_knobPixmap.reset(new QPixmap(embed::getIconPixmap(knobFilename.toUtf8().constData()))); + if (!this->isEnabled()) + { + convertPixmapToGrayScale(m_knobPixmap); + } setFixedSize( m_knobPixmap->width(), m_knobPixmap->height() ); } } @@ -152,17 +162,6 @@ void Knob::onKnobNumUpdated() -Knob::~Knob() -{ - if( m_knobPixmap ) - { - delete m_knobPixmap; - } -} - - - - void Knob::setLabel( const QString & txt ) { m_label = txt; @@ -382,6 +381,10 @@ bool Knob::updateAngle() void Knob::drawKnob( QPainter * _p ) { + bool enabled = this->isEnabled(); + setarcColor(enabled ? m_arcActiveColor : m_arcInactiveColor); + setlineColor(enabled ? m_lineActiveColor : m_lineInactiveColor); + if( updateAngle() == false && !m_cache.isNull() ) { _p->drawImage( 0, 0, m_cache ); @@ -440,33 +443,24 @@ 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 ); + p.setPen(QPen(lineColor(), 2)); switch( m_knobNum ) { case knobSmall_17: { - p.setPen( QPen( lineColor(), 2 ) ); p.drawLine( calculateLine( mid, radius-2 ) ); break; } case knobBright_26: { - p.setPen( QPen( lineColor(), 2 ) ); p.drawLine( calculateLine( mid, radius-5 ) ); break; } case knobDark_28: { - p.setPen( QPen( lineColor(), 2 ) ); const float rb = qMax( ( radius - 10 ) / 3.0, 0.0 ); const float re = qMax( ( radius - 4 ), 0.0 ); @@ -477,7 +471,6 @@ void Knob::drawKnob( QPainter * _p ) } case knobVintage_32: { - p.setPen( QPen( lineColor(), 2 ) ); p.drawLine( calculateLine( mid, radius-2, 2 ) ); break; } @@ -839,3 +832,37 @@ void Knob::doConnections() this, SLOT( update() ) ); } } + + +void Knob::changeEvent(QEvent * ev) +{ + if (ev->type() == QEvent::EnabledChange) + { + onKnobNumUpdated(); + if (!m_label.isEmpty()) + { + setLabel(m_label); + } + m_cache = QImage(); + update(); + } +} + + +void convertPixmapToGrayScale(std::unique_ptr &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((0.2126*pix.red() + 0.7152*pix.green() + 0.0722*pix.blue())); + QRgba64 pix_gray64; + pix_gray64 = QRgba64::fromRgba(gscale, gscale, gscale, quint8(pix.alpha())); + temp.setPixelColor(i, j, pix_gray64); + } + } + pixMap->convertFromImage(temp); +} From 36742fb7225caa2d423210a442b5f31dcbd579ea Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Sun, 16 Aug 2020 20:20:58 +0200 Subject: [PATCH 4/8] Update include/Knob.h Co-authored-by: Hyunjin Song --- include/Knob.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Knob.h b/include/Knob.h index b9c3e338db7..9bfa73fd621 100644 --- a/include/Knob.h +++ b/include/Knob.h @@ -82,7 +82,7 @@ class LMMS_EXPORT Knob : public QWidget, public FloatModelView Knob( knobTypes _knob_num, QWidget * _parent = NULL, const QString & _name = QString() ); Knob( QWidget * _parent = NULL, const QString & _name = QString() ); //!< default ctor Knob( const Knob& other ) = delete; - virtual ~Knob() {}; + virtual ~Knob() = default; // TODO: remove inline void setHintText( const QString & _txt_before, From 57c32c23b2cf6621dc6c68808ddbde763fa73bc7 Mon Sep 17 00:00:00 2001 From: Thomas Mueller <64359888+thmueller64@users.noreply.github.com> Date: Mon, 17 Aug 2020 00:21:35 +0200 Subject: [PATCH 5/8] Add properties for disabled knobs. --- data/themes/classic/style.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/data/themes/classic/style.css b/data/themes/classic/style.css index cf609066a81..3aa3d6674d2 100644 --- a/data/themes/classic/style.css +++ b/data/themes/classic/style.css @@ -11,6 +11,11 @@ QMdiArea { background-image: url(resources:background_artwork.png); } +Knob { + qproperty-lineInactiveColor: rgb(120, 120, 120); + qproperty-arcInactiveColor: rgba(120, 120, 120, 70); +} + AutomationEditor { background-color: rgb(0, 0, 0); color: #e0e0e0; From 5c5c4942854be41e73b1326802da70a44c21aa61 Mon Sep 17 00:00:00 2001 From: thmueller64 <64359888+thmueller64@users.noreply.github.com> Date: Mon, 17 Aug 2020 20:07:59 +0200 Subject: [PATCH 6/8] Update src/gui/widgets/Knob.cpp Co-authored-by: Dominic Clark --- src/gui/widgets/Knob.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index 01496c1688b..6b657a9a2ff 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -856,12 +856,10 @@ void convertPixmapToGrayScale(std::unique_ptr &pixMap) { for (int j = 0; j < temp.width(); ++j) { - QColor pix; - pix = temp.pixelColor(i, j); - quint8 gscale = quint8((0.2126*pix.red() + 0.7152*pix.green() + 0.0722*pix.blue())); - QRgba64 pix_gray64; - pix_gray64 = QRgba64::fromRgba(gscale, gscale, gscale, quint8(pix.alpha())); - temp.setPixelColor(i, j, pix_gray64); + const auto pix = temp.pixelColor(i, j); + const auto gscale = 0.2126 * pix.redF() + 0.7152 * pix.greenF() + 0.0722 * pix.blueF(); + const auto pixGray = QColor::fromRgbF(gscale, gscale, gscale, pix.alphaF()); + temp.setPixelColor(i, j, pixGray); } } pixMap->convertFromImage(temp); From 232ecf3939074363817f63f404ff062b703424ee Mon Sep 17 00:00:00 2001 From: Thomas Mueller <64359888+thmueller64@users.noreply.github.com> Date: Mon, 17 Aug 2020 20:57:51 +0200 Subject: [PATCH 7/8] Changes suggested by review. --- include/Knob.h | 3 +-- src/gui/widgets/Knob.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/Knob.h b/include/Knob.h index 9bfa73fd621..3d27cd7dd8e 100644 --- a/include/Knob.h +++ b/include/Knob.h @@ -42,7 +42,7 @@ enum knobTypes } ; -void convertPixmapToGrayScale(std::unique_ptr &pixMap); +void convertPixmapToGrayScale(QPixmap &pixMap); class LMMS_EXPORT Knob : public QWidget, public FloatModelView { @@ -82,7 +82,6 @@ class LMMS_EXPORT Knob : public QWidget, public FloatModelView Knob( knobTypes _knob_num, QWidget * _parent = NULL, const QString & _name = QString() ); Knob( QWidget * _parent = NULL, const QString & _name = QString() ); //!< default ctor Knob( const Knob& other ) = delete; - virtual ~Knob() = default; // TODO: remove inline void setHintText( const QString & _txt_before, diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index 6b657a9a2ff..85381ad2bfd 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #ifndef __USE_XOPEN #define __USE_XOPEN @@ -46,6 +47,7 @@ #include "MainWindow.h" #include "ProjectJournal.h" #include "Song.h" +#include "stdshims.h" #include "StringPairDrag.h" #include "TextFloat.h" @@ -58,7 +60,6 @@ Knob::Knob( knobTypes _knob_num, QWidget * _parent, const QString & _name ) : QWidget( _parent ), FloatModelView( new FloatModel( 0, 0, 0, 1, NULL, _name, true ), this ), m_label( "" ), - m_knobPixmap( nullptr ), m_volumeKnob( false ), m_volumeRatio( 100.0, 0.0, 1000000.0 ), m_buttonPressed( false ), @@ -150,10 +151,10 @@ void Knob::onKnobNumUpdated() } // If knobFilename is still empty here we should get the fallback pixmap of size 1x1 - m_knobPixmap.reset(new QPixmap(embed::getIconPixmap(knobFilename.toUtf8().constData()))); + m_knobPixmap = make_unique(QPixmap(embed::getIconPixmap(knobFilename.toUtf8().constData()))); if (!this->isEnabled()) { - convertPixmapToGrayScale(m_knobPixmap); + convertPixmapToGrayScale(*m_knobPixmap.get()); } setFixedSize( m_knobPixmap->width(), m_knobPixmap->height() ); } @@ -849,9 +850,9 @@ void Knob::changeEvent(QEvent * ev) } -void convertPixmapToGrayScale(std::unique_ptr &pixMap) +void convertPixmapToGrayScale(QPixmap& pixMap) { - QImage temp = pixMap->toImage().convertToFormat(QImage::Format_ARGB32); + QImage temp = pixMap.toImage().convertToFormat(QImage::Format_ARGB32); for (int i = 0; i < temp.height(); ++i) { for (int j = 0; j < temp.width(); ++j) @@ -862,5 +863,5 @@ void convertPixmapToGrayScale(std::unique_ptr &pixMap) temp.setPixelColor(i, j, pixGray); } } - pixMap->convertFromImage(temp); + pixMap.convertFromImage(temp); } From ba39988d3a7d424fb414c3dd4d672f4444a786dc Mon Sep 17 00:00:00 2001 From: Thomas Mueller <64359888+thmueller64@users.noreply.github.com> Date: Tue, 25 Aug 2020 19:41:57 +0200 Subject: [PATCH 8/8] Remove getters and setters for arc and line colors. Include QPixmap. --- include/Knob.h | 9 +-------- src/gui/widgets/Knob.cpp | 38 ++++---------------------------------- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/include/Knob.h b/include/Knob.h index 3d27cd7dd8e..3c730e3dd60 100644 --- a/include/Knob.h +++ b/include/Knob.h @@ -27,6 +27,7 @@ #define KNOB_H #include +#include #include #include @@ -60,8 +61,6 @@ class LMMS_EXPORT Knob : public QWidget, public FloatModelView // Unfortunately, the gradient syntax doesn't create our gradient // correctly so we need to do this: Q_PROPERTY(QColor outerColor READ outerColor WRITE setOuterColor) - Q_PROPERTY(QColor lineColor READ lineColor WRITE setlineColor) - Q_PROPERTY(QColor arcColor READ arcColor WRITE setarcColor) Q_PROPERTY(QColor lineActiveColor MEMBER m_lineActiveColor) Q_PROPERTY(QColor lineInactiveColor MEMBER m_lineInactiveColor) @@ -115,10 +114,6 @@ class LMMS_EXPORT Knob : public QWidget, public FloatModelView QColor outerColor() const; void setOuterColor( const QColor & c ); - QColor lineColor() const; - void setlineColor( const QColor & c ); - QColor arcColor() const; - void setarcColor( const QColor & c ); QColor textColor() const; void setTextColor( const QColor & c ); @@ -195,8 +190,6 @@ private slots: float m_outerRadius; float m_lineWidth; QColor m_outerColor; - QColor m_lineColor; //!< unused yet - QColor m_arcColor; //!< unused yet QColor m_lineActiveColor; QColor m_lineInactiveColor; diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index 85381ad2bfd..60b671556a2 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #ifndef __USE_XOPEN #define __USE_XOPEN @@ -307,35 +306,6 @@ void Knob::setOuterColor( const QColor & c ) -QColor Knob::lineColor() const -{ - return m_lineColor; -} - - - -void Knob::setlineColor( const QColor & c ) -{ - m_lineColor = c; -} - - - -QColor Knob::arcColor() const -{ - return m_arcColor; -} - - - -void Knob::setarcColor( const QColor & c ) -{ - m_arcColor = c; -} - - - - QColor Knob::textColor() const { return m_textColor; @@ -383,8 +353,8 @@ bool Knob::updateAngle() void Knob::drawKnob( QPainter * _p ) { bool enabled = this->isEnabled(); - setarcColor(enabled ? m_arcActiveColor : m_arcInactiveColor); - setlineColor(enabled ? m_lineActiveColor : m_lineInactiveColor); + QColor currentArcColor = enabled ? m_arcActiveColor : m_arcInactiveColor; + QColor currentLineColor = enabled ? m_lineActiveColor : m_lineInactiveColor; if( updateAngle() == false && !m_cache.isNull() ) { @@ -444,10 +414,10 @@ void Knob::drawKnob( QPainter * _p ) const int arcLineWidth = 2; const int arcRectSize = m_knobPixmap->width() - arcLineWidth; - p.setPen(QPen(arcColor(), 2)); + p.setPen(QPen(currentArcColor, 2)); p.drawArc( mid.x() - arcRectSize/2, 1, arcRectSize, arcRectSize, 315*16, 16*m_totalAngle ); - p.setPen(QPen(lineColor(), 2)); + p.setPen(QPen(currentLineColor, 2)); switch( m_knobNum ) { case knobSmall_17: