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.
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -263,6 +263,8 @@ protected:
|
||||
|
||||
DataFile createTCODataFiles(const QVector<TrackContentObjectView *> & tcos) const;
|
||||
|
||||
virtual void paintTextLabel(QString const & text, QPainter & painter);
|
||||
|
||||
|
||||
protected slots:
|
||||
void updateLength();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ) );
|
||||
|
||||
@@ -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 ) );
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user