New initial view and adding about dialog
authortimoph <timop.harkonen@gmail.com>
Sat, 24 Apr 2010 17:46:10 +0000 (17:46 +0000)
committertimoph <timop.harkonen@gmail.com>
Sat, 24 Apr 2010 17:46:10 +0000 (17:46 +0000)
git-svn-id: file:///svnroot/impuzzle/trunk@19 e6bec12f-0854-4cc4-ad26-6875f1509f77

15 files changed:
debian/changelog
src/aboutdialog.cpp [new file with mode: 0644]
src/aboutdialog.h [new file with mode: 0644]
src/defines.h
src/gameview.cpp
src/introitem.cpp
src/introitem.h
src/main.cpp
src/mainwindow.cpp
src/mainwindow.h
src/settings.cpp
src/settings.h
src/settingsdialog.cpp
src/settingsdialog.h
src/src.pro

index 99b4fc7..7a1e3b0 100644 (file)
@@ -1,3 +1,10 @@
+impuzzle (0.5-1maemo0) unstable; urgency=low
+
+  * Implemented: New initial view
+  * Implemented: About dialog
+
+ -- Timo Härkönen <timop.harkonen@gmail.com>  Sat, 24 Apr 2010 20:44:00 +0200
+
 impuzzle (0.4-2maemo0) unstable; urgency=low
 
   * Fixes: Saving not enabled after game is restored
diff --git a/src/aboutdialog.cpp b/src/aboutdialog.cpp
new file mode 100644 (file)
index 0000000..3504367
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+  Image Puzzle - A set your pieces straight game
+  Copyright (C) 2009  Timo Härkönen
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "aboutdialog.h"
+#include "defines.h"
+
+#include <QTextEdit>
+#include <QVBoxLayout>
+
+AboutDialog::AboutDialog(QWidget *parent) :
+        QDialog(parent)
+{
+    setModal(true);
+
+    setWindowTitle(tr("About ImPuzzle"));
+
+    textEdit_ = new QTextEdit;
+
+    QString txt =   "ImPuzzle - A set your pieces straight game<br />"
+                    "Copyright (C) 2009  Timo H&auml;rk&ouml;nen<br />"
+                    "<br />"
+                    "This program is free software: you can redistribute it and/or modify<br />"
+                    "it under the terms of the GNU General Public License as published by<br />"
+                    "the Free Software Foundation, either version 3 of the License, or<br />"
+                    "(at your option) any later version.<br />"
+                    "<br />"
+                    "This program is distributed in the hope that it will be useful,<br />"
+                    "but WITHOUT ANY WARRANTY; without even the implied warranty of<br />"
+                    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br />"
+                    "<a href=\"http://www.gnu.org/licenses/gpl.txt\">GNU General Public License</a> for more details.<br />";
+
+    //textEdit_->setText(txt);
+    textEdit_->setHtml(txt);
+
+    mainLayout_ = new QVBoxLayout;
+    mainLayout_->addWidget(textEdit_);
+
+    setLayout(mainLayout_);
+}
diff --git a/src/aboutdialog.h b/src/aboutdialog.h
new file mode 100644 (file)
index 0000000..08a027f
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+  Image Puzzle - A set your pieces straight game
+  Copyright (C) 2009  Timo Härkönen
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ABOUTDIALOG_H
+#define ABOUTDIALOG_H
+
+#include <QDialog>
+
+class QTextEdit;
+class QVBoxLayout;
+
+class AboutDialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    AboutDialog(QWidget *parent = 0);
+
+private:
+    QTextEdit *textEdit_;
+    QVBoxLayout *mainLayout_;
+};
+#endif
index ded9e0e..716c393 100644 (file)
@@ -37,4 +37,6 @@
 #define RESTORE_FILE "impuzzle.dat"
 #define HOME_DIRECTORY ".impuzzle"
 
+#define IMPUZZLE_VERSION "0.5"
+
 #endif // DEFINES_H
