2 Image Puzzle - A set your pieces straight game
3 Copyright (C) 2009 Timo Härkönen
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.
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.
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/>.
19 #include "mainwindow.h"
22 #include "settingsdialog.h"
23 #include "aboutdialog.h"
24 #include "puzzleitem.h"
32 #include "imageimporter.h"
34 MainWindow *MainWindow::instance_ = 0;
36 MainWindow::MainWindow(QWidget *parent) :
42 setCentralWidget(GameView::instance());
43 settingsDialog_ = new SettingsDialog(this);
45 setWindowTitle(tr("ImPuzzle"));
47 connect(GameView::instance(), SIGNAL(gameWon()), this, SLOT(gameEnded()));
48 connect(GameView::instance(), SIGNAL(gameRestored()), this, SLOT(enableSaving()));
51 MainWindow *MainWindow::instance()
54 instance_ = new MainWindow;
60 void MainWindow::createMenu()
62 menu_ = menuBar()->addMenu("");
63 menu_->addAction(newGameAction_);
64 menu_->addAction(saveAction_);
65 menu_->addAction(aboutAction_);
66 menu_->addAction(importAction_);
69 void MainWindow::createActions()
71 newGameAction_ = new QAction(tr("New game"), this);
72 connect(newGameAction_, SIGNAL(triggered()), this, SLOT(newGameClicked()));
74 importAction_ = new QAction(tr("Import image"), this);
75 connect(importAction_, SIGNAL(triggered()), this, SLOT(importClicked()));
76 importAction_->setDisabled(true);
78 aboutAction_ = new QAction(tr("About ImPuzzle"), this);
79 connect(aboutAction_, SIGNAL(triggered()), this, SLOT(aboutClicked()));
81 saveAction_ = new QAction(tr("Save and quit"), this);
82 connect(saveAction_, SIGNAL(triggered()), GameView::instance(), SLOT(saveGame()));
83 saveAction_->setDisabled(true);
86 void MainWindow::importClicked()
91 void MainWindow::newGameClicked()
93 settingsDialog_->exec();
95 GameView::instance()->setPieces(ImageImporter::instance()->newPieces(Settings::instance()->image(), Settings::instance()->pieceCount()));
99 void MainWindow::aboutClicked()
101 AboutDialog *dialog = new AboutDialog(this);
103 dialog->deleteLater();
106 void MainWindow::gameEnded()
108 if(saveAction_->isEnabled()) {
109 saveAction_->setDisabled(true);
110 PuzzleItem::resetMoveCount();
114 void MainWindow::enableSaving()
116 if(!saveAction_->isEnabled()) {
117 saveAction_->setEnabled(true);