From 8ad5232cc1d3dfbfeaaf5495872641d0fbac23f3 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 16 Jul 2017 16:10:42 +0200 Subject: [PATCH 1/4] Make text rendering consistent for TrackContentObjectViews Add the method paintTextLabel to TrackContentObjectView. This methods implements the painting of a given text on a given painter. The new implementation does not draw any text label in case the trimmed text becomes empty. Use the method paintTextLabel to paint the text for automation patterns, BB patterns and instrument patterns. Adjust the style sheet of the classic and default theme by moving the font definition from PatternView into TrackContentObjectView so that it can be used by all inheriting classes. --- data/themes/classic/style.css | 3 ++- data/themes/default/style.css | 3 ++- include/Track.h | 2 ++ src/core/Track.cpp | 26 ++++++++++++++++++++++++++ src/gui/AutomationPatternView.cpp | 20 +------------------- src/tracks/BBTrack.cpp | 20 +------------------- src/tracks/Pattern.cpp | 23 +---------------------- 7 files changed, 35 insertions(+), 62 deletions(-) diff --git a/data/themes/classic/style.css b/data/themes/classic/style.css index 11a5e440ef9..888525a1953 100644 --- a/data/themes/classic/style.css +++ b/data/themes/classic/style.css @@ -615,13 +615,14 @@ TrackContentObjectView { qproperty-textColor: rgb( 255, 255, 255 ); qproperty-textShadowColor: rgb( 0, 0, 0 ); qproperty-gradient: true; /* boolean property, set true to have a gradient */ + + font-size: 11px; } /* instrument pattern */ PatternView { background-color: rgb( 119, 199, 216 ); color: rgb( 187, 227, 236 ); - font-size: 11px; } /* sample track pattern */ diff --git a/data/themes/default/style.css b/data/themes/default/style.css index 7680b7aae82..b148034a84b 100644 --- a/data/themes/default/style.css +++ b/data/themes/default/style.css @@ -622,13 +622,14 @@ TrackContentObjectView { qproperty-textColor: #fff; qproperty-textShadowColor: rgb(0,0,0,200); qproperty-gradient: false; /* boolean property, set true to have a gradient */ + + font-size: 11px; } /* instrument pattern */ PatternView { background-color: #21A14F; color: rgba(255,255,255,220); - font-size: 11px; } /* sample track pattern */ diff --git a/include/Track.h b/include/Track.h index dcb1648e0f5..b96575dcf6d 100644 --- a/include/Track.h +++ b/include/Track.h @@ -263,6 +263,8 @@ public slots: DataFile createTCODataFiles(const QVector & tcos) const; + virtual void paintTextLabel(QString const & text, QPainter & painter); + protected slots: void updateLength(); diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 7795b205c56..bc7e6f321b2 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -627,6 +627,32 @@ DataFile TrackContentObjectView::createTCODataFiles( return dataFile; } +void TrackContentObjectView::paintTextLabel(QString const & text, QPainter & painter) +{ + if (text.trimmed() == "") + { + return; + } + + painter.setRenderHint( QPainter::TextAntialiasing ); + + QFont labelFont = this->font(); + labelFont.setHintingPreference( QFont::PreferFullHinting ); + painter.setFont( labelFont ); + + const int textTop = TCO_BORDER_WIDTH + 1; + const int textLeft = TCO_BORDER_WIDTH + 3; + + 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.setPen( textColor() ); + painter.drawText( textLeft, textTop + fontMetrics.ascent(), elidedPatternName ); +} + /*! \brief Handle a mouse press on this trackContentObjectView. * * Handles the various ways in which a trackContentObjectView can be diff --git a/src/gui/AutomationPatternView.cpp b/src/gui/AutomationPatternView.cpp index 465ac69e347..78b697ca4a1 100644 --- a/src/gui/AutomationPatternView.cpp +++ b/src/gui/AutomationPatternView.cpp @@ -369,25 +369,7 @@ void AutomationPatternView::paintEvent( QPaintEvent * ) } // pattern name - p.setRenderHint( QPainter::TextAntialiasing ); - - if( m_staticTextName.text() != m_pat->name() ) - { - m_staticTextName.setText( m_pat->name() ); - } - - QFont font; - font.setHintingPreference( QFont::PreferFullHinting ); - font.setPointSize( 8 ); - p.setFont( font ); - - const int textTop = TCO_BORDER_WIDTH + 1; - const int textLeft = TCO_BORDER_WIDTH + 1; - - p.setPen( textShadowColor() ); - p.drawStaticText( textLeft + 1, textTop + 1, m_staticTextName ); - p.setPen( textColor() ); - p.drawStaticText( textLeft, textTop, m_staticTextName ); + paintTextLabel(m_pat->name(), p); // inner border p.setPen( c.lighter( current ? 160 : 130 ) ); diff --git a/src/tracks/BBTrack.cpp b/src/tracks/BBTrack.cpp index b1f46a92d45..25baf2be03b 100644 --- a/src/tracks/BBTrack.cpp +++ b/src/tracks/BBTrack.cpp @@ -267,25 +267,7 @@ void BBTCOView::paintEvent( QPaintEvent * ) } // pattern name - p.setRenderHint( QPainter::TextAntialiasing ); - - if( m_staticTextName.text() != m_bbTCO->name() ) - { - m_staticTextName.setText( m_bbTCO->name() ); - } - - QFont font; - font.setHintingPreference( QFont::PreferFullHinting ); - font.setPointSize( 8 ); - p.setFont( font ); - - const int textTop = TCO_BORDER_WIDTH + 1; - const int textLeft = TCO_BORDER_WIDTH + 1; - - p.setPen( textShadowColor() ); - p.drawStaticText( textLeft + 1, textTop + 1, m_staticTextName ); - p.setPen( textColor() ); - p.drawStaticText( textLeft, textTop, m_staticTextName ); + paintTextLabel(m_bbTCO->name(), p); // inner border p.setPen( c.lighter( 130 ) ); diff --git a/src/tracks/Pattern.cpp b/src/tracks/Pattern.cpp index 119124ab1ed..5c6e2e76771 100644 --- a/src/tracks/Pattern.cpp +++ b/src/tracks/Pattern.cpp @@ -1074,28 +1074,7 @@ void PatternView::paintEvent( QPaintEvent * ) if (!beatPattern && !isDefaultName) { - p.setRenderHint( QPainter::TextAntialiasing ); - - QFont labelFont = this->font(); - labelFont.setHintingPreference( QFont::PreferFullHinting ); - p.setFont( labelFont ); - - const int textTop = TCO_BORDER_WIDTH + 1; - const int textLeft = TCO_BORDER_WIDTH + 3; - - QFontMetrics fontMetrics(labelFont); - QString elidedPatternName = fontMetrics.elidedText(m_pat->name(), Qt::ElideMiddle, width() - 2 * textLeft); - - QColor transparentBlack(0, 0, 0, 75); - p.fillRect(QRect(0, 0, width(), fontMetrics.height() + 2 * textTop), transparentBlack); - - if( m_staticTextName.text() != elidedPatternName ) - { - m_staticTextName.setText( elidedPatternName ); - } - - p.setPen( textColor() ); - p.drawStaticText( textLeft, textTop, m_staticTextName ); + paintTextLabel(m_pat->name(), p); } // inner border From 0277c8a2701070f088763a710054d692a015dfae Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 16 Jul 2017 16:21:33 +0200 Subject: [PATCH 2/4] 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 888525a1953..4b81322784a 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 b148034a84b..109b1a68d99 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 b96575dcf6d..f0e00d54448 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 @@ class TrackContentObjectView : public selectableObject, public ModelView 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 @@ class TrackContentObjectView : public selectableObject, public ModelView 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 @@ protected slots: 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 bc7e6f321b2..a46a83a8acb 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 ); From ad827daee86f6fc2e266f7fc75dedbf6721d182a Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Tue, 18 Jul 2017 19:52:17 +0200 Subject: [PATCH 3/4] Handle cases where elided text becomes empty or "..." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Render the whole text if the elided text becomes empty or if it only contains one character, i.e. if it becomes "…". Solved as implemented because I was not able to check for "…" explicitly, i.e. the comparison against "…" still failed. --- src/core/Track.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/Track.cpp b/src/core/Track.cpp index a46a83a8acb..ed0637a1691 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -656,6 +656,11 @@ void TrackContentObjectView::paintTextLabel(QString const & text, QPainter & pai QFontMetrics fontMetrics(labelFont); QString elidedPatternName = fontMetrics.elidedText(text, Qt::ElideMiddle, width() - 2 * textLeft); + if (elidedPatternName.length() < 2) + { + elidedPatternName = text.trimmed(); + } + painter.fillRect(QRect(0, 0, width(), fontMetrics.height() + 2 * textTop), textBackgroundColor()); painter.setPen( textColor() ); From e21db01380f8abe0ca6f2d75f24ba0be0e3eb094 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Tue, 18 Jul 2017 22:11:25 +0200 Subject: [PATCH 4/4] Add back the rendering of text shadows for pattern labels Add back the rendering of text shadows for pattern labels. If some design does not want shadows beneath the text it's always possible to set the CSS property qproperty-textShadowColor to something completely transparent. --- src/core/Track.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/Track.cpp b/src/core/Track.cpp index ed0637a1691..f39abb0cca1 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -663,8 +663,11 @@ void TrackContentObjectView::paintTextLabel(QString const & text, QPainter & pai painter.fillRect(QRect(0, 0, width(), fontMetrics.height() + 2 * textTop), textBackgroundColor()); + int const finalTextTop = textTop + fontMetrics.ascent(); + painter.setPen(textShadowColor()); + painter.drawText( textLeft + 1, finalTextTop + 1, elidedPatternName ); painter.setPen( textColor() ); - painter.drawText( textLeft, textTop + fontMetrics.ascent(), elidedPatternName ); + painter.drawText( textLeft, finalTextTop, elidedPatternName ); } /*! \brief Handle a mouse press on this trackContentObjectView.