mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Remove hardcoding of delegate height to accomodate different font sizes
This commit is contained in:
@@ -34,12 +34,6 @@
|
|||||||
#define PADDING_BETWEEN_STARS 2
|
#define PADDING_BETWEEN_STARS 2
|
||||||
#define STAR_SIZE 12
|
#define STAR_SIZE 12
|
||||||
|
|
||||||
#ifdef Q_WS_MAC
|
|
||||||
#define TOPLEVEL_ACCOUNT_HEIGHT 72
|
|
||||||
#else
|
|
||||||
#define TOPLEVEL_ACCOUNT_HEIGHT 68
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ICONSIZE 40
|
#define ICONSIZE 40
|
||||||
#define WRENCH_SIZE 24
|
#define WRENCH_SIZE 24
|
||||||
#define SMALL_WRENCH_SIZE 16
|
#define SMALL_WRENCH_SIZE 16
|
||||||
@@ -52,6 +46,7 @@ using namespace Accounts;
|
|||||||
|
|
||||||
AccountDelegate::AccountDelegate( QObject* parent )
|
AccountDelegate::AccountDelegate( QObject* parent )
|
||||||
: QStyledItemDelegate ( parent )
|
: QStyledItemDelegate ( parent )
|
||||||
|
, m_accountRowHeight( -1 )
|
||||||
{
|
{
|
||||||
|
|
||||||
m_defaultCover.load( RESPATH "images/sipplugin-online.png" );
|
m_defaultCover.load( RESPATH "images/sipplugin-online.png" );
|
||||||
@@ -75,11 +70,22 @@ AccountDelegate::AccountDelegate( QObject* parent )
|
|||||||
|
|
||||||
|
|
||||||
QSize
|
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() );
|
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 )
|
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 )
|
else if ( rowType == AccountModel::TopLevelFactory )
|
||||||
{
|
{
|
||||||
// Make more space for each account we have to show.
|
// 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 );
|
return QSize( 200, TOPLEVEL_ACCOUNT_HEIGHT );
|
||||||
|
|
||||||
const QList< Account* > accts = index.data( AccountModel::ChildrenOfFactoryRole ).value< QList< Tomahawk::Accounts::Account* > >();
|
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 ] )
|
if ( s != m_sizeHints[ index ] )
|
||||||
const_cast< AccountDelegate* >( this )->sizeHintChanged( index ); // FU KTHBBQ
|
const_cast< AccountDelegate* >( this )->sizeHintChanged( index ); // FU KTHBBQ
|
||||||
|
@@ -64,6 +64,7 @@ private:
|
|||||||
mutable QHash< QPersistentModelIndex, QRect > m_cachedStarRects;
|
mutable QHash< QPersistentModelIndex, QRect > m_cachedStarRects;
|
||||||
mutable QHash< QPersistentModelIndex, QRect > m_cachedConfigRects;
|
mutable QHash< QPersistentModelIndex, QRect > m_cachedConfigRects;
|
||||||
mutable QHash< QPersistentModelIndex, QSize > m_sizeHints;
|
mutable QHash< QPersistentModelIndex, QSize > m_sizeHints;
|
||||||
|
mutable int m_accountRowHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user