mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
* Greatly improved sidebar performance by pre-caching all QIcons.
This commit is contained in:
parent
a65d037def
commit
ea21848811
@ -39,6 +39,7 @@ CategoryAddItem::CategoryAddItem( SourcesModel* model, SourceTreeItem* parent, S
|
||||
: SourceTreeItem( model, parent, SourcesModel::CategoryAdd )
|
||||
, m_categoryType( type )
|
||||
{
|
||||
m_icon = QIcon( RESPATH "images/add.png" );
|
||||
}
|
||||
|
||||
|
||||
@ -125,7 +126,7 @@ CategoryAddItem::flags() const
|
||||
QIcon
|
||||
CategoryAddItem::icon() const
|
||||
{
|
||||
return QIcon( RESPATH "images/add.png" );
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,6 +42,7 @@ private slots:
|
||||
|
||||
private:
|
||||
SourcesModel::CategoryType m_categoryType;
|
||||
QIcon m_icon;
|
||||
};
|
||||
|
||||
class CategoryItem : public SourceTreeItem
|
||||
|
@ -185,7 +185,7 @@ CollectionItem::activate()
|
||||
QIcon
|
||||
CollectionItem::icon() const
|
||||
{
|
||||
if( m_source.isNull() )
|
||||
if ( m_source.isNull() )
|
||||
return m_superCol;
|
||||
else
|
||||
{
|
||||
|
@ -43,6 +43,8 @@ PlaylistItem::PlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const pla
|
||||
connect( pl.data(), SIGNAL( changed() ),
|
||||
SIGNAL( updated() ), Qt::QueuedConnection );
|
||||
|
||||
m_icon = QIcon( RESPATH "images/playlist-icon.png" );
|
||||
|
||||
if( ViewManager::instance()->pageForPlaylist( pl ) )
|
||||
model()->linkSourceItemToPage( this, ViewManager::instance()->pageForPlaylist( pl ) );
|
||||
}
|
||||
@ -213,7 +215,7 @@ PlaylistItem::parsedDroppedTracks( const QList< query_ptr >& tracks)
|
||||
QIcon
|
||||
PlaylistItem::icon() const
|
||||
{
|
||||
return QIcon( RESPATH "images/playlist-icon.png" );
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
|
||||
@ -255,6 +257,9 @@ DynamicPlaylistItem::DynamicPlaylistItem( SourcesModel* mdl, SourceTreeItem* par
|
||||
connect( pl.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ),
|
||||
SLOT( onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision ) ), Qt::QueuedConnection );
|
||||
|
||||
m_stationIcon = QIcon( RESPATH "images/station.png" );
|
||||
m_automaticPlaylistIcon = QIcon( RESPATH "images/automatic-playlist.png" );
|
||||
|
||||
if( ViewManager::instance()->pageForDynPlaylist( pl ) )
|
||||
model()->linkSourceItemToPage( this, ViewManager::instance()->pageForDynPlaylist( pl ) );
|
||||
}
|
||||
@ -379,10 +384,13 @@ DynamicPlaylistItem::willAcceptDrag( const QMimeData* data ) const
|
||||
QIcon
|
||||
DynamicPlaylistItem::icon() const
|
||||
{
|
||||
if( m_dynplaylist->mode() == OnDemand ) {
|
||||
return QIcon( RESPATH "images/station.png" );
|
||||
} else {
|
||||
return QIcon( RESPATH "images/automatic-playlist.png" );
|
||||
if ( m_dynplaylist->mode() == OnDemand )
|
||||
{
|
||||
return m_stationIcon;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_automaticPlaylistIcon;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ private slots:
|
||||
private:
|
||||
bool m_loaded;
|
||||
Tomahawk::playlist_ptr m_playlist;
|
||||
QIcon m_icon;
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::DropTypes)
|
||||
|
||||
@ -74,6 +75,7 @@ public:
|
||||
virtual QIcon icon() const;
|
||||
|
||||
virtual SourceTreeItem* activateCurrent();
|
||||
|
||||
private slots:
|
||||
void onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision revision );
|
||||
|
||||
@ -81,6 +83,9 @@ private:
|
||||
void checkReparentHackNeeded( const Tomahawk::DynamicPlaylistRevision& rev );
|
||||
|
||||
Tomahawk::dynplaylist_ptr m_dynplaylist;
|
||||
|
||||
QIcon m_stationIcon;
|
||||
QIcon m_automaticPlaylistIcon;
|
||||
};
|
||||
|
||||
|
||||
|
@ -74,7 +74,9 @@ SourceDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex&
|
||||
SourceTreeItem *item = index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >();
|
||||
|
||||
if ( index.data( SourcesModel::SourceTreeItemTypeRole ).toInt() == SourcesModel::Collection )
|
||||
{
|
||||
return QSize( option.rect.width(), 44 );
|
||||
}
|
||||
else if ( m_expandedMap.contains( index ) )
|
||||
{
|
||||
if ( !m_expandedMap.value( index )->initialized() )
|
||||
@ -214,24 +216,24 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
||||
|
||||
// Get whole rect for the menu
|
||||
QRect itemsRect = option.rect.adjusted( -option.rect.x(), m_expandedMap.value( index )->originalSize().height(), 0, 0 );
|
||||
|
||||
QPoint cursorPos = m_parent->mapFromGlobal( QCursor::pos() );
|
||||
bool cursorInRect = false;
|
||||
if ( itemsRect.contains( cursorPos ) )
|
||||
cursorInRect = true;
|
||||
bool cursorInRect = itemsRect.contains( cursorPos );
|
||||
|
||||
// draw the background
|
||||
QLinearGradient linearGradient( itemsRect.topLeft(), itemsRect.bottomLeft() );
|
||||
linearGradient.setColorAt( 0.0, Qt::white );
|
||||
// linearGradient.setColorAt( 0.8, QColor( 0xd6, 0xd6, 0xd6 ) ); // light grey
|
||||
// linearGradient.setColorAt( 1.0, QColor( 0xf4, 0x17, 0x05 ) ); // dark red
|
||||
// linearGradient.setColorAt( 1.0, QColor( 0xb1, 0xb1, 0xb1 ) ); // not so light but still not dark grey
|
||||
linearGradient.setColorAt( 0.9, QColor( 0x88, 0x88, 0x88 ) );
|
||||
linearGradient.setColorAt( 1.0, QColor( 0x99, 0x99, 0x99 ) ); // dark grey
|
||||
if ( m_gradient.finalStop() != itemsRect.bottomLeft() )
|
||||
{
|
||||
m_gradient = QLinearGradient( itemsRect.topLeft(), itemsRect.bottomLeft() );
|
||||
m_gradient.setColorAt( 0.0, Qt::white );
|
||||
// m_gradient.setColorAt( 0.8, QColor( 0xd6, 0xd6, 0xd6 ) ); // light grey
|
||||
// m_gradient.setColorAt( 1.0, QColor( 0xf4, 0x17, 0x05 ) ); // dark red
|
||||
// m_gradient.setColorAt( 1.0, QColor( 0xb1, 0xb1, 0xb1 ) ); // not so light but still not dark grey
|
||||
m_gradient.setColorAt( 0.9, QColor( 0x88, 0x88, 0x88 ) );
|
||||
m_gradient.setColorAt( 1.0, QColor( 0x99, 0x99, 0x99 ) ); // dark grey
|
||||
}
|
||||
|
||||
QPen pen = painter->pen();
|
||||
painter->setPen( QPen( Qt::NoPen ) );
|
||||
painter->setBrush( linearGradient );
|
||||
painter->setBrush( m_gradient );
|
||||
painter->drawRect( itemsRect );
|
||||
|
||||
// calculate sizes for the icons
|
||||
@ -253,7 +255,6 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
||||
|
||||
QRect textRect;
|
||||
QRect imageRect;
|
||||
|
||||
SourceTreeItem::DropTypes dropTypes = item->supportedDropTypes( m_dropMimeData );
|
||||
|
||||
int count = 0;
|
||||
@ -303,11 +304,11 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
||||
{
|
||||
// draw close icon
|
||||
int padding = 3;
|
||||
m_iconHeight = ( o3.rect.height() - 2*padding );
|
||||
m_iconHeight = ( o3.rect.height() - 2 * padding );
|
||||
QPixmap p( RESPATH "images/list-remove.png" );
|
||||
p = p.scaledToHeight( m_iconHeight, Qt::SmoothTransformation );
|
||||
|
||||
QRect r ( o3.rect.right() - padding - m_iconHeight, padding + o3.rect.y(), m_iconHeight, m_iconHeight );
|
||||
QRect r( o3.rect.right() - padding - m_iconHeight, padding + o3.rect.y(), m_iconHeight, m_iconHeight );
|
||||
painter->drawPixmap( r, p );
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ protected:
|
||||
|
||||
private slots:
|
||||
void animationFinished( const QModelIndex& );
|
||||
|
||||
private:
|
||||
QAbstractItemView* m_parent;
|
||||
mutable int m_iconHeight;
|
||||
@ -63,6 +64,7 @@ private:
|
||||
QMap< int, QString > m_dropTypeTextMap;
|
||||
QMap< int, QPixmap > m_dropTypeImageMap;
|
||||
|
||||
mutable QLinearGradient m_gradient;
|
||||
};
|
||||
|
||||
#endif // SOURCEDELEGATE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user