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; diff --git a/include/Knob.h b/include/Knob.h index 4f806473118..e2f78212b5f 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) @@ -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 { diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index 167c3ecf883..d7889594697 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 Knob::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 @@ -99,26 +86,86 @@ 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; } +} + + + + +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(); } +void convertPixmapToGrayScale(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_gray64; + pix_gray64 = QRgba64::fromRgba( gscale, gscale, gscale, quint8(pix.alpha()) ); + temp.setPixelColor(i, j, pix_gray64); + } + } + pixmap->convertFromImage(temp); +} + + + + +void Knob::resetPixmap() +{ + if( m_knobPixmap ) + { + delete m_knobPixmap; + } +} + + + + void Knob::onKnobNumUpdated() { if( m_knobNum != knobStyled ) @@ -143,8 +190,14 @@ 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() ) ); + if ( !this->isEnabled() ) + { + convertPixmapToGrayScale( m_knobPixmap ); + } + setFixedSize( m_knobPixmap->width(), m_knobPixmap->height() ); } } @@ -154,10 +207,7 @@ void Knob::onKnobNumUpdated() Knob::~Knob() { - if( m_knobPixmap ) - { - delete m_knobPixmap; - } + resetPixmap(); } @@ -440,14 +490,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 ) @@ -839,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(); +} +