From b07264e2e749dd79473cf4d8947e2f9c2a0d6023 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 22 May 2017 21:29:58 -0400 Subject: Clean up the new LIconCache class quite a bit (seems finished - just untested). --- src-qt5/core/libLumina/LIconCache.cpp | 62 ++++++++++++++++++++++++++++++++--- src-qt5/core/libLumina/LIconCache.h | 6 ++++ src-qt5/core/libLumina/LIconCache.pri | 2 ++ 3 files changed, 66 insertions(+), 4 deletions(-) (limited to 'src-qt5/core/libLumina') diff --git a/src-qt5/core/libLumina/LIconCache.cpp b/src-qt5/core/libLumina/LIconCache.cpp index 8ff4a8d7..18fc48c1 100644 --- a/src-qt5/core/libLumina/LIconCache.cpp +++ b/src-qt5/core/libLumina/LIconCache.cpp @@ -7,6 +7,9 @@ #include "LIconCache.h" #include +#include + +#include LIconCache::LIconCache(QObject *parent = 0{ @@ -105,7 +108,7 @@ QString LIconCache::findFile(QString icon){ } -void LIconCache::loadIcon(QAbstractButton *button, QString icon, bool noThumb = false){ +void LIconCache::loadIcon(QAbstractButton *button, QString icon, bool noThumb){ //See if the icon has already been loaded into the HASH if(HASH.contains(icon)){ if(!noThumb && !HASH[icon].thumbnail.isNull()){ button->setIcon( HASH[icon].thumbnail ); return; } @@ -120,7 +123,7 @@ void LIconCache::loadIcon(QAbstractButton *button, QString icon, bool noThumb = QtConcurrent::run(this, &LIconCache::ReadFile, this, icon, idata.fullpath); } -void LIconCache::loadIcon(QLabel *label, QString icon, bool noThumb = false){ +void LIconCache::loadIcon(QLabel *label, QString icon, bool noThumb){ //See if the icon has already been loaded into the HASH if(HASH.contains(icon)){ if(!noThumb && !HASH[icon].thumbnail.isNull()){ button->setIcon( HASH[icon].thumbnail ); return; } @@ -135,6 +138,34 @@ void LIconCache::loadIcon(QLabel *label, QString icon, bool noThumb = false){ QtConcurrent::run(this, &LIconCache::ReadFile, this, icon, idata.fullpath); } +void LIconCache::clearIconTheme(){ + //use when the icon theme changes to refresh all requested icons + QStringList keys = HASH.keys(); + for(int i=0; iappend(file.readAll()); + file.close(); + } + obj->emit InternalIconLoaded(id, cdt, BA); } // === PRIVATE SLOTS === void LIconCache::IconLoaded(QString id, QDateTime sync, QByteArray *data){ - + QPixmap pix = QPixmap::fromRawData(data); + delete data; //no longer used - free this up + if(!HASH.contains(id)){ return; } //icon loading cancelled - just stop here + if(!pix.isValid()){ HASH.remove(id); } + else{ + icon_data idat = HASH[id]; + idat.lastsync = sync; + idat.icon.addPixmap(pix); + //Now throw this icon into any pending objects + for(int i=0; isetIcon(idat.icon); } + idat.pendingButtons.clear(); + for(int i=0; isetPixmap(pix.scaled(idat.pendingLabels[i]->sizeHint(), Qt::KeepAspectRatio, Qt::SmoothTransformation); } + idat.pendingLabels.clear(); + //Now update the hash and let the world know it is available now + HASH.insert(id, idat); + this->emit IconAvailable(id); + } } diff --git a/src-qt5/core/libLumina/LIconCache.h b/src-qt5/core/libLumina/LIconCache.h index 08726399..e2335c01 100644 --- a/src-qt5/core/libLumina/LIconCache.h +++ b/src-qt5/core/libLumina/LIconCache.h @@ -35,8 +35,14 @@ public: bool isLoaded(QString icon); QString findFile(QString icon); //find the full path of a given file/name (searching the current Icon theme) + //Special loading routines for QLabel and QAbstractButton (pushbutton, toolbutton, etc) void loadIcon(QAbstractButton *button, QString icon, bool noThumb = false); void loadIcon(QLabel *label, QString icon, bool noThumb = false); + + QIcon loadIcon(QString icon, bool noThumb = false); //generic loading routine - does not background the loading of icons when not in the cache + + void clearIconTheme(); //use when the icon theme changes to refresh all requested icons + void clearAll(); //Clear all cached icons private: QHash HASH; diff --git a/src-qt5/core/libLumina/LIconCache.pri b/src-qt5/core/libLumina/LIconCache.pri index f1f58f16..baf72b01 100644 --- a/src-qt5/core/libLumina/LIconCache.pri +++ b/src-qt5/core/libLumina/LIconCache.pri @@ -1,3 +1,5 @@ +QT *= concurrent + HEADERS *= $${PWD}/LIconCache.h SOURCES *= $${PWD}/LIconCache.cpp -- cgit