Add sudoku Game
41
src/boardArea.cpp
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Class for drawing the board.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#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 ()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
29
src/boardArea.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
Class of the drawinf of the board.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOARDAREA_H
|
||||||
|
#define BOARDAREA_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
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
|
||||||
BIN
src/images/logo32.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src/images/mac/editredo.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/images/mac/editundo.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/images/mac/filenew.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/images/mac/fileopen.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
src/images/mac/fileprint.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
src/images/mac/filesave.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/images/win/editredo.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/images/win/editundo.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/images/win/filenew.png
Normal file
|
After Width: | Height: | Size: 977 B |
BIN
src/images/win/fileopen.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
src/images/win/fileprint.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/images/win/filesave.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
20
src/main.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/******************************************
|
||||||
|
*
|
||||||
|
* Main function of the sudoku program.
|
||||||
|
*
|
||||||
|
******************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#include <qapplication.h>
|
||||||
|
#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();
|
||||||
|
}
|
||||||
16
src/src.pro
Normal file
@@ -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
|
||||||
162
src/sudoku.cpp
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
* Main file of the sudoku program.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "sudoku.h"
|
||||||
|
#include "boardArea.h"
|
||||||
|
|
||||||
|
#include <qaction.h>
|
||||||
|
#include <qmenu.h>
|
||||||
|
#include <qmenubar.h>
|
||||||
|
#include <qtoolbar.h>
|
||||||
|
|
||||||
|
|
||||||
|
#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 ()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
43
src/sudoku.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#ifndef SUDOKU_H
|
||||||
|
#define SUDOKU_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <qmainwindow.h>
|
||||||
|
|
||||||
|
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
|
||||||
18
src/sudoku.qrc
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE RCC><RCC version="1.0">
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>images/logo32.png</file>
|
||||||
|
<file>images/mac/editredo.png</file>
|
||||||
|
<file>images/mac/editundo.png</file>
|
||||||
|
<file>images/mac/filenew.png</file>
|
||||||
|
<file>images/mac/fileopen.png</file>
|
||||||
|
<file>images/mac/fileprint.png</file>
|
||||||
|
<file>images/mac/filesave.png</file>
|
||||||
|
<file>images/win/editredo.png</file>
|
||||||
|
<file>images/win/editundo.png</file>
|
||||||
|
<file>images/win/filenew.png</file>
|
||||||
|
<file>images/win/fileopen.png</file>
|
||||||
|
<file>images/win/fileprint.png</file>
|
||||||
|
<file>images/win/filesave.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
|
|
||||||
6
sudoku.pro
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
SUBDIRS += src
|
||||||
|
TEMPLATE = subdirs
|
||||||
|
CONFIG += release \
|
||||||
|
warn_on \
|
||||||
|
qt \
|
||||||
|
thread
|
||||||