From bd629e6178f273c8e7d1fea48473ff7595fa8e9d Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 2 Jul 2012 23:10:24 +0200 Subject: [PATCH] * Moved itemSize from model to delegate. --- src/libtomahawk/playlist/GridItemDelegate.cpp | 11 ++++++++--- src/libtomahawk/playlist/GridItemDelegate.h | 4 ++++ src/libtomahawk/playlist/GridView.cpp | 6 +++--- src/libtomahawk/playlist/GridView.h | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/libtomahawk/playlist/GridItemDelegate.cpp b/src/libtomahawk/playlist/GridItemDelegate.cpp index f64aee9f1..66472f2d6 100644 --- a/src/libtomahawk/playlist/GridItemDelegate.cpp +++ b/src/libtomahawk/playlist/GridItemDelegate.cpp @@ -64,8 +64,13 @@ GridItemDelegate::GridItemDelegate( QAbstractItemView* parent, PlayableProxyMode QSize GridItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const { - QSize size = QStyledItemDelegate::sizeHint( option, index ); - return size; + if ( m_itemSize.isNull() ) + { + QSize size = QStyledItemDelegate::sizeHint( option, index ); + return size; + } + else + return m_itemSize; } @@ -363,7 +368,7 @@ GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q // reset mouse cursor. we switch to a pointing hand cursor when hovering an artist name m_view->setCursor( Qt::ArrowCursor ); - + if ( hoveringArtist ) { diff --git a/src/libtomahawk/playlist/GridItemDelegate.h b/src/libtomahawk/playlist/GridItemDelegate.h index 89474a91b..7409f0fdd 100644 --- a/src/libtomahawk/playlist/GridItemDelegate.h +++ b/src/libtomahawk/playlist/GridItemDelegate.h @@ -41,6 +41,9 @@ Q_OBJECT public: GridItemDelegate( QAbstractItemView* parent = 0, PlayableProxyModel* proxy = 0 ); + QSize itemSize() const { return m_itemSize; } + void setItemSize( const QSize& size ) { m_itemSize = size; } + protected: void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; @@ -70,6 +73,7 @@ private: QAbstractItemView* m_view; PlayableProxyModel* m_model; + QSize m_itemSize; mutable QHash< QPersistentModelIndex, QRect > m_artistNameRects; mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_covers; diff --git a/src/libtomahawk/playlist/GridView.cpp b/src/libtomahawk/playlist/GridView.cpp index 7726c2478..912db36e0 100644 --- a/src/libtomahawk/playlist/GridView.cpp +++ b/src/libtomahawk/playlist/GridView.cpp @@ -229,7 +229,7 @@ GridView::verifySize() const int overlapRows = m_model->rowCount( QModelIndex() ) % itemsPerRow; const int rows = floor( (double)m_model->rowCount( QModelIndex() ) / (double)itemsPerRow ); - const int newHeight = rows * m_model->itemSize().height(); + const int newHeight = rows * m_delegate->itemSize().height(); if ( newHeight > 0 ) setFixedHeight( newHeight ); @@ -257,8 +257,8 @@ GridView::layoutItems() const int remSpace = rectWidth - ( itemsPerRow * itemWidth ); const int extraSpace = remSpace / itemsPerRow; const int newItemWidth = itemWidth + extraSpace; - - m_model->setItemSize( QSize( newItemWidth, newItemWidth ) ); + + m_delegate->setItemSize( QSize( newItemWidth, newItemWidth ) ); verifySize(); if ( !m_inited ) diff --git a/src/libtomahawk/playlist/GridView.h b/src/libtomahawk/playlist/GridView.h index 4326f84ed..e3cbd7a5c 100644 --- a/src/libtomahawk/playlist/GridView.h +++ b/src/libtomahawk/playlist/GridView.h @@ -50,6 +50,7 @@ public: PlayableModel* model() const { return m_model; } PlayableProxyModel* proxyModel() const { return m_proxyModel; } + GridItemDelegate* delegate() const { return m_delegate; } bool autoFitItems() const { return m_autoFitItems; } void setAutoFitItems( bool b ) { m_autoFitItems = b; } @@ -111,7 +112,7 @@ private: bool m_inited; bool m_autoFitItems; bool m_autoResize; - + QRect m_paintRect; };