2 Copyright 2007 Dmitry Suzdalev <dimsuz@gmail.com>
3 Copyright 2007-2008 Fela Winkelmolen <fela.kde@gmail.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <KSvgRenderer>
26 #include <kpixmapcache.h>
28 Renderer
* Renderer::self()
30 static Renderer instance
;
36 m_renderer
= new KSvgRenderer();
37 m_cache
= new KPixmapCache("kbreakout");
38 m_cache
->setCacheLimit(3*1024); // TODO: put somewhere else!!!!!!!! (also in KNetWalk!!)
40 if(!loadTheme(Settings::theme()))
41 kDebug() << "Failed to load any game theme!";
50 bool Renderer::loadTheme(const QString
& themeName
)
52 // variable saying whether to discard old cache upon
53 // successful new theme loading
54 // we won't discard it if m_currentTheme is empty meaning that
55 // this is the first time loadTheme() is called
56 // (i.e. during startup) as we want to pick the cache from disc
57 bool discardCache
= !m_currentTheme
.isEmpty();
59 if(!m_currentTheme
.isEmpty() && m_currentTheme
== themeName
) {
60 kDebug() << "Notice: not loading the same theme";
61 return true; // this is not an error
64 if (!theme
.load(themeName
)) {
65 kDebug() << "Failed to load theme" << Settings::theme();
66 kDebug() << "Trying to load default";
67 if(!theme
.loadDefault())
71 m_currentTheme
= themeName
;
73 bool res
= m_renderer
->load( theme
.graphics() );
74 kDebug() << "loading" << theme
.graphics();
75 if (!res
) return false;
78 kDebug() << "discarding cache";
84 QPixmap
Renderer::renderedSvgElement(const QString
&id
, const QSize
&size
) const
86 int const w
= size
.width();
87 int const h
= size
.height();
91 QString("%1-%2x%3").arg(id
).arg(w
).arg(h
);
92 if(m_cache
->find(cacheName
, pixmap
)) return pixmap
;
95 kDebug() << "re-rendering pixmap" << cacheName
;
96 pixmap
= QPixmap(size
);
97 pixmap
.fill(Qt::transparent
);
100 if (!m_renderer
->elementExists(id
)) {
101 kDebug() << "Invalid elementId: " << id
;
105 m_renderer
->render(&p
, id
/*, size*/);
107 m_cache
->insert(cacheName
, pixmap
);
108 kDebug() << "cache size:" << m_cache
->size() << "kb";