From a23e34488655e71805e8c4e1be894b0934d563fb Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 16 Jul 2017 16:10:42 +0200 Subject: [PATCH] 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 11a5e440e..888525a19 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 7680b7aae..b148034a8 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 dcb1648e0..b96575dcf 100644 --- a/include/Track.h +++ b/include/Track.h @@ -263,6 +263,8 @@ protected: 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 7795b205c..bc7e6f321 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 465ac69e3..78b697ca4 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 b1f46a92d..25baf2be0 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 119124ab1..5c6e2e767 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