diff options
author | Alexis Menard <alexis.menard@trolltech.com> | 2009-09-01 14:25:49 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@trolltech.com> | 2009-09-01 14:26:46 (GMT) |
commit | 9f59fb741183e1235b2a385b0e688e4a7f4b15c9 (patch) | |
tree | 17dd583116acc5ee5ff28914713e063204558e9b /demos/sub-attaq | |
parent | 45b3c4c151ad5c4d7361aa331bb4184bbed23681 (diff) | |
download | Qt-9f59fb741183e1235b2a385b0e688e4a7f4b15c9.zip Qt-9f59fb741183e1235b2a385b0e688e4a7f4b15c9.tar.gz Qt-9f59fb741183e1235b2a385b0e688e4a7f4b15c9.tar.bz2 |
Make sub-attaq working without the popup which make it working on
Mac.
Diffstat (limited to 'demos/sub-attaq')
-rw-r--r-- | demos/sub-attaq/graphicsscene.cpp | 13 | ||||
-rw-r--r-- | demos/sub-attaq/graphicsscene.h | 2 | ||||
-rw-r--r-- | demos/sub-attaq/states.cpp | 25 | ||||
-rw-r--r-- | demos/sub-attaq/states.h | 2 | ||||
-rw-r--r-- | demos/sub-attaq/sub-attaq.pro | 18 | ||||
-rw-r--r-- | demos/sub-attaq/textinformationitem.cpp | 54 | ||||
-rw-r--r-- | demos/sub-attaq/textinformationitem.h | 55 |
7 files changed, 153 insertions, 16 deletions
diff --git a/demos/sub-attaq/graphicsscene.cpp b/demos/sub-attaq/graphicsscene.cpp index b4fd0c9..79de011 100644 --- a/demos/sub-attaq/graphicsscene.cpp +++ b/demos/sub-attaq/graphicsscene.cpp @@ -51,6 +51,7 @@ #include "animationmanager.h" #include "qanimationstate.h" #include "progressitem.h" +#include "textinformationitem.h" //Qt #include <QtCore/QPropertyAnimation> @@ -112,6 +113,8 @@ GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode) //The item that display score and level progressItem = new ProgressItem(backgroundItem); + textInformationItem = new TextInformationItem(backgroundItem); + textInformationItem->hide(); //We create the boat boat = new Boat(); addItem(boat); @@ -244,15 +247,15 @@ void GraphicsScene::setupScene(const QList<QAction *> &actions) lettersFadingState->setAnimation(lettersGroupFading); //if new game then we fade out the welcome screen and start playing - lettersMovingState->addTransition(newAction, SIGNAL(triggered()),lettersFadingState); - lettersFadingState->addTransition(lettersFadingState, SIGNAL(animationFinished()),gameState); + lettersMovingState->addTransition(newAction, SIGNAL(triggered()), lettersFadingState); + lettersFadingState->addTransition(lettersFadingState, SIGNAL(animationFinished()), gameState); //New Game is triggered then player start playing - gameState->addTransition(newAction, SIGNAL(triggered()),gameState); + gameState->addTransition(newAction, SIGNAL(triggered()), gameState); //Wanna quit, then connect to CTRL+Q - gameState->addTransition(quitAction, SIGNAL(triggered()),final); - lettersMovingState->addTransition(quitAction, SIGNAL(triggered()),final); + gameState->addTransition(quitAction, SIGNAL(triggered()), final); + lettersMovingState->addTransition(quitAction, SIGNAL(triggered()), final); //Welcome screen is the initial state machine->setInitialState(lettersMovingState); diff --git a/demos/sub-attaq/graphicsscene.h b/demos/sub-attaq/graphicsscene.h index 073ad17..8fa62f7 100644 --- a/demos/sub-attaq/graphicsscene.h +++ b/demos/sub-attaq/graphicsscene.h @@ -54,6 +54,7 @@ class Torpedo; class Bomb; class PixmapItem; class ProgressItem; +class TextInformationItem; QT_BEGIN_NAMESPACE class QAction; QT_END_NAMESPACE @@ -108,6 +109,7 @@ private: Mode mode; PixmapItem *backgroundItem; ProgressItem *progressItem; + TextInformationItem *textInformationItem; QAction * newAction; QAction * quitAction; Boat *boat; diff --git a/demos/sub-attaq/states.cpp b/demos/sub-attaq/states.cpp index 75a2615..5c809cb 100644 --- a/demos/sub-attaq/states.cpp +++ b/demos/sub-attaq/states.cpp @@ -47,6 +47,7 @@ #include "torpedo.h" #include "animationmanager.h" #include "progressitem.h" +#include "textinformationitem.h" //Qt #include <QtGui/QMessageBox> @@ -226,8 +227,15 @@ void LostState::onEntry(QEvent *) //We clear the scene scene->clearScene(); - //we have only one view - QMessageBox::information(scene->views().at(0),"You lose",message); + //We inform the player + scene->textInformationItem->setMessage(message); + scene->textInformationItem->show(); +} + +void LostState::onExit(QEvent *) +{ + //we hide the information + scene->textInformationItem->hide(); } /** Win State */ @@ -242,7 +250,7 @@ void WinState::onEntry(QEvent *) QString message; if (scene->levelsData.size() - 1 != game->currentLevel) { - message = QString("You win the level %1. Your score is %2.\nPress Space to continue after closing this dialog.").arg(game->currentLevel+1).arg(game->score); + message = QString("You win the level %1. Your score is %2.\nPress Space to continue.").arg(game->currentLevel+1).arg(game->score); //We increment the level number game->currentLevel++; } else { @@ -253,8 +261,15 @@ void WinState::onEntry(QEvent *) game->score = 0; } - //we have only one view - QMessageBox::information(scene->views().at(0),"You win",message); + //We inform the player + scene->textInformationItem->setMessage(message); + scene->textInformationItem->show(); +} + +void WinState::onExit(QEvent *) +{ + //we hide the information + scene->textInformationItem->hide(); } /** UpdateScore State */ diff --git a/demos/sub-attaq/states.h b/demos/sub-attaq/states.h index 7635c0c..3176571 100644 --- a/demos/sub-attaq/states.h +++ b/demos/sub-attaq/states.h @@ -113,6 +113,7 @@ public: protected: void onEntry(QEvent *); + void onExit(QEvent *); private : GraphicsScene *scene; PlayState *game; @@ -125,6 +126,7 @@ public: protected: void onEntry(QEvent *); + void onExit(QEvent *); private : GraphicsScene *scene; PlayState *game; diff --git a/demos/sub-attaq/sub-attaq.pro b/demos/sub-attaq/sub-attaq.pro index ad1327d..ba2b54b 100644 --- a/demos/sub-attaq/sub-attaq.pro +++ b/demos/sub-attaq/sub-attaq.pro @@ -1,5 +1,4 @@ contains(QT_CONFIG, opengl):QT += opengl - HEADERS += boat.h \ bomb.h \ mainwindow.h \ @@ -13,7 +12,8 @@ HEADERS += boat.h \ submarine_p.h \ custompropertyanimation.h \ qanimationstate.h \ - progressitem.h + progressitem.h \ + textinformationitem.h SOURCES += boat.cpp \ bomb.cpp \ main.cpp \ @@ -26,12 +26,18 @@ SOURCES += boat.cpp \ states.cpp \ custompropertyanimation.cpp \ qanimationstate.cpp \ - progressitem.cpp + progressitem.cpp \ + textinformationitem.cpp RESOURCES += subattaq.qrc # install target.path = $$[QT_INSTALL_DEMOS]/animation/sub-attaq -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS sub-attaq.pro pics +sources.files = $$SOURCES \ + $$HEADERS \ + $$RESOURCES \ + $$FORMS \ + sub-attaq.pro \ + pics sources.path = $$[QT_INSTALL_DEMOS]/animation/sub-attaq -INSTALLS += target sources - +INSTALLS += target \ + sources diff --git a/demos/sub-attaq/textinformationitem.cpp b/demos/sub-attaq/textinformationitem.cpp new file mode 100644 index 0000000..759aa56 --- /dev/null +++ b/demos/sub-attaq/textinformationitem.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "textinformationitem.h" +#include "pixmapitem.h" + +TextInformationItem::TextInformationItem (QGraphicsItem * parent) + : QGraphicsTextItem(parent) +{ + setFont(QFont("Comic Sans MS", 25)); +} +#include <QDebug> +void TextInformationItem::setMessage(const QString& text) +{ + setHtml(text); + setPos(parentItem()->boundingRect().center().x() - boundingRect().size().width()/2 , parentItem()->boundingRect().center().y()); +} diff --git a/demos/sub-attaq/textinformationitem.h b/demos/sub-attaq/textinformationitem.h new file mode 100644 index 0000000..aa7f0be --- /dev/null +++ b/demos/sub-attaq/textinformationitem.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TEXTINFORMATIONITEM_H +#define TEXTINFORMATIONITEM_H + +//Qt +#include <QtGui/QGraphicsTextItem> + +class TextInformationItem : public QGraphicsTextItem +{ +public: + TextInformationItem(QGraphicsItem * parent = 0); + void setMessage(const QString& text); +}; + +#endif // TEXTINFORMATIONITEM_H |