From ab026b5e2f4f5cd46726865b190ea903dad96d34 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 9 Mar 2012 14:56:34 -0500 Subject: [PATCH] Remove hardcoding of delegate height to accomodate different font sizes --- src/AccountDelegate.cpp | 24 +++++++++++++++--------- src/AccountDelegate.h | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/AccountDelegate.cpp b/src/AccountDelegate.cpp index 4af815b76..57a00a941 100644 --- a/src/AccountDelegate.cpp +++ b/src/AccountDelegate.cpp @@ -34,12 +34,6 @@ #define PADDING_BETWEEN_STARS 2 #define STAR_SIZE 12 -#ifdef Q_WS_MAC -#define TOPLEVEL_ACCOUNT_HEIGHT 72 -#else -#define TOPLEVEL_ACCOUNT_HEIGHT 68 -#endif - #define ICONSIZE 40 #define WRENCH_SIZE 24 #define SMALL_WRENCH_SIZE 16 @@ -52,6 +46,7 @@ using namespace Accounts; AccountDelegate::AccountDelegate( QObject* parent ) : QStyledItemDelegate ( parent ) + , m_accountRowHeight( -1 ) { m_defaultCover.load( RESPATH "images/sipplugin-online.png" ); @@ -75,11 +70,22 @@ AccountDelegate::AccountDelegate( QObject* parent ) QSize -AccountDelegate::sizeHint( const QStyleOptionViewItem&, const QModelIndex& index ) const +AccountDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const { AccountModel::RowType rowType = static_cast< AccountModel::RowType >( index.data( AccountModel::RowTypeRole ).toInt() ); + if ( m_accountRowHeight < 0 ) + { + // Haven't calculated normal item height yet, do it once and save it + QStyleOptionViewItemV4 opt( option ); + initStyleOption( &opt, index ); + m_accountRowHeight = 6 * opt.fontMetrics.height(); + } + if ( rowType == AccountModel::TopLevelAccount || rowType == AccountModel::UniqueFactory || rowType == AccountModel::CustomAccount ) - return QSize( 200, TOPLEVEL_ACCOUNT_HEIGHT ); + { + + return QSize( 200, m_accountRowHeight ); + } else if ( rowType == AccountModel::TopLevelFactory ) { // Make more space for each account we have to show. @@ -88,7 +94,7 @@ AccountDelegate::sizeHint( const QStyleOptionViewItem&, const QModelIndex& index return QSize( 200, TOPLEVEL_ACCOUNT_HEIGHT ); const QList< Account* > accts = index.data( AccountModel::ChildrenOfFactoryRole ).value< QList< Tomahawk::Accounts::Account* > >(); - const QSize s = QSize( 200, TOPLEVEL_ACCOUNT_HEIGHT + 12 * accts.size()-1 ); + const QSize s = QSize( 200, m_accountRowHeight + 12 * accts.size()-1 ); if ( s != m_sizeHints[ index ] ) const_cast< AccountDelegate* >( this )->sizeHintChanged( index ); // FU KTHBBQ diff --git a/src/AccountDelegate.h b/src/AccountDelegate.h index 6787489b4..01c7f6a9c 100644 --- a/src/AccountDelegate.h +++ b/src/AccountDelegate.h @@ -64,6 +64,7 @@ private: mutable QHash< QPersistentModelIndex, QRect > m_cachedStarRects; mutable QHash< QPersistentModelIndex, QRect > m_cachedConfigRects; mutable QHash< QPersistentModelIndex, QSize > m_sizeHints; + mutable int m_accountRowHeight; }; }