From bc3824dfad5f4aa3f7b8bf68b168fa673f68fcad Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 23 Dec 2012 18:52:56 +0100 Subject: [PATCH] * Fixed default row-height for TreeItemDelegate. --- src/libtomahawk/playlist/TreeItemDelegate.cpp | 29 +++++++++++++++++++ src/libtomahawk/playlist/TreeItemDelegate.h | 4 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/TreeItemDelegate.cpp b/src/libtomahawk/playlist/TreeItemDelegate.cpp index 207feca47..de7776f76 100644 --- a/src/libtomahawk/playlist/TreeItemDelegate.cpp +++ b/src/libtomahawk/playlist/TreeItemDelegate.cpp @@ -45,6 +45,35 @@ TreeItemDelegate::TreeItemDelegate( TreeView* parent, TreeProxyModel* proxy ) } +QSize +TreeItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const +{ + QSize size = QStyledItemDelegate::sizeHint( option, index ); + + if ( index.isValid() ) + { + PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); + if ( item ) + { + if ( item->album() ) + { + size.setHeight( option.fontMetrics.height() * 3 ); + return size; + } + else if ( item->query() || item->result() ) + { + size.setHeight( option.fontMetrics.height() * 1.6 ); + return size; + } + } + } + + // artist per default + size.setHeight( option.fontMetrics.height() * 4 ); + return size; +} + + void TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { diff --git a/src/libtomahawk/playlist/TreeItemDelegate.h b/src/libtomahawk/playlist/TreeItemDelegate.h index 84dc69f45..7f80e50e7 100644 --- a/src/libtomahawk/playlist/TreeItemDelegate.h +++ b/src/libtomahawk/playlist/TreeItemDelegate.h @@ -36,7 +36,9 @@ class DLLEXPORT TreeItemDelegate : public QStyledItemDelegate Q_OBJECT public: - TreeItemDelegate( TreeView* parent = 0, TreeProxyModel* proxy = 0 ); + TreeItemDelegate( TreeView* parent, TreeProxyModel* proxy ); + + virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; protected: void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;