1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

* Moved itemSize from model to delegate.

This commit is contained in:
Christian Muehlhaeuser
2012-07-02 23:10:24 +02:00
parent 1860d7732a
commit bd629e6178
4 changed files with 17 additions and 7 deletions

View File

@@ -63,10 +63,15 @@ GridItemDelegate::GridItemDelegate( QAbstractItemView* parent, PlayableProxyMode
QSize QSize
GridItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const GridItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
if ( m_itemSize.isNull() )
{ {
QSize size = QStyledItemDelegate::sizeHint( option, index ); QSize size = QStyledItemDelegate::sizeHint( option, index );
return size; return size;
} }
else
return m_itemSize;
}
void void

View File

@@ -41,6 +41,9 @@ Q_OBJECT
public: public:
GridItemDelegate( QAbstractItemView* parent = 0, PlayableProxyModel* proxy = 0 ); GridItemDelegate( QAbstractItemView* parent = 0, PlayableProxyModel* proxy = 0 );
QSize itemSize() const { return m_itemSize; }
void setItemSize( const QSize& size ) { m_itemSize = size; }
protected: protected:
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
@@ -70,6 +73,7 @@ private:
QAbstractItemView* m_view; QAbstractItemView* m_view;
PlayableProxyModel* m_model; PlayableProxyModel* m_model;
QSize m_itemSize;
mutable QHash< QPersistentModelIndex, QRect > m_artistNameRects; mutable QHash< QPersistentModelIndex, QRect > m_artistNameRects;
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_covers; mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_covers;

View File

@@ -229,7 +229,7 @@ GridView::verifySize()
const int overlapRows = m_model->rowCount( QModelIndex() ) % itemsPerRow; const int overlapRows = m_model->rowCount( QModelIndex() ) % itemsPerRow;
const int rows = floor( (double)m_model->rowCount( QModelIndex() ) / (double)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 ) if ( newHeight > 0 )
setFixedHeight( newHeight ); setFixedHeight( newHeight );
@@ -258,7 +258,7 @@ GridView::layoutItems()
const int extraSpace = remSpace / itemsPerRow; const int extraSpace = remSpace / itemsPerRow;
const int newItemWidth = itemWidth + extraSpace; const int newItemWidth = itemWidth + extraSpace;
m_model->setItemSize( QSize( newItemWidth, newItemWidth ) ); m_delegate->setItemSize( QSize( newItemWidth, newItemWidth ) );
verifySize(); verifySize();
if ( !m_inited ) if ( !m_inited )

View File

@@ -50,6 +50,7 @@ public:
PlayableModel* model() const { return m_model; } PlayableModel* model() const { return m_model; }
PlayableProxyModel* proxyModel() const { return m_proxyModel; } PlayableProxyModel* proxyModel() const { return m_proxyModel; }
GridItemDelegate* delegate() const { return m_delegate; }
bool autoFitItems() const { return m_autoFitItems; } bool autoFitItems() const { return m_autoFitItems; }
void setAutoFitItems( bool b ) { m_autoFitItems = b; } void setAutoFitItems( bool b ) { m_autoFitItems = b; }