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:
@@ -64,8 +64,13 @@ 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
|
||||||
{
|
{
|
||||||
QSize size = QStyledItemDelegate::sizeHint( option, index );
|
if ( m_itemSize.isNull() )
|
||||||
return size;
|
{
|
||||||
|
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
|
// reset mouse cursor. we switch to a pointing hand cursor when hovering an artist name
|
||||||
m_view->setCursor( Qt::ArrowCursor );
|
m_view->setCursor( Qt::ArrowCursor );
|
||||||
|
|
||||||
if ( hoveringArtist )
|
if ( hoveringArtist )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@@ -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;
|
||||||
|
@@ -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 );
|
||||||
@@ -257,8 +257,8 @@ GridView::layoutItems()
|
|||||||
const int remSpace = rectWidth - ( itemsPerRow * itemWidth );
|
const int remSpace = rectWidth - ( itemsPerRow * itemWidth );
|
||||||
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 )
|
||||||
|
@@ -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; }
|
||||||
@@ -111,7 +112,7 @@ private:
|
|||||||
bool m_inited;
|
bool m_inited;
|
||||||
bool m_autoFitItems;
|
bool m_autoFitItems;
|
||||||
bool m_autoResize;
|
bool m_autoResize;
|
||||||
|
|
||||||
QRect m_paintRect;
|
QRect m_paintRect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user