From 87dd871c6c614e0456f6827ae3b3c5f1b7b70f0d Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 14 Jun 2012 21:46:17 +0200 Subject: [PATCH] * GridView now supports auto-resizing to fit its contents. --- src/libtomahawk/playlist/GridView.cpp | 8 ++++++++ src/libtomahawk/playlist/GridView.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/libtomahawk/playlist/GridView.cpp b/src/libtomahawk/playlist/GridView.cpp index 35eeb558a..3d935b876 100644 --- a/src/libtomahawk/playlist/GridView.cpp +++ b/src/libtomahawk/playlist/GridView.cpp @@ -74,6 +74,7 @@ GridView::GridView( QWidget* parent ) setStyleSheet( "QListView { background-color: #323435; }" ); setAutoFitItems( true ); + setAutoResize( false ); setProxyModel( new PlayableProxyModel( this ) ); /* m_overlay->setText( tr( "After you have scanned your music collection you will find your latest album additions right here." ) ); @@ -221,6 +222,13 @@ GridView::layoutItems() m_model->setItemSize( QSize( newItemWidth, newItemWidth ) ); + if ( autoResize() ) + { + int rows = ceil( (double)m_proxyModel->rowCount( QModelIndex() ) / (double)itemsPerRow ); + int newHeight = rows * newItemWidth; + setFixedHeight( newHeight ); + } + if ( !m_inited ) { m_inited = true; diff --git a/src/libtomahawk/playlist/GridView.h b/src/libtomahawk/playlist/GridView.h index a69120969..ffb5befa9 100644 --- a/src/libtomahawk/playlist/GridView.h +++ b/src/libtomahawk/playlist/GridView.h @@ -54,6 +54,9 @@ public: bool autoFitItems() const { return m_autoFitItems; } void setAutoFitItems( bool b ) { m_autoFitItems = b; } + bool autoResize() const { return m_autoResize; } + void setAutoResize( bool b ) { m_autoResize = b; } + void setPlayableModel( PlayableModel* model ); void setModel( QAbstractItemModel* model ); @@ -105,6 +108,7 @@ private: QString m_emptyTip; bool m_inited; bool m_autoFitItems; + bool m_autoResize; QRect m_paintRect; };