From f15fe18360d2bba7eb07b03a8b00ab9a5188f2c1 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 16 Jul 2017 16:21:33 +0200 Subject: [PATCH] Expose the background color of the text labels in the style sheet Add a new property "textBackgroundColor" to TrackContentObjectView to expose the property to the style sheets. Use this property in the code that renders the text labels. Adjust the two existing style sheets. --- data/themes/classic/style.css | 1 + data/themes/default/style.css | 1 + include/Track.h | 4 ++++ src/core/Track.cpp | 13 +++++++++++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/data/themes/classic/style.css b/data/themes/classic/style.css index 888525a19..4b8132278 100644 --- a/data/themes/classic/style.css +++ b/data/themes/classic/style.css @@ -613,6 +613,7 @@ TrackContentObjectView { qproperty-selectedColor: rgb( 0, 125, 255 ); qproperty-BBPatternBackground: rgb( 80, 80, 80 ); qproperty-textColor: rgb( 255, 255, 255 ); + qproperty-textBackgroundColor: rgba(0, 0, 0, 75); qproperty-textShadowColor: rgb( 0, 0, 0 ); qproperty-gradient: true; /* boolean property, set true to have a gradient */ diff --git a/data/themes/default/style.css b/data/themes/default/style.css index b148034a8..109b1a68d 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -620,6 +620,7 @@ TrackContentObjectView { qproperty-selectedColor: #006B65; qproperty-BBPatternBackground: #373d48; qproperty-textColor: #fff; + qproperty-textBackgroundColor: rgba(0, 0, 0, 75); qproperty-textShadowColor: rgb(0,0,0,200); qproperty-gradient: false; /* boolean property, set true to have a gradient */ diff --git a/include/Track.h b/include/Track.h index b96575dcf..f0e00d544 100644 --- a/include/Track.h +++ b/include/Track.h @@ -196,6 +196,7 @@ class TrackContentObjectView : public selectableObject, public ModelView Q_PROPERTY( QColor mutedBackgroundColor READ mutedBackgroundColor WRITE setMutedBackgroundColor ) Q_PROPERTY( QColor selectedColor READ selectedColor WRITE setSelectedColor ) Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor ) + Q_PROPERTY( QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor ) Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor ) Q_PROPERTY( QColor BBPatternBackground READ BBPatternBackground WRITE setBBPatternBackground ) Q_PROPERTY( bool gradient READ gradient WRITE setGradient ) @@ -215,6 +216,7 @@ public: QColor mutedBackgroundColor() const; QColor selectedColor() const; QColor textColor() const; + QColor textBackgroundColor() const; QColor textShadowColor() const; QColor BBPatternBackground() const; bool gradient() const; @@ -222,6 +224,7 @@ public: void setMutedBackgroundColor( const QColor & c ); void setSelectedColor( const QColor & c ); void setTextColor( const QColor & c ); + void setTextBackgroundColor( const QColor & c ); void setTextShadowColor( const QColor & c ); void setBBPatternBackground( const QColor & c ); void setGradient( const bool & b ); @@ -299,6 +302,7 @@ private: QColor m_mutedBackgroundColor; QColor m_selectedColor; QColor m_textColor; + QColor m_textBackgroundColor; QColor m_textShadowColor; QColor m_BBPatternBackground; bool m_gradient; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index bc7e6f321..a46a83a8a 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -354,6 +354,11 @@ QColor TrackContentObjectView::selectedColor() const QColor TrackContentObjectView::textColor() const { return m_textColor; } +QColor TrackContentObjectView::textBackgroundColor() const +{ + return m_textBackgroundColor; +} + QColor TrackContentObjectView::textShadowColor() const { return m_textShadowColor; } @@ -376,6 +381,11 @@ void TrackContentObjectView::setSelectedColor( const QColor & c ) void TrackContentObjectView::setTextColor( const QColor & c ) { m_textColor = QColor( c ); } +void TrackContentObjectView::setTextBackgroundColor( const QColor & c ) +{ + m_textBackgroundColor = c; +} + void TrackContentObjectView::setTextShadowColor( const QColor & c ) { m_textShadowColor = QColor( c ); } @@ -646,8 +656,7 @@ void TrackContentObjectView::paintTextLabel(QString const & text, QPainter & pai QFontMetrics fontMetrics(labelFont); QString elidedPatternName = fontMetrics.elidedText(text, Qt::ElideMiddle, width() - 2 * textLeft); - QColor transparentBlack(0, 0, 0, 75); - painter.fillRect(QRect(0, 0, width(), fontMetrics.height() + 2 * textTop), transparentBlack); + painter.fillRect(QRect(0, 0, width(), fontMetrics.height() + 2 * textTop), textBackgroundColor()); painter.setPen( textColor() ); painter.drawText( textLeft, textTop + fontMetrics.ascent(), elidedPatternName );