summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-07-13 20:14:11 +0000
committerStijn Buys <ingar@osirion.org>2013-07-13 20:14:11 +0000
commit8b7b9e3c69fc138c4288036a2e659ac39badb902 (patch)
tree69a51d13c327be07f6b526060b87bec83ab74712 /src
parent13393a3a2c30abac42c97fd37afdbdcd9a3a111e (diff)
Adds a settings class, use APPDATA/Sudoku Solver as homedir on win32, renames the UNIX homedir to ~/.sudokusolver
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/solverwindow.cc20
-rw-r--r--src/sudokuwidget.cc15
3 files changed, 8 insertions, 28 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 5c329b4..fbdb4a9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,6 +14,7 @@ sudokusolver_SOURCES = \
cell.cc \
main.cc \
mainwindow.cc \
+ settings.cc \
solverwindow.cc \
sudoku.cc \
sudokuwidget.cc
diff --git a/src/solverwindow.cc b/src/solverwindow.cc
index 9e0c782..0c2b082 100644
--- a/src/solverwindow.cc
+++ b/src/solverwindow.cc
@@ -1,4 +1,5 @@
+#include "settings.h"
#include "solverwindow.h"
#include "sudokuwidget.h"
#include "sudoku.h"
@@ -11,14 +12,6 @@
#include <QVBoxLayout>
#include <QPushButton>
-/*
- * FIXME
- * On windows, this results in a rather awkward directory.
- * The homepath should probably be a setting.
- * This should move to mainwindow
- * */
-const QString HOMEDIR(QDir::homePath() + "/.sudoku");
-
SolverWindow::SolverWindow()
{
QHBoxLayout *windowlayout = new QHBoxLayout();
@@ -29,13 +22,6 @@ SolverWindow::SolverWindow()
// set window layout
setLayout(windowlayout);
-
- // create home directory
- // FIXME this should move to mainwindow
- QDir directory;
- if (!directory.exists(HOMEDIR)) {
- directory.mkdir(HOMEDIR);
- }
}
void SolverWindow::openFromFile(const QString & filename)
@@ -128,7 +114,7 @@ void SolverWindow::saveToFile(const QString & filename)
void SolverWindow::doOpen()
{
- QString filename = QFileDialog::getOpenFileName(this, tr("Open"), HOMEDIR, "Sudoku (*.sudoku)");
+ QString filename = QFileDialog::getOpenFileName(this, tr("Open"), globalSettings().homePath(), "Sudoku (*.sudoku)");
if (!filename.isEmpty()) {
openFromFile(filename);
@@ -167,7 +153,7 @@ void SolverWindow::doSave()
void SolverWindow::doSaveAs()
{
// QFileDialog::getSaveFileName() warns about existing files
- QString filename = QFileDialog::getSaveFileName(this, tr("Save as..."), HOMEDIR, "Sudoku (*.sudoku)");
+ QString filename = QFileDialog::getSaveFileName(this, tr("Save as..."), globalSettings().homePath(), "Sudoku (*.sudoku)");
if (!filename.isEmpty()) {
saveToFile(filename);
diff --git a/src/sudokuwidget.cc b/src/sudokuwidget.cc
index b42637c..78e90fd 100644
--- a/src/sudokuwidget.cc
+++ b/src/sudokuwidget.cc
@@ -1,18 +1,11 @@
#include "sudokuwidget.h"
+#include "settings.h"
#include <QLineEdit>
#include <QGridLayout>
#include <QString>
-/*
- * TODO
- * This should be moved into a global configuration sectoion
- * with a settings dialog
- * */
-const QColor color_invalid_value(255, 0, 0);
-const QColor color_input_error(195, 195, 195);
-
SudokuWidget::SudokuWidget()
{
for (int row = 0; row < 9; row++) {
@@ -41,7 +34,7 @@ void SudokuWidget::verify(const QString & text)
values.cell(row, column).set_value(0);
QPalette child_palette(palette());
if (!sudokuwidget_value[row][column]->text().isEmpty()) {
- child_palette.setColor(QPalette::Base, color_input_error);
+ child_palette.setColor(QPalette::Base, globalSettings().colorInputError());
}
sudokuwidget_value[row][column]->setPalette(child_palette);
}
@@ -57,7 +50,7 @@ void SudokuWidget::verify(const QString & text)
if ( (i > 0) && (i <= 9) ) {
// set background color depending on the validity of the cell value
if (!values.cell(row, column).valid()) {
- child_palette.setColor(QPalette::Base, color_invalid_value);
+ child_palette.setColor(QPalette::Base, globalSettings().colorInvalidValue());
}
sudokuwidget_value[row][column]->setPalette(child_palette);
}
@@ -82,7 +75,7 @@ void SudokuWidget::set_values(const Sudoku & values)
// set background color depending on the validity of the cell value
if (!values.cell(row, column).valid()) {
- child_palette.setColor(QPalette::Base, color_invalid_value);
+ child_palette.setColor(QPalette::Base, globalSettings().colorInvalidValue());
}
} else {
sudokuwidget_value[row][column]->clear();