From 9830b20ca15128d6ef4a92ab5124cd626913ce57 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 17 Apr 2013 06:45:14 +0200 Subject: [PATCH] * Updated Album- & PlaylistChartItemDelegate. --- .../playlist/AlbumItemDelegate.cpp | 25 +++++++--- .../playlist/PlaylistChartItemDelegate.cpp | 50 +++++++++++-------- .../playlist/PlaylistChartItemDelegate.h | 16 +++--- 3 files changed, 54 insertions(+), 37 deletions(-) diff --git a/src/libtomahawk/playlist/AlbumItemDelegate.cpp b/src/libtomahawk/playlist/AlbumItemDelegate.cpp index 51d75bf08..c93f9996a 100644 --- a/src/libtomahawk/playlist/AlbumItemDelegate.cpp +++ b/src/libtomahawk/playlist/AlbumItemDelegate.cpp @@ -119,21 +119,28 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, painter->setFont( boldFont ); painter->setPen( option.palette.text().color().lighter( 450 ) ); - + QRect figureRect = r.adjusted( 4, 0, 0, 0 ); figureRect.setWidth( QFontMetrics( painter->font() ).width( "888" ) ); painter->drawText( figureRect, QString::number( index.row() + 1 ), QTextOption( Qt::AlignCenter ) ); r.adjust( figureRect.width() + 12, 0, 0, 0 ); - QRect leftRect = r.adjusted( 0, 0, -48, 0 ); QRect rightRect = r.adjusted( r.width() - smallBoldFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 ); - - QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() ); - painter->setPen( opt.palette.text().color() ); - painter->drawText( leftRect, text, m_centerOption ); + QRect leftRect = r.adjusted( 0, 0, -( rightRect.width() + 8 ), 0 ); const int sourceIconSize = r.height(); - if ( q->numResults() && !q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ).isNull() ) + + if ( hoveringOver() == index && index.column() == 0 ) + { + const QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, QSize( sourceIconSize, sourceIconSize ) ); + QRect arrowRect = QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, infoIcon.width(), infoIcon.height() ); + painter->drawPixmap( arrowRect, infoIcon ); + + setInfoButtonRect( index, arrowRect ); + rightRect.moveLeft( rightRect.left() - infoIcon.width() - 8 ); + leftRect.adjust( 0, 0, -( infoIcon.width() + 8 ), 0 ); + } + else if ( q->numResults() && !q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ).isNull() ) { const QPixmap sourceIcon = q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ); painter->setOpacity( 0.8 ); @@ -142,6 +149,10 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, rightRect.moveLeft( rightRect.left() - sourceIcon.width() - 8 ); } + QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() ); + painter->setPen( opt.palette.text().color() ); + painter->drawText( leftRect, text, m_centerOption ); + if ( duration > 0 ) { painter->setPen( opt.palette.text().color() ); diff --git a/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp index 448da44da..4365f57f7 100644 --- a/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp @@ -43,7 +43,7 @@ using namespace Tomahawk; PlaylistChartItemDelegate::PlaylistChartItemDelegate( TrackView* parent, PlayableProxyModel* proxy ) - : QStyledItemDelegate( (QObject*)parent ) + : PlaylistItemDelegate( parent, proxy ) , m_view( parent ) , m_model( proxy ) { @@ -59,11 +59,8 @@ PlaylistChartItemDelegate::PlaylistChartItemDelegate( TrackView* parent, Playabl m_bottomOption = QTextOption( Qt::AlignBottom ); m_bottomOption.setWrapMode( QTextOption::NoWrap ); - connect( this, SIGNAL( updateIndex( QModelIndex ) ), parent, SLOT( update( QModelIndex ) ) ); - - connect( m_model, SIGNAL( modelReset() ), this, SLOT( modelChanged() ) ); - if ( PlaylistView* plView = qobject_cast< PlaylistView* >( parent ) ) - connect( plView, SIGNAL( modelChanged() ), this, SLOT( modelChanged() ) ); + connect( proxy, SIGNAL( modelReset() ), SLOT( modelChanged() ) ); + connect( parent, SIGNAL( modelChanged() ), SLOT( modelChanged() ) ); } @@ -99,15 +96,6 @@ PlaylistChartItemDelegate::sizeHint( const QStyleOptionViewItem& option, const Q } -void -PlaylistChartItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ) const -{ - initStyleOption( option, index ); - - TomahawkUtils::prepareStyleOption( option, index, item ); -} - - void PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { @@ -204,7 +192,29 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& painter->drawPixmap( pixmapRect, pixmap ); r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 ); - QRect leftRect = r.adjusted( 0, 0, -durationFontMetrics.width( TomahawkUtils::timeToString( duration ) ) - 8, 0 ); + QRect rightRect = r.adjusted( r.width() - durationFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 ); + QRect leftRect = r.adjusted( 0, 0, -( rightRect.width() + 8 ), 0 ); + +/* const int sourceIconSize = r.height(); + + if ( hoveringOver() == index && index.column() == 0 ) + { + const QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, QSize( sourceIconSize, sourceIconSize ) ); + QRect arrowRect = QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, infoIcon.width(), infoIcon.height() ); + painter->drawPixmap( arrowRect, infoIcon ); + + setInfoButtonRect( index, arrowRect ); + rightRect.moveLeft( rightRect.left() - infoIcon.width() - 8 ); + leftRect.adjust( 0, 0, -( infoIcon.width() + 8 ), 0 ); + } + else if ( q->numResults() && !q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ).isNull() ) + { + const QPixmap sourceIcon = q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ); + painter->setOpacity( 0.8 ); + painter->drawPixmap( QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, sourceIcon.width(), sourceIcon.height() ), sourceIcon ); + painter->setOpacity( 1.0 ); + rightRect.moveLeft( rightRect.left() - sourceIcon.width() - 8 ); + }*/ painter->setFont( boldFont ); QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() ); @@ -216,10 +226,9 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& if ( duration > 0 ) { + painter->setPen( opt.palette.text().color() ); painter->setFont( durationFont ); - QRect rightRect = r.adjusted( r.width() - durationFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 ); - text = painter->fontMetrics().elidedText( TomahawkUtils::timeToString( duration ), Qt::ElideRight, rightRect.width() ); - painter->drawText( rightRect, text, m_centerRightOption ); + painter->drawText( rightRect, TomahawkUtils::timeToString( duration ), m_centerRightOption ); } } painter->restore(); @@ -229,7 +238,8 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& void PlaylistChartItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx ) { - emit updateIndex( idx ); + if ( idx.isValid() ) + emit updateIndex( idx ); } diff --git a/src/libtomahawk/playlist/PlaylistChartItemDelegate.h b/src/libtomahawk/playlist/PlaylistChartItemDelegate.h index 7db81512d..9b38e53a5 100644 --- a/src/libtomahawk/playlist/PlaylistChartItemDelegate.h +++ b/src/libtomahawk/playlist/PlaylistChartItemDelegate.h @@ -19,9 +19,9 @@ #ifndef PLAYLISTCHARTITEMDELEGATE_H #define PLAYLISTCHARTITEMDELEGATE_H -#include #include +#include "PlaylistItemDelegate.h" #include "DllMacro.h" #include "Typedefs.h" @@ -35,36 +35,32 @@ class PlayableItem; class PlayableProxyModel; class TrackView; -class DLLEXPORT PlaylistChartItemDelegate : public QStyledItemDelegate +class DLLEXPORT PlaylistChartItemDelegate : public PlaylistItemDelegate { Q_OBJECT public: PlaylistChartItemDelegate( TrackView* parent = 0, PlayableProxyModel* proxy = 0 ); -signals: - void updateIndex( const QModelIndex& idx ); + virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; protected: void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; - QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; private slots: - void modelChanged(); void doUpdateIndex( const QPersistentModelIndex& idx ); + void modelChanged(); private: - void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ) const; - QTextOption m_topOption; QTextOption m_centerOption; QTextOption m_centerRightOption; QTextOption m_bottomOption; + mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps; + TrackView* m_view; PlayableProxyModel* m_model; - - mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps; }; #endif // PLAYLISTCHARTITEMDELEGATE_H