Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hard-coding of knob and LCDWidget text color #2716

Merged
merged 1 commit into from
Apr 9, 2016
Merged
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
29 changes: 18 additions & 11 deletions include/Knob.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class EXPORT Knob : public QWidget, public FloatModelView
mapPropertyFromModel(float,volumeRatio,setVolumeRatio,m_volumeRatio);

Q_PROPERTY(knobTypes knobNum READ knobNum WRITE setknobNum)

Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not color? Or is it reserved for something else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/LMMS/lmms/blob/master/data/themes/default/style.css#L582

It seems to be reserved for the knob color. Also, it'd be inconsistent with the rest of the codebase.


void initUi( const QString & _name ); //!< to be called by ctors
void onKnobNumUpdated(); //!< to be called when you updated @a m_knobNum
Expand All @@ -81,35 +83,38 @@ class EXPORT Knob : public QWidget, public FloatModelView
setDescription( _txt_before );
setUnit( _txt_after );
}
void setLabel( const QString & _txt );
void setLabel( const QString & txt );

void setTotalAngle( float _angle );
void setTotalAngle( float angle );

// Begin styled knob accessors
float innerRadius() const;
void setInnerRadius( float _r );
void setInnerRadius( float r );

float outerRadius() const;
void setOuterRadius( float _r );
void setOuterRadius( float r );

knobTypes knobNum() const;
void setknobNum( knobTypes _k );
void setknobNum( knobTypes k );

QPointF centerPoint() const;
float centerPointX() const;
void setCenterPointX( float _c );
void setCenterPointX( float c );
float centerPointY() const;
void setCenterPointY( float _c );
void setCenterPointY( float c );

float lineWidth() const;
void setLineWidth( float _w );
void setLineWidth( float w );

QColor outerColor() const;
void setOuterColor( const QColor & _c );
void setOuterColor( const QColor & c );
QColor lineColor() const;
void setlineColor( const QColor & _c );
void setlineColor( const QColor & c );
QColor arcColor() const;
void setarcColor( const QColor & _c );
void setarcColor( const QColor & c );

QColor textColor() const;
void setTextColor( const QColor & c );


signals:
Expand Down Expand Up @@ -186,6 +191,8 @@ private slots:
QColor m_outerColor;
QColor m_lineColor; //!< unused yet
QColor m_arcColor; //!< unused yet

QColor m_textColor;

knobTypes m_knobNum;

Expand Down
18 changes: 16 additions & 2 deletions include/LcdWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
class EXPORT LcdWidget : public QWidget
{
Q_OBJECT

// theming qproperties
Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor )
Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )

public:
LcdWidget( QWidget* parent, const QString& name = QString::null );
LcdWidget( int numDigits, QWidget* parent, const QString& name = QString::null );
Expand All @@ -54,13 +59,19 @@ class EXPORT LcdWidget : public QWidget

inline int numDigits() const { return m_numDigits; }
inline void setNumDigits( int n ) { m_numDigits = n; updateSize(); }

QColor textColor() const;
void setTextColor( const QColor & c );

QColor textShadowColor() const;
void setTextShadowColor( const QColor & c );

public slots:
virtual void setMarginWidth( int _width );
virtual void setMarginWidth( int width );


protected:
virtual void paintEvent( QPaintEvent * _me );
virtual void paintEvent( QPaintEvent * pe );

virtual void updateSize();

Expand All @@ -81,6 +92,9 @@ public slots:
QString m_label;
QPixmap* m_lcdPixmap;

QColor m_textColor;
QColor m_textShadowColor;

int m_cellWidth;
int m_cellHeight;
int m_numDigits;
Expand Down
67 changes: 41 additions & 26 deletions src/gui/widgets/Knob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ TextFloat * Knob::s_textFloat = NULL;
m_volumeRatio( 100.0, 0.0, 1000000.0 ), \
m_buttonPressed( false ), \
m_angle( -10 ), \
m_lineWidth(0)
m_lineWidth( 0 ), \
m_textColor( 255, 255, 255 )

Knob::Knob( knobTypes _knob_num, QWidget * _parent, const QString & _name ) :
DEFAULT_KNOB_INITIALIZER_LIST,
Expand Down Expand Up @@ -173,9 +174,9 @@ Knob::~Knob()



