From: timoph Date: Sat, 2 Jan 2010 17:37:39 +0000 (+0000) Subject: Added settings dialog X-Git-Tag: 0.7.2~27 X-Git-Url: http://git.maemo.org/git/?p=impuzzle;a=commitdiff_plain;h=fdcfe62bec5ff683a2e728b4b49c93c807edc316 Added settings dialog git-svn-id: file:///svnroot/impuzzle/trunk@7 e6bec12f-0854-4cc4-ad26-6875f1509f77 --- diff --git a/debian/changelog b/debian/changelog index 692fd6f..3bbd7bd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +impuzzle (0.2-1maemo0) unstable; urgency=low + + * Fixes: All pieces movable after shuffle + + -- Timo Härkönen Sat, 2 Jan 2010 17:26:12 +0200 + impuzzle (0.1-1maemo1) unstable; urgency=low * Fixes: Typo in package dependencies diff --git a/src/defines.h b/src/defines.h index 8584b5e..e977a23 100644 --- a/src/defines.h +++ b/src/defines.h @@ -25,4 +25,7 @@ #define GAME_VERSION = "0.1" +#define EASY_PIECE_COUNT 12 +#define HARD_PIECE_COUNT 20 + #endif // DEFINES_H diff --git a/src/imageimporter.cpp b/src/imageimporter.cpp index 961171f..dab504b 100644 --- a/src/imageimporter.cpp +++ b/src/imageimporter.cpp @@ -46,6 +46,7 @@ QList ImageImporter::newPieces(const QPixmap &pixmap, const int co QPixmap tmp; if(pixmap.isNull()) { + qDebug() << "Got NULL image - using default.jpg"; tmp = QPixmap(":/images/default.jpg"); } else { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e95883f..b728d4d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -18,6 +18,8 @@ #include "mainwindow.h" #include "gameview.h" +#include "settings.h" +#include "settingsdialog.h" #include #include @@ -49,6 +51,9 @@ void MainWindow::createActions() importAction_ = new QAction(tr("Import image"), this); connect(importAction_, SIGNAL(triggered()), this, SLOT(importClicked())); importAction_->setDisabled(true); + + settingsAction_ = new QAction(tr("Settings"), this); + connect(settingsAction_, SIGNAL(triggered()), this, SLOT(settingsClicked())); } void MainWindow::importClicked() @@ -58,5 +63,13 @@ void MainWindow::importClicked() void MainWindow::newGameClicked() { - GameView::instance()->setPieces(ImageImporter::instance()->newPieces(0, 20)); + SettingsDialog dialog(this); + dialog.exec(); + + GameView::instance()->setPieces(ImageImporter::instance()->newPieces(Settings::instance()->image(), Settings::instance()->pieceCount())); +} + +void MainWindow::settingsClicked() +{ + } diff --git a/src/mainwindow.h b/src/mainwindow.h index f42c97b..f101b5b 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -31,9 +31,10 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget *parent = 0); -public slots: +private slots: void newGameClicked(); void importClicked(); + void settingsClicked(); private: void createActions(); @@ -41,6 +42,7 @@ private: QAction *newGameAction_; QAction *importAction_; + QAction *settingsAction_; QMenu *menu_; }; diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..ecbd675 --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,39 @@ +#include "settings.h" + +Settings *Settings::instance_ = 0; + +Settings::Settings(QObject *parent) : + QObject(parent) +{ + pieceCount_ = 12; + image_ = 0; +} + +Settings *Settings::instance() +{ + if(!instance_) { + instance_ = new Settings; + } + + return instance_; +} + +int Settings::pieceCount() const +{ + return pieceCount_; +} + +void Settings::setPieceCount(const int pieces) +{ + pieceCount_ = pieces; +} + +QPixmap Settings::image() const +{ + return image_; +} + +void Settings::setImage(const QPixmap &image) +{ + image_ = image; +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..06b1a54 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,28 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include + +class Settings : public QObject +{ + Q_OBJECT + +public: + static Settings *instance(); + + int pieceCount() const; + void setPieceCount(const int pieces); + + QPixmap image() const; + void setImage(const QPixmap &image); + +private: + Settings(QObject *parent = 0); + + static Settings *instance_; + + int pieceCount_; + QPixmap image_; +}; +#endif diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp new file mode 100644 index 0000000..0c2b751 --- /dev/null +++ b/src/settingsdialog.cpp @@ -0,0 +1,43 @@ +#include "settingsdialog.h" +#include "settings.h" +#include "defines.h" + +#include +#include +#include +#include +#include + +SettingsDialog::SettingsDialog(QWidget *parent) : + QDialog(parent) +{ + setModal(true); + + easyButton_ = new QRadioButton(tr("Easy")); + easyButton_->setChecked(true); + hardButton_ = new QRadioButton(tr("Hard")); + + buttonLayout_ = new QHBoxLayout; + buttonLayout_->addWidget(easyButton_); + buttonLayout_->addWidget(hardButton_); + + buttonGroup_ = new QGroupBox(tr("Difficulty")); + buttonGroup_->setLayout(buttonLayout_); + + mainLayout_ = new QVBoxLayout; + mainLayout_->addWidget(buttonGroup_); + + setLayout(mainLayout_); + + connect(easyButton_, SIGNAL(toggled(bool)), this, SLOT(difficultySelectionChanged(bool))); +} + +void SettingsDialog::difficultySelectionChanged(bool value) +{ + if(value) { + Settings::instance()->setPieceCount(EASY_PIECE_COUNT); + } + else { + Settings::instance()->setPieceCount(HARD_PIECE_COUNT); + } +} diff --git a/src/settingsdialog.h b/src/settingsdialog.h new file mode 100644 index 0000000..53feb67 --- /dev/null +++ b/src/settingsdialog.h @@ -0,0 +1,30 @@ +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include + +class QVBoxLayout; +class QGroupBox; +class QRadioButton; +class QHBoxLayout; + +class SettingsDialog : public QDialog +{ + Q_OBJECT + +public: + SettingsDialog(QWidget *parent = 0); + +private slots: + void difficultySelectionChanged(bool value); + +private: + QVBoxLayout *mainLayout_; + QHBoxLayout *buttonLayout_; + + QRadioButton *easyButton_; + QRadioButton *hardButton_; + + QGroupBox *buttonGroup_; +}; +#endif diff --git a/src/src.pro b/src/src.pro index 901d8f4..de7ab4e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -11,7 +11,9 @@ HEADERS += gameview.h \ puzzleitem.h \ newgamedialog.h \ defines.h \ - introitem.h + introitem.h \ + settings.h \ + settingsdialog.h SOURCES += gameview.cpp \ main.cpp \ @@ -19,7 +21,9 @@ SOURCES += gameview.cpp \ imageimporter.cpp \ puzzleitem.cpp \ newgamedialog.cpp \ - introitem.cpp + introitem.cpp \ + settings.cpp \ + settingsdialog.cpp RESOURCES += resources.qrc