index e0d5b06..3223602 100644 (file)
@@ -51,13 +51,14 @@ GameView *GameView::instance_ = 0;
 GameView::GameView(QWidget *parent) :
         QGraphicsView(parent)
 {
+    setBackgroundBrush(Qt::black);
     qsrand(QDateTime::currentDateTime().toTime_t());
     scene_ = new QGraphicsScene;
     hiddenIndex_ = -1;
     setScene(scene_);
 
     introItem_ = new IntroItem;
-    introItem_->setText("Select new game from menu to play");
+    introItem_->setText("- ImPuzzle -");
 
     verticalStep_ = 0;
     horizontalStep_ = 0;
index 98e0baf..0b7b270 100644 (file)
@@ -1,5 +1,24 @@
+/*
+  Image Puzzle - A set your pieces straight game
+  Copyright (C) 2009  Timo Härkönen
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include "introitem.h"
 #include "defines.h"
+#include "mainwindow.h"
 
 #include <QPainter>
 #include <QFontMetricsF>
@@ -21,21 +40,72 @@ void IntroItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
     Q_UNUSED(widget)
 
     painter->save();
+    painter->setRenderHint(QPainter::Antialiasing, true);
+    painter->setPen(Qt::NoPen);
+
+    const int dots = 96;
+
+    int hstep = boundingRect().width() / dots;
+    int vstep = boundingRect().height() / dots;
+
+    QColor colors[3] = {QColor(255, 255, 255), QColor(0, 0, 0), QColor(127, 127, 127)};
+
+    for(int i = 0; i < dots; ++i) {
+        for(int j = 0; j < dots; ++j) {
+            painter->setBrush(QBrush(colors[qrand() % 2]));
+            painter->drawRect(QRect(QPoint(i * hstep, j * vstep),
+                                    QPoint((i+1) * hstep, (j+1) * vstep)));
+        }
+    }
 
     painter->setBrush(Qt::NoBrush);
     painter->setPen(Qt::black);
 
+    QFont font = painter->font();
+    font.setPointSize(72);
+    font.setBold(true);
+    painter->setFont(font);
+
     // Get font metrics
     QFontMetricsF fontMetricsF(painter->font());
     QRectF textRectF = fontMetricsF.boundingRect(text_);
-    int horizontalIntend = (IMAGE_WIDTH - textRectF.width()) / 2;
-    int verticalIntend = (IMAGE_HEIGHT - textRectF.height()) / 2;
+    int horizontalIntend = (boundingRect().width() - textRectF.width()) / 2 - 10;
+    int verticalIntend = (boundingRect().height() - textRectF.height()) / 2 - 10;
+
+    // Draw rect behind the text
+    painter->setBrush(QBrush(QColor(0,0,0,192)));
+    painter->setPen(Qt::NoPen);
+    painter->drawRect(boundingRect()
+                      .adjusted(0, verticalIntend, 5, -verticalIntend));
 
+    painter->setPen(Qt::black);
+    painter->setBrush(Qt::NoBrush);
     // Draw text aligned to the center of boundingRect
+    QPen pen = painter->pen();
+    pen.setCosmetic(true);
+    pen.setColor(QColor(255,20,0,192));
+
+    painter->setPen(pen);
     painter->drawText(boundingRect()
                       .adjusted(horizontalIntend, verticalIntend,-horizontalIntend, -verticalIntend),
                       text_);
 
+    pen.setColor(QColor(Qt::white));
+    painter->setPen(pen);
+    font.setPointSize(12);
+    painter->setFont(font);
+
+    QString txt = QString("Version %1").arg(IMPUZZLE_VERSION);
+
+    QFontMetricsF fm(painter->font());
+    QRectF trect = fm.boundingRect(txt);
+
+    QTextOption textOption;
+    textOption.setAlignment(Qt::AlignRight);
+
+    painter->drawText(boundingRect().adjusted(0, verticalIntend * 2 - trect.height(), -trect.width(), 0),
+                      txt, textOption);
+
     painter->restore();
 }
 
@@ -52,3 +122,10 @@ void IntroItem::setText(const QString &txt)
         update();
     }
 }
+
+void IntroItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+    Q_UNUSED(event);
+
+    MainWindow::instance()->newGameClicked();
+}
index 40a8ccd..a0c0bb1 100644 (file)
@@ -1,3 +1,21 @@
+/*
+  Image Puzzle - A set your pieces straight game
+  Copyright (C) 2009  Timo Härkönen
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef INTROITEM_H
 #define INTROITEM_H
 
@@ -12,6 +30,9 @@ public:
     QString text() const;
     void setText(const QString &txt);
 
+protected:
+    void mousePressEvent(QGraphicsSceneMouseEvent *event);
+
 private:
     QString text_;
 };
index 13c7841..2aa6758 100644 (file)
@@ -24,8 +24,7 @@ int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
 
-    MainWindow mw;
-    mw.show();
+    MainWindow::instance()->show();
 
     return app.exec();
 }
index 514dcec..fea49c2 100644 (file)
@@ -20,6 +20,7 @@
 #include "gameview.h"
 #include "settings.h"
 #include "settingsdialog.h"
+#include "aboutdialog.h"
 #include "puzzleitem.h"
 
 #include <QAction>
@@ -30,6 +31,8 @@
 
 #include "imageimporter.h"
 
+MainWindow *MainWindow::instance_ = 0;
+
 MainWindow::MainWindow(QWidget *parent) :
         QMainWindow(parent)
 {
@@ -45,11 +48,21 @@ MainWindow::MainWindow(QWidget *parent) :
     connect(GameView::instance(), SIGNAL(gameRestored()), this, SLOT(enableSaving()));
 }
 
+MainWindow *MainWindow::instance()
+{
+    if(!instance_) {
+        instance_ = new MainWindow;
+    }
+
+    return instance_;
+}
+
 void MainWindow::createMenu()
 {
     menu_ = menuBar()->addMenu("");
     menu_->addAction(newGameAction_);
     menu_->addAction(saveAction_);
+    menu_->addAction(aboutAction_);
     menu_->addAction(importAction_);
 }
 
@@ -62,8 +75,8 @@ void MainWindow::createActions()
     connect(importAction_, SIGNAL(triggered()), this, SLOT(importClicked()));
     importAction_->setDisabled(true);
 
-    settingsAction_ = new QAction(tr("Settings"), this);
-    connect(settingsAction_, SIGNAL(triggered()), this, SLOT(settingsClicked()));
+    aboutAction_ = new QAction(tr("About ImPuzzle"), this);
+    connect(aboutAction_, SIGNAL(triggered()), this, SLOT(aboutClicked()));
 
     saveAction_ = new QAction(tr("Save and quit"), this);
     connect(saveAction_, SIGNAL(triggered()), GameView::instance(), SLOT(saveGame()));
@@ -83,9 +96,11 @@ void MainWindow::newGameClicked()
     enableSaving();
 }
 
-void MainWindow::settingsClicked()
+void MainWindow::aboutClicked()
 {
-
+    AboutDialog *dialog = new AboutDialog(this);
+    dialog->exec();
+    dialog->deleteLater();
 }
 
 void MainWindow::gameEnded()
index 7367cf0..91e9234 100644 (file)
@@ -30,22 +30,26 @@ class MainWindow : public QMainWindow
     Q_OBJECT
 
 public:
-    MainWindow(QWidget *parent = 0);
+    static MainWindow *instance();
 
-private slots:
+public slots:
     void newGameClicked();
+
+private slots:
     void importClicked();
-    void settingsClicked();
+    void aboutClicked();
     void gameEnded();
     void enableSaving();
 
 private:
+    MainWindow(QWidget *parent = 0);
     void createActions();
     void createMenu();
 
+    static MainWindow *instance_;
     QAction *newGameAction_;
     QAction *importAction_;
-    QAction *settingsAction_;
+    QAction *aboutAction_;
     QAction *saveAction_;
 
     QMenu *menu_;
index 93af8ba..3a418be 100644 (file)
@@ -1,3 +1,21 @@
+/*
+  Image Puzzle - A set your pieces straight game
+  Copyright (C) 2009  Timo Härkönen
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include "settings.h"
 #include "defines.h"
 
index 4d69150..bb45e67 100644 (file)
@@ -1,3 +1,21 @@
+/*
+  Image Puzzle - A set your pieces straight game
+  Copyright (C) 2009  Timo Härkönen
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef SETTINGS_H
 #define SETTINGS_H
 
index 778666d..be783dc 100644 (file)
@@ -1,3 +1,21 @@
+/*
+  Image Puzzle - A set your pieces straight game
+  Copyright (C) 2009  Timo Härkönen
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include "settingsdialog.h"
 #include "settings.h"
 #include "defines.h"
index 757a489..05a759b 100644 (file)
@@ -1,3 +1,21 @@
+/*
+  Image Puzzle - A set your pieces straight game
+  Copyright (C) 2009  Timo Härkönen
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef SETTINGSDIALOG_H
 #define SETTINGSDIALOG_H
 
index c92dcfd..e99e8ed 100644 (file)
@@ -16,7 +16,8 @@ HEADERS += gameview.h \
     defines.h \
     introitem.h \
     settings.h \
-    settingsdialog.h
+    settingsdialog.h \
+    aboutdialog.h
 
 SOURCES += gameview.cpp \
     main.cpp \
@@ -25,7 +26,8 @@ SOURCES += gameview.cpp \
     puzzleitem.cpp \
     introitem.cpp \
     settings.cpp \
-    settingsdialog.cpp
+    settingsdialog.cpp \
+    aboutdialog.cpp
 
 RESOURCES += resources.qrc