void GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); if ( !item ) return; QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, QModelIndex() ); qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); painter->save(); painter->setRenderHint( QPainter::Antialiasing ); QRect r = option.rect; QString top, bottom; if ( !item->album().isNull() ) { top = item->album()->name(); if ( !item->album()->artist().isNull() ) bottom = item->album()->artist()->name(); } else if ( !item->artist().isNull() ) { top = item->artist()->name(); } else { top = item->query()->track(); bottom = item->query()->artist(); } if ( !m_covers.contains( index ) ) { if ( !item->album().isNull() ) { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::Grid ) ) ); } else if ( !item->artist().isNull() ) { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->artist(), r.size(), TomahawkUtils::Grid ) ) ); } else { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->query(), r.size(), TomahawkUtils::Grid ) ) ); } NewClosure( m_covers[ index ], SIGNAL( repaintRequest() ), const_cast<GridItemDelegate*>(this), SLOT( doUpdateIndex( QPersistentModelIndex ) ), QPersistentModelIndex( index ) )->setAutoDelete( false ); } QSharedPointer< Tomahawk::PixmapDelegateFader > fader = m_covers[ index ]; if ( fader->size() != r.size() ) fader->setSize( r.size() ); const QPixmap cover = fader->currentPixmap(); painter->drawPixmap( r, cover ); qreal opacity = -1.; if ( m_hoverFaders.contains( index ) ) { const qreal pct = ( m_hoverFaders[ index ]->currentFrame() / 100. ); opacity = 0.35 - pct * 0.35; } else if ( m_hoverIndex == index ) { opacity = 0.35; } if ( opacity > -1. ) { painter->save(); painter->setPen( QColor( 33, 33, 33 ) ); painter->setBrush( QColor( 33, 33, 33 ) ); painter->setOpacity( opacity ); painter->drawRect( r ); painter->restore(); } painter->save(); painter->setPen( Qt::black ); painter->setBrush( Qt::black ); painter->setOpacity( 0.5 ); painter->drawRoundedRect( r.adjusted( 4, +r.height() - 36, -4, -4 ), 3, 3 ); painter->restore(); painter->setPen( opt.palette.color( QPalette::HighlightedText ) ); QTextOption to; to.setWrapMode( QTextOption::NoWrap ); QString text; QFont font = opt.font; font.setPointSize( TomahawkUtils::defaultFontSize() ); QFont boldFont = font; boldFont.setBold( true ); boldFont.setPointSize( TomahawkUtils::defaultFontSize() + 1 ); QRect textRect = option.rect.adjusted( 6, option.rect.height() - 36, -4, -6 ); painter->setFont( font ); int bottomHeight = painter->fontMetrics().boundingRect( bottom ).height(); painter->setFont( boldFont ); int topHeight = painter->fontMetrics().boundingRect( top ).height(); bool oneLiner = false; if ( bottom.isEmpty() ) oneLiner = true; else oneLiner = ( textRect.height() < topHeight + bottomHeight ); if ( oneLiner ) { to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); } else { to.setAlignment( Qt::AlignHCenter | Qt::AlignTop ); text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); painter->setFont( font ); // If the user is hovering over an artist rect, draw a background so she knows it's clickable QRect r = textRect; r.setTop( r.bottom() - painter->fontMetrics().height() ); r.adjust( 4, 0, -4, -1 ); if ( m_hoveringOver == index ) { TomahawkUtils::drawQueryBackground( painter, opt.palette, r, 1.1 ); painter->setPen( opt.palette.color( QPalette::HighlightedText ) ); } to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom ); text = painter->fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 10 ); painter->drawText( textRect.adjusted( 5, -1, -5, -1 ), text, to ); // Calculate rect of artist on-hover button click area m_artistNameRects[ index ] = r; } painter->restore(); }
void GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); if ( !item || !index.isValid() ) return; QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, QModelIndex() ); // qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); QRect r = option.rect; r.setHeight( r.width() ); QString top, bottom; if ( !item->album().isNull() ) { top = item->album()->name(); if ( !item->album()->artist().isNull() ) bottom = item->album()->artist()->name(); } else if ( !item->artist().isNull() ) { top = item->artist()->name(); } else if ( !item->query().isNull() ) { top = item->query()->track()->track(); bottom = item->query()->track()->artist(); } else { return; } painter->save(); painter->setRenderHint( QPainter::TextAntialiasing ); if ( !m_covers.contains( index ) ) { if ( !item->album().isNull() ) { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::Original, false ) ) ); } else if ( !item->artist().isNull() ) { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->artist(), r.size(), TomahawkUtils::Original, false ) ) ); } else { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->query(), r.size(), TomahawkUtils::Original, false ) ) ); } NewClosure( m_covers[ index ], SIGNAL( repaintRequest() ), const_cast<GridItemDelegate*>(this), SLOT( doUpdateIndex( QPersistentModelIndex ) ), QPersistentModelIndex( index ) )->setAutoDelete( false ); } QSharedPointer< Tomahawk::PixmapDelegateFader > fader = m_covers[ index ]; if ( fader->size() != r.size() ) fader->setSize( r.size() ); const QPixmap cover = fader->currentPixmap(); qreal opacity = -1.0; qreal pct = -1.0; if ( m_hoverFaders.contains( index ) ) { pct = ( m_hoverFaders[ index ]->currentFrame() / 100.0 ); opacity = 1.0 - pct * 0.70; } else if ( m_hoverIndex == index ) { opacity = 0.3; pct = 1.0; } if ( opacity > -1.0 ) { painter->save(); const int cropIn = pct * ( (qreal)cover.width() * 0.10 ); const QRect crop = cover.rect().adjusted( cropIn, cropIn, -cropIn, -cropIn ); painter->drawPixmap( r, cover.copy( crop ).scaled( r.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) ); painter->setOpacity( 1.0 - opacity ); painter->setPen( Qt::transparent ); painter->setBrush( Qt::black ); painter->drawRect( r ); painter->restore(); } else { painter->drawPixmap( r, cover ); } QTextOption to; to.setWrapMode( QTextOption::NoWrap ); QString text; QRect textRect = option.rect.adjusted( 0, r.height() + m_margin / 4, 0, -m_margin / 2 + m_margin / 8 ); bool oneLiner = false; if ( bottom.isEmpty() ) oneLiner = true; painter->setPen( TomahawkStyle::SELECTION_FOREGROUND ); painter->setFont( m_font ); painter->setPen( Qt::black ); painter->setOpacity( 0.8 ); if ( m_showPosition ) { painter->save(); if ( !oneLiner ) { QFont figFont = m_font; figFont.setPixelSize( textRect.height() - m_margin / 8 ); painter->setFont( figFont ); } const QString fig = QString::number( index.row() + 1 ); painter->drawText( textRect, fig, QTextOption( Qt::AlignLeft | Qt::AlignVCenter ) ); textRect.adjust( painter->fontMetrics().boundingRect( textRect, Qt::AlignLeft | Qt::AlignVCenter, fig ).width() + m_margin / 4, 0, 0, 0 ); painter->restore(); } if ( oneLiner ) { // If the user is hovering over an artist rect, draw a background so they knows it's clickable if ( m_hoveringOverArtist == index ) { QFont f = painter->font(); f.setUnderline( true ); painter->setFont( f ); } to.setAlignment( Qt::AlignLeft | Qt::AlignTop ); text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - m_margin / 4 ); painter->drawText( textRect, text, to ); // Calculate rect of artist on-hover button click area m_artistNameRects[ index ] = painter->fontMetrics().boundingRect( textRect, Qt::AlignLeft | Qt::AlignTop, text ); } else { painter->save(); // If the user is hovering over an album rect, underline the album name if ( m_hoveringOverAlbum == index ) { QFont f = painter->font(); f.setUnderline( true ); painter->setFont( f ); } if ( m_showBuyButtons && !item->query().isNull() ) { textRect.adjust( 0, 0, 0, -40 ); } to.setAlignment( Qt::AlignLeft | Qt::AlignTop ); text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - m_margin / 4 ); painter->drawText( textRect, text, to ); if ( item->album() ) { // Calculate rect of album on-hover button click area m_albumNameRects[ index ] = painter->fontMetrics().boundingRect( textRect, Qt::AlignLeft | Qt::AlignTop, text ); } painter->restore(); painter->save(); painter->setOpacity( 0.6 ); painter->setFont( m_smallFont ); // If the user is hovering over an artist rect, underline the artist name if ( m_hoveringOverArtist == index ) { QFont f = painter->font(); f.setUnderline( true ); painter->setFont( f ); } textRect.adjust( 0, painter->fontMetrics().height() + m_margin / 16, 0, 0 ); to.setAlignment( Qt::AlignLeft | Qt::AlignBottom ); text = painter->fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - m_margin / 4 ); painter->drawText( textRect, text, to ); // Calculate rect of artist on-hover button click area m_artistNameRects[ index ] = painter->fontMetrics().boundingRect( textRect, Qt::AlignLeft | Qt::AlignBottom, text ); painter->restore(); if ( m_showBuyButtons && !item->query().isNull() ) { QRect r = textRect; r.setY( textRect.y() + textRect.height() + 8 ); r.setHeight( 32 ); m_buyButtonRects[ index ] = r; QString text; bool itemsAvailable = false; if ( item->result() && ( ( !item->result()->downloadFormats().isEmpty() && !DownloadManager::instance()->localFileForDownload( item->result()->downloadFormats().first().url.toString() ).isEmpty() ) || ( item->result()->downloadJob() && item->result()->downloadJob()->state() == DownloadJob::Finished ) ) ) { text = tr( "View in Finder" ); } else if ( item->query() && item->query()->numResults( true ) && !item->query()->results().first()->downloadFormats().isEmpty() ) { text = tr( "Download %1" ).arg( item->query()->results().first()->downloadFormats().first().extension.toUpper() ); itemsAvailable = true; } else if ( item->query()->numResults( true ) && !item->query()->results().first()->purchaseUrl().isEmpty() ) { text = tr( "Buy" ); } if ( !item->result() || !item->result()->downloadJob() || item->result()->downloadJob()->state() == DownloadJob::Finished ) { if ( !text.isEmpty() ) DropDownButton::drawPrimitive( painter, r, text, m_hoveringOverBuyButton == index, itemsAvailable ); else m_buyButtonRects.remove( index ); } else { painter->setPen( TomahawkStyle::PLAYLIST_PROGRESS_FOREGROUND.darker() ); painter->setBrush( TomahawkStyle::PLAYLIST_PROGRESS_BACKGROUND ); painter->drawRect( r.adjusted( 2, 2, -2, -2 ) ); painter->setPen( TomahawkStyle::PLAYLIST_PROGRESS_FOREGROUND ); painter->setBrush( TomahawkStyle::PLAYLIST_PROGRESS_FOREGROUND ); QRect fillp = r.adjusted( 3, 3, -3, -3 ); fillp.setWidth( float(fillp.width()) * ( float(item->result()->downloadJob()->progressPercentage()) / 100.0 ) ); painter->drawRect( fillp ); } } } painter->restore(); }
void AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { AlbumItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); if ( !item ) return; QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, QModelIndex() ); qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); painter->save(); painter->setRenderHint( QPainter::Antialiasing ); /* if ( !( option.state & QStyle::State_Selected ) ) { QRect shadowRect = option.rect.adjusted( 5, 4, -5, -40 ); painter->setPen( QColor( 90, 90, 90 ) ); painter->drawRoundedRect( shadowRect, 0.5, 0.5 ); QPen shadowPen( QColor( 30, 30, 30 ) ); shadowPen.setWidth( 0.4 ); painter->drawLine( shadowRect.bottomLeft() + QPoint( -1, 2 ), shadowRect.bottomRight() + QPoint( 1, 2 ) ); shadowPen.setColor( QColor( 160, 160, 160 ) ); painter->setPen( shadowPen ); painter->drawLine( shadowRect.topLeft() + QPoint( -1, 2 ), shadowRect.bottomLeft() + QPoint( -1, 2 ) ); painter->drawLine( shadowRect.topRight() + QPoint( 2, 2 ), shadowRect.bottomRight() + QPoint( 2, 2 ) ); painter->drawLine( shadowRect.bottomLeft() + QPoint( 0, 3 ), shadowRect.bottomRight() + QPoint( 0, 3 ) ); shadowPen.setColor( QColor( 180, 180, 180 ) ); painter->setPen( shadowPen ); painter->drawLine( shadowRect.topLeft() + QPoint( -2, 3 ), shadowRect.bottomLeft() + QPoint( -2, 1 ) ); painter->drawLine( shadowRect.topRight() + QPoint( 3, 3 ), shadowRect.bottomRight() + QPoint( 3, 1 ) ); painter->drawLine( shadowRect.bottomLeft() + QPoint( 0, 4 ), shadowRect.bottomRight() + QPoint( 0, 4 ) ); }*/ // QRect r = option.rect.adjusted( 6, 5, -6, -41 ); QRect r = option.rect; QString top, bottom; if ( !item->album().isNull() ) { top = item->album()->name(); if ( !item->album()->artist().isNull() ) bottom = item->album()->artist()->name(); } else if ( !item->artist().isNull() ) { top = item->artist()->name(); } else { top = item->query()->track(); bottom = item->query()->artist(); } if ( !m_covers.contains( index ) ) { if ( !item->album().isNull() ) { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::Grid ) ) ); } else if ( !item->artist().isNull() ) { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->artist(), r.size(), TomahawkUtils::Grid ) ) ); } else { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->query(), r.size(), TomahawkUtils::Grid ) ) ); } _detail::Closure* closure = NewClosure( m_covers[ index ], SIGNAL( repaintRequest() ), const_cast<AlbumItemDelegate*>(this), SLOT( doUpdateIndex( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); closure->setAutoDelete( false ); } const QPixmap cover = m_covers[ index ]->currentPixmap(); if ( false && option.state & QStyle::State_Selected ) { #if defined(Q_WS_MAC) || defined(Q_WS_WIN) painter->save(); QPainterPath border; border.addRoundedRect( r.adjusted( -2, -2, 2, 2 ), 3, 3 ); QPen borderPen( QColor( 86, 170, 243 ) ); borderPen.setWidth( 5 ); painter->setPen( borderPen ); painter->drawPath( border ); painter->restore(); #else opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) ); #endif } painter->drawPixmap( r, cover.scaled( r.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) ); if ( m_hoverIndex == index ) { painter->save(); painter->setPen( QColor( 33, 33, 33 ) ); painter->setBrush( QColor( 33, 33, 33 ) ); painter->setOpacity( 0.5 ); painter->drawRect( r ); painter->restore(); } painter->save(); painter->setPen( QColor( 33, 33, 33 ) ); painter->setBrush( QColor( 33, 33, 33 ) ); painter->setOpacity( 0.5 ); painter->drawRoundedRect( r.adjusted( 4, +r.height() - 36, -4, -4 ), 3, 3 ); painter->restore(); painter->setPen( opt.palette.color( QPalette::HighlightedText ) ); QTextOption to; to.setWrapMode( QTextOption::NoWrap ); QString text; QFont font = opt.font; font.setPixelSize( 10 ); QFont boldFont = font; boldFont.setBold( true ); boldFont.setPixelSize( 14 ); QRect textRect = option.rect.adjusted( 6, option.rect.height() - 36, -4, -6 ); painter->setFont( boldFont ); bool oneLiner = false; if ( bottom.isEmpty() ) oneLiner = true; else oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( top ).height() || textRect.height() / 2 < painter->fontMetrics().boundingRect( bottom ).height() ); if ( oneLiner ) { to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); } else { to.setAlignment( Qt::AlignHCenter | Qt::AlignTop ); text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); painter->setFont( font ); // If the user is hovering over an artist rect, draw a background so she knows it's clickable QRect r = textRect; r.setTop( r.bottom() - painter->fontMetrics().height() ); r.adjust( 4, 0, -4, -1 ); if ( m_hoveringOver == index ) { TomahawkUtils::drawQueryBackground( painter, opt.palette, r, 1.1 ); painter->setPen( opt.palette.color( QPalette::HighlightedText ) ); } else { /* if ( !( option.state & QStyle::State_Selected ) ) #ifdef Q_WS_MAC painter->setPen( opt.palette.color( QPalette::Dark ).darker( 200 ) ); #else painter->setPen( opt.palette.color( QPalette::Dark ) ); #endif*/ } to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom ); text = painter->fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 10 ); painter->drawText( textRect.adjusted( 5, -1, -5, -1 ), text, to ); // Calculate rect of artist on-hover button click area m_artistNameRects[ index ] = r; } painter->restore(); }
void GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); if ( !item || !index.isValid() ) return; QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, QModelIndex() ); qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); QRect r = option.rect; QString top, bottom; if ( !item->album().isNull() ) { top = item->album()->name(); if ( !item->album()->artist().isNull() ) bottom = item->album()->artist()->name(); } else if ( !item->artist().isNull() ) { top = item->artist()->name(); } else if ( !item->query().isNull() ) { top = item->query()->track()->track(); bottom = item->query()->track()->artist(); } else { return; } painter->save(); painter->setRenderHint( QPainter::Antialiasing ); if ( !m_covers.contains( index ) ) { if ( !item->album().isNull() ) { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::Grid ) ) ); } else if ( !item->artist().isNull() ) { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->artist(), r.size(), TomahawkUtils::Grid ) ) ); } else { m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->query(), r.size(), TomahawkUtils::Grid ) ) ); } NewClosure( m_covers[ index ], SIGNAL( repaintRequest() ), const_cast<GridItemDelegate*>(this), SLOT( doUpdateIndex( QPersistentModelIndex ) ), QPersistentModelIndex( index ) )->setAutoDelete( false ); } QSharedPointer< Tomahawk::PixmapDelegateFader > fader = m_covers[ index ]; if ( fader->size() != r.size() ) fader->setSize( r.size() ); const QPixmap cover = fader->currentPixmap(); painter->drawPixmap( r, cover ); qreal opacity = -1.; if ( m_hoverFaders.contains( index ) ) { const qreal pct = ( m_hoverFaders[ index ]->currentFrame() / 100.0 ); opacity = 0.35 - pct * 0.35; } else if ( m_hoverIndex == index ) { opacity = 0.35; } if ( opacity > -1.0 ) { painter->save(); painter->setPen( TomahawkStyle::HOVER_GLOW ); painter->setBrush( TomahawkStyle::HOVER_GLOW ); painter->setOpacity( opacity ); painter->drawRect( r ); painter->restore(); } QTextOption to; to.setWrapMode( QTextOption::NoWrap ); QString text; QFont font = opt.font; font.setPointSize( TomahawkUtils::defaultFontSize() ); QFont boldFont = font; boldFont.setBold( true ); boldFont.setPointSize( TomahawkUtils::defaultFontSize() + 1 ); int bottomHeight = QFontMetrics( font ).boundingRect( bottom ).height(); int topHeight = QFontMetrics( boldFont ).boundingRect( top ).height(); int frameHeight = bottomHeight + topHeight + 10; QColor c1; c1.setRgb( 0, 0, 0 ); c1.setAlphaF( 0.00 ); QColor c2; c2.setRgb( 0, 0, 0 ); c2.setAlphaF( 0.88 ); QRect gradientRect = r.adjusted( 0, r.height() - frameHeight * 2, 0, 0 ); QLinearGradient gradient( QPointF( 0, 0 ), QPointF( 0, 1 ) ); gradient.setCoordinateMode( QGradient::ObjectBoundingMode ); gradient.setColorAt( 0.0, c1 ); gradient.setColorAt( 0.6, c2 ); gradient.setColorAt( 1.0, c2 ); painter->save(); painter->setPen( Qt::transparent ); painter->setBrush( gradient ); painter->drawRect( gradientRect ); painter->restore(); painter->setPen( TomahawkStyle::SELECTION_FOREGROUND ); QRect textRect = option.rect.adjusted( 6, option.rect.height() - frameHeight, -6, -6 ); bool oneLiner = false; if ( bottom.isEmpty() ) oneLiner = true; painter->setFont( boldFont ); if ( oneLiner ) { to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); } else { to.setAlignment( Qt::AlignHCenter | Qt::AlignTop ); text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); painter->setFont( font ); // If the user is hovering over an artist rect, draw a background so she knows it's clickable QRect r = textRect; r.setTop( r.bottom() - painter->fontMetrics().height() ); r.adjust( 4, 0, -4, -1 ); if ( m_hoveringOver == index ) { TomahawkUtils::drawQueryBackground( painter, r ); painter->setPen( TomahawkStyle::SELECTION_FOREGROUND ); } to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom ); text = painter->fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 10 ); painter->drawText( textRect.adjusted( 5, -1, -5, -1 ), text, to ); // Calculate rect of artist on-hover button click area m_artistNameRects[ index ] = r; } painter->restore(); }