Commit 55589ab6 authored by Luigi Toscano's avatar Luigi Toscano

Port from KPixmapCache to KImageCache

parent 63f378e1
...@@ -14,6 +14,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS ...@@ -14,6 +14,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
CoreAddons CoreAddons
Crash Crash
DBusAddons DBusAddons
GuiAddons
I18n I18n
ItemModels ItemModels
KDELibs4Support KDELibs4Support
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include <QSvgRenderer> #include <QSvgRenderer>
#include <kpixmapcache.h>
#include <KDebug> #include <KDebug>
#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
#include <libkdegamesprivate/kgametheme.h> #include <libkdegamesprivate/kgametheme.h>
...@@ -43,8 +42,7 @@ Renderer* Renderer::instance() { ...@@ -43,8 +42,7 @@ Renderer* Renderer::instance() {
Renderer::Renderer() { Renderer::Renderer() {
m_renderer = new QSvgRenderer(); m_renderer = new QSvgRenderer();
m_cache = new KPixmapCache("ksudoku-cache"); m_cache = new KImageCache(QStringLiteral("ksudoku-cache"), 3*1024);
m_cache->setCacheLimit(3*1024);
m_mathdokuStyle = false; m_mathdokuStyle = false;
if(!loadTheme(Settings::theme())) if(!loadTheme(Settings::theme()))
...@@ -84,7 +82,7 @@ bool Renderer::loadTheme(const QString& themeName) { ...@@ -84,7 +82,7 @@ bool Renderer::loadTheme(const QString& themeName) {
if(discardCache) { if(discardCache) {
kDebug() << "discarding cache"; kDebug() << "discarding cache";
m_cache->discard(); m_cache->clear();
} }
fillNameHashes(); fillNameHashes();
...@@ -148,14 +146,14 @@ QPixmap Renderer::renderBackground(const QSize& size) const { ...@@ -148,14 +146,14 @@ QPixmap Renderer::renderBackground(const QSize& size) const {
QPixmap pix; QPixmap pix;
QString cacheName = QString("background_%1x%2").arg(size.width()).arg(size.height()); QString cacheName = QString("background_%1x%2").arg(size.width()).arg(size.height());
if(!m_cache->find(cacheName, pix)) if(!m_cache->findPixmap(cacheName, &pix))
{ {
pix = QPixmap(size); pix = QPixmap(size);
pix.fill(Qt::transparent); pix.fill(Qt::transparent);
QPainter p(&pix); QPainter p(&pix);
m_renderer->render(&p, "background"); m_renderer->render(&p, "background");
p.end(); p.end();
m_cache->insert(cacheName, pix); m_cache->insertPixmap(cacheName, pix)
} }
return pix; return pix;
} }
...@@ -184,7 +182,7 @@ QPixmap Renderer::renderSpecial(SpecialType type, int size) const { ...@@ -184,7 +182,7 @@ QPixmap Renderer::renderSpecial(SpecialType type, int size) const {
QString cacheName = QString("special_%1_%2").arg(m_specialNames[type]).arg(size); QString cacheName = QString("special_%1_%2").arg(m_specialNames[type]).arg(size);
QPixmap pix; QPixmap pix;
if(!m_cache->find(cacheName, pix)) { if(!m_cache->findPixmap(cacheName, &pix)) {
pix = QPixmap(size, size); pix = QPixmap(size, size);
pix.fill(Qt::transparent); pix.fill(Qt::transparent);
QPainter p(&pix); QPainter p(&pix);
...@@ -198,7 +196,7 @@ QPixmap Renderer::renderSpecial(SpecialType type, int size) const { ...@@ -198,7 +196,7 @@ QPixmap Renderer::renderSpecial(SpecialType type, int size) const {
m_renderer->render(&p, m_specialNames[type], r); m_renderer->render(&p, m_specialNames[type], r);
p.end(); p.end();
m_cache->insert(cacheName, pix); m_cache->insertPixmap(cacheName, pix);
} }
return pix; return pix;
...@@ -216,7 +214,7 @@ QPixmap Renderer::renderSymbol(int symbol, int size, int max, SymbolType type) c ...@@ -216,7 +214,7 @@ QPixmap Renderer::renderSymbol(int symbol, int size, int max, SymbolType type) c
QString cacheName = QString("%1_%2_%3_%4").arg(set).arg(symbol).arg(size).arg(type); QString cacheName = QString("%1_%2_%3_%4").arg(set).arg(symbol).arg(size).arg(type);
QPixmap pix; QPixmap pix;
if(!m_cache->find(cacheName, pix)) { if(!m_cache->findPixmap(cacheName, &pix)) {
pix = QPixmap(size, size); pix = QPixmap(size, size);
pix.fill(Qt::transparent); pix.fill(Qt::transparent);
QPainter p(&pix); QPainter p(&pix);
...@@ -247,7 +245,7 @@ QPixmap Renderer::renderSymbol(int symbol, int size, int max, SymbolType type) c ...@@ -247,7 +245,7 @@ QPixmap Renderer::renderSymbol(int symbol, int size, int max, SymbolType type) c
break; break;
} }
p.end(); p.end();
m_cache->insert(cacheName, pix); m_cache->insertPixmap(cacheName, pix);
} }
return pix; return pix;
...@@ -300,7 +298,7 @@ QPixmap Renderer::renderMarker(int symbol, int range, int size) const { ...@@ -300,7 +298,7 @@ QPixmap Renderer::renderMarker(int symbol, int range, int size) const {
QString groupName = QString("markers%1").arg(range); QString groupName = QString("markers%1").arg(range);
QString cacheName = QString("%1_%2_%3").arg(groupName).arg(symbol).arg(size); QString cacheName = QString("%1_%2_%3").arg(groupName).arg(symbol).arg(size);
QPixmap pix; QPixmap pix;
if(!m_cache->find(cacheName, pix)) { if(!m_cache->findPixmap(cacheName, &pix)) {
pix = QPixmap(size, size); pix = QPixmap(size, size);
pix.fill(Qt::transparent); pix.fill(Qt::transparent);
QPainter p(&pix); QPainter p(&pix);
...@@ -316,7 +314,7 @@ QPixmap Renderer::renderMarker(int symbol, int range, int size) const { ...@@ -316,7 +314,7 @@ QPixmap Renderer::renderMarker(int symbol, int range, int size) const {
m_renderer->render(&p, QString("%1_%2").arg(set).arg(symbol), r); m_renderer->render(&p, QString("%1_%2").arg(set).arg(symbol), r);
p.end(); p.end();
m_cache->insert(cacheName, pix); m_cache->insertPixmap(cacheName, pix);
} }
return pix; return pix;
...@@ -383,7 +381,7 @@ QPixmap Renderer::renderBorder(int border, GroupTypes type, int size) const { ...@@ -383,7 +381,7 @@ QPixmap Renderer::renderBorder(int border, GroupTypes type, int size) const {
QString cacheName = QString("contour_%1_%2_%3").arg(m_borderTypes[type]).arg(m_borderNames[border]).arg(size); QString cacheName = QString("contour_%1_%2_%3").arg(m_borderTypes[type]).arg(m_borderNames[border]).arg(size);
QPixmap pix; QPixmap pix;
if(!m_cache->find(cacheName, pix)) { if(!m_cache->findPixmap(cacheName, &pix)) {
pix = QPixmap(size, size); pix = QPixmap(size, size);
pix.fill(Qt::transparent); pix.fill(Qt::transparent);
QPainter p(&pix); QPainter p(&pix);
...@@ -397,7 +395,7 @@ QPixmap Renderer::renderBorder(int border, GroupTypes type, int size) const { ...@@ -397,7 +395,7 @@ QPixmap Renderer::renderBorder(int border, GroupTypes type, int size) const {
m_renderer->render(&p, QString("%1_%2").arg(m_borderTypes[type]).arg(m_borderNames[border]), r); m_renderer->render(&p, QString("%1_%2").arg(m_borderTypes[type]).arg(m_borderNames[border]), r);
p.end(); p.end();
m_cache->insert(cacheName, pix); m_cache->insertPixmap(cacheName, pix);
} }
return pix; return pix;
...@@ -408,7 +406,7 @@ QPixmap Renderer::renderSpecial3D(SpecialType type, int size) const { ...@@ -408,7 +406,7 @@ QPixmap Renderer::renderSpecial3D(SpecialType type, int size) const {
QString cacheName = QString("special_%1_%2").arg(m_special3dNames[type]).arg(size); QString cacheName = QString("special_%1_%2").arg(m_special3dNames[type]).arg(size);
QPixmap pix; QPixmap pix;
if(!m_cache->find(cacheName, pix)) { if(!m_cache->findPixmap(cacheName, &pix)) {
pix = QPixmap(size, size); pix = QPixmap(size, size);
pix.fill(Qt::transparent); pix.fill(Qt::transparent);
QPainter p(&pix); QPainter p(&pix);
...@@ -422,7 +420,7 @@ QPixmap Renderer::renderSpecial3D(SpecialType type, int size) const { ...@@ -422,7 +420,7 @@ QPixmap Renderer::renderSpecial3D(SpecialType type, int size) const {
m_renderer->render(&p, m_special3dNames[type], r); m_renderer->render(&p, m_special3dNames[type], r);
p.end(); p.end();
m_cache->insert(cacheName, pix); m_cache->insertPixmap(cacheName, pix);
} }
return pix; return pix;
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#ifndef _KSUDOKU_RENDERER_H_ #ifndef _KSUDOKU_RENDERER_H_
#define _KSUDOKU_RENDERER_H_ #define _KSUDOKU_RENDERER_H_
#include <KImageCache>
#include <QVector> #include <QVector>
// #include <QPixmap> // #include <QPixmap>
#include <QString> #include <QString>
...@@ -28,7 +30,6 @@ ...@@ -28,7 +30,6 @@
class QPixmap; class QPixmap;
class QSize; class QSize;
class QSvgRenderer; class QSvgRenderer;
class KPixmapCache;
namespace ksudoku { namespace ksudoku {
...@@ -122,7 +123,7 @@ private: ...@@ -122,7 +123,7 @@ private:
QVector<QString> m_markerNames; QVector<QString> m_markerNames;
QString m_currentTheme; QString m_currentTheme;
QSvgRenderer* m_renderer; QSvgRenderer* m_renderer;
KPixmapCache* m_cache; KImageCache* m_cache;
bool m_mathdokuStyle; bool m_mathdokuStyle;
}; };
......
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