From: timoph Date: Sat, 24 Apr 2010 17:46:10 +0000 (+0000) Subject: New initial view and adding about dialog X-Git-Tag: 0.7.2~15 X-Git-Url: http://git.maemo.org/git/?p=impuzzle;a=commitdiff_plain;h=efc46c69cd39215ef1699c577668ea8854385257;hp=a99fb2957d3f32c8cedb73c942cad34db832086b New initial view and adding about dialog git-svn-id: file:///svnroot/impuzzle/trunk@19 e6bec12f-0854-4cc4-ad26-6875f1509f77 --- diff --git a/debian/changelog b/debian/changelog index 99b4fc7..7a1e3b0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +impuzzle (0.5-1maemo0) unstable; urgency=low + + * Implemented: New initial view + * Implemented: About dialog + + -- Timo Härkönen 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 index 0000000..3504367 --- /dev/null +++ b/src/aboutdialog.cpp @@ -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 . + */ + +#include "aboutdialog.h" +#include "defines.h" + +#include +#include + +AboutDialog::AboutDialog(QWidget *parent) : + QDialog(parent) +{ + setModal(true); + + setWindowTitle(tr("About ImPuzzle")); + + textEdit_ = new QTextEdit; + + QString txt = "ImPuzzle - 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.
"; + + //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 index 0000000..08a027f --- /dev/null +++ b/src/aboutdialog.h @@ -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 . + */ + +#ifndef ABOUTDIALOG_H +#define ABOUTDIALOG_H + +#include + +class QTextEdit; +class QVBoxLayout; + +class AboutDialog : public QDialog +{ + Q_OBJECT + +public: + AboutDialog(QWidget *parent = 0); + +private: + QTextEdit *textEdit_; + QVBoxLayout *mainLayout_; +}; +#endif diff --git a/src/defines.h b/src/defines.h index ded9e0e..716c393 100644 --- a/src/defines.h +++ b/src/defines.h @@ -37,4 +37,6 @@ #define RESTORE_FILE "impuzzle.dat" #define HOME_DIRECTORY ".impuzzle" +#define IMPUZZLE_VERSION "0.5" + #endif // DEFINES_H diff --git a/src/gameview.cpp b/src/gameview.cpp index e0d5b06..3223602 100644 --- a/src/gameview.cpp +++ b/src/gameview.cpp @@ -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; diff --git a/src/introitem.cpp b/src/introitem.cpp index 98e0baf..0b7b270 100644 --- a/src/introitem.cpp +++ b/src/introitem.cpp @@ -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 . + */ + #include "introitem.h" #include "defines.h" +#include "mainwindow.h" #include #include @@ -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(); +} diff --git a/src/introitem.h b/src/introitem.h index 40a8ccd..a0c0bb1 100644 --- a/src/introitem.h +++ b/src/introitem.h @@ -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 . + */ + #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_; }; diff --git a/src/main.cpp b/src/main.cpp index 13c7841..2aa6758 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,8 +24,7 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - MainWindow mw; - mw.show(); + MainWindow::instance()->show(); return app.exec(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 514dcec..fea49c2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -20,6 +20,7 @@ #include "gameview.h" #include "settings.h" #include "settingsdialog.h" +#include "aboutdialog.h" #include "puzzleitem.h" #include @@ -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() diff --git a/src/mainwindow.h b/src/mainwindow.h index 7367cf0..91e9234 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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_; diff --git a/src/settings.cpp b/src/settings.cpp index 93af8ba..3a418be 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -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 . + */ + #include "settings.h" #include "defines.h" diff --git a/src/settings.h b/src/settings.h index 4d69150..bb45e67 100644 --- a/src/settings.h +++ b/src/settings.h @@ -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 . + */ + #ifndef SETTINGS_H #define SETTINGS_H diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 778666d..be783dc 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -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 . + */ + #include "settingsdialog.h" #include "settings.h" #include "defines.h" diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 757a489..05a759b 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -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 . + */ + #ifndef SETTINGSDIALOG_H #define SETTINGSDIALOG_H diff --git a/src/src.pro b/src/src.pro index c92dcfd..e99e8ed 100644 --- a/src/src.pro +++ b/src/src.pro @@ -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