Commit b8d994a3 authored by Johannes Bergmeier's avatar Johannes Bergmeier

- Added missing .desktop file

- Added theme-selection in configuration

svn path=/trunk/KDE/kdegames/ksudoku/; revision=796416
parent 8f6906a6
......@@ -32,6 +32,7 @@
#include <KStandardAction>
#include <KAction>
#include <KConfigDialog>
#include <KGameThemeSelector>
#include <KCmdLineArgs>
#include <KAboutData>
......@@ -47,6 +48,7 @@
//#include "exportdlg.h"
#include "ksview.h"
#include "gameactions.h"
#include "renderer.h"
#include "puzzle.h" // TODO
#include "serializer.h"
......@@ -563,17 +565,20 @@ void KSudoku::optionsPreferences()
GameConfig* gameConfig = new GameConfig();
dialog->addPage(gameConfig, i18nc("Game Section in Config", "Game"), "games-config-options");
dialog->addPage(new KGameThemeSelector(dialog, Settings::self(), KGameThemeSelector::NewStuffDisableDownload), i18n("Theme"), "games-config-theme");
SymbolConfig* symbolConfig = new SymbolConfig(&m_symbols);
dialog->addPage(symbolConfig, i18n("Symbol Themes"), "games-config-theme");
dialog->setHelp(QString(),"ksudoku");
connect(dialog, SIGNAL(settingsChanged(const QString&)), SLOT(updateSettings()));
dialog->show();
dialog->show();
}
void KSudoku::updateSettings() {
m_symbols.setEnabledTables(Settings::symbols());
Renderer::instance()->loadTheme(Settings::theme());
KsView* view = currentView();
if(view) {
int order = view->game().order();
......
......@@ -13,6 +13,9 @@
</entry>
</group>
<group name="Themes">
<entry name="Theme" type="String" key="theme">
<label>The graphical theme to be used.</label>
</entry>
<entry name="Symbols" type="StringList" key="symbols">
<label>Select the themes you want to use</label>
<default>digits,letters_lower</default>
......
......@@ -3,6 +3,9 @@
#include <KSvgRenderer>
#include <KStandardDirs>
#include <kpixmapcache.h>
#include <KGameTheme>
#include "settings.h"
#include <QPixmap>
#include <QPainter>
......@@ -17,11 +20,12 @@ Renderer* Renderer::instance() {
}
Renderer::Renderer() {
m_renderer = new KSvgRenderer();
m_cache = new KPixmapCache("ksudoku-cache");
m_cache->setCacheLimit(3*1024);
m_renderer = new KSvgRenderer(KStandardDirs::locate("appdata", "themes/ksudoku_sample.svg"));
fillNameHashes();
if(!loadTheme(Settings::theme()))
kDebug() << "Failed to load any game theme!";
}
Renderer::~Renderer() {
......@@ -29,6 +33,41 @@ Renderer::~Renderer() {
delete m_renderer;
}
bool Renderer::loadTheme(const QString& themeName) {
bool discardCache = !m_currentTheme.isEmpty();
if(!m_currentTheme.isEmpty() && m_currentTheme == themeName) {
kDebug() << "Notice: loading the same theme";
return true; // this is not an error
}
m_currentTheme = themeName;
KGameTheme theme;
if(themeName.isEmpty() || !theme.load(themeName)) {
kDebug()<< "Failed to load theme" << Settings::theme();
kDebug() << "Trying to load default";
if(!theme.loadDefault())
return false;
discardCache = true;
m_currentTheme = "default";
}
bool res = m_renderer->load(theme.graphics());
kDebug() << "loading" << theme.graphics();
if(!res)
return false;
if(discardCache) {
kDebug() << "discarding cache";
m_cache->discard();
}
fillNameHashes();
return true;
}
void Renderer::fillNameHashes() {
m_borderNames = QVector<QString>();
m_borderNames << "";
......
......@@ -70,6 +70,8 @@ enum SupportFlag {
public:
static Renderer* instance();
bool loadTheme(const QString& themeName);
QPixmap renderBackground(const QSize& size) const;
QPixmap renderSpecial(SpecialType type, int size) const;
......@@ -99,6 +101,7 @@ private:
QVector<QString> m_specialNames;
QVector<QString> m_special3dNames;
QVector<QString> m_markerNames;
QString m_currentTheme;
KSvgRenderer* m_renderer;
KPixmapCache* m_cache;
};
......
......@@ -630,6 +630,7 @@ void View2D::selectValue(int value) {
}
void View2D::settingsChanged() {
m_scene->setSceneSize(size());
}
}
install(
FILES ksudoku_sample.svg
# *** Missing in repository: *** ksudoku_sample.desktop
FILES ksudoku_sample.svg ksudoku_sample.desktop
DESTINATION ${DATA_INSTALL_DIR}/ksudoku/themes
)
[KGameTheme]
Name=Sample
Description=KSudoku sample theme for KDE 4
VersionFormat=1
Author=Johannes Bergmeier
AuthorEmail=Johannes.Bergmeier@gmx.net
Type=SVG
FileName=ksudoku_sample.svg
#Preview=sample_preview.png
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