1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-13 17:43:59 +02:00

* A few sidebar-delegate fixes. Const whenever you 'konnst'.

This commit is contained in:
Christian Muehlhaeuser
2014-09-01 02:06:51 +02:00
parent 8e3231facd
commit 02a3bd931f

View File

@@ -85,7 +85,7 @@ SourceDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex&
} }
else if ( type == SourcesModel::Group ) else if ( type == SourcesModel::Group )
{ {
int groupSpacer = index.row() > 0 ? option.fontMetrics.height() * 2.5 : option.fontMetrics.height() * 0.8; const int groupSpacer = index.row() > 0 ? option.fontMetrics.height() * 2.5 : option.fontMetrics.height() * 0.8;
return QSize( option.rect.width(), option.fontMetrics.height() + groupSpacer ); return QSize( option.rect.width(), option.fontMetrics.height() + groupSpacer );
} }
else else
@@ -133,7 +133,7 @@ SourceDelegate::paintStandardItem( QPainter* painter, const QStyleOptionViewItem
} }
QRect textRect = opt.rect.adjusted( iconRect.width() + 22, 0, -32 - figWidth, 0 ); QRect textRect = opt.rect.adjusted( iconRect.width() + 22, 0, -32 - figWidth, 0 );
QString text = painter->fontMetrics().elidedText( upperCase ? opt.text.toUpper() : opt.text, Qt::ElideRight, textRect.width() ); const QString text = painter->fontMetrics().elidedText( upperCase ? opt.text.toUpper() : opt.text, Qt::ElideRight, textRect.width() );
{ {
QTextOption to( Qt::AlignVCenter ); QTextOption to( Qt::AlignVCenter );
to.setWrapMode( QTextOption::NoWrap ); to.setWrapMode( QTextOption::NoWrap );
@@ -166,9 +166,9 @@ SourceDelegate::paintDecorations( QPainter* painter, const QStyleOptionViewItem&
if ( playable && playing && item->isBeingPlayed() ) if ( playable && playing && item->isBeingPlayed() )
{ {
int iconW = option.rect.height() - 8; const int iconW = option.rect.height() - 8;
QRect iconRect = QRect( 8, option.rect.y() + 4, iconW, iconW ); const QRect iconRect( 8, option.rect.y() + 4, iconW, iconW );
QPixmap speaker = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeakerDark, TomahawkUtils::Original, iconRect.size() ); const QPixmap speaker = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeakerDark, TomahawkUtils::Original, iconRect.size() );
painter->drawPixmap( iconRect, speaker ); painter->drawPixmap( iconRect, speaker );
} }
@@ -364,14 +364,12 @@ SourceDelegate::paintSource( QPainter* painter, const QStyleOptionViewItem& opti
{ {
if ( shouldDrawDropHint ) if ( shouldDrawDropHint )
{ {
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - iconRectVertMargin, iconRectVertMargin, -iconRectVertMargin, -iconRectVertMargin ); const QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - iconRectVertMargin, iconRectVertMargin, -iconRectVertMargin, -iconRectVertMargin );
painter->drawPixmap( figRect, TomahawkUtils::defaultPixmap( TomahawkUtils::Inbox, TomahawkUtils::Original, figRect.size() ) ); painter->drawPixmap( figRect, TomahawkUtils::defaultPixmap( TomahawkUtils::Inbox, TomahawkUtils::Original, figRect.size() ) );
} }
else else
{ {
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 16, 0, -14, -option.rect.height() + option.fontMetrics.height() * 1.1 ); const QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 16, 0, -14, 0 );
int hd = ( option.rect.height() - figRect.height() ) / 2;
figRect.adjust( 0, hd, 0, hd );
painter->drawText( figRect, tracks, QTextOption( Qt::AlignVCenter | Qt::AlignRight ) ); painter->drawText( figRect, tracks, QTextOption( Qt::AlignVCenter | Qt::AlignRight ) );
} }
} }
@@ -389,11 +387,9 @@ SourceDelegate::paintCategory( QPainter* painter, const QStyleOptionViewItem& op
font.setPointSize( TomahawkUtils::defaultFontSize() - 1 ); font.setPointSize( TomahawkUtils::defaultFontSize() - 1 );
painter->setFont( font ); painter->setFont( font );
QTextOption to( Qt::AlignVCenter );
painter->setPen( Qt::black ); painter->setPen( Qt::black );
painter->setOpacity( 0.5 ); painter->setOpacity( 0.5 );
painter->drawText( option.rect.translated( 16, 0 ), index.data().toString().toUpper(), to ); painter->drawText( option.rect.translated( 16, 0 ), index.data().toString().toUpper(), QTextOption( Qt::AlignVCenter ) );
if ( option.state & QStyle::State_MouseOver ) if ( option.state & QStyle::State_MouseOver )
{ {
@@ -401,13 +397,11 @@ SourceDelegate::paintCategory( QPainter* painter, const QStyleOptionViewItem& op
if ( option.state & QStyle::State_Open ) if ( option.state & QStyle::State_Open )
text = tr( "Hide" ); text = tr( "Hide" );
QFont font = option.font; painter->setFont( option.font );
painter->setFont( font );
QTextOption to( Qt::AlignVCenter | Qt::AlignRight );
// draw close icon // draw close icon
painter->setPen( TomahawkStyle::GROUP_HEADER ); painter->setPen( TomahawkStyle::GROUP_HEADER );
painter->drawText( option.rect.translated( -4, 0 ), text, to ); painter->drawText( option.rect.translated( -4, 0 ), text, QTextOption( Qt::AlignVCenter | Qt::AlignRight ) );
} }
painter->restore(); painter->restore();
@@ -423,11 +417,9 @@ SourceDelegate::paintGroup( QPainter* painter, const QStyleOptionViewItem& optio
font.setPointSize( TomahawkUtils::defaultFontSize() - 1 ); font.setPointSize( TomahawkUtils::defaultFontSize() - 1 );
painter->setFont( font ); painter->setFont( font );
QTextOption to( Qt::AlignBottom );
painter->setPen( Qt::black ); painter->setPen( Qt::black );
painter->setOpacity( 0.5 ); painter->setOpacity( 0.5 );
painter->drawText( option.rect.adjusted( 32, 0, -32, -8 ), index.data().toString().toUpper(), to ); painter->drawText( option.rect.adjusted( 32, 0, -32, -8 ), index.data().toString().toUpper(), QTextOption( Qt::AlignBottom ) );
if ( option.state & QStyle::State_MouseOver ) if ( option.state & QStyle::State_MouseOver )
{ {
@@ -435,13 +427,11 @@ SourceDelegate::paintGroup( QPainter* painter, const QStyleOptionViewItem& optio
if ( option.state & QStyle::State_Open ) if ( option.state & QStyle::State_Open )
text = tr( "Hide" ); text = tr( "Hide" );
QFont font = option.font; painter->setFont( option.font );
painter->setFont( font );
QTextOption to( Qt::AlignBottom | Qt::AlignRight );
// draw close icon // draw close icon
painter->setPen( TomahawkStyle::GROUP_HEADER ); painter->setPen( TomahawkStyle::GROUP_HEADER );
painter->drawText( option.rect.translated( -4, -6 ), text, to ); painter->drawText( option.rect.translated( -4, -6 ), text, QTextOption( Qt::AlignBottom | Qt::AlignRight ) );
} }
painter->restore(); painter->restore();
@@ -482,7 +472,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
counter = counter.parent(); counter = counter.parent();
} }
int indentDelta = optIndentation.rect.x() - m_parent->viewport()->x(); const int indentDelta = optIndentation.rect.x() - m_parent->viewport()->x();
optIndentation.rect.setX( optIndentation.rect.x() - indentDelta + indentMult * TREEVIEW_INDENT_ADD ); optIndentation.rect.setX( optIndentation.rect.x() - indentDelta + indentMult * TREEVIEW_INDENT_ADD );
opt.rect.setX( 0 ); opt.rect.setX( 0 );
} }
@@ -501,9 +491,8 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
} }
else if ( type == SourcesModel::Divider ) else if ( type == SourcesModel::Divider )
{ {
QRect middle = optIndentation.rect.adjusted( 0, 2, 0, -2 ); const QRect middle = optIndentation.rect.adjusted( 0, 2, 0, -2 );
const QColor bgcolor = opt.palette.color( QPalette::Base );
QColor bgcolor = opt.palette.color( QPalette::Base );
painter->setPen( bgcolor.darker( 120 ) ); painter->setPen( bgcolor.darker( 120 ) );
painter->drawLine( middle.topLeft(), middle.topRight() ); painter->drawLine( middle.topLeft(), middle.topRight() );
@@ -548,7 +537,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
paintStandardItem( painter, optIndentation, index ); paintStandardItem( painter, optIndentation, index );
// draw close icon // draw close icon
QRect r( opt.rect.right() - 4 - m_iconHeight, opt.rect.y() + ( opt.rect.height() - m_iconHeight ) / 2, m_iconHeight, m_iconHeight ); const QRect r( opt.rect.right() - 4 - m_iconHeight, opt.rect.y() + ( opt.rect.height() - m_iconHeight ) / 2, m_iconHeight, m_iconHeight );
painter->drawPixmap( r, TomahawkUtils::defaultPixmap( TomahawkUtils::ListRemove, TomahawkUtils::Original, r.size() ) ); painter->drawPixmap( r, TomahawkUtils::defaultPixmap( TomahawkUtils::ListRemove, TomahawkUtils::Original, r.size() ) );
} }
else else
@@ -677,8 +666,8 @@ SourceDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt
QStyleOptionViewItemV4 o = option; QStyleOptionViewItemV4 o = option;
initStyleOption( &o, index ); initStyleOption( &o, index );
int padding = 3; const int padding = 3;
QRect r ( o.rect.right() - padding - m_iconHeight, padding + o.rect.y(), m_iconHeight, m_iconHeight ); const QRect r( o.rect.right() - padding - m_iconHeight, padding + o.rect.y(), m_iconHeight, m_iconHeight );
if ( r.contains( mEvent->pos() ) ) if ( r.contains( mEvent->pos() ) )
{ {