diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 13 | ||||
-rw-r--r-- | src/mainwindow.cc | 7 | ||||
-rw-r--r-- | src/mainwindow.h | 12 | ||||
-rw-r--r-- | src/solverwindow.cc | 47 | ||||
-rw-r--r-- | src/solverwindow.h | 15 | ||||
-rw-r--r-- | src/sudoku.cc | 15 | ||||
-rw-r--r-- | src/sudoku.h | 30 | ||||
-rw-r--r-- | src/sudokuwidget.cc | 20 | ||||
-rw-r--r-- | src/sudokuwidget.h | 22 |
9 files changed, 138 insertions, 43 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index a67c97d..943ed52 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,17 +1,20 @@ -bin_PROGRAMS = sudosolve +bin_PROGRAMS = sudokusolver # You have two .cpp files you wrote, editor.cpp and another.cpp # Remember to include the name of the resource file with the .cpp extension. -sudosolve_SOURCES = \ +sudokusolver_SOURCES = \ main.cc \ mainwindow.cc \ - sudoku.cc + solverwindow.cc \ + sudoku.cc \ + sudokuwidget.cc # You have one .h file, it's called editor.h. Therefore, here I list # its mocced name, moc_editor.cpp. -nodist_sudosolve_SOURCES = \ +nodist_sudokusolver_SOURCES = \ moc_mainwindow.cc \ - moc_sudoku.cc + moc_solverwindow.cc \ + moc_sudokuwidget.cc # This rule lets GNU make create any moc_*.cpp from the equivalent *.h moc_%.cc: %.h diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 60d2dcf..f109a86 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -1,10 +1,9 @@ #include "mainwindow.h" -#include "sudoku.h" +#include "solverwindow.h" MainWindow::MainWindow() { - mainwindow_sudoku = new Sudoku(); - - setCentralWidget(mainwindow_sudoku); + SolverWindow *solverwindow = new SolverWindow(); + setCentralWidget(solverwindow); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 09f22dd..19d45c8 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,11 +1,11 @@ -#ifndef __INCLUDED_SUDOSOLVE_MAINWINDOW__ -#define __INCLUDED_SUDOSOLVE_MAINWINDOW__ +#ifndef __INCLUDED_SUDOKUSOLVER_MAINWINDOW__ +#define __INCLUDED_SUDOKUSOLVER_MAINWINDOW__ #include <QtGui> #include <QMainWindow> -class Sudoku; +class SudokuWidget; class MainWindow : public QMainWindow { @@ -13,10 +13,6 @@ class MainWindow : public QMainWindow public: MainWindow(); - -private: - Sudoku *mainwindow_sudoku; - }; -#endif // __INCLUDED_SUDOSOLVE_MAINWINDOW__
\ No newline at end of file +#endif // __INCLUDED_SUDOKUSOLVER_MAINWINDOW__
\ No newline at end of file diff --git a/src/solverwindow.cc b/src/solverwindow.cc new file mode 100644 index 0000000..9a04e46 --- /dev/null +++ b/src/solverwindow.cc @@ -0,0 +1,47 @@ + +#include "solverwindow.h" +#include "sudokuwidget.h" + +#include <QHBoxLayout> +#include <QVBoxLayout> + +#include <QPushButton> + +SolverWindow::SolverWindow() +{ + QHBoxLayout *windowlayout = new QHBoxLayout(); + + + // sidebar + QVBoxLayout *sidebarlayout = new QVBoxLayout(); + + // add load button + QPushButton *loadbutton = new QPushButton(tr("Load")); + sidebarlayout->addWidget(loadbutton); + + // add save button + QPushButton *savebutton = new QPushButton(tr("Save")); + sidebarlayout->addWidget(savebutton); + + // add step button + QPushButton *stepbutton = new QPushButton(tr("Step")); + sidebarlayout->addWidget(stepbutton); + + // add stretch + sidebarlayout->addStretch(1); + + // add clear button + QPushButton *clearbutton = new QPushButton(tr("Clear")); + sidebarlayout->addWidget(clearbutton); + + // add sidebar layout + windowlayout->addLayout(sidebarlayout); + + + // sudoku widget + SudokuWidget *sudokuwidget = new SudokuWidget(); + windowlayout->addWidget(sudokuwidget); + + // set window layout + setLayout(windowlayout); +} diff --git a/src/solverwindow.h b/src/solverwindow.h new file mode 100644 index 0000000..4743332 --- /dev/null +++ b/src/solverwindow.h @@ -0,0 +1,15 @@ + +#ifndef __INCLUDED_SUDOKUSOLVER_SOLVERWINDOW__ +#define __INCLUDED_SUDOKUSOLVER_SOLVERWINDOW__ + +#include <QWidget> + +class SolverWindow : public QWidget +{ + Q_OBJECT + +public: + SolverWindow(); +}; + +#endif // __INCLUDED_SUDOKUSOLVER_SOLVERWINDOW__
\ No newline at end of file diff --git a/src/sudoku.cc b/src/sudoku.cc index f676bb1..28e59b6 100644 --- a/src/sudoku.cc +++ b/src/sudoku.cc @@ -1,20 +1,11 @@ #include "sudoku.h" -#include <QLineEdit> -#include <QGridLayout> - Sudoku::Sudoku() { - QGridLayout *gridlayout = new QGridLayout(); - - for (size_t row = 0; row < 9; row++) { - for (size_t column = 0; column < 9 ; column++) { - sudoku_value[row][column] = new QLineEdit(); - gridlayout->addWidget(sudoku_value[row][column], row, column); + for (int row = 0; row < 9; row++) { + for (int column = 0; column < 9; column++) { + sudoku_value[row][column] = 0; } - } - - setLayout(gridlayout); }
\ No newline at end of file diff --git a/src/sudoku.h b/src/sudoku.h index c9d38e6..2059a81 100644 --- a/src/sudoku.h +++ b/src/sudoku.h @@ -1,22 +1,24 @@ -#ifndef __INCLUDED_SUDOSOLVE_SUDOKU__ -#define __INCLUDED_SUDOSOLVE_SUDOKU__ +#ifndef __INCLUDED_SUDOKUSOLVER_SUDOKU__ +#define __INCLUDED_SUDOKUSOLVER_SUDOKU__ -#include <QtGui> -#include <QWidget> - -class QLineEdit; - -class Sudoku : public QWidget -{ - Q_OBJECT +class Sudoku { public: Sudoku(); - + + // inspector + inline int value(int row, int column) const { + return sudoku_value[row][column]; + } + + // mutator + inline int & value(int row, int column) { + return sudoku_value[row][column]; + } + private: - QLineEdit * sudoku_value[9][9]; - + int sudoku_value[9][9]; }; -#endif // __INCLUDED_SUDOSOLVE_SUDOKU__
\ No newline at end of file +#endif // __INCLUDED_SUDOKUSOLVER_SUDOKU__ diff --git a/src/sudokuwidget.cc b/src/sudokuwidget.cc new file mode 100644 index 0000000..ef60e67 --- /dev/null +++ b/src/sudokuwidget.cc @@ -0,0 +1,20 @@ + +#include "sudokuwidget.h" + +#include <QLineEdit> +#include <QGridLayout> + +SudokuWidget::SudokuWidget() +{ + QGridLayout *gridlayout = new QGridLayout(); + + for (int row = 0; row < 9; row++) { + for (int column = 0; column < 9 ; column++) { + sudokuwidget_value[row][column] = new QLineEdit(); + gridlayout->addWidget(sudokuwidget_value[row][column], row, column); + } + + } + + setLayout(gridlayout); +}
\ No newline at end of file diff --git a/src/sudokuwidget.h b/src/sudokuwidget.h new file mode 100644 index 0000000..59e4f3c --- /dev/null +++ b/src/sudokuwidget.h @@ -0,0 +1,22 @@ + +#ifndef __INCLUDED_SUDOKUSOLVER_SUDOKUWIDGET__ +#define __INCLUDED_SUDOKUSOLVER_SUDOKUWIDGET__ + +#include <QtGui> +#include <QWidget> + +class QLineEdit; + +class SudokuWidget : public QWidget +{ + Q_OBJECT + +public: + SudokuWidget(); + +private: + QLineEdit * sudokuwidget_value[9][9]; + +}; + +#endif // __INCLUDED_SUDOKUSOLVER_SUDOKUWIDGET__
\ No newline at end of file |