From 86422655ef6dbaf369294795d8b3ee7b96ac45ee Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 12 Jun 2013 13:35:11 +0200 Subject: [PATCH] * Auto-resize PlaylistWidget. --- src/libtomahawk/widgets/Dashboard.cpp | 20 ++++++++++++++++++-- src/libtomahawk/widgets/Dashboard.h | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/widgets/Dashboard.cpp b/src/libtomahawk/widgets/Dashboard.cpp index 7aeb3c2f1..e74b37e2a 100644 --- a/src/libtomahawk/widgets/Dashboard.cpp +++ b/src/libtomahawk/widgets/Dashboard.cpp @@ -43,7 +43,6 @@ #include #include - #define HISTORY_PLAYLIST_ITEMS 10 #define HISTORY_TRACK_ITEMS 15 @@ -243,7 +242,7 @@ void Dashboard::onPlaylistActivated( const QModelIndex& item ) { Tomahawk::playlist_ptr pl = item.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >(); - if( Tomahawk::dynplaylist_ptr dynplaylist = pl.dynamicCast< Tomahawk::DynamicPlaylist >() ) + if ( Tomahawk::dynplaylist_ptr dynplaylist = pl.dynamicCast< Tomahawk::DynamicPlaylist >() ) ViewManager::instance()->show( dynplaylist ); else ViewManager::instance()->show( pl ); @@ -412,5 +411,22 @@ void PlaylistWidget::setModel( QAbstractItemModel* model ) { QListView::setModel( model ); + + connect( model, SIGNAL( modelReset() ), SLOT( verifySize() ) ); + connect( model, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( verifySize() ) ); + connect( model, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( verifySize() ) ); + emit modelChanged(); + verifySize(); } + + +void +PlaylistWidget::verifySize() +{ + if ( !model() ) + return; + + if ( model()->rowCount() > 0 ) + setFixedHeight( model()->rowCount() * itemDelegate()->sizeHint( QStyleOptionViewItem(), model()->index( 0, 0 ) ).height() + frameWidth() * 2 ); +} \ No newline at end of file diff --git a/src/libtomahawk/widgets/Dashboard.h b/src/libtomahawk/widgets/Dashboard.h index 69824cc8b..f8372b2af 100644 --- a/src/libtomahawk/widgets/Dashboard.h +++ b/src/libtomahawk/widgets/Dashboard.h @@ -73,6 +73,9 @@ public: signals: void modelChanged(); +private slots: + void verifySize(); + private: OverlayWidget* m_overlay; };