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:
parent
bcf9475f2b
commit
6200983dbc
@ -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(),
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user