1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00

Add pixmap cache to source icons.

This commit is contained in:
John Maguire 2012-01-04 12:04:17 +00:00
parent bcf9475f2b
commit 6200983dbc
2 changed files with 22 additions and 7 deletions

View File

@ -444,13 +444,13 @@ QString SongSourceDelegate::displayText(const QVariant& value, const QLocale&) c
return ""; return "";
} }
void SongSourceDelegate::paint( QPixmap SongSourceDelegate::LookupPixmap(const QUrl& url, const QSize& size) const {
QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QPixmap pixmap;
PlaylistDelegateBase::paint(painter, option, index); if (cache_.find(url.scheme(), &pixmap)) {
QStyleOptionViewItem option_copy(option); return pixmap;
initStyleOption(&option_copy, index); }
QIcon icon; QIcon icon;
const QUrl& url = index.data().toUrl();
const UrlHandler* handler = player_->HandlerForUrl(url); const UrlHandler* handler = player_->HandlerForUrl(url);
if (handler) { if (handler) {
icon = handler->icon(); icon = handler->icon();
@ -461,7 +461,18 @@ void SongSourceDelegate::paint(
icon = IconLoader::Load("folder-sound"); icon = IconLoader::Load("folder-sound");
} }
} }
QPixmap pixmap = icon.pixmap(option_copy.decorationSize.height()); pixmap = icon.pixmap(size.height());
cache_.insert(url.scheme(), pixmap);
return pixmap;
}
void SongSourceDelegate::paint(
QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
PlaylistDelegateBase::paint(painter, option, index);
QStyleOptionViewItem option_copy(option);
initStyleOption(&option_copy, index);
const QUrl& url = index.data().toUrl();
QPixmap pixmap = LookupPixmap(url, option_copy.decorationSize);
const int margin = (option_copy.rect.width() - pixmap.width()) / 2; const int margin = (option_copy.rect.width() - pixmap.width()) / 2;
QRect draw_rect( QRect draw_rect(
margin + option_copy.rect.x(), margin + option_copy.rect.x(),

View File

@ -23,6 +23,7 @@
#include "widgets/ratingwidget.h" #include "widgets/ratingwidget.h"
#include <QCompleter> #include <QCompleter>
#include <QPixmapCache>
#include <QStringListModel> #include <QStringListModel>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QTreeView> #include <QTreeView>
@ -183,7 +184,10 @@ class SongSourceDelegate : public PlaylistDelegateBase {
void paint(QPainter* paint, const QStyleOptionViewItem& option, const QModelIndex& index) const; void paint(QPainter* paint, const QStyleOptionViewItem& option, const QModelIndex& index) const;
private: private:
QPixmap LookupPixmap(const QUrl& url, const QSize& size) const;
Player* player_; Player* player_;
mutable QPixmapCache cache_;
}; };
#endif // PLAYLISTDELEGATES_H #endif // PLAYLISTDELEGATES_H