1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2025-02-09 00:08:43 +01:00

Use static QPixmapCache everywhere

This commit is contained in:
Jonas Kvinge 2021-07-11 01:43:52 +02:00
parent b8b21d53e1
commit f21be30004
5 changed files with 7 additions and 11 deletions

View File

@ -43,6 +43,7 @@
#include <QUrl> #include <QUrl>
#include <QImage> #include <QImage>
#include <QPixmap> #include <QPixmap>
#include <QPixmapCache>
#include <QPainter> #include <QPainter>
#include <QPalette> #include <QPalette>
#include <QColor> #include <QColor>
@ -794,7 +795,7 @@ QString InternetSearchView::PixmapCacheKey(const InternetSearchView::Result &res
} }
bool InternetSearchView::FindCachedPixmap(const InternetSearchView::Result &result, QPixmap *pixmap) const { bool InternetSearchView::FindCachedPixmap(const InternetSearchView::Result &result, QPixmap *pixmap) const {
return pixmap_cache_.find(result.pixmap_cache_key_, pixmap); return QPixmapCache::find(result.pixmap_cache_key_, pixmap);
} }
void InternetSearchView::LazyLoadAlbumCover(const QModelIndex &proxy_index) { void InternetSearchView::LazyLoadAlbumCover(const QModelIndex &proxy_index) {
@ -840,7 +841,7 @@ void InternetSearchView::LazyLoadAlbumCover(const QModelIndex &proxy_index) {
const InternetSearchView::Result result = item_song->data(InternetSearchModel::Role_Result).value<InternetSearchView::Result>(); const InternetSearchView::Result result = item_song->data(InternetSearchModel::Role_Result).value<InternetSearchView::Result>();
QPixmap cached_pixmap; QPixmap cached_pixmap;
if (pixmap_cache_.find(result.pixmap_cache_key_, &cached_pixmap)) { if (QPixmapCache::find(result.pixmap_cache_key_, &cached_pixmap)) {
item_album->setData(cached_pixmap, Qt::DecorationRole); item_album->setData(cached_pixmap, Qt::DecorationRole);
} }
else { else {
@ -861,7 +862,7 @@ void InternetSearchView::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoad
if (albumcover_result.success && !albumcover_result.image_scaled.isNull()) { if (albumcover_result.success && !albumcover_result.image_scaled.isNull()) {
QPixmap pixmap = QPixmap::fromImage(albumcover_result.image_scaled); QPixmap pixmap = QPixmap::fromImage(albumcover_result.image_scaled);
if (!pixmap.isNull()) { if (!pixmap.isNull()) {
pixmap_cache_.insert(key, pixmap); QPixmapCache::insert(key, pixmap);
} }
if (idx.isValid()) { if (idx.isValid()) {
QStandardItem *item = front_model_->itemFromIndex(idx); QStandardItem *item = front_model_->itemFromIndex(idx);

View File

@ -38,7 +38,6 @@
#include <QUrl> #include <QUrl>
#include <QImage> #include <QImage>
#include <QPixmap> #include <QPixmap>
#include <QPixmapCache>
#include <QMetaType> #include <QMetaType>
#include "core/song.h" #include "core/song.h"
@ -216,7 +215,6 @@ class InternetSearchView : public QWidget {
AlbumCoverLoaderOptions cover_loader_options_; AlbumCoverLoaderOptions cover_loader_options_;
QMap<quint64, QPair<QModelIndex, QString>> cover_loader_tasks_; QMap<quint64, QPair<QModelIndex, QString>> cover_loader_tasks_;
QPixmapCache pixmap_cache_;
}; };
Q_DECLARE_METATYPE(InternetSearchView::Result) Q_DECLARE_METATYPE(InternetSearchView::Result)

View File

@ -45,6 +45,7 @@
#include <QUrl> #include <QUrl>
#include <QIcon> #include <QIcon>
#include <QPixmap> #include <QPixmap>
#include <QPixmapCache>
#include <QPainter> #include <QPainter>
#include <QColor> #include <QColor>
#include <QPen> #include <QPen>
@ -469,13 +470,13 @@ QPixmap SongSourceDelegate::LookupPixmap(const Song::Source source, const QSize
QPixmap pixmap; QPixmap pixmap;
QString cache_key = QString("%1-%2x%3").arg(Song::TextForSource(source)).arg(size.width()).arg(size.height()); QString cache_key = QString("%1-%2x%3").arg(Song::TextForSource(source)).arg(size.width()).arg(size.height());
if (pixmap_cache_.find(cache_key, &pixmap)) { if (QPixmapCache::find(cache_key, &pixmap)) {
return pixmap; return pixmap;
} }
QIcon icon(Song::IconForSource(source)); QIcon icon(Song::IconForSource(source));
pixmap = icon.pixmap(size.height()); pixmap = icon.pixmap(size.height());
pixmap_cache_.insert(cache_key, pixmap); QPixmapCache::insert(cache_key, pixmap);
return pixmap; return pixmap;

View File

@ -35,7 +35,6 @@
#include <QVariant> #include <QVariant>
#include <QUrl> #include <QUrl>
#include <QPixmap> #include <QPixmap>
#include <QPixmapCache>
#include <QPainter> #include <QPainter>
#include <QRect> #include <QRect>
#include <QColor> #include <QColor>
@ -203,8 +202,6 @@ class SongSourceDelegate : public PlaylistDelegateBase {
private: private:
QPixmap LookupPixmap(const Song::Source source, const QSize size) const; QPixmap LookupPixmap(const Song::Source source, const QSize size) const;
mutable QPixmapCache pixmap_cache_;
}; };
class RatingItemDelegate : public PlaylistDelegateBase { class RatingItemDelegate : public PlaylistDelegateBase {

View File

@ -30,7 +30,6 @@
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QPixmap> #include <QPixmap>
#include <QPixmapCache>
#include "core/song.h" #include "core/song.h"
#include "core/simpletreemodel.h" #include "core/simpletreemodel.h"