From c0a4f675446ff328d98a0a2d782623dc9d47aa0a Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 2 Jul 2017 20:47:14 +0200 Subject: [PATCH] Render a black semitransparent rectangle beneath the elided pattern text Make the pattern names better readable by rendering them on top of a semitransparent black rectangle. Elide the text and make it render a bit more to the right. --- src/tracks/Pattern.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/tracks/Pattern.cpp b/src/tracks/Pattern.cpp index 6757df22b..d4780f2b7 100644 --- a/src/tracks/Pattern.cpp +++ b/src/tracks/Pattern.cpp @@ -1070,27 +1070,31 @@ void PatternView::paintEvent( QPaintEvent * ) } // pattern name - p.setRenderHint( QPainter::TextAntialiasing ); - bool isDefaultName = m_pat->name() == m_pat->instrumentTrack()->name(); - if( !isDefaultName && m_staticTextName.text() != m_pat->name() ) + if (!beatPattern && !isDefaultName) { - m_staticTextName.setText( m_pat->name() ); - } + p.setRenderHint( QPainter::TextAntialiasing ); - QFont font; - font.setHintingPreference( QFont::PreferFullHinting ); - font.setPointSize( 8 ); - p.setFont( font ); + 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; + const int textTop = TCO_BORDER_WIDTH + 1; + const int textLeft = TCO_BORDER_WIDTH + 3; + + QFontMetrics fontMetrics(font); + 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 ); + } - if( !isDefaultName ) - { - p.setPen( textShadowColor() ); - p.drawStaticText( textLeft + 1, textTop + 1, m_staticTextName ); p.setPen( textColor() ); p.drawStaticText( textLeft, textTop, m_staticTextName ); }