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 "";
}
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);
QPixmap SongSourceDelegate::LookupPixmap(const QUrl& url, const QSize& size) const {
QPixmap pixmap;
if (cache_.find(url.scheme(), &pixmap)) {
return pixmap;
}
QIcon icon;
const QUrl& url = index.data().toUrl();
const UrlHandler* handler = player_->HandlerForUrl(url);
if (handler) {
icon = handler->icon();
@ -461,7 +461,18 @@ void SongSourceDelegate::paint(
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;
QRect draw_rect(
margin + option_copy.rect.x(),

View File

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