void Knob::setLabel( const QString & _txt )
void Knob::setLabel( const QString & txt )
{
m_label = _txt;
m_label = txt;
if( m_knobPixmap )
{
setFixedSize( qMax<int>( m_knobPixmap->width(),
Expand All @@ -188,15 +189,15 @@ void Knob::setLabel( const QString & _txt )



void Knob::setTotalAngle( float _angle )
void Knob::setTotalAngle( float angle )
{
if( _angle < 10.0 )
if( angle < 10.0 )
{
m_totalAngle = 10.0;
}
else
{
m_totalAngle = _angle;
m_totalAngle = angle;
}

update();
Expand All @@ -212,9 +213,9 @@ float Knob::innerRadius() const



void Knob::setInnerRadius( float _r )
void Knob::setInnerRadius( float r )
{
m_innerRadius = _r;
m_innerRadius = r;
}


Expand All @@ -226,9 +227,9 @@ float Knob::outerRadius() const



void Knob::setOuterRadius( float _r )
void Knob::setOuterRadius( float r )
{
m_outerRadius = _r;
m_outerRadius = r;
}


Expand All @@ -242,11 +243,11 @@ knobTypes Knob::knobNum() const



void Knob::setknobNum( knobTypes _k )
void Knob::setknobNum( knobTypes k )
{
if( m_knobNum != _k )
if( m_knobNum != k )
{
m_knobNum = _k;
m_knobNum = k;
onKnobNumUpdated();
}
}
Expand All @@ -268,9 +269,9 @@ float Knob::centerPointX() const



void Knob::setCenterPointX( float _c )
void Knob::setCenterPointX( float c )
{
m_centerPoint.setX( _c );
m_centerPoint.setX( c );
}


Expand All @@ -282,9 +283,9 @@ float Knob::centerPointY() const



void Knob::setCenterPointY( float _c )
void Knob::setCenterPointY( float c )
{
m_centerPoint.setY( _c );
m_centerPoint.setY( c );
}


Expand All @@ -296,9 +297,9 @@ float Knob::lineWidth() const



void Knob::setLineWidth( float _w )
void Knob::setLineWidth( float w )
{
m_lineWidth = _w;
m_lineWidth = w;
}


Expand All @@ -310,9 +311,9 @@ QColor Knob::outerColor() const



void Knob::setOuterColor( const QColor & _c )
void Knob::setOuterColor( const QColor & c )
{
m_outerColor = _c;
m_outerColor = c;
}


Expand All @@ -324,9 +325,9 @@ QColor Knob::lineColor() const



void Knob::setlineColor( const QColor & _c )
void Knob::setlineColor( const QColor & c )
{
m_lineColor = _c;
m_lineColor = c;
}


Expand All @@ -338,14 +339,28 @@ QColor Knob::arcColor() const



void Knob::setarcColor( const QColor & _c )
void Knob::setarcColor( const QColor & c )
{
m_arcColor = _c;
m_arcColor = c;
}




QColor Knob::textColor() const
{
return m_textColor;
}



void Knob::setTextColor( const QColor & c )
{
m_textColor = c;
}



QLineF Knob::calculateLine( const QPointF & _mid, float _radius, float _innerRadius ) const
{
const float rarc = m_angle * F_PI / 180.0;
Expand Down Expand Up @@ -680,7 +695,7 @@ void Knob::paintEvent( QPaintEvent * _me )
p.drawText( width() / 2 -
p.fontMetrics().width( m_label ) / 2 + 1,
height() - 1, m_label );*/
p.setPen( QColor( 255, 255, 255 ) );
p.setPen( textColor() );
p.drawText( width() / 2 -
p.fontMetrics().width( m_label ) / 2,
height() - 2, m_label );
Expand Down
42 changes: 35 additions & 7 deletions src/gui/widgets/LcdWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
//! @todo: in C++11, we can use delegating ctors
#define DEFAULT_LCDWIDGET_INITIALIZER_LIST \
QWidget( parent ), \
m_label()
m_label(), \
m_textColor( 255, 255, 255 ), \
m_textShadowColor( 64, 64, 64 )

LcdWidget::LcdWidget( QWidget* parent, const QString& name ) :
DEFAULT_LCDWIDGET_INITIALIZER_LIST,
Expand Down Expand Up @@ -109,6 +111,32 @@ void LcdWidget::setValue( int value )



QColor LcdWidget::textColor() const
{
return m_textColor;
}

void LcdWidget::setTextColor( const QColor & c )
{
m_textColor = c;
}




QColor LcdWidget::textShadowColor() const
{
return m_textShadowColor;
}

void LcdWidget::setTextShadowColor( const QColor & c )
{
m_textShadowColor = c;
}




void LcdWidget::paintEvent( QPaintEvent* )
{
QPainter p( this );
Expand Down Expand Up @@ -182,11 +210,11 @@ void LcdWidget::paintEvent( QPaintEvent* )
if( !m_label.isEmpty() )
{
p.setFont( pointSizeF( p.font(), 6.5 ) );
p.setPen( QColor( 64, 64, 64 ) );
p.setPen( textShadowColor() );
p.drawText( width() / 2 -
p.fontMetrics().width( m_label ) / 2 + 1,
height(), m_label );
p.setPen( QColor( 255, 255, 255 ) );
p.setPen( textColor() );
p.drawText( width() / 2 -
p.fontMetrics().width( m_label ) / 2,
height() - 1, m_label );
Expand All @@ -197,18 +225,18 @@ void LcdWidget::paintEvent( QPaintEvent* )



void LcdWidget::setLabel( const QString & _txt )
void LcdWidget::setLabel( const QString& label )
{
m_label = _txt;
m_label = label;
updateSize();
}




void LcdWidget::setMarginWidth( int _width )
void LcdWidget::setMarginWidth( int width )
{
m_marginWidth = _width;
m_marginWidth = width;

updateSize();
}
Expand Down