1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Remove hardcoding of delegate height to accomodate different font sizes

This commit is contained in:
Leo Franchi 2012-03-09 14:56:34 -05:00
parent 99aea14b62
commit ab026b5e2f
2 changed files with 16 additions and 9 deletions

View File

@ -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

View File

@ -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;
};
}