From 168d6e5763685b57c2ddd444209374c37bc5fdec Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 5 Jun 2012 18:50:44 +0000 Subject: Added solverwindow and sidebar buttons, added Sudoku value container class. --- src/Makefile.am | 13 ++++++++----- src/mainwindow.cc | 7 +++---- src/mainwindow.h | 12 ++++-------- src/solverwindow.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/solverwindow.h | 15 +++++++++++++++ src/sudoku.cc | 15 +++------------ src/sudoku.h | 30 ++++++++++++++++-------------- src/sudokuwidget.cc | 20 ++++++++++++++++++++ src/sudokuwidget.h | 22 ++++++++++++++++++++++ 9 files changed, 138 insertions(+), 43 deletions(-) create mode 100644 src/solverwindow.cc create mode 100644 src/solverwindow.h create mode 100644 src/sudokuwidget.cc create mode 100644 src/sudokuwidget.h 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 #include -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 +#include + +#include + +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 + +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 -#include - 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 -#include - -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 +#include + +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 +#include + +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 -- cgit v1.2.3