summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuigi Toscano <[email protected]>2017-04-08 01:46:09 +0200
committerLuigi Toscano <[email protected]>2017-04-08 01:46:09 +0200
commita07c02a398a8c3ff647bf361c30307ba5a11515d (patch)
treebb656cb87d781bac9284ea62a616f19d3f95c740
parent74210ecf1d9044bfa41c43b47023d361e170d1ea (diff)
Port from KPixmapCache to KImageCache
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/fromlibkdegames/cardcache.cpp38
-rw-r--r--src/fromlibkdegames/cardcache.h4
-rw-r--r--src/fromlibkdegames/cardcache_p.h5
5 files changed, 24 insertions, 25 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d8303ba..a07a5c2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,6 +15,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Crash
DBusAddons
DocTools
+ GuiAddons
I18n
ItemModels
KDELibs4Support
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 74a5b74..0a5f3a1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -45,6 +45,7 @@ target_link_libraries(lskat
Qt5::Gui
Qt5::Svg
KF5::Crash
+ KF5::GuiAddons
KF5::KDELibs4Support
KF5KDEGames
)
diff --git a/src/fromlibkdegames/cardcache.cpp b/src/fromlibkdegames/cardcache.cpp
index 08cadf2..c936b03 100644
--- a/src/fromlibkdegames/cardcache.cpp
+++ b/src/fromlibkdegames/cardcache.cpp
@@ -32,7 +32,6 @@
#include <QDir>
#include <QSvgRenderer>
-#include <kpixmapcache.h>
#include <kconfig.h>
#include <kstandarddirs.h>
@@ -225,7 +224,7 @@ void KCardCachePrivate::submitRendering(const QString &key, const QImage &image)
qCDebug(LSKAT_LOG) << "Received render of" << key << "from rendering thread.";
QPixmap pix = QPixmap::fromImage(image);
QMutexLocker l(cacheMutex);
- cache->insert(key, pix);
+ cache->insertPixmap(key, pix);
}
LoadThread::LoadThread(KCardCachePrivate *d_)
@@ -317,10 +316,10 @@ QPixmap KCardCache::backside() const
{
QMutexLocker l(d->cacheMutex);
- if (d->cache && (!d->cache->find(key, pix) || pix.isNull()))
+ if (d->cache && (!d->cache->findPixmap(key, &pix) || pix.isNull()))
{
pix = d->renderSvg(element);
- d->cache->insert(key, pix);
+ d->cache->insertPixmap(key, pix);
}
}
// Make sure we never return an invalid pixmap
@@ -337,10 +336,10 @@ QPixmap KCardCache::frontside(const KCardInfo &info) const
{
QMutexLocker l(d->cacheMutex);
- if (d->cache && (!d->cache->find(key, pix) || pix.isNull()))
+ if (d->cache && (!d->cache->findPixmap(key, &pix) || pix.isNull()))
{
pix = d->renderSvg(info.svgName());
- d->cache->insert(key, pix);
+ d->cache->insertPixmap(key, pix);
}
}
// Make sure we never return an invalid pixmap
@@ -364,17 +363,14 @@ void KCardCache::setDeckName(const QString &theme)
{
QMutexLocker l(d->cacheMutex);
delete d->cache;
- d->cache = new KPixmapCache(QString::fromLatin1("kdegames-cards_%1").arg(theme));
- d->cache->setUseQPixmapCache(true);
+ // The default size is arbitrary: it reflects the old KPixmapCache default
+ // and it seems to match the real maximum size for the decks
+ d->cache = new KImageCache(QString::fromLatin1("kdegames-cards_%1").arg(theme), 3*(1024<<10));
QDateTime dt = QFileInfo(CardDeckInfo::svgFilePath(theme)).lastModified();
-//PORT QT5
-#if 0
- if (d->cache->timestamp() < dt.toTime_t())
+ if (d->cache->lastModifiedTime() < dt)
{
- d->cache->discard();
- d->cache->setTimestamp(dt.toTime_t());
+ d->cache->clear();
}
-#endif
}
{
QMutexLocker l(d->rendererMutex);
@@ -399,7 +395,7 @@ void KCardCache::loadTheme(LoadInfos infos)
delete d->loadThread;
// We have to compile the list of elements to load here, because we can not
- // check the contents of the KPixmapCache from outside the GUI thread.
+ // check the contents of the KImageCache from outside the GUI thread.
QStringList elements;
QPixmap pix;
if (infos &KCardCache::LoadFrontSide)
@@ -418,7 +414,7 @@ void KCardCache::loadTheme(LoadInfos infos)
QString key = keyForPixmap(d->deckName, element, d->size);
{
QMutexLocker l(d->cacheMutex);
- if (d->cache && !d->cache->find(key, pix))
+ if (d->cache && !d->cache->findPixmap(key, &pix))
elements << element;
}
}
@@ -441,7 +437,7 @@ QSizeF KCardCache::defaultCardSize(const KCardInfo &info) const
QString key = d->deckName + QLatin1Char('_') + info.svgName() + QLatin1String("_default");
{
QMutexLocker(d->cacheMutex);
- if (d->cache && d->cache->find(key, pix))
+ if (d->cache && d->cache->findPixmap(key, &pix))
return pix.size();
}
@@ -454,7 +450,7 @@ QSizeF KCardCache::defaultCardSize(const KCardInfo &info) const
{
QMutexLocker(d->cacheMutex);
if (d->cache)
- d->cache->insert(key, pix);
+ d->cache->insertPixmap(key, pix);
}
return pix.size();
@@ -470,7 +466,7 @@ QSizeF KCardCache::defaultBackSize() const
QString key = d->deckName + QLatin1Char('_') + element + QLatin1String("_default");
{
QMutexLocker(d->cacheMutex);
- if (d->cache && d->cache->find(key, pix))
+ if (d->cache && d->cache->findPixmap(key, &pix))
return pix.size();
}
@@ -483,7 +479,7 @@ QSizeF KCardCache::defaultBackSize() const
{
QMutexLocker(d->cacheMutex);
if (d->cache)
- d->cache->insert(key, pix);
+ d->cache->insertPixmap(key, pix);
}
return pix.size();
@@ -493,5 +489,5 @@ void KCardCache::invalidateCache()
{
QMutexLocker l(d->cacheMutex);
if (d->cache)
- d->cache->discard();
+ d->cache->clear();
}
diff --git a/src/fromlibkdegames/cardcache.h b/src/fromlibkdegames/cardcache.h
index 2200b4f..33618c5 100644
--- a/src/fromlibkdegames/cardcache.h
+++ b/src/fromlibkdegames/cardcache.h
@@ -58,7 +58,7 @@ private:
*
* Card games such as lskat or kpat should use this cache
* to load the various decks into QPixmaps instead of inventing
- * their own. It uses KPixmapCache behind the scenes, set up to
+ * their own. It uses KImageCache behind the scenes, set up to
* use disk and memory caching. Thus a SVG card deck that was loaded
* by kpat for the size 100x200 does not need re-rendering when
* requested from lskat.
@@ -97,7 +97,7 @@ public:
Q_DECLARE_FLAGS(LoadInfos, LoadInfo)
/**
- * Constructor creates and initializes a KPixmapCache for all KDE Games
+ * Constructor creates and initializes a KImageCache
* card games
*/
KCardCache();
diff --git a/src/fromlibkdegames/cardcache_p.h b/src/fromlibkdegames/cardcache_p.h
index 0aef8da..ee606cb 100644
--- a/src/fromlibkdegames/cardcache_p.h
+++ b/src/fromlibkdegames/cardcache_p.h
@@ -20,6 +20,8 @@
#ifndef CARDCACHE_P_H
#define CARDCACHE_P_H
+#include <KImageCache>
+
#include <QImage>
#include <QThread>
#include <QString>
@@ -27,7 +29,6 @@
#include <QSize>
#include "cardcache.h"
-class KPixmapCache;
class QMutex;
class QSvgRenderer;
class LoadThread;
@@ -36,7 +37,7 @@ class KCardCachePrivate : public QObject
{
Q_OBJECT
public:
- KPixmapCache *cache;
+ KImageCache *cache;
QMutex *cacheMutex;
QMutex *rendererMutex;
LoadThread *loadThread;