Commit a07c02a3 authored by Luigi Toscano's avatar Luigi Toscano

Port from KPixmapCache to KImageCache

parent 74210ecf
......@@ -15,6 +15,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Crash
DBusAddons
DocTools
GuiAddons
I18n
ItemModels
KDELibs4Support
......
......@@ -45,6 +45,7 @@ target_link_libraries(lskat
Qt5::Gui
Qt5::Svg
KF5::Crash
KF5::GuiAddons
KF5::KDELibs4Support
KF5KDEGames
)
......
......@@ -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();
}
......@@ -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();
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment