From d5266f71474f675491ad3133f7bc783ee2c96153 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 23 Jun 2011 20:02:26 +0200 Subject: [PATCH] * Fix the styling of the now playing row in the TreeView. --- .../playlist/playlistitemdelegate.cpp | 4 +-- src/libtomahawk/playlist/treeitemdelegate.cpp | 26 +++++++++++++++++-- src/libtomahawk/playlist/treeitemdelegate.h | 7 +++-- src/libtomahawk/playlist/treemodel.cpp | 6 ----- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/libtomahawk/playlist/playlistitemdelegate.cpp b/src/libtomahawk/playlist/playlistitemdelegate.cpp index b6d7b4f88..dd9a4ef16 100644 --- a/src/libtomahawk/playlist/playlistitemdelegate.cpp +++ b/src/libtomahawk/playlist/playlistitemdelegate.cpp @@ -258,8 +258,8 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt if ( m_view->header()->visualIndex( index.column() ) == 0 ) { r.adjust( 0, 0, 0, -3 ); - painter->drawPixmap( r.adjusted( 3, 3, 18 - r.width(), 0 ), m_nowPlayingIcon ); - r.adjust( 22, 0, 0, 3 ); + painter->drawPixmap( r.adjusted( 3, 1, 18 - r.width(), 1 ), m_nowPlayingIcon ); + r.adjust( 25, 0, 0, 3 ); } painter->setPen( opt.palette.text().color() ); diff --git a/src/libtomahawk/playlist/treeitemdelegate.cpp b/src/libtomahawk/playlist/treeitemdelegate.cpp index 3ad8e2cc8..c42b51ee6 100644 --- a/src/libtomahawk/playlist/treeitemdelegate.cpp +++ b/src/libtomahawk/playlist/treeitemdelegate.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "query.h" #include "result.h" @@ -30,13 +31,15 @@ #include "treemodelitem.h" #include "treeproxymodel.h" +#include "artistview.h" -TreeItemDelegate::TreeItemDelegate( QAbstractItemView* parent, TreeProxyModel* proxy ) +TreeItemDelegate::TreeItemDelegate( ArtistView* parent, TreeProxyModel* proxy ) : QStyledItemDelegate( (QObject*)parent ) , m_view( parent ) , m_model( proxy ) { + m_nowPlayingIcon = QPixmap( RESPATH "images/now-playing-speaker.png" ); } @@ -82,8 +85,27 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, o.state |= QStyle::State_Selected; } - return QStyledItemDelegate::paint( painter, o, index ); + qApp->style()->drawControl( QStyle::CE_ItemViewItem, &o, painter ); + + { + QRect r = o.rect.adjusted( 3, 0, 0, 0 ); + + // Paint Now Playing Speaker Icon + if ( item->isPlaying() && m_view->header()->visualIndex( index.column() ) == 0 ) + { + r.adjust( 0, 0, 0, -3 ); + painter->drawPixmap( r.adjusted( 3, 1, 18 - r.width(), 1 ), m_nowPlayingIcon ); + r.adjust( 25, 0, 0, 3 ); + } + + painter->setPen( o.palette.text().color() ); + + QTextOption to( Qt::AlignVCenter ); + QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 ); + painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, to ); + } } + return; } else return; diff --git a/src/libtomahawk/playlist/treeitemdelegate.h b/src/libtomahawk/playlist/treeitemdelegate.h index 234b0d326..5074305e0 100644 --- a/src/libtomahawk/playlist/treeitemdelegate.h +++ b/src/libtomahawk/playlist/treeitemdelegate.h @@ -23,6 +23,7 @@ #include "dllmacro.h" +class ArtistView; class TreeProxyModel; class DLLEXPORT TreeItemDelegate : public QStyledItemDelegate @@ -30,7 +31,7 @@ class DLLEXPORT TreeItemDelegate : public QStyledItemDelegate Q_OBJECT public: - TreeItemDelegate( QAbstractItemView* parent = 0, TreeProxyModel* proxy = 0 ); + TreeItemDelegate( ArtistView* parent = 0, TreeProxyModel* proxy = 0 ); protected: void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; @@ -39,8 +40,10 @@ protected: // QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const; private: - QAbstractItemView* m_view; + ArtistView* m_view; TreeProxyModel* m_model; + + QPixmap m_nowPlayingIcon; }; #endif // TREEITEMDELEGATE_H diff --git a/src/libtomahawk/playlist/treemodel.cpp b/src/libtomahawk/playlist/treemodel.cpp index 020a21a78..c57d17b94 100644 --- a/src/libtomahawk/playlist/treemodel.cpp +++ b/src/libtomahawk/playlist/treemodel.cpp @@ -215,12 +215,6 @@ TreeModel::data( const QModelIndex& index, int role ) const return QSize( 128, 0 ); } - if ( role == Qt::DecorationRole ) - { - if ( entry->isPlaying() && index.column() == 0 ) - return QPixmap( RESPATH "images/now-playing-speaker.png" ); - } - if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole ) return QVariant();