Save and restore
[impuzzle] / src / mainwindow.cpp
1 /*
2   Image Puzzle - A set your pieces straight game
3   Copyright (C) 2009  Timo Härkönen
4
5   This program is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "mainwindow.h"
20 #include "gameview.h"
21 #include "settings.h"
22 #include "settingsdialog.h"
23
24 #include <QAction>
25 #include <QMenu>
26 #include <QMenuBar>
27
28 #include "imageimporter.h"
29
30 MainWindow::MainWindow(QWidget *parent) :
31         QMainWindow(parent)
32 {
33     createActions();
34     createMenu();
35
36     setCentralWidget(GameView::instance());
37     settingsDialog_ = new SettingsDialog(this);
38
39     setWindowTitle(tr("ImPuzzle"));
40 }
41
42 void MainWindow::createMenu()
43 {
44     menu_ = menuBar()->addMenu("");
45     menu_->addAction(newGameAction_);
46     menu_->addAction(saveAction_);
47     menu_->addAction(importAction_);
48 }
49
50 void MainWindow::createActions()
51 {
52     newGameAction_ = new QAction(tr("New game"), this);
53     connect(newGameAction_, SIGNAL(triggered()), this, SLOT(newGameClicked()));
54
55     importAction_ = new QAction(tr("Import image"), this);
56     connect(importAction_, SIGNAL(triggered()), this, SLOT(importClicked()));
57     importAction_->setDisabled(true);
58
59     settingsAction_ = new QAction(tr("Settings"), this);
60     connect(settingsAction_, SIGNAL(triggered()), this, SLOT(settingsClicked()));
61
62     saveAction_ = new QAction(tr("Save game"), this);
63     connect(saveAction_, SIGNAL(triggered()), GameView::instance(), SLOT(saveGame()));
64 }
65
66 void MainWindow::importClicked()
67 {
68
69 }
70
71 void MainWindow::newGameClicked()
72 {
73     //SettingsDialog dialog(this);
74     //dialog.exec();
75     settingsDialog_->exec();
76
77     GameView::instance()->setPieces(ImageImporter::instance()->newPieces(Settings::instance()->image(), Settings::instance()->pieceCount()));
78 }
79
80 void MainWindow::settingsClicked()
81 {
82
83 }