Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions include/Knob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 );

Expand All @@ -145,6 +148,7 @@ private slots:
private:
QString displayValue() const;

void initLineColors();
void doConnections() override;

QLineF calculateLine( const QPointF & _mid, float _radius,
Expand All @@ -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
{
Expand Down
130 changes: 105 additions & 25 deletions src/gui/widgets/Knob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,48 +77,95 @@ 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
// had been hard coded in the drawKnob method for the different knob types. Now the
// 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 )
Expand All @@ -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() );
}
}
Expand All @@ -154,10 +207,7 @@ void Knob::onKnobNumUpdated()

Knob::~Knob()
{
if( m_knobPixmap )
{
delete m_knobPixmap;
}
resetPixmap();
}


Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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();
}