summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Wadham <[email protected]>2015-06-25 14:02:22 +1000
committerIan Wadham <[email protected]>2015-06-25 14:02:22 +1000
commitd9fc531eaaf1653314f8973e13be42e8811a39ab (patch)
treeaf2df37c18647f2688b444d3f1bb466b29e48c94
parenta8083240580c8d0b2921838fe29b6a83351361ac (diff)
Add code to support Mathdoku - Settable Size puzzle-shapes.
-rw-r--r--src/gui/configgame.ui72
-rw-r--r--src/gui/gamevariants.cpp16
-rw-r--r--src/gui/ksudoku.kcfg3
-rw-r--r--src/gui/serializer.cpp24
4 files changed, 100 insertions, 15 deletions
diff --git a/src/gui/configgame.ui b/src/gui/configgame.ui
index 872c216..d100473 100644
--- a/src/gui/configgame.ui
+++ b/src/gui/configgame.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>413</width>
- <height>466</height>
+ <width>462</width>
+ <height>521</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -32,7 +32,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
- <height>30</height>
+ <height>20</height>
</size>
</property>
</spacer>
@@ -87,7 +87,71 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
- <height>30</height>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_5">
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QSpinBox" name="kcfg_MathdokuSize">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <horstretch>200</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>84</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="minimum">
+ <number>3</number>
+ </property>
+ <property name="maximum">
+ <number>9</number>
+ </property>
+ <property name="value">
+ <number>6</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_4">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Mathdoku puzzle size (3-9)</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>20</height>
</size>
</property>
</spacer>
diff --git a/src/gui/gamevariants.cpp b/src/gui/gamevariants.cpp
index 024e596..e31ef6c 100644
--- a/src/gui/gamevariants.cpp
+++ b/src/gui/gamevariants.cpp
@@ -353,10 +353,12 @@ bool CustomGame::canStartEmpty() const {
}
Game CustomGame::startEmpty() {
- if(!m_graph) {
- m_graph = ksudoku::Serializer::loadCustomShape(m_url, 0, 0);
- if(!m_graph) return Game();
+ if(m_graph) {
+ delete m_graph; // Create SKGraph every time, so that Mathdoku
+ m_graph = 0; // Settable always gets the latest size setting.
}
+ m_graph = ksudoku::Serializer::loadCustomShape(m_url, 0, 0);
+ if(!m_graph) return Game();
Puzzle* puzzle = new Puzzle(m_graph, false);
puzzle->init();
@@ -365,10 +367,12 @@ Game CustomGame::startEmpty() {
}
Game CustomGame::createGame(int difficulty, int symmetry) {
- if(!m_graph) {
- m_graph = ksudoku::Serializer::loadCustomShape(m_url, 0, 0);
- if(!m_graph) return Game();
+ if(m_graph) {
+ delete m_graph; // Create SKGraph every time, so that Mathdoku
+ m_graph = 0; // Settable always gets the latest size setting.
}
+ m_graph = ksudoku::Serializer::loadCustomShape(m_url, 0, 0);
+ if(!m_graph) return Game();
Puzzle* puzzle = new Puzzle(m_graph, true);
puzzle->init(difficulty, symmetry);
diff --git a/src/gui/ksudoku.kcfg b/src/gui/ksudoku.kcfg
index 9bbf8a2..6e7145f 100644
--- a/src/gui/ksudoku.kcfg
+++ b/src/gui/ksudoku.kcfg
@@ -17,6 +17,9 @@
<entry name="ShowHighlights3D" type="Bool" key="showHighlights3D">
<default>true</default>
</entry>
+ <entry name="MathdokuSize" type="Int" key="mathdokuSize">
+ <default>6</default>
+ </entry>
<entry name="OverallSize3D" type="Int" key="overallSize3D">
<default>10</default>
</entry>
diff --git a/src/gui/serializer.cpp b/src/gui/serializer.cpp
index 3a43e1e..4fa9ee2 100644
--- a/src/gui/serializer.cpp
+++ b/src/gui/serializer.cpp
@@ -36,6 +36,7 @@
#include "ksudoku.h"
#include "symbols.h"
+#include "settings.h"
namespace ksudoku {
@@ -188,7 +189,9 @@ SKGraph* Serializer::deserializeGraph(QDomElement element) {
if(orderStr.isNull())
return 0;
// IDW TODO - Allow symbolic values for Mathdoku, set from user-config.
- int order = orderStr.toInt(&noFailure, 0);
+ int order = (orderStr == QString("Mathdoku")) ?
+ Settings::mathdokuSize() :
+ orderStr.toInt(&noFailure, 0);
if(!noFailure)
return 0;
@@ -207,10 +210,21 @@ SKGraph* Serializer::deserializeGraph(QDomElement element) {
return graph;
} else if(type == "custom") {
int err=0;
- int ncliques = readInt(element,"ncliques", &err);
- int sizeX = readInt(element,"sizeX",&err);
- int sizeY = readInt(element,"sizeY",&err);
- int sizeZ = readInt(element,"sizeZ",&err);
+ int ncliques;
+ int sizeX;
+ int sizeY;
+ int sizeZ;
+ if (orderStr != QString("Mathdoku")) {
+ ncliques = readInt(element,"ncliques", &err);
+ sizeX = readInt(element,"sizeX",&err);
+ sizeY = readInt(element,"sizeY",&err);
+ }
+ else {
+ ncliques = 2 * order;
+ sizeX = order;
+ sizeY = order;
+ }
+ sizeZ = readInt(element,"sizeZ",&err);
QString name = element.attribute("name");
QString typeName = element.attribute("specific-type");