commit 2e68340b3ac15893cfc1aa6bbed55c1890ab7dfe Author: jb Date: Mon Mar 16 22:39:40 2009 +0000 Add sudoku Game diff --git a/src/boardArea.cpp b/src/boardArea.cpp new file mode 100644 index 0000000..791f036 --- /dev/null +++ b/src/boardArea.cpp @@ -0,0 +1,41 @@ +/* + + Class for drawing the board. + +*/ + + +#include + +#include "boardArea.h" + + +/* Constructor. */ +BoardArea::BoardArea (QWidget *parent) : QWidget(parent) +{ + setBackgroundRole(QPalette::Base); +} + +QSize BoardArea::minimumSizeHint() const +{ + return QSize(270, 270); +} + +QSize BoardArea::sizeHint() const +{ + return QSize(300, 300); +} + +void BoardArea::paintEvent(QPaintEvent *) +{ + QRect rect(10, 20, 80, 60); + QPainter painter(this); + painter.drawLine(QPoint (10,10), QPoint (200, 200)); + painter.restore(); +} + +/* This function draw the complet board. */ +void BoardArea::drawBoard () +{ + +} diff --git a/src/boardArea.h b/src/boardArea.h new file mode 100644 index 0000000..1d796f8 --- /dev/null +++ b/src/boardArea.h @@ -0,0 +1,29 @@ +/* + Class of the drawinf of the board. + +*/ + +#ifndef BOARDAREA_H +#define BOARDAREA_H + +#include + +class BoardArea : public QWidget +{ + Q_OBJECT + +public: + BoardArea (QWidget *parent = 0); + QSize minimumSizeHint() const; + QSize sizeHint() const; + +protected: + void paintEvent(QPaintEvent *event); + +private: + void drawBoard (); +}; + + + +#endif diff --git a/src/images/logo32.png b/src/images/logo32.png new file mode 100644 index 0000000..577fdb9 Binary files /dev/null and b/src/images/logo32.png differ diff --git a/src/images/mac/editredo.png b/src/images/mac/editredo.png new file mode 100644 index 0000000..8875bf2 Binary files /dev/null and b/src/images/mac/editredo.png differ diff --git a/src/images/mac/editundo.png b/src/images/mac/editundo.png new file mode 100644 index 0000000..a3bd5e0 Binary files /dev/null and b/src/images/mac/editundo.png differ diff --git a/src/images/mac/filenew.png b/src/images/mac/filenew.png new file mode 100644 index 0000000..fa33277 Binary files /dev/null and b/src/images/mac/filenew.png differ diff --git a/src/images/mac/fileopen.png b/src/images/mac/fileopen.png new file mode 100644 index 0000000..9a10086 Binary files /dev/null and b/src/images/mac/fileopen.png differ diff --git a/src/images/mac/fileprint.png b/src/images/mac/fileprint.png new file mode 100644 index 0000000..e1e6c0d Binary files /dev/null and b/src/images/mac/fileprint.png differ diff --git a/src/images/mac/filesave.png b/src/images/mac/filesave.png new file mode 100644 index 0000000..b41ecf5 Binary files /dev/null and b/src/images/mac/filesave.png differ diff --git a/src/images/win/editredo.png b/src/images/win/editredo.png new file mode 100644 index 0000000..9d679fe Binary files /dev/null and b/src/images/win/editredo.png differ diff --git a/src/images/win/editundo.png b/src/images/win/editundo.png new file mode 100644 index 0000000..eee23d2 Binary files /dev/null and b/src/images/win/editundo.png differ diff --git a/src/images/win/filenew.png b/src/images/win/filenew.png new file mode 100644 index 0000000..dd795cf Binary files /dev/null and b/src/images/win/filenew.png differ diff --git a/src/images/win/fileopen.png b/src/images/win/fileopen.png new file mode 100644 index 0000000..58d7014 Binary files /dev/null and b/src/images/win/fileopen.png differ diff --git a/src/images/win/fileprint.png b/src/images/win/fileprint.png new file mode 100644 index 0000000..2afb769 Binary files /dev/null and b/src/images/win/fileprint.png differ diff --git a/src/images/win/filesave.png b/src/images/win/filesave.png new file mode 100644 index 0000000..604ee3b Binary files /dev/null and b/src/images/win/filesave.png differ diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..ee04bf1 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,20 @@ +/****************************************** + * + * Main function of the sudoku program. + * + ******************************************/ + + +#include +#include "sudoku.h" + +int main (int argc, char **argv) + { + Q_INIT_RESOURCE (sudoku); + QApplication a (argc, argv); + /* Create a new Sudoku object. */ + Sudoku * mw = new Sudoku (); + mw->resize (300,300); + mw->show(); + return a.exec(); +} diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..31f1194 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,16 @@ +SOURCES += sudoku.cpp \ + main.cpp \ + boardArea.cpp + +HEADERS += sudoku.h boardArea.h + +TEMPLATE = app + +CONFIG += release \ + warn_on \ + thread \ + qt + +RESOURCES += sudoku.qrc + +TARGET = ../bin/sudoku diff --git a/src/sudoku.cpp b/src/sudoku.cpp new file mode 100644 index 0000000..c5d20da --- /dev/null +++ b/src/sudoku.cpp @@ -0,0 +1,162 @@ +/* + * Main file of the sudoku program. + * + */ + + +#include "sudoku.h" +#include "boardArea.h" + +#include +#include +#include +#include + + +#ifdef Q_WS_MAC +const QString rsrcPath = ":/images/mac"; +#else +const QString rsrcPath = ":/images/win"; +#endif + +Sudoku::Sudoku (QWidget *parent) : QMainWindow (parent) +{ + setupFileActions(); + setupEditActions(); + board = new BoardArea (this); + setCentralWidget(board); +} + +Sudoku::~Sudoku() +{ + +} + +/************************************************************************* + * This function initialise the file Menu. + ************************************************************************* + */ +void Sudoku::setupFileActions() +{ + QToolBar *tb = new QToolBar (this); + tb->setWindowTitle (tr ("File Actions")); + addToolBar (tb); + + QMenu *menu = new QMenu (tr("&File"), this); + menuBar()->addMenu (menu); + + QAction *a; + + a = new QAction (QIcon (rsrcPath + "/filenew.png"), tr ("&New Game..."), + this); + a->setShortcut (Qt::CTRL + Qt::Key_N); + connect (a, SIGNAL (triggered ()), this, SLOT (fileNewGame ())); + tb->addAction (a); + menu->addAction (a); + + a = new QAction (QIcon (rsrcPath + "/fileopen.png"), tr ("&Open Sudoku..."), + this); + a->setShortcut (Qt::CTRL + Qt::Key_O); + connect (a, SIGNAL (triggered ()), this, SLOT (fileOpen ())); + tb->addAction (a); + menu->addAction (a); + + menu->addSeparator (); + + actionSave = a = new QAction (QIcon (rsrcPath + "/filesave.png"), + tr ("&Save..."), this); + a->setShortcut (Qt::CTRL + Qt::Key_S); + connect (a, SIGNAL (triggered ()), this, SLOT (fileSave ())); + a->setEnabled (false); + tb->addAction (a); + menu->addAction (a); + + a = new QAction (tr ("Save &As..."), this); + connect (a, SIGNAL (triggered ()), this, SLOT (fileSaveAs ())); + menu->addAction (a); + menu->addSeparator (); + + a = new QAction (QIcon (rsrcPath + "/fileprint.png"), tr ("&Print..."), + this); + a->setShortcut (Qt::CTRL + Qt::Key_P); + connect (a, SIGNAL (triggered ()), this, SLOT (filePrint ())); + tb->addAction(a); + menu->addAction(a); + + a = new QAction (tr ("&Close"), this); + a->setShortcut (Qt::CTRL + Qt::Key_W); + connect (a, SIGNAL (triggered ()), this, SLOT (fileClose ())); + menu->addAction (a); + + a = new QAction (tr ("E&xit"), this); + a->setShortcut (Qt::CTRL + Qt::Key_Q); + connect (a, SIGNAL (triggered ()), this, SLOT (fileExit ())); + menu->addAction (a); + +} + + +/************************************************************************* + * This function initialise the Edit Menu. + ************************************************************************* + */ +void Sudoku::setupEditActions() +{ + QToolBar *tb = new QToolBar (this); + tb->setWindowTitle (tr ("Edit Actions")); + addToolBar (tb); + + QMenu *menu = new QMenu (tr ("&Edit"), this); + menuBar()->addMenu (menu); + + QAction *a; + a = actionUndo = new QAction (QIcon(rsrcPath + "/editundo.png"), + tr ("&Undo"), this); + a->setShortcut (Qt::CTRL + Qt::Key_Z); + tb->addAction (a); + menu->addAction (a); + a = actionRedo = new QAction (QIcon(rsrcPath + "/editredo.png"), + tr("&Redo"), this); + a->setShortcut (Qt::CTRL + Qt::Key_Y); + tb->addAction (a); + menu->addAction(a); + +} + +/* Slots ............................................................. */ + + +void Sudoku::fileNewGame () +{ + +} + +void Sudoku::fileOpen () +{ + +} + +void Sudoku::fileSave () +{ + +} + +void Sudoku::fileSaveAs () +{ + +} + +void Sudoku::filePrint () +{ + +} + +void Sudoku::fileClose () +{ + +} + +void Sudoku::fileExit () +{ + +} diff --git a/src/sudoku.h b/src/sudoku.h new file mode 100644 index 0000000..0ab62d5 --- /dev/null +++ b/src/sudoku.h @@ -0,0 +1,43 @@ +#ifndef SUDOKU_H +#define SUDOKU_H + + +#include + +class QAction; +class QMenu; + +class BoardArea; + +class Sudoku : public QMainWindow +{ + Q_OBJECT + +public: + Sudoku (QWidget *parent = 0); + ~Sudoku(); + +private: + void setupFileActions(); + void setupEditActions(); + +private slots: + void fileNewGame (); + void fileOpen (); + void fileSave (); + void fileSaveAs (); + void filePrint (); + void fileClose (); + void fileExit (); + +private: + BoardArea *board; + + QAction *actionSave, + *actionUndo, + *actionRedo; + + QToolBar *tb; +}; + +#endif diff --git a/src/sudoku.qrc b/src/sudoku.qrc new file mode 100644 index 0000000..f052555 --- /dev/null +++ b/src/sudoku.qrc @@ -0,0 +1,18 @@ + + + images/logo32.png + images/mac/editredo.png + images/mac/editundo.png + images/mac/filenew.png + images/mac/fileopen.png + images/mac/fileprint.png + images/mac/filesave.png + images/win/editredo.png + images/win/editundo.png + images/win/filenew.png + images/win/fileopen.png + images/win/fileprint.png + images/win/filesave.png + + + diff --git a/sudoku.pro b/sudoku.pro new file mode 100644 index 0000000..20f1cba --- /dev/null +++ b/sudoku.pro @@ -0,0 +1,6 @@ +SUBDIRS += src +TEMPLATE = subdirs +CONFIG += release \ + warn_on \ + qt \ + thread