diff options
author | Tobias Koenig <tokoe@kde.org> | 2009-06-04 18:44:12 (GMT) |
---|---|---|
committer | Tobias Koenig <tokoe@kde.org> | 2009-06-04 18:44:12 (GMT) |
commit | 5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd (patch) | |
tree | a1fc7824b38c3b712893794cfe55fa285cd3c760 /examples | |
parent | f7741b78c90abcb272345810d55e446a7f390032 (diff) | |
parent | b1b09172aee658e085423ddf6abfea291a072c74 (diff) | |
download | Qt-5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd.zip Qt-5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd.tar.gz Qt-5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd.tar.bz2 |
Merge commit 'qt-mainline/master'
Diffstat (limited to 'examples')
220 files changed, 14115 insertions, 359 deletions
diff --git a/examples/animation/README b/examples/animation/README new file mode 100644 index 0000000..6a892f8 --- /dev/null +++ b/examples/animation/README @@ -0,0 +1,38 @@ +The animation framework aims to provide an easy way for creating animated and +smooth GUI's. By animating Qt properties, the framework provides great freedom +for animating widgets and other QObjects. The framework can also be used with +the Graphics View framework. + +The example launcher provided with Qt can be used to explore each of the +examples in this directory. + +Documentation for these examples can be found via the Tutorial and Examples +link in the main Qt documentation. + + +Finding the Qt Examples and Demos launcher +========================================== + +On Windows: + +The launcher can be accessed via the Windows Start menu. Select the menu +entry entitled "Qt Examples and Demos" entry in the submenu containing +the Qt tools. + +On Mac OS X: + +For the binary distribution, the qtdemo executable is installed in the +/Developer/Applications/Qt directory. For the source distribution, it is +installed alongside the other Qt tools on the path specified when Qt is +configured. + +On Unix/Linux: + +The qtdemo executable is installed alongside the other Qt tools on the path +specified when Qt is configured. + +On all platforms: + +The source code for the launcher can be found in the demos/qtdemo directory +in the Qt package. This example is built at the same time as the Qt libraries, +tools, examples, and demonstrations. diff --git a/examples/animation/animatedtiles/animatedtiles.pro b/examples/animation/animatedtiles/animatedtiles.pro new file mode 100644 index 0000000..1840b17 --- /dev/null +++ b/examples/animation/animatedtiles/animatedtiles.pro @@ -0,0 +1,8 @@ +SOURCES = main.cpp +RESOURCES = animatedtiles.qrc + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/animation/animatedtiles +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS animatedtiles.pro images +sources.path = $$[QT_INSTALL_EXAMPLES]/animation/animatedtiles +INSTALLS += target sources diff --git a/examples/animation/animatedtiles/animatedtiles.qrc b/examples/animation/animatedtiles/animatedtiles.qrc new file mode 100644 index 0000000..c43a979 --- /dev/null +++ b/examples/animation/animatedtiles/animatedtiles.qrc @@ -0,0 +1,11 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>images/Time-For-Lunch-2.jpg</file> + <file>images/centered.png</file> + <file>images/ellipse.png</file> + <file>images/figure8.png</file> + <file>images/kinetic.png</file> + <file>images/random.png</file> + <file>images/tile.png</file> +</qresource> +</RCC> diff --git a/examples/animation/animatedtiles/images/Time-For-Lunch-2.jpg b/examples/animation/animatedtiles/images/Time-For-Lunch-2.jpg Binary files differnew file mode 100644 index 0000000..c57a555 --- /dev/null +++ b/examples/animation/animatedtiles/images/Time-For-Lunch-2.jpg diff --git a/examples/animation/animatedtiles/images/centered.png b/examples/animation/animatedtiles/images/centered.png Binary files differnew file mode 100644 index 0000000..e416156 --- /dev/null +++ b/examples/animation/animatedtiles/images/centered.png diff --git a/examples/animation/animatedtiles/images/ellipse.png b/examples/animation/animatedtiles/images/ellipse.png Binary files differnew file mode 100644 index 0000000..2c3ba88 --- /dev/null +++ b/examples/animation/animatedtiles/images/ellipse.png diff --git a/examples/animation/animatedtiles/images/figure8.png b/examples/animation/animatedtiles/images/figure8.png Binary files differnew file mode 100644 index 0000000..6b05804 --- /dev/null +++ b/examples/animation/animatedtiles/images/figure8.png diff --git a/examples/animation/animatedtiles/images/kinetic.png b/examples/animation/animatedtiles/images/kinetic.png Binary files differnew file mode 100644 index 0000000..55cfa55 --- /dev/null +++ b/examples/animation/animatedtiles/images/kinetic.png diff --git a/examples/animation/animatedtiles/images/random.png b/examples/animation/animatedtiles/images/random.png Binary files differnew file mode 100644 index 0000000..415d96f --- /dev/null +++ b/examples/animation/animatedtiles/images/random.png diff --git a/examples/animation/animatedtiles/images/tile.png b/examples/animation/animatedtiles/images/tile.png Binary files differnew file mode 100644 index 0000000..c8f39d8 --- /dev/null +++ b/examples/animation/animatedtiles/images/tile.png diff --git a/examples/animation/animatedtiles/main.cpp b/examples/animation/animatedtiles/main.cpp new file mode 100644 index 0000000..4b1d99d --- /dev/null +++ b/examples/animation/animatedtiles/main.cpp @@ -0,0 +1,280 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include <QtCore/qstate.h> + +class Pixmap : public QObject, public QGraphicsPixmapItem +{ + Q_OBJECT + Q_PROPERTY(QPointF pos READ pos WRITE setPos) +public: + Pixmap(const QPixmap &pix) + : QObject(), QGraphicsPixmapItem(pix) + { + setCacheMode(DeviceCoordinateCache); + } +}; + +class Button : public QGraphicsWidget +{ + Q_OBJECT +public: + Button(const QPixmap &pixmap, QGraphicsItem *parent = 0) + : QGraphicsWidget(parent), _pix(pixmap) + { + setAcceptHoverEvents(true); + setCacheMode(DeviceCoordinateCache); + } + + QRectF boundingRect() const + { + return QRectF(-65, -65, 130, 130); + } + + QPainterPath shape() const + { + QPainterPath path; + path.addEllipse(boundingRect()); + return path; + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) + { + bool down = option->state & QStyle::State_Sunken; + QRectF r = boundingRect(); + QLinearGradient grad(r.topLeft(), r.bottomRight()); + grad.setColorAt(down ? 1 : 0, option->state & QStyle::State_MouseOver ? Qt::white : Qt::lightGray); + grad.setColorAt(down ? 0 : 1, Qt::darkGray); + painter->setPen(Qt::darkGray); + painter->setBrush(grad); + painter->drawEllipse(r); + QLinearGradient grad2(r.topLeft(), r.bottomRight()); + grad.setColorAt(down ? 1 : 0, Qt::darkGray); + grad.setColorAt(down ? 0 : 1, Qt::lightGray); + painter->setPen(Qt::NoPen); + painter->setBrush(grad); + if (down) + painter->translate(2, 2); + painter->drawEllipse(r.adjusted(5, 5, -5, -5)); + painter->drawPixmap(-_pix.width()/2, -_pix.height()/2, _pix); + } + +signals: + void pressed(); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *) + { + emit pressed(); + update(); + } + + void mouseReleaseEvent(QGraphicsSceneMouseEvent *) + { + update(); + } + +private: + QPixmap _pix; +}; + +class View : public QGraphicsView +{ +public: + View(QGraphicsScene *scene) : QGraphicsView(scene) { } + +protected: + void resizeEvent(QResizeEvent *event) + { + QGraphicsView::resizeEvent(event); + fitInView(sceneRect(), Qt::KeepAspectRatio); + } +}; + +int main(int argc, char **argv) +{ + Q_INIT_RESOURCE(animatedtiles); + + QApplication app(argc, argv); + + QPixmap kineticPix(":/images/kinetic.png"); + QPixmap bgPix(":/images/Time-For-Lunch-2.jpg"); + + QGraphicsScene scene(-350, -350, 700, 700); + + QList<Pixmap *> items; + for (int i = 0; i < 64; ++i) { + Pixmap *item = new Pixmap(kineticPix); + item->setOffset(-kineticPix.width()/2, -kineticPix.height()/2); + item->setZValue(i); + items << item; + scene.addItem(item); + } + + // Buttons + QGraphicsItem *buttonParent = new QGraphicsRectItem; + Button *ellipseButton = new Button(QPixmap(":/images/ellipse.png"), buttonParent); + Button *figure8Button = new Button(QPixmap(":/images/figure8.png"), buttonParent); + Button *randomButton = new Button(QPixmap(":/images/random.png"), buttonParent); + Button *tiledButton = new Button(QPixmap(":/images/tile.png"), buttonParent); + Button *centeredButton = new Button(QPixmap(":/images/centered.png"), buttonParent); + + ellipseButton->setPos(-100, -100); + figure8Button->setPos(100, -100); + randomButton->setPos(0, 0); + tiledButton->setPos(-100, 100); + centeredButton->setPos(100, 100); + + scene.addItem(buttonParent); + buttonParent->scale(0.75, 0.75); + buttonParent->setPos(200, 200); + buttonParent->setZValue(65); + + // States + QState *rootState = new QState; + QState *ellipseState = new QState(rootState); + QState *figure8State = new QState(rootState); + QState *randomState = new QState(rootState); + QState *tiledState = new QState(rootState); + QState *centeredState = new QState(rootState); + + // Values + for (int i = 0; i < 64; ++i) { + Pixmap *item = items.at(i); + // Ellipse + ellipseState->assignProperty(item, "pos", + QPointF(cos((i / 63.0) * 6.28) * 250, + sin((i / 63.0) * 6.28) * 250)); + + // Figure 8 + figure8State->assignProperty(item, "pos", + QPointF(sin((i / 63.0) * 6.28) * 250, + sin(((i * 2)/63.0) * 6.28) * 250)); + + // Random + randomState->assignProperty(item, "pos", + QPointF(-250 + qrand() % 500, + -250 + qrand() % 500)); + + // Tiled + tiledState->assignProperty(item, "pos", + QPointF(((i % 8) - 4) * kineticPix.width() + kineticPix.width() / 2, + ((i / 8) - 4) * kineticPix.height() + kineticPix.height() / 2)); + + // Centered + centeredState->assignProperty(item, "pos", QPointF()); + } + + // Ui + View *view = new View(&scene); + view->setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Animated Tiles")); + view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); + view->setBackgroundBrush(bgPix); + view->setCacheMode(QGraphicsView::CacheBackground); + view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); + view->show(); + + QStateMachine states; + states.addState(rootState); + states.setInitialState(rootState); + rootState->setInitialState(centeredState); + + QParallelAnimationGroup *group = new QParallelAnimationGroup; + for (int i = 0; i < 64; ++i) { + QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos"); + anim->setDuration(750 + i * 25); + anim->setEasingCurve(QEasingCurve::InOutBack); + group->addAnimation(anim); + } + QAbstractTransition *trans = rootState->addTransition(ellipseButton, SIGNAL(pressed()), ellipseState); + trans->addAnimation(group); + + group = new QParallelAnimationGroup; + for (int i = 0; i < 64; ++i) { + QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos"); + anim->setDuration(750 + i * 25); + anim->setEasingCurve(QEasingCurve::InOutBack); + group->addAnimation(anim); + } + trans = rootState->addTransition(figure8Button, SIGNAL(pressed()), figure8State); + trans->addAnimation(group); + + group = new QParallelAnimationGroup; + for (int i = 0; i < 64; ++i) { + QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos"); + anim->setDuration(750 + i * 25); + anim->setEasingCurve(QEasingCurve::InOutBack); + group->addAnimation(anim); + } + trans = rootState->addTransition(randomButton, SIGNAL(pressed()), randomState); + trans->addAnimation(group); + + group = new QParallelAnimationGroup; + for (int i = 0; i < 64; ++i) { + QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos"); + anim->setDuration(750 + i * 25); + anim->setEasingCurve(QEasingCurve::InOutBack); + group->addAnimation(anim); + } + trans = rootState->addTransition(tiledButton, SIGNAL(pressed()), tiledState); + trans->addAnimation(group); + + group = new QParallelAnimationGroup; + for (int i = 0; i < 64; ++i) { + QPropertyAnimation *anim = new QPropertyAnimation(items[i], "pos"); + anim->setDuration(750 + i * 25); + anim->setEasingCurve(QEasingCurve::InOutBack); + group->addAnimation(anim); + } + trans = rootState->addTransition(centeredButton, SIGNAL(pressed()), centeredState); + trans->addAnimation(group); + + states.start(); + QTimer timer; + timer.start(125); + timer.setSingleShot(true); + rootState->addTransition(&timer, SIGNAL(timeout()), ellipseState); + + return app.exec(); +} + +#include "main.moc" diff --git a/examples/animation/animation.pro b/examples/animation/animation.pro new file mode 100644 index 0000000..9a2874b --- /dev/null +++ b/examples/animation/animation.pro @@ -0,0 +1,16 @@ +TEMPLATE = \ + subdirs +SUBDIRS += \ + animatedtiles \ + appchooser \ + easing \ + moveblocks \ + states \ + stickman \ + sub-attaq + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/animation +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS animation.pro README +sources.path = $$[QT_INSTALL_EXAMPLES]/animation +INSTALLS += target sources diff --git a/examples/animation/appchooser/accessories-dictionary.png b/examples/animation/appchooser/accessories-dictionary.png Binary files differnew file mode 100644 index 0000000..e9bd55d --- /dev/null +++ b/examples/animation/appchooser/accessories-dictionary.png diff --git a/examples/animation/appchooser/akregator.png b/examples/animation/appchooser/akregator.png Binary files differnew file mode 100644 index 0000000..a086f45 --- /dev/null +++ b/examples/animation/appchooser/akregator.png diff --git a/examples/animation/appchooser/appchooser.pro b/examples/animation/appchooser/appchooser.pro new file mode 100644 index 0000000..847b60a --- /dev/null +++ b/examples/animation/appchooser/appchooser.pro @@ -0,0 +1,8 @@ +SOURCES = main.cpp +RESOURCES = appchooser.qrc + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/animation/appchooser +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS appchooser.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/animation/appchooser +INSTALLS += target sources diff --git a/examples/animation/appchooser/appchooser.qrc b/examples/animation/appchooser/appchooser.qrc new file mode 100644 index 0000000..28a3e1c --- /dev/null +++ b/examples/animation/appchooser/appchooser.qrc @@ -0,0 +1,8 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>accessories-dictionary.png</file> + <file>akregator.png</file> + <file>digikam.png</file> + <file>k3b.png</file> +</qresource> +</RCC> diff --git a/examples/animation/appchooser/digikam.png b/examples/animation/appchooser/digikam.png Binary files differnew file mode 100644 index 0000000..9de9fb2 --- /dev/null +++ b/examples/animation/appchooser/digikam.png diff --git a/examples/animation/appchooser/k3b.png b/examples/animation/appchooser/k3b.png Binary files differnew file mode 100644 index 0000000..bbcafcf --- /dev/null +++ b/examples/animation/appchooser/k3b.png diff --git a/examples/animation/appchooser/main.cpp b/examples/animation/appchooser/main.cpp new file mode 100644 index 0000000..44457f7 --- /dev/null +++ b/examples/animation/appchooser/main.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <QtGui> + + +class Pixmap : public QGraphicsWidget +{ + Q_OBJECT + +public: + Pixmap(const QPixmap &pix, QGraphicsItem *parent = 0) + : QGraphicsWidget(parent), orig(pix), p(pix) + { + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + { + painter->drawPixmap(QPointF(), p); + } + + virtual void mousePressEvent(QGraphicsSceneMouseEvent * ) + { + emit clicked(); + } + + virtual void setGeometry(const QRectF &rect) + { + QGraphicsWidget::setGeometry(rect); + + if (rect.size().width() > orig.size().width()) + p = orig.scaled(rect.size().toSize()); + else + p = orig; + } + +Q_SIGNALS: + void clicked(); + +private: + QPixmap orig; + QPixmap p; +}; + +void createStates(const QObjectList &objects, + const QRect &selectedRect, QState *parent) +{ + for (int i = 0; i < objects.size(); ++i) { + QState *state = new QState(parent); + state->assignProperty(objects.at(i), "geometry", selectedRect); + parent->addTransition(objects.at(i), SIGNAL(clicked()), state); + } +} + +void createAnimations(const QObjectList &objects, QStateMachine *machine) +{ + for (int i=0; i<objects.size(); ++i) + machine->addDefaultAnimation(new QPropertyAnimation(objects.at(i), "geometry")); +} + +int main(int argc, char **argv) +{ + Q_INIT_RESOURCE(appchooser); + + QApplication app(argc, argv); + + Pixmap *p1 = new Pixmap(QPixmap(":/digikam.png")); + Pixmap *p2 = new Pixmap(QPixmap(":/akregator.png")); + Pixmap *p3 = new Pixmap(QPixmap(":/accessories-dictionary.png")); + Pixmap *p4 = new Pixmap(QPixmap(":/k3b.png")); + + p1->setObjectName("p1"); + p2->setObjectName("p2"); + p3->setObjectName("p3"); + p4->setObjectName("p4"); + + p1->setGeometry(QRectF(0.0, 0.0, 64.0, 64.0)); + p2->setGeometry(QRectF(236.0, 0.0, 64.0, 64.0)); + p3->setGeometry(QRectF(236.0, 236.0, 64.0, 64.0)); + p4->setGeometry(QRectF(0.0, 236.0, 64.0, 64.0)); + + QGraphicsScene scene(0, 0, 300, 300); + scene.setBackgroundBrush(Qt::white); + scene.addItem(p1); + scene.addItem(p2); + scene.addItem(p3); + scene.addItem(p4); + + QGraphicsView window(&scene); + window.setFrameStyle(0); + window.setAlignment(Qt::AlignLeft | Qt::AlignTop); + window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + QStateMachine machine; + machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties); + + QState *group = new QState(machine.rootState()); + group->setObjectName("group"); + QRect selectedRect(86, 86, 128, 128); + + QState *idleState = new QState(group); + group->setInitialState(idleState); + + QObjectList objects; + objects << p1 << p2 << p3 << p4; + createStates(objects, selectedRect, group); + createAnimations(objects, &machine); + + machine.setInitialState(group); + machine.start(); + + window.resize(300, 300); + window.show(); + + return app.exec(); +} + +#include "main.moc" diff --git a/examples/animation/easing/animation.h b/examples/animation/easing/animation.h new file mode 100644 index 0000000..d4d699d --- /dev/null +++ b/examples/animation/easing/animation.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANIMATION_H +#define ANIMATION_H + +#include <QtGui> + +#include <QtCore/qpropertyanimation.h> + +class Animation : public QPropertyAnimation { +public: + enum PathType { + LinearPath, + CirclePath, + NPathTypes + }; + Animation(QObject *target, const QByteArray &prop) + : QPropertyAnimation(target, prop) + { + setPathType(LinearPath); + } + + void setPathType(PathType pathType) + { + if (pathType >= NPathTypes) + qWarning("Unknown pathType %d", pathType); + + m_pathType = pathType; + m_path = QPainterPath(); + } + + void updateCurrentTime(int msecs) + { + if (m_pathType == CirclePath) { + if (m_path.isEmpty()) { + QPointF to = endValue().toPointF(); + QPointF from = startValue().toPointF(); + m_path.moveTo(from); + m_path.addEllipse(QRectF(from, to)); + } + int dura = duration(); + const qreal progress = ((dura == 0) ? 1 : ((((currentTime() - 1) % dura) + 1) / qreal(dura))); + + qreal easedProgress = easingCurve().valueForProgress(progress); + if (easedProgress > 1.0) { + easedProgress -= 1.0; + } else if (easedProgress < 0) { + easedProgress += 1.0; + } + QPointF pt = m_path.pointAtPercent(easedProgress); + updateCurrentValue(pt); + emit valueChanged(pt); + } else { + QPropertyAnimation::updateCurrentTime(msecs); + } + } + + QPainterPath m_path; + PathType m_pathType; +}; + +#endif // ANIMATION_H diff --git a/examples/animation/easing/easing.pro b/examples/animation/easing/easing.pro new file mode 100644 index 0000000..8e8a35f --- /dev/null +++ b/examples/animation/easing/easing.pro @@ -0,0 +1,14 @@ +HEADERS = window.h \ + animation.h +SOURCES = main.cpp \ + window.cpp + +FORMS = form.ui + +RESOURCES = easing.qrc + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/animation/easing +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS easing.pro images +sources.path = $$[QT_INSTALL_EXAMPLES]/animation/easing +INSTALLS += target sources diff --git a/examples/animation/easing/easing.qrc b/examples/animation/easing/easing.qrc new file mode 100644 index 0000000..7e112d3 --- /dev/null +++ b/examples/animation/easing/easing.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> + <qresource> + <file>images/qt-logo.png</file> + </qresource> + </RCC>
\ No newline at end of file diff --git a/examples/animation/easing/form.ui b/examples/animation/easing/form.ui new file mode 100644 index 0000000..b60ade8 --- /dev/null +++ b/examples/animation/easing/form.ui @@ -0,0 +1,201 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Form</class> + <widget class="QWidget" name="Form"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>545</width> + <height>471</height> + </rect> + </property> + <property name="windowTitle"> + <string>Easing curves</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="2"> + <widget class="QListWidget" name="easingCurvePicker"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>120</height> + </size> + </property> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="movement"> + <enum>QListView::Static</enum> + </property> + <property name="isWrapping" stdset="0"> + <bool>false</bool> + </property> + <property name="viewMode"> + <enum>QListView::IconMode</enum> + </property> + <property name="selectionRectVisible"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="1" column="0"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>Path type</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QRadioButton" name="lineRadio"> + <property name="text"> + <string>Line</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <attribute name="buttonGroup"> + <string>buttonGroup</string> + </attribute> + </widget> + </item> + <item> + <widget class="QRadioButton" name="circleRadio"> + <property name="text"> + <string>Circle</string> + </property> + <attribute name="buttonGroup"> + <string>buttonGroup</string> + </attribute> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Properties</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <property name="fieldGrowthPolicy"> + <enum>QFormLayout::AllNonFixedFieldsGrow</enum> + </property> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Period</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QDoubleSpinBox" name="periodSpinBox"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="minimum"> + <double>-1.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.100000000000000</double> + </property> + <property name="value"> + <double>-1.000000000000000</double> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Amplitude</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QDoubleSpinBox" name="amplitudeSpinBox"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="minimum"> + <double>-1.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.100000000000000</double> + </property> + <property name="value"> + <double>-1.000000000000000</double> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Overshoot</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QDoubleSpinBox" name="overshootSpinBox"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="minimum"> + <double>-1.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.100000000000000</double> + </property> + <property name="value"> + <double>-1.000000000000000</double> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item row="1" column="1"> + <widget class="QGraphicsView" name="graphicsView"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> + <buttongroups> + <buttongroup name="buttonGroup"/> + </buttongroups> +</ui> diff --git a/examples/animation/easing/images/qt-logo.png b/examples/animation/easing/images/qt-logo.png Binary files differnew file mode 100644 index 0000000..14ddf2a --- /dev/null +++ b/examples/animation/easing/images/qt-logo.png diff --git a/examples/animation/easing/main.cpp b/examples/animation/easing/main.cpp new file mode 100644 index 0000000..bd10df2 --- /dev/null +++ b/examples/animation/easing/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include "window.h" + +int main(int argc, char **argv) +{ + Q_INIT_RESOURCE(easing); + QApplication app(argc, argv); + Window w; + w.resize(400, 400); + w.show(); + return app.exec(); +} diff --git a/examples/animation/easing/window.cpp b/examples/animation/easing/window.cpp new file mode 100644 index 0000000..cf4be15 --- /dev/null +++ b/examples/animation/easing/window.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "window.h" + +Window::Window(QWidget *parent) + : QWidget(parent), m_iconSize(64, 64) +{ + m_ui.setupUi(this); + QButtonGroup *buttonGroup = qFindChild<QButtonGroup *>(this); // ### workaround for uic in 4.4 + m_ui.easingCurvePicker->setIconSize(m_iconSize); + m_ui.easingCurvePicker->setMinimumHeight(m_iconSize.height() + 50); + buttonGroup->setId(m_ui.lineRadio, 0); + buttonGroup->setId(m_ui.circleRadio, 1); + + QEasingCurve dummy; + m_ui.periodSpinBox->setValue(dummy.period()); + m_ui.amplitudeSpinBox->setValue(dummy.amplitude()); + m_ui.overshootSpinBox->setValue(dummy.overshoot()); + + connect(m_ui.easingCurvePicker, SIGNAL(currentRowChanged(int)), this, SLOT(curveChanged(int))); + connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(pathChanged(int))); + connect(m_ui.periodSpinBox, SIGNAL(valueChanged(double)), this, SLOT(periodChanged(double))); + connect(m_ui.amplitudeSpinBox, SIGNAL(valueChanged(double)), this, SLOT(amplitudeChanged(double))); + connect(m_ui.overshootSpinBox, SIGNAL(valueChanged(double)), this, SLOT(overshootChanged(double))); + createCurveIcons(); + + QPixmap pix(QLatin1String(":/images/qt-logo.png")); + m_item = new PixmapItem(pix); + m_scene.addItem(m_item); + m_ui.graphicsView->setScene(&m_scene); + + m_anim = new Animation(m_item, "pos"); + m_anim->setEasingCurve(QEasingCurve::OutBounce); + m_ui.easingCurvePicker->setCurrentRow(int(QEasingCurve::OutBounce)); + + startAnimation(); +} + +void Window::createCurveIcons() +{ + QPixmap pix(m_iconSize); + QPainter painter(&pix); + QLinearGradient gradient(0,0, 0, m_iconSize.height()); + gradient.setColorAt(0.0, QColor(240, 240, 240)); + gradient.setColorAt(1.0, QColor(224, 224, 224)); + QBrush brush(gradient); + const QMetaObject &mo = QEasingCurve::staticMetaObject; + QMetaEnum metaEnum = mo.enumerator(mo.indexOfEnumerator("Type")); + // Skip QEasingCurve::Custom + for (int i = 0; i < QEasingCurve::NCurveTypes - 1; ++i) { + painter.fillRect(QRect(QPoint(0, 0), m_iconSize), brush); + QEasingCurve curve((QEasingCurve::Type)i); + painter.setPen(QColor(0, 0, 255, 64)); + qreal xAxis = m_iconSize.height()/1.5; + qreal yAxis = m_iconSize.width()/3; + painter.drawLine(0, xAxis, m_iconSize.width(), xAxis); + painter.drawLine(yAxis, 0, yAxis, m_iconSize.height()); + painter.setPen(Qt::black); + + qreal curveScale = m_iconSize.height()/2; + QPoint currentPos(yAxis, xAxis); + + for (qreal t = 0; t < 1.0; t+=1.0/curveScale) { + QPoint to; + to.setX(yAxis + curveScale * t); + to.setY(xAxis - curveScale * curve.valueForProgress(t)); + painter.drawLine(currentPos, to); + currentPos = to; + } + QListWidgetItem *item = new QListWidgetItem; + item->setIcon(QIcon(pix)); + item->setText(metaEnum.key(i)); + m_ui.easingCurvePicker->addItem(item); + } +} + +void Window::startAnimation() +{ + m_anim->setStartValue(QPointF(0, 0)); + m_anim->setEndValue(QPointF(100, 100)); + m_anim->setDuration(2000); + m_anim->setLoopCount(-1); // forever + m_anim->start(); +} + +void Window::curveChanged(int row) +{ + QEasingCurve::Type curveType = (QEasingCurve::Type)row; + m_anim->setEasingCurve(curveType); + m_anim->setCurrentTime(0); + + bool isElastic = curveType >= QEasingCurve::InElastic && curveType <= QEasingCurve::OutInElastic; + bool isBounce = curveType >= QEasingCurve::InBounce && curveType <= QEasingCurve::OutInBounce; + m_ui.periodSpinBox->setEnabled(isElastic); + m_ui.amplitudeSpinBox->setEnabled(isElastic || isBounce); + m_ui.overshootSpinBox->setEnabled(curveType >= QEasingCurve::InBack && curveType <= QEasingCurve::OutInBack); +} + +void Window::pathChanged(int index) +{ + m_anim->setPathType((Animation::PathType)index); +} + +void Window::periodChanged(double value) +{ + QEasingCurve curve = m_anim->easingCurve(); + curve.setPeriod(value); + m_anim->setEasingCurve(curve); +} + +void Window::amplitudeChanged(double value) +{ + QEasingCurve curve = m_anim->easingCurve(); + curve.setAmplitude(value); + m_anim->setEasingCurve(curve); +} + +void Window::overshootChanged(double value) +{ + QEasingCurve curve = m_anim->easingCurve(); + curve.setOvershoot(value); + m_anim->setEasingCurve(curve); +} + diff --git a/examples/animation/easing/window.h b/examples/animation/easing/window.h new file mode 100644 index 0000000..f3a8cb3 --- /dev/null +++ b/examples/animation/easing/window.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "ui_form.h" +#include "animation.h" + +class PixmapItem : public QObject, public QGraphicsPixmapItem +{ + Q_OBJECT + Q_PROPERTY(QPointF pos READ pos WRITE setPos) +public: + PixmapItem(const QPixmap &pix) : QGraphicsPixmapItem(pix) + { + } +}; + +class Window : public QWidget { + Q_OBJECT +public: + Window(QWidget *parent = 0); +private slots: + void curveChanged(int row); + void pathChanged(int index); + void periodChanged(double); + void amplitudeChanged(double); + void overshootChanged(double); + +private: + void createCurveIcons(); + void startAnimation(); + + Ui::Form m_ui; + QGraphicsScene m_scene; + PixmapItem *m_item; + Animation *m_anim; + QSize m_iconSize; + + +}; diff --git a/examples/animation/moveblocks/main.cpp b/examples/animation/moveblocks/main.cpp new file mode 100644 index 0000000..d315112 --- /dev/null +++ b/examples/animation/moveblocks/main.cpp @@ -0,0 +1,295 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <QtGui> + +class StateSwitchEvent: public QEvent +{ +public: + StateSwitchEvent() + : QEvent(Type(StateSwitchType)) + { + } + + StateSwitchEvent(int rand) + : QEvent(Type(StateSwitchType)), + m_rand(rand) + { + } + + enum { StateSwitchType = QEvent::User + 256 }; + + int rand() const { return m_rand; } + +private: + int m_rand; +}; + + +class QGraphicsRectWidget : public QGraphicsWidget +{ +public: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, + QWidget *) + { + painter->fillRect(rect(), Qt::blue); + } +}; + +class StateSwitchTransition: public QAbstractTransition +{ +public: + StateSwitchTransition(int rand) + : QAbstractTransition(), + m_rand(rand) + { + } + +protected: + virtual bool eventTest(QEvent *event) + { + return (event->type() == QEvent::Type(StateSwitchEvent::StateSwitchType)) + && (static_cast<StateSwitchEvent *>(event)->rand() == m_rand); + } + + virtual void onTransition(QEvent *) {} + +private: + int m_rand; +}; + +class StateSwitcher : public QState +{ + Q_OBJECT +public: + StateSwitcher(QStateMachine *machine) + : QState(machine->rootState()), m_machine(machine), + m_stateCount(0), m_lastIndex(0) + { } + + virtual void onEntry(QEvent *) + { + int n; + while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex) + { } + m_lastIndex = n; + m_machine->postEvent(new StateSwitchEvent(n)); + } + virtual void onExit(QEvent *) {} + + void addState(QState *state, QAbstractAnimation *animation) { + StateSwitchTransition *trans = new StateSwitchTransition(++m_stateCount); + trans->setTargetState(state); + addTransition(trans); + trans->addAnimation(animation); + } + + +private: + QStateMachine *m_machine; + int m_stateCount; + int m_lastIndex; +}; + +QState *createGeometryState(QObject *w1, const QRect &rect1, + QObject *w2, const QRect &rect2, + QObject *w3, const QRect &rect3, + QObject *w4, const QRect &rect4, + QState *parent) +{ + QState *result = new QState(parent); + result->assignProperty(w1, "geometry", rect1); + result->assignProperty(w1, "geometry", rect1); + result->assignProperty(w2, "geometry", rect2); + result->assignProperty(w3, "geometry", rect3); + result->assignProperty(w4, "geometry", rect4); + + return result; +} + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + +#if 0 + QWidget window; + QPalette palette; + palette.setBrush(QPalette::Window, Qt::black); + window.setPalette(palette); + QPushButton *button1 = new QPushButton("A", &window); + QPushButton *button2 = new QPushButton("B", &window); + QPushButton *button3 = new QPushButton("C", &window); + QPushButton *button4 = new QPushButton("D", &window); + + button1->setObjectName("button1"); + button2->setObjectName("button2"); + button3->setObjectName("button3"); + button4->setObjectName("button4"); +#else + QGraphicsRectWidget *button1 = new QGraphicsRectWidget; + QGraphicsRectWidget *button2 = new QGraphicsRectWidget; + QGraphicsRectWidget *button3 = new QGraphicsRectWidget; + QGraphicsRectWidget *button4 = new QGraphicsRectWidget; + button2->setZValue(1); + button3->setZValue(2); + button4->setZValue(3); + QGraphicsScene scene(0, 0, 300, 300); + scene.setBackgroundBrush(Qt::black); + scene.addItem(button1); + scene.addItem(button2); + scene.addItem(button3); + scene.addItem(button4); + + QGraphicsView window(&scene); + window.setFrameStyle(0); + window.setAlignment(Qt::AlignLeft | Qt::AlignTop); + window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); +#endif + QStateMachine machine; + + QState *group = new QState(); + group->setObjectName("group"); + QTimer timer; + timer.setInterval(1250); + timer.setSingleShot(true); + QObject::connect(group, SIGNAL(entered()), &timer, SLOT(start())); + + QState *state1; + QState *state2; + QState *state3; + QState *state4; + QState *state5; + QState *state6; + QState *state7; + + state1 = createGeometryState(button1, QRect(100, 0, 50, 50), + button2, QRect(150, 0, 50, 50), + button3, QRect(200, 0, 50, 50), + button4, QRect(250, 0, 50, 50), + group); + state2 = createGeometryState(button1, QRect(250, 100, 50, 50), + button2, QRect(250, 150, 50, 50), + button3, QRect(250, 200, 50, 50), + button4, QRect(250, 250, 50, 50), + group); + state3 = createGeometryState(button1, QRect(150, 250, 50, 50), + button2, QRect(100, 250, 50, 50), + button3, QRect(50, 250, 50, 50), + button4, QRect(0, 250, 50, 50), + group); + state4 = createGeometryState(button1, QRect(0, 150, 50, 50), + button2, QRect(0, 100, 50, 50), + button3, QRect(0, 50, 50, 50), + button4, QRect(0, 0, 50, 50), + group); + state5 = createGeometryState(button1, QRect(100, 100, 50, 50), + button2, QRect(150, 100, 50, 50), + button3, QRect(100, 150, 50, 50), + button4, QRect(150, 150, 50, 50), + group); + state6 = createGeometryState(button1, QRect(50, 50, 50, 50), + button2, QRect(200, 50, 50, 50), + button3, QRect(50, 200, 50, 50), + button4, QRect(200, 200, 50, 50), + group); + state7 = createGeometryState(button1, QRect(0, 0, 50, 50), + button2, QRect(250, 0, 50, 50), + button3, QRect(0, 250, 50, 50), + button4, QRect(250, 250, 50, 50), + group); + group->setInitialState(state1); + + QParallelAnimationGroup animationGroup; + QSequentialAnimationGroup *subGroup; + + QPropertyAnimation *anim = new QPropertyAnimation(button4, "geometry"); + anim->setDuration(1000); + anim->setEasingCurve(QEasingCurve::OutElastic); + animationGroup.addAnimation(anim); + + subGroup = new QSequentialAnimationGroup(&animationGroup); + subGroup->addPause(100); + anim = new QPropertyAnimation(button3, "geometry"); + anim->setDuration(1000); + anim->setEasingCurve(QEasingCurve::OutElastic); + subGroup->addAnimation(anim); + + subGroup = new QSequentialAnimationGroup(&animationGroup); + subGroup->addPause(150); + anim = new QPropertyAnimation(button2, "geometry"); + anim->setDuration(1000); + anim->setEasingCurve(QEasingCurve::OutElastic); + subGroup->addAnimation(anim); + + subGroup = new QSequentialAnimationGroup(&animationGroup); + subGroup->addPause(200); + anim = new QPropertyAnimation(button1, "geometry"); + anim->setDuration(1000); + anim->setEasingCurve(QEasingCurve::OutElastic); + subGroup->addAnimation(anim); + + StateSwitcher *stateSwitcher = new StateSwitcher(&machine); + stateSwitcher->setObjectName("stateSwitcher"); + group->addTransition(&timer, SIGNAL(timeout()), stateSwitcher); + stateSwitcher->addState(state1, &animationGroup); + stateSwitcher->addState(state2, &animationGroup); + stateSwitcher->addState(state3, &animationGroup); + stateSwitcher->addState(state4, &animationGroup); + stateSwitcher->addState(state5, &animationGroup); + stateSwitcher->addState(state6, &animationGroup); + stateSwitcher->addState(state7, &animationGroup); + + machine.addState(group); + machine.setInitialState(group); + machine.start(); + + + window.resize(300, 300); + window.show(); + + qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); + + return app.exec(); +} + +#include "main.moc" diff --git a/examples/animation/moveblocks/moveblocks.pro b/examples/animation/moveblocks/moveblocks.pro new file mode 100644 index 0000000..b8e88b2 --- /dev/null +++ b/examples/animation/moveblocks/moveblocks.pro @@ -0,0 +1,7 @@ +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/animation/moveblocks +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS moveblocks.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/animation/moveblocks +INSTALLS += target sources diff --git a/examples/animation/states/accessories-dictionary.png b/examples/animation/states/accessories-dictionary.png Binary files differnew file mode 100644 index 0000000..e9bd55d --- /dev/null +++ b/examples/animation/states/accessories-dictionary.png diff --git a/examples/animation/states/akregator.png b/examples/animation/states/akregator.png Binary files differnew file mode 100644 index 0000000..a086f45 --- /dev/null +++ b/examples/animation/states/akregator.png diff --git a/examples/animation/states/digikam.png b/examples/animation/states/digikam.png Binary files differnew file mode 100644 index 0000000..9de9fb2 --- /dev/null +++ b/examples/animation/states/digikam.png diff --git a/examples/animation/states/help-browser.png b/examples/animation/states/help-browser.png Binary files differnew file mode 100644 index 0000000..db92faa --- /dev/null +++ b/examples/animation/states/help-browser.png diff --git a/examples/animation/states/k3b.png b/examples/animation/states/k3b.png Binary files differnew file mode 100644 index 0000000..bbcafcf --- /dev/null +++ b/examples/animation/states/k3b.png diff --git a/examples/animation/states/kchart.png b/examples/animation/states/kchart.png Binary files differnew file mode 100644 index 0000000..1dd115b --- /dev/null +++ b/examples/animation/states/kchart.png diff --git a/examples/animation/states/main.cpp b/examples/animation/states/main.cpp new file mode 100644 index 0000000..17a7a8e --- /dev/null +++ b/examples/animation/states/main.cpp @@ -0,0 +1,284 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +class Pixmap : public QGraphicsWidget +{ + Q_OBJECT +public: + Pixmap(const QPixmap &pix) : QGraphicsWidget(), p(pix) + { + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + { + painter->drawPixmap(QPointF(), p); + } + +protected: + QSizeF sizeHint(Qt::SizeHint, const QSizeF & = QSizeF()) + { + return QSizeF(p.width(), p.height()); + } + +private: + QPixmap p; +}; + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(states); + + QApplication app(argc, argv); + + // Text edit and button + QTextEdit *edit = new QTextEdit; + edit->setText("asdf lkjha yuoiqwe asd iuaysd u iasyd uiy " + "asdf lkjha yuoiqwe asd iuaysd u iasyd uiy " + "asdf lkjha yuoiqwe asd iuaysd u iasyd uiy " + "asdf lkjha yuoiqwe asd iuaysd u iasyd uiy!"); + + QPushButton *button = new QPushButton; + QGraphicsProxyWidget *buttonProxy = new QGraphicsProxyWidget; + buttonProxy->setWidget(button); + QGraphicsProxyWidget *editProxy = new QGraphicsProxyWidget; + editProxy->setWidget(edit); + + QGroupBox *box = new QGroupBox; + box->setFlat(true); + box->setTitle("Options"); + + QVBoxLayout *layout2 = new QVBoxLayout; + box->setLayout(layout2); + layout2->addWidget(new QRadioButton("Herring")); + layout2->addWidget(new QRadioButton("Blue Parrot")); + layout2->addWidget(new QRadioButton("Petunias")); + layout2->addStretch(); + + QGraphicsProxyWidget *boxProxy = new QGraphicsProxyWidget; + boxProxy->setWidget(box); + + // Parent widget + QGraphicsWidget *widget = new QGraphicsWidget; + QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, widget); + layout->addItem(editProxy); + layout->addItem(buttonProxy); + widget->setLayout(layout); + + Pixmap *p1 = new Pixmap(QPixmap(":/digikam.png")); + Pixmap *p2 = new Pixmap(QPixmap(":/akregator.png")); + Pixmap *p3 = new Pixmap(QPixmap(":/accessories-dictionary.png")); + Pixmap *p4 = new Pixmap(QPixmap(":/k3b.png")); + Pixmap *p5 = new Pixmap(QPixmap(":/help-browser.png")); + Pixmap *p6 = new Pixmap(QPixmap(":/kchart.png")); + + QGraphicsScene scene(0, 0, 400, 300); + scene.setBackgroundBrush(scene.palette().window()); + scene.addItem(widget); + scene.addItem(boxProxy); + scene.addItem(p1); + scene.addItem(p2); + scene.addItem(p3); + scene.addItem(p4); + scene.addItem(p5); + scene.addItem(p6); + + QStateMachine machine; + QState *root = machine.rootState(); + QState *state1 = new QState(root); + QState *state2 = new QState(root); + QState *state3 = new QState(root); + machine.setInitialState(state1); + + // State 1 + state1->assignProperty(button, "text", "Switch to state 2"); + state1->assignProperty(widget, "geometry", QRectF(0, 0, 400, 150)); + state1->assignProperty(box, "geometry", QRect(-200, 150, 200, 150)); + state1->assignProperty(p1, "geometry", QRectF(68, 185, 64, 64)); + state1->assignProperty(p2, "geometry", QRectF(168, 185, 64, 64)); + state1->assignProperty(p3, "geometry", QRectF(268, 185, 64, 64)); + state1->assignProperty(p4, "geometry", QRectF(68-150, 48-150, 64, 64)); + state1->assignProperty(p5, "geometry", QRectF(168, 48-150, 64, 64)); + state1->assignProperty(p6, "geometry", QRectF(268+150, 48-150, 64, 64)); + state1->assignProperty(p1, "zRotation", qreal(0)); + state1->assignProperty(p2, "zRotation", qreal(0)); + state1->assignProperty(p3, "zRotation", qreal(0)); + state1->assignProperty(p4, "zRotation", qreal(-270)); + state1->assignProperty(p5, "zRotation", qreal(-90)); + state1->assignProperty(p6, "zRotation", qreal(270)); + state1->assignProperty(boxProxy, "opacity", qreal(0)); + state1->assignProperty(p1, "opacity", qreal(1)); + state1->assignProperty(p2, "opacity", qreal(1)); + state1->assignProperty(p3, "opacity", qreal(1)); + state1->assignProperty(p4, "opacity", qreal(0)); + state1->assignProperty(p5, "opacity", qreal(0)); + state1->assignProperty(p6, "opacity", qreal(0)); + + // State 2 + state2->assignProperty(button, "text", "Switch to state 3"); + state2->assignProperty(widget, "geometry", QRectF(200, 150, 200, 150)); + state2->assignProperty(box, "geometry", QRect(9, 150, 190, 150)); + state2->assignProperty(p1, "geometry", QRectF(68-150, 185+150, 64, 64)); + state2->assignProperty(p2, "geometry", QRectF(168, 185+150, 64, 64)); + state2->assignProperty(p3, "geometry", QRectF(268+150, 185+150, 64, 64)); + state2->assignProperty(p4, "geometry", QRectF(64, 48, 64, 64)); + state2->assignProperty(p5, "geometry", QRectF(168, 48, 64, 64)); + state2->assignProperty(p6, "geometry", QRectF(268, 48, 64, 64)); + state2->assignProperty(p1, "zRotation", qreal(-270)); + state2->assignProperty(p2, "zRotation", qreal(90)); + state2->assignProperty(p3, "zRotation", qreal(270)); + state2->assignProperty(p4, "zRotation", qreal(0)); + state2->assignProperty(p5, "zRotation", qreal(0)); + state2->assignProperty(p6, "zRotation", qreal(0)); + state2->assignProperty(boxProxy, "opacity", qreal(1)); + state2->assignProperty(p1, "opacity", qreal(0)); + state2->assignProperty(p2, "opacity", qreal(0)); + state2->assignProperty(p3, "opacity", qreal(0)); + state2->assignProperty(p4, "opacity", qreal(1)); + state2->assignProperty(p5, "opacity", qreal(1)); + state2->assignProperty(p6, "opacity", qreal(1)); + + // State 3 + state3->assignProperty(button, "text", "Switch to state 1"); + state3->assignProperty(p1, "geometry", QRectF(5, 5, 64, 64)); + state3->assignProperty(p2, "geometry", QRectF(5, 5 + 64 + 5, 64, 64)); + state3->assignProperty(p3, "geometry", QRectF(5, 5 + (64 + 5) + 64, 64, 64)); + state3->assignProperty(p4, "geometry", QRectF(5 + 64 + 5, 5, 64, 64)); + state3->assignProperty(p5, "geometry", QRectF(5 + 64 + 5, 5 + 64 + 5, 64, 64)); + state3->assignProperty(p6, "geometry", QRectF(5 + 64 + 5, 5 + (64 + 5) + 64, 64, 64)); + state3->assignProperty(widget, "geometry", QRectF(138, 5, 400 - 138, 200)); + state3->assignProperty(box, "geometry", QRect(5, 205, 400, 90)); + state3->assignProperty(p1, "opacity", qreal(1)); + state3->assignProperty(p2, "opacity", qreal(1)); + state3->assignProperty(p3, "opacity", qreal(1)); + state3->assignProperty(p4, "opacity", qreal(1)); + state3->assignProperty(p5, "opacity", qreal(1)); + state3->assignProperty(p6, "opacity", qreal(1)); + + QParallelAnimationGroup animation1; + + QSequentialAnimationGroup *animation1SubGroup; + animation1SubGroup = new QSequentialAnimationGroup(&animation1); + animation1SubGroup->addPause(250); + animation1SubGroup->addAnimation(new QPropertyAnimation(box, "geometry")); + + animation1.addAnimation(new QPropertyAnimation(widget, "geometry")); + animation1.addAnimation(new QPropertyAnimation(p1, "geometry")); + animation1.addAnimation(new QPropertyAnimation(p2, "geometry")); + animation1.addAnimation(new QPropertyAnimation(p3, "geometry")); + animation1.addAnimation(new QPropertyAnimation(p4, "geometry")); + animation1.addAnimation(new QPropertyAnimation(p5, "geometry")); + animation1.addAnimation(new QPropertyAnimation(p6, "geometry")); + animation1.addAnimation(new QPropertyAnimation(p1, "zRotation")); + animation1.addAnimation(new QPropertyAnimation(p2, "zRotation")); + animation1.addAnimation(new QPropertyAnimation(p3, "zRotation")); + animation1.addAnimation(new QPropertyAnimation(p4, "zRotation")); + animation1.addAnimation(new QPropertyAnimation(p5, "zRotation")); + animation1.addAnimation(new QPropertyAnimation(p6, "zRotation")); + animation1.addAnimation(new QPropertyAnimation(p1, "opacity")); + animation1.addAnimation(new QPropertyAnimation(p2, "opacity")); + animation1.addAnimation(new QPropertyAnimation(p3, "opacity")); + animation1.addAnimation(new QPropertyAnimation(p4, "opacity")); + animation1.addAnimation(new QPropertyAnimation(p5, "opacity")); + animation1.addAnimation(new QPropertyAnimation(p6, "opacity")); + + QParallelAnimationGroup animation2; + animation2.addAnimation(new QPropertyAnimation(box, "geometry")); + animation2.addAnimation(new QPropertyAnimation(widget, "geometry")); + animation2.addAnimation(new QPropertyAnimation(p1, "geometry")); + animation2.addAnimation(new QPropertyAnimation(p2, "geometry")); + animation2.addAnimation(new QPropertyAnimation(p3, "geometry")); + animation2.addAnimation(new QPropertyAnimation(p4, "geometry")); + animation2.addAnimation(new QPropertyAnimation(p5, "geometry")); + animation2.addAnimation(new QPropertyAnimation(p6, "geometry")); + animation2.addAnimation(new QPropertyAnimation(p1, "zRotation")); + animation2.addAnimation(new QPropertyAnimation(p2, "zRotation")); + animation2.addAnimation(new QPropertyAnimation(p3, "zRotation")); + animation2.addAnimation(new QPropertyAnimation(p4, "zRotation")); + animation2.addAnimation(new QPropertyAnimation(p5, "zRotation")); + animation2.addAnimation(new QPropertyAnimation(p6, "zRotation")); + animation2.addAnimation(new QPropertyAnimation(p1, "opacity")); + animation2.addAnimation(new QPropertyAnimation(p2, "opacity")); + animation2.addAnimation(new QPropertyAnimation(p3, "opacity")); + animation2.addAnimation(new QPropertyAnimation(p4, "opacity")); + animation2.addAnimation(new QPropertyAnimation(p5, "opacity")); + animation2.addAnimation(new QPropertyAnimation(p6, "opacity")); + + QParallelAnimationGroup animation3; + animation3.addAnimation(new QPropertyAnimation(box, "geometry")); + animation3.addAnimation(new QPropertyAnimation(widget, "geometry")); + animation3.addAnimation(new QPropertyAnimation(p1, "geometry")); + animation3.addAnimation(new QPropertyAnimation(p2, "geometry")); + animation3.addAnimation(new QPropertyAnimation(p3, "geometry")); + animation3.addAnimation(new QPropertyAnimation(p4, "geometry")); + animation3.addAnimation(new QPropertyAnimation(p5, "geometry")); + animation3.addAnimation(new QPropertyAnimation(p6, "geometry")); + animation3.addAnimation(new QPropertyAnimation(p1, "zRotation")); + animation3.addAnimation(new QPropertyAnimation(p2, "zRotation")); + animation3.addAnimation(new QPropertyAnimation(p3, "zRotation")); + animation3.addAnimation(new QPropertyAnimation(p4, "zRotation")); + animation3.addAnimation(new QPropertyAnimation(p5, "zRotation")); + animation3.addAnimation(new QPropertyAnimation(p6, "zRotation")); + animation3.addAnimation(new QPropertyAnimation(p1, "opacity")); + animation3.addAnimation(new QPropertyAnimation(p2, "opacity")); + animation3.addAnimation(new QPropertyAnimation(p3, "opacity")); + animation3.addAnimation(new QPropertyAnimation(p4, "opacity")); + animation3.addAnimation(new QPropertyAnimation(p5, "opacity")); + animation3.addAnimation(new QPropertyAnimation(p6, "opacity")); + + QAbstractTransition *t1 = state1->addTransition(button, SIGNAL(clicked()), state2); + t1->addAnimation(&animation1); + QAbstractTransition *t2 = state2->addTransition(button, SIGNAL(clicked()), state3); + t2->addAnimation(&animation2); + QAbstractTransition *t3 = state3->addTransition(button, SIGNAL(clicked()), state1); + t3->addAnimation(&animation3); + + machine.start(); + + QGraphicsView view(&scene); + view.show(); + + return app.exec(); +} + +#include "main.moc" diff --git a/examples/animation/states/states.pro b/examples/animation/states/states.pro new file mode 100644 index 0000000..f4d1e0b --- /dev/null +++ b/examples/animation/states/states.pro @@ -0,0 +1,8 @@ +SOURCES += main.cpp +RESOURCES += states.qrc + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/animation/states +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS states.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/animation/states +INSTALLS += target sources diff --git a/examples/animation/states/states.qrc b/examples/animation/states/states.qrc new file mode 100644 index 0000000..60ab3f7 --- /dev/null +++ b/examples/animation/states/states.qrc @@ -0,0 +1,10 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>accessories-dictionary.png</file> + <file>akregator.png</file> + <file>digikam.png</file> + <file>help-browser.png</file> + <file>k3b.png</file> + <file>kchart.png</file> +</qresource> +</RCC> diff --git a/examples/animation/stickman/animation.cpp b/examples/animation/stickman/animation.cpp new file mode 100644 index 0000000..c2c6bd1 --- /dev/null +++ b/examples/animation/stickman/animation.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "animation.h" + +#include <QPointF> +#include <QIODevice> +#include <QDataStream> + +class Frame +{ +public: + Frame() { + } + + int nodeCount() const + { + return m_nodePositions.size(); + } + + void setNodeCount(int nodeCount) + { + while (nodeCount > m_nodePositions.size()) + m_nodePositions.append(QPointF()); + + while (nodeCount < m_nodePositions.size()) + m_nodePositions.removeLast(); + } + + QPointF nodePos(int idx) const + { + return m_nodePositions.at(idx); + } + + void setNodePos(int idx, const QPointF &pos) + { + m_nodePositions[idx] = pos; + } + +private: + QList<QPointF> m_nodePositions; +}; + +Animation::Animation() +{ + m_currentFrame = 0; + m_frames.append(new Frame); +} + +Animation::~Animation() +{ + qDeleteAll(m_frames); +} + +void Animation::setTotalFrames(int totalFrames) +{ + while (m_frames.size() < totalFrames) + m_frames.append(new Frame); + + while (totalFrames < m_frames.size()) + delete m_frames.takeLast(); +} + +int Animation::totalFrames() const +{ + return m_frames.size(); +} + +void Animation::setCurrentFrame(int currentFrame) +{ + m_currentFrame = qMax(qMin(currentFrame, totalFrames()-1), 0); +} + +int Animation::currentFrame() const +{ + return m_currentFrame; +} + +void Animation::setNodeCount(int nodeCount) +{ + Frame *frame = m_frames.at(m_currentFrame); + frame->setNodeCount(nodeCount); +} + +int Animation::nodeCount() const +{ + Frame *frame = m_frames.at(m_currentFrame); + return frame->nodeCount(); +} + +void Animation::setNodePos(int idx, const QPointF &pos) +{ + Frame *frame = m_frames.at(m_currentFrame); + frame->setNodePos(idx, pos); +} + +QPointF Animation::nodePos(int idx) const +{ + Frame *frame = m_frames.at(m_currentFrame); + return frame->nodePos(idx); +} + +QString Animation::name() const +{ + return m_name; +} + +void Animation::setName(const QString &name) +{ + m_name = name; +} + +void Animation::save(QIODevice *device) const +{ + QDataStream stream(device); + stream << m_name; + stream << m_frames.size(); + foreach (Frame *frame, m_frames) { + stream << frame->nodeCount(); + for (int i=0; i<frame->nodeCount(); ++i) + stream << frame->nodePos(i); + } +} + +void Animation::load(QIODevice *device) +{ + if (!m_frames.isEmpty()) + qDeleteAll(m_frames); + + m_frames.clear(); + + QDataStream stream(device); + stream >> m_name; + + int frameCount; + stream >> frameCount; + + for (int i=0; i<frameCount; ++i) { + + int nodeCount; + stream >> nodeCount; + + Frame *frame = new Frame; + frame->setNodeCount(nodeCount); + + for (int j=0; j<nodeCount; ++j) { + QPointF pos; + stream >> pos; + + frame->setNodePos(j, pos); + } + + m_frames.append(frame); + } +} diff --git a/examples/animation/stickman/animation.h b/examples/animation/stickman/animation.h new file mode 100644 index 0000000..b0b39c9 --- /dev/null +++ b/examples/animation/stickman/animation.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANIMATION_H +#define ANIMATION_H + +#include <QPointF> +#include <QList> +#include <QString> + +class Frame; +QT_BEGIN_NAMESPACE +class QIODevice; +QT_END_NAMESPACE +class Animation +{ +public: + Animation(); + ~Animation(); + + void setTotalFrames(int totalFrames); + int totalFrames() const; + + void setCurrentFrame(int currentFrame); + int currentFrame() const; + + void setNodeCount(int nodeCount); + int nodeCount() const; + + void setNodePos(int idx, const QPointF &pos); + QPointF nodePos(int idx) const; + + QString name() const; + void setName(const QString &name); + + void save(QIODevice *device) const; + void load(QIODevice *device); + +private: + QString m_name; + QList<Frame *> m_frames; + int m_currentFrame; +}; + +#endif diff --git a/examples/animation/stickman/animations/chilling b/examples/animation/stickman/animations/chilling Binary files differnew file mode 100644 index 0000000..a81fc7a --- /dev/null +++ b/examples/animation/stickman/animations/chilling diff --git a/examples/animation/stickman/animations/dancing b/examples/animation/stickman/animations/dancing Binary files differnew file mode 100644 index 0000000..462f66f --- /dev/null +++ b/examples/animation/stickman/animations/dancing diff --git a/examples/animation/stickman/animations/dead b/examples/animation/stickman/animations/dead Binary files differnew file mode 100644 index 0000000..9859b4b --- /dev/null +++ b/examples/animation/stickman/animations/dead diff --git a/examples/animation/stickman/animations/jumping b/examples/animation/stickman/animations/jumping Binary files differnew file mode 100644 index 0000000..12661a1 --- /dev/null +++ b/examples/animation/stickman/animations/jumping diff --git a/examples/animation/stickman/editor/animationdialog.cpp b/examples/animation/stickman/editor/animationdialog.cpp new file mode 100644 index 0000000..441517d --- /dev/null +++ b/examples/animation/stickman/editor/animationdialog.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "animationdialog.h" +#include "stickman.h" +#include "animation.h" +#include "node.h" + +#include <QHBoxLayout> +#include <QStackedWidget> +#include <QSpinBox> +#include <QPushButton> +#include <QLabel> +#include <QLineEdit> +#include <QMessageBox> +#include <QFileDialog> + +AnimationDialog::AnimationDialog(StickMan *stickman, QWidget *parent) + : QDialog(parent), m_animation(0), m_stickman(stickman) +{ + initUi(); +} + +AnimationDialog::~AnimationDialog() +{ + delete m_animation; +} + +void AnimationDialog::initUi() +{ + setWindowTitle("Animation"); + setEnabled(false); + + // Second page + m_currentFrame = new QSpinBox(); + m_totalFrames = new QSpinBox(); + m_name = new QLineEdit(); + + connect(m_currentFrame, SIGNAL(valueChanged(int)), this, SLOT(currentFrameChanged(int))); + connect(m_totalFrames, SIGNAL(valueChanged(int)), this, SLOT(totalFramesChanged(int))); + connect(m_name, SIGNAL(textChanged(QString)), this, SLOT(setCurrentAnimationName(QString))); + + QGridLayout *gridLayout = new QGridLayout(this); + gridLayout->addWidget(new QLabel("Name:"), 0, 0, 1, 2); + gridLayout->addWidget(m_name, 0, 2, 1, 2); + gridLayout->addWidget(new QLabel("Frame:"), 1, 0); + gridLayout->addWidget(m_currentFrame, 1, 1); + gridLayout->addWidget(new QLabel("of total # of frames: "), 1, 2); + gridLayout->addWidget(m_totalFrames, 1, 3); +} + +void AnimationDialog::initFromAnimation() +{ + m_currentFrame->setRange(0, m_animation->totalFrames()-1); + m_currentFrame->setValue(m_animation->currentFrame()); + + m_totalFrames->setRange(1, 1000); + m_totalFrames->setValue(m_animation->totalFrames()); + + m_name->setText(m_animation->name()); +} + +void AnimationDialog::saveAnimation() +{ + saveCurrentFrame(); + + QString fileName = QFileDialog::getSaveFileName(this, "Save animation"); + + QFile file(fileName); + if (file.open(QIODevice::WriteOnly)) + m_animation->save(&file); +} + +void AnimationDialog::loadAnimation() +{ + if (maybeSave() != QMessageBox::Cancel) { + QString fileName = QFileDialog::getOpenFileName(this, "Open animation"); + + QFile file(fileName); + if (file.open(QIODevice::ReadOnly)) { + if (m_animation == 0) + newAnimation(); + + m_animation->load(&file); + stickManFromCurrentFrame(); + initFromAnimation(); + } + } +} + +QMessageBox::StandardButton AnimationDialog::maybeSave() +{ + if (m_animation == 0) + return QMessageBox::No; + + QMessageBox::StandardButton button = QMessageBox::question(this, "Save?", "Do you want to save your changes?", + QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); + if (button == QMessageBox::Save) + saveAnimation(); + + return button; +} + +void AnimationDialog::newAnimation() +{ + if (maybeSave() != QMessageBox::Cancel) { + setEnabled(true); + delete m_animation; + m_animation = new Animation(); + initFromAnimation(); + } +} + +// Gets the data from the stickman and stores it in current frame +void AnimationDialog::saveCurrentFrame() +{ + int count = m_stickman->nodeCount(); + m_animation->setNodeCount(count); + for (int i=0; i<count; ++i) { + QGraphicsItem *node = m_stickman->node(i); + m_animation->setNodePos(i, node->pos()); + } +} + +// Gets the data from the current frame and sets the stickman +void AnimationDialog::stickManFromCurrentFrame() +{ + int count = m_animation->nodeCount(); + for (int i=0;i<count;++i) { + QGraphicsItem *node = m_stickman->node(i); + node->setPos(m_animation->nodePos(i)); + } +} + +void AnimationDialog::currentFrameChanged(int currentFrame) +{ + saveCurrentFrame(); + qDebug("currentFrame: %d", currentFrame); + m_animation->setCurrentFrame(currentFrame); + stickManFromCurrentFrame(); + initFromAnimation(); +} + +void AnimationDialog::totalFramesChanged(int totalFrames) +{ + m_animation->setTotalFrames(totalFrames); + stickManFromCurrentFrame(); + initFromAnimation(); +} + +void AnimationDialog::setCurrentAnimationName(const QString &name) +{ + m_animation->setName(name); +} diff --git a/examples/animation/stickman/editor/animationdialog.h b/examples/animation/stickman/editor/animationdialog.h new file mode 100644 index 0000000..6025088 --- /dev/null +++ b/examples/animation/stickman/editor/animationdialog.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANIMATIONDIALOG_H +#define ANIMATIONDIALOG_H + +#include <QDialog> +#include <QMessageBox> + +QT_BEGIN_NAMESPACE +class QSpinBox; +class QLineEdit; +QT_END_NAMESPACE +class StickMan; +class Animation; +class AnimationDialog: public QDialog +{ + Q_OBJECT +public: + AnimationDialog(StickMan *stickMan, QWidget *parent = 0); + ~AnimationDialog(); + +public slots: + void currentFrameChanged(int currentFrame); + void totalFramesChanged(int totalFrames); + void setCurrentAnimationName(const QString &name); + + void newAnimation(); + void saveAnimation(); + void loadAnimation(); + +private: + void saveCurrentFrame(); + void stickManFromCurrentFrame(); + void initFromAnimation(); + void initUi(); + QMessageBox::StandardButton maybeSave(); + + QSpinBox *m_currentFrame; + QSpinBox *m_totalFrames; + QLineEdit *m_name; + Animation *m_animation; + StickMan *m_stickman; +}; + +#endif diff --git a/examples/animation/stickman/editor/editor.pri b/examples/animation/stickman/editor/editor.pri new file mode 100644 index 0000000..7ad9edb --- /dev/null +++ b/examples/animation/stickman/editor/editor.pri @@ -0,0 +1,2 @@ +SOURCES += $$PWD/animationdialog.cpp $$PWD/mainwindow.cpp +HEADERS += $$PWD/animationdialog.h $$PWD/mainwindow.h diff --git a/examples/animation/stickman/editor/mainwindow.cpp b/examples/animation/stickman/editor/mainwindow.cpp new file mode 100644 index 0000000..c6464c6 --- /dev/null +++ b/examples/animation/stickman/editor/mainwindow.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "mainwindow.h" +#include "animationdialog.h" +#include "stickman.h" + +#include <QMenuBar> +#include <QApplication> + +MainWindow::MainWindow(StickMan *stickMan) +{ + initActions(stickMan); +} + +MainWindow::~MainWindow() +{ +} + +void MainWindow::initActions(StickMan *stickMan) +{ + AnimationDialog *dialog = new AnimationDialog(stickMan, this); + dialog->show(); + + QMenu *fileMenu = menuBar()->addMenu("&File"); + QAction *loadAction = fileMenu->addAction("&Open"); + QAction *saveAction = fileMenu->addAction("&Save"); + QAction *exitAction = fileMenu->addAction("E&xit"); + + QMenu *animationMenu = menuBar()->addMenu("&Animation"); + QAction *newAnimationAction = animationMenu->addAction("&New animation"); + + connect(loadAction, SIGNAL(triggered()), dialog, SLOT(loadAnimation())); + connect(saveAction, SIGNAL(triggered()), dialog, SLOT(saveAnimation())); + connect(exitAction, SIGNAL(triggered()), QApplication::instance(), SLOT(quit())); + connect(newAnimationAction, SIGNAL(triggered()), dialog, SLOT(newAnimation())); + +} diff --git a/examples/animation/stickman/editor/mainwindow.h b/examples/animation/stickman/editor/mainwindow.h new file mode 100644 index 0000000..4c2b949 --- /dev/null +++ b/examples/animation/stickman/editor/mainwindow.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +class StickMan; +class MainWindow: public QMainWindow +{ +public: + MainWindow(StickMan *stickMan); + ~MainWindow(); + +private: + void initActions(StickMan *stickMan); +}; + +#endif diff --git a/examples/animation/stickman/graphicsview.cpp b/examples/animation/stickman/graphicsview.cpp new file mode 100644 index 0000000..754f3bc --- /dev/null +++ b/examples/animation/stickman/graphicsview.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "graphicsview.h" +#include "editor/mainwindow.h" +#include "stickman.h" + +#include <QtGui/QKeyEvent> +#include <QtGui/QGraphicsScene> +#include <QtGui/QGraphicsView> + +GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent), m_editor(0) {} + +void GraphicsView::keyPressEvent(QKeyEvent *e) +{ + if (e->key() == Qt::Key_Escape) + close(); + +#if 0 + if (e->key() == Qt::Key_F1) { + if (m_editor == 0) { + QGraphicsScene *scene = new QGraphicsScene; + StickMan *stickMan = new StickMan; + stickMan->setDrawSticks(true); + scene->addItem(stickMan); + + QGraphicsView *view = new QGraphicsView; + view->setBackgroundBrush(Qt::black); + view->setRenderHints(QPainter::Antialiasing); + view->setScene(scene); + + m_editor = new MainWindow(stickMan); + m_editor->setCentralWidget(view); + } + + m_editor->showMaximized(); + } +#endif + + emit keyPressed(Qt::Key(e->key())); +} + + diff --git a/examples/animation/stickman/graphicsview.h b/examples/animation/stickman/graphicsview.h new file mode 100644 index 0000000..2515418 --- /dev/null +++ b/examples/animation/stickman/graphicsview.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GRAPHICSVIEW_H +#define GRAPHICSVIEW + +#include <QtGui/QGraphicsView> + +class MainWindow; +class GraphicsView: public QGraphicsView +{ + Q_OBJECT +public: + GraphicsView(QWidget *parent = 0); + +protected: + void keyPressEvent(QKeyEvent *); + +signals: + void keyPressed(int key); + +private: + MainWindow *m_editor; +}; + +#endif diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp new file mode 100644 index 0000000..eb4ed11 --- /dev/null +++ b/examples/animation/stickman/lifecycle.cpp @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "lifecycle.h" +#include "stickman.h" +#include "node.h" +#include "animation.h" +#include "graphicsview.h" + +#include <QtCore> +#include <QtGui> + +class KeyPressTransition: public QSignalTransition +{ +public: + KeyPressTransition(GraphicsView *receiver, Qt::Key key) + : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key) + { + } + KeyPressTransition(GraphicsView *receiver, Qt::Key key, QAbstractState *target) + : QSignalTransition(receiver, SIGNAL(keyPressed(int)), QList<QAbstractState*>() << target), m_key(key) + { + } + + virtual bool eventTest(QEvent *e) + { + if (QSignalTransition::eventTest(e)) { + QVariant key = static_cast<QSignalEvent*>(e)->arguments().at(0); + return (key.toInt() == int(m_key)); + } + + return false; + } +private: + Qt::Key m_key; +}; + +//! [4] +class LightningStrikesTransition: public QEventTransition +{ +public: + LightningStrikesTransition(QAbstractState *target) + : QEventTransition(this, QEvent::Timer, QList<QAbstractState*>() << target) + { + qsrand((uint)QDateTime::currentDateTime().toTime_t()); + startTimer(1000); + } + + virtual bool eventTest(QEvent *e) + { + return QEventTransition::eventTest(e) && ((qrand() % 50) == 0); + } +}; +//! [4] + +LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver) + : m_stickMan(stickMan), m_keyReceiver(keyReceiver) +{ + // Create animation group to be used for all transitions + m_animationGroup = new QParallelAnimationGroup(); + const int stickManNodeCount = m_stickMan->nodeCount(); + for (int i=0; i<stickManNodeCount; ++i) { + QPropertyAnimation *pa = new QPropertyAnimation(m_stickMan->node(i), "position"); + m_animationGroup->addAnimation(pa); + } + + // Set up intial state graph +//! [3] + m_machine = new QStateMachine(); + m_machine->addDefaultAnimation(m_animationGroup); +//! [3] + + m_alive = new QState(m_machine->rootState()); + m_alive->setObjectName("alive"); + + // Make it blink when lightning strikes before entering dead animation + QState *lightningBlink = new QState(m_machine->rootState()); + lightningBlink->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::white); + lightningBlink->assignProperty(m_stickMan, "penColor", Qt::black); + lightningBlink->assignProperty(m_stickMan, "fillColor", Qt::white); + lightningBlink->assignProperty(m_stickMan, "isDead", true); + +//! [5] + QTimer *timer = new QTimer(lightningBlink); + timer->setSingleShot(true); + timer->setInterval(100); + QObject::connect(lightningBlink, SIGNAL(entered()), timer, SLOT(start())); + QObject::connect(lightningBlink, SIGNAL(exited()), timer, SLOT(stop())); +//! [5] + + m_dead = new QState(m_machine->rootState()); + m_dead->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::black); + m_dead->assignProperty(m_stickMan, "penColor", Qt::white); + m_dead->assignProperty(m_stickMan, "fillColor", Qt::black); + m_dead->setObjectName("dead"); + + // Idle state (sets no properties) + m_idle = new QState(m_alive); + m_idle->setObjectName("idle"); + + m_alive->setInitialState(m_idle); + + // Lightning strikes at random + m_alive->addTransition(new LightningStrikesTransition(lightningBlink)); +//! [0] + lightningBlink->addTransition(timer, SIGNAL(timeout()), m_dead); +//! [0] + + m_machine->setInitialState(m_alive); +} + +void LifeCycle::setDeathAnimation(const QString &fileName) +{ + QState *deathAnimation = makeState(m_dead, fileName); + m_dead->setInitialState(deathAnimation); +} + +void LifeCycle::start() +{ + m_machine->start(); +} + +void LifeCycle::addActivity(const QString &fileName, Qt::Key key) +{ + QState *state = makeState(m_alive, fileName); + m_alive->addTransition(new KeyPressTransition(m_keyReceiver, key, state)); +} + +QState *LifeCycle::makeState(QState *parentState, const QString &animationFileName) +{ + QState *topLevel = new QState(parentState); + + Animation animation; + { + QFile file(animationFileName); + if (file.open(QIODevice::ReadOnly)) + animation.load(&file); + } + + const int frameCount = animation.totalFrames(); + QState *previousState = 0; + for (int i=0; i<frameCount; ++i) { + animation.setCurrentFrame(i); + +//! [1] + QState *frameState = new QState(topLevel); + const int nodeCount = animation.nodeCount(); + for (int j=0; j<nodeCount; ++j) + frameState->assignProperty(m_stickMan->node(j), "position", animation.nodePos(j)); +//! [1] + + frameState->setObjectName(QString::fromLatin1("frame %0").arg(i)); + if (previousState == 0) + topLevel->setInitialState(frameState); + else +//! [2] + previousState->addTransition(previousState, SIGNAL(polished()), frameState); +//! [2] + + previousState = frameState; + } + + // Loop + previousState->addTransition(previousState, SIGNAL(polished()), topLevel->initialState()); + + return topLevel; + +} + +LifeCycle::~LifeCycle() +{ + delete m_machine; + delete m_animationGroup; +} diff --git a/examples/animation/stickman/lifecycle.h b/examples/animation/stickman/lifecycle.h new file mode 100644 index 0000000..2be4762 --- /dev/null +++ b/examples/animation/stickman/lifecycle.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LIFECYCLE_H +#define LIFECYCLE_H + +#include <Qt> + +class StickMan; +QT_BEGIN_NAMESPACE +class QStateMachine; +class QAnimationGroup; +class QState; +class QAbstractState; +class QAbstractTransition; +QT_END_NAMESPACE +class GraphicsView; +class LifeCycle +{ +public: + LifeCycle(StickMan *stickMan, GraphicsView *keyEventReceiver); + ~LifeCycle(); + + void setDeathAnimation(const QString &fileName); + void addActivity(const QString &fileName, Qt::Key key); + + void start(); + +private: + QState *makeState(QState *parentState, const QString &animationFileName); + + StickMan *m_stickMan; + QStateMachine *m_machine; + QAnimationGroup *m_animationGroup; + GraphicsView *m_keyReceiver; + + QState *m_alive; + QState *m_dead; + QState *m_idle; +}; + +#endif diff --git a/examples/animation/stickman/main.cpp b/examples/animation/stickman/main.cpp new file mode 100644 index 0000000..62d8252 --- /dev/null +++ b/examples/animation/stickman/main.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "animation.h" +#include "node.h" +#include "lifecycle.h" +#include "stickman.h" +#include "graphicsview.h" + +#include <QtCore> +#include <QtGui> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + StickMan *stickMan = new StickMan; + stickMan->setDrawSticks(false); + + QGraphicsTextItem *textItem = new QGraphicsTextItem(); + textItem->setHtml("<font color=\"white\"><b>Stickman</b>" + "<p>" + "Tell the stickman what to do!" + "</p>" + "<p><i>" + "<li>Press <font color=\"purple\">J</font> to make the stickman jump.</li>" + "<li>Press <font color=\"purple\">D</font> to make the stickman dance.</li>" + "<li>Press <font color=\"purple\">C</font> to make him chill out.</li>" + "<li>When you are done, press <font color=\"purple\">Escape</font>.</li>" + "</i></p>" + "<p>If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again." + "</p></font>"); + qreal w = textItem->boundingRect().width(); + QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect(); + textItem->setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0); + + QGraphicsScene *scene = new QGraphicsScene(); + scene->addItem(stickMan); + scene->addItem(textItem); + scene->setBackgroundBrush(Qt::black); + + GraphicsView *view = new GraphicsView(); + view->setRenderHints(QPainter::Antialiasing); + view->setTransformationAnchor(QGraphicsView::NoAnchor); + view->setScene(scene); + view->showFullScreen(); + view->setFocus(); + view->setSceneRect(scene->sceneRect()); + + LifeCycle *cycle = new LifeCycle(stickMan, view); + cycle->setDeathAnimation("animations/dead"); + + cycle->addActivity("animations/jumping", Qt::Key_J); + cycle->addActivity("animations/dancing", Qt::Key_D); + cycle->addActivity("animations/chilling", Qt::Key_C); + cycle->start(); + + return app.exec(); +} diff --git a/examples/animation/stickman/node.cpp b/examples/animation/stickman/node.cpp new file mode 100644 index 0000000..9c485d9 --- /dev/null +++ b/examples/animation/stickman/node.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "node.h" +#include "stickman.h" + +#include <QRectF> +#include <QPainter> +#include <QGraphicsSceneMouseEvent> + +Node::Node(const QPointF &pos, QGraphicsItem *parent) + : QGraphicsItem(parent), m_dragging(false) +{ + setPos(pos); +} + +Node::~Node() +{ +} + +QRectF Node::boundingRect() const +{ + return QRectF(-6.0, -6.0, 12.0, 12.0); +} + +void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + painter->setPen(Qt::white); + painter->drawEllipse(QPointF(0.0, 0.0), 5.0, 5.0); +} + +QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == QGraphicsItem::ItemPositionChange) + emit positionChanged(); + + return QGraphicsItem::itemChange(change, value); +} + +void Node::mousePressEvent(QGraphicsSceneMouseEvent *) +{ + m_dragging = true; +} + +void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_dragging) + setPos(mapToParent(event->pos())); +} + +void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *) +{ + m_dragging = false; +} diff --git a/examples/animation/stickman/node.h b/examples/animation/stickman/node.h new file mode 100644 index 0000000..72eae87 --- /dev/null +++ b/examples/animation/stickman/node.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef NODE_H +#define NODE_H + +#include <QGraphicsItem> + +class Node: public QObject, public QGraphicsItem +{ + Q_OBJECT + Q_PROPERTY(QPointF position READ pos WRITE setPos); +public: + Node(const QPointF &pos, QGraphicsItem *parent = 0); + ~Node(); + + QRectF boundingRect() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + +signals: + void positionChanged(); + +protected: + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + + void mousePressEvent(QGraphicsSceneMouseEvent *); + void mouseMoveEvent(QGraphicsSceneMouseEvent *); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *); + +private: + bool m_dragging; +}; + +#endif diff --git a/examples/animation/stickman/stickman.cpp b/examples/animation/stickman/stickman.cpp new file mode 100644 index 0000000..a3b200c --- /dev/null +++ b/examples/animation/stickman/stickman.cpp @@ -0,0 +1,343 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "stickman.h" +#include "node.h" + +#include <QPainter> +#include <QTimer> + +#define _USE_MATH_DEFINES +#include <math.h> + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +static const int NodeCount = 16; +static const qreal Coords[NodeCount * 2] = { + 0.0, -150.0, // head, #0 + + 0.0, -100.0, // body pentagon, top->bottom, left->right, #1 - 5 + -50.0, -50.0, + 50.0, -50.0, + -25.0, 50.0, + 25.0, 50.0, + + -100.0, 0.0, // right arm, #6 - 7 + -125.0, 50.0, + + 100.0, 0.0, // left arm, #8 - 9 + 125.0, 50.0, + + -35.0, 75.0, // lower body, #10 - 11 + 35.0, 75.0, + + -25.0, 200.0, // right leg, #12 - 13 + -30.0, 300.0, + + 25.0, 200.0, // left leg, #14 - 15 + 30.0, 300.0 + +}; + +static const int BoneCount = 24; +static const int Bones[BoneCount * 2] = { + 0, 1, // neck + + 1, 2, // body + 1, 3, + 1, 4, + 1, 5, + 2, 3, + 2, 4, + 2, 5, + 3, 4, + 3, 5, + 4, 5, + + 2, 6, // right arm + 6, 7, + + 3, 8, // left arm + 8, 9, + + 4, 10, // lower body + 4, 11, + 5, 10, + 5, 11, + 10, 11, + + 10, 12, // right leg + 12, 13, + + 11, 14, // left leg + 14, 15 + +}; + +StickMan::StickMan() +{ + m_nodes = new Node*[NodeCount]; + m_sticks = true; + m_isDead = false; + m_pixmap = QPixmap("images/head.png"); + m_penColor = Qt::white; + m_fillColor = Qt::black; + + // Set up start position of limbs + for (int i=0; i<NodeCount; ++i) { + m_nodes[i] = new Node(QPointF(Coords[i * 2], Coords[i * 2 + 1]), this); + connect(m_nodes[i], SIGNAL(positionChanged()), this, SLOT(childPositionChanged())); + } + + m_perfectBoneLengths = new qreal[BoneCount]; + for (int i=0; i<BoneCount; ++i) { + int n1 = Bones[i * 2]; + int n2 = Bones[i * 2 + 1]; + + Node *node1 = m_nodes[n1]; + Node *node2 = m_nodes[n2]; + + QPointF dist = node1->pos() - node2->pos(); + m_perfectBoneLengths[i] = sqrt(pow(dist.x(),2) + pow(dist.y(),2)); + } + + startTimer(10); +} + +StickMan::~StickMan() +{ + delete m_nodes; +} + +void StickMan::childPositionChanged() +{ + prepareGeometryChange(); +} + +void StickMan::setDrawSticks(bool on) +{ + m_sticks = on; + for (int i=0;i<nodeCount();++i) { + Node *node = m_nodes[i]; + node->setVisible(on); + } +} + +QRectF StickMan::boundingRect() const +{ + // account for head radius=50.0 plus pen which is 5.0 + return childrenBoundingRect().adjusted(-55.0, -55.0, 55.0, 55.0); +} + +int StickMan::nodeCount() const +{ + return NodeCount; +} + +Node *StickMan::node(int idx) const +{ + if (idx >= 0 && idx < NodeCount) + return m_nodes[idx]; + else + return 0; +} + +void StickMan::timerEvent(QTimerEvent *) +{ + update(); +} + +void StickMan::stabilize() +{ + static const qreal threshold = 0.001; + + for (int i=0; i<BoneCount; ++i) { + int n1 = Bones[i * 2]; + int n2 = Bones[i * 2 + 1]; + + Node *node1 = m_nodes[n1]; + Node *node2 = m_nodes[n2]; + + QPointF pos1 = node1->pos(); + QPointF pos2 = node2->pos(); + + QPointF dist = pos1 - pos2; + qreal length = sqrt(pow(dist.x(),2) + pow(dist.y(),2)); + qreal diff = (length - m_perfectBoneLengths[i]) / length; + + QPointF p = dist * (0.5 * diff); + if (p.x() > threshold && p.y() > threshold) { + pos1 -= p; + pos2 += p; + + node1->setPos(pos1); + node2->setPos(pos2); + } + } +} + +QPointF StickMan::posFor(int idx) const +{ + return m_nodes[idx]->pos(); +} + +//#include <QTime> +void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + /* static int frames = 0; + static QTime time; + if (frames++ % 100 == 0) { + frames = 1; + time.restart(); + } + + if (time.elapsed() > 0) { + painter->setPen(Qt::white); + painter->drawText(0, 0, QString::number(frames / (time.elapsed() / 1000.0))); + }*/ + + stabilize(); + if (m_sticks) { + painter->setPen(Qt::white); + for (int i=0; i<BoneCount; ++i) { + int n1 = Bones[i * 2]; + int n2 = Bones[i * 2 + 1]; + + Node *node1 = m_nodes[n1]; + Node *node2 = m_nodes[n2]; + + painter->drawLine(node1->pos(), node2->pos()); + } + } else { + // first bone is neck and will be used for head + + QPainterPath path; + path.moveTo(posFor(0)); + path.lineTo(posFor(1)); + + // right arm + path.lineTo(posFor(2)); + path.lineTo(posFor(6)); + path.lineTo(posFor(7)); + + // left arm + path.moveTo(posFor(3)); + path.lineTo(posFor(8)); + path.lineTo(posFor(9)); + + // body + path.moveTo(posFor(2)); + path.lineTo(posFor(4)); + path.lineTo(posFor(10)); + path.lineTo(posFor(11)); + path.lineTo(posFor(5)); + path.lineTo(posFor(3)); + path.lineTo(posFor(1)); + + // right leg + path.moveTo(posFor(10)); + path.lineTo(posFor(12)); + path.lineTo(posFor(13)); + + // left leg + path.moveTo(posFor(11)); + path.lineTo(posFor(14)); + path.lineTo(posFor(15)); + + painter->setPen(QPen(m_penColor, 5.0, Qt::SolidLine, Qt::RoundCap)); + painter->drawPath(path); + + { + int n1 = Bones[0]; + int n2 = Bones[1]; + Node *node1 = m_nodes[n1]; + Node *node2 = m_nodes[n2]; + + QPointF dist = node2->pos() - node1->pos(); + + qreal sinAngle = dist.x() / sqrt(pow(dist.x(), 2) + pow(dist.y(), 2)); + qreal angle = asin(sinAngle) * 180.0 / M_PI; + + QPointF headPos = node1->pos(); + painter->translate(headPos); + painter->rotate(-angle); + + painter->setBrush(m_fillColor); + painter->drawEllipse(QPointF(0,0), 50.0, 50.0); + + painter->setBrush(m_penColor); + painter->setPen(QPen(m_penColor, 2.5, Qt::SolidLine, Qt::RoundCap)); + + // eyes + if (m_isDead) { + painter->drawLine(-30.0, -30.0, -20.0, -20.0); + painter->drawLine(-20.0, -30.0, -30.0, -20.0); + + painter->drawLine(20.0, -30.0, 30.0, -20.0); + painter->drawLine(30.0, -30.0, 20.0, -20.0); + } else { + painter->drawChord(QRectF(-30.0, -30.0, 25.0, 70.0), 30.0*16, 120.0*16); + painter->drawChord(QRectF(5.0, -30.0, 25.0, 70.0), 30.0*16, 120.0*16); + } + + // mouth + if (m_isDead) { + painter->drawLine(-28.0, 2.0, 29.0, 2.0); + } else { + painter->setBrush(QColor(128, 0, 64 )); + painter->drawChord(QRectF(-28.0, 2.0-55.0/2.0, 57.0, 55.0), 0.0, -180.0*16); + } + + // pupils + if (!m_isDead) { + painter->setPen(QPen(m_fillColor, 1.0, Qt::SolidLine, Qt::RoundCap)); + painter->setBrush(m_fillColor); + painter->drawEllipse(QPointF(-12.0, -25.0), 5.0, 5.0); + painter->drawEllipse(QPointF(22.0, -25.0), 5.0, 5.0); + } + } + } +} + + + diff --git a/examples/animation/stickman/stickman.h b/examples/animation/stickman/stickman.h new file mode 100644 index 0000000..6395272 --- /dev/null +++ b/examples/animation/stickman/stickman.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef STICKMAN_H +#define STICKMAN_H + +#include <QGraphicsItem> + +const int LimbCount = 16; + +class Node; +QT_BEGIN_NAMESPACE +class QTimer; +QT_END_NAMESPACE +class StickMan: public QObject, public QGraphicsItem +{ + Q_OBJECT + Q_PROPERTY(QColor penColor WRITE setPenColor READ penColor) + Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor) + Q_PROPERTY(bool isDead WRITE setIsDead READ isDead) +public: + StickMan(); + ~StickMan(); + + virtual QRectF boundingRect() const; + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + + int nodeCount() const; + Node *node(int idx) const; + + void setDrawSticks(bool on); + bool drawSticks() const { return m_sticks; } + + QColor penColor() const { return m_penColor; } + void setPenColor(const QColor &color) { m_penColor = color; } + + QColor fillColor() const { return m_fillColor; } + void setFillColor(const QColor &color) { m_fillColor = color; } + + bool isDead() const { return m_isDead; } + void setIsDead(bool isDead) { m_isDead = isDead; } + +public slots: + void stabilize(); + void childPositionChanged(); + +protected: + void timerEvent(QTimerEvent *e); + +private: + QPointF posFor(int idx) const; + + Node **m_nodes; + qreal *m_perfectBoneLengths; + + uint m_sticks : 1; + uint m_isDead : 1; + uint m_reserved : 30; + + QPixmap m_pixmap; + QColor m_penColor; + QColor m_fillColor; +}; + +#endif // STICKMAN_H diff --git a/examples/animation/stickman/stickman.pro b/examples/animation/stickman/stickman.pro new file mode 100644 index 0000000..1dbbce9 --- /dev/null +++ b/examples/animation/stickman/stickman.pro @@ -0,0 +1,21 @@ +HEADERS += stickman.h \ + animation.h \ + node.h \ + lifecycle.h \ + graphicsview.h +SOURCES += main.cpp \ + stickman.cpp \ + animation.cpp \ + node.cpp \ + lifecycle.cpp \ + graphicsview.cpp + +INCLUDEPATH += $$PWD + +include(editor/editor.pri) + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/animation/stickman +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS stickman.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/animation/stickman +INSTALLS += target sources diff --git a/examples/animation/sub-attaq/animationmanager.cpp b/examples/animation/sub-attaq/animationmanager.cpp new file mode 100644 index 0000000..477d3bd --- /dev/null +++ b/examples/animation/sub-attaq/animationmanager.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "animationmanager.h" + +//Qt +#include <QtCore/QAbstractAnimation> +#include <QtCore/QDebug> + +// the universe's only animation manager +AnimationManager *AnimationManager::instance = 0; + +AnimationManager::AnimationManager() +{ +} + +AnimationManager *AnimationManager::self() +{ + if (!instance) + instance = new AnimationManager; + return instance; +} + +void AnimationManager::registerAnimation(QAbstractAnimation *anim) +{ + animations.append(anim); +} + +void AnimationManager::unregisterAnimation(QAbstractAnimation *anim) +{ + animations.removeAll(anim); +} + +void AnimationManager::unregisterAllAnimations() +{ + animations.clear(); +} + +void AnimationManager::pauseAll() +{ + foreach (QAbstractAnimation* animation, animations) + { + if (animation->state() == QAbstractAnimation::Running) + animation->pause(); + } +} +void AnimationManager::resumeAll() +{ + foreach (QAbstractAnimation* animation, animations) + { + if (animation->state() == QAbstractAnimation::Paused) + animation->resume(); + } +} diff --git a/examples/animation/sub-attaq/animationmanager.h b/examples/animation/sub-attaq/animationmanager.h new file mode 100644 index 0000000..a563c96 --- /dev/null +++ b/examples/animation/sub-attaq/animationmanager.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ANIMATIONMANAGER_H +#define ANIMATIONMANAGER_H + +#include <QtCore/QObject> + +QT_BEGIN_NAMESPACE +class QAbstractAnimation; +QT_END_NAMESPACE + +class AnimationManager : public QObject +{ +Q_OBJECT +public: + AnimationManager(); + void registerAnimation(QAbstractAnimation *anim); + void unregisterAnimation(QAbstractAnimation *anim); + void unregisterAllAnimations(); + static AnimationManager *self(); + +public slots: + void pauseAll(); + void resumeAll(); + +private: + static AnimationManager *instance; + QList<QAbstractAnimation *> animations; +}; + +#endif // ANIMATIONMANAGER_H diff --git a/examples/animation/sub-attaq/boat.cpp b/examples/animation/sub-attaq/boat.cpp new file mode 100644 index 0000000..63d12bb --- /dev/null +++ b/examples/animation/sub-attaq/boat.cpp @@ -0,0 +1,318 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "boat.h" +#include "boat_p.h" +#include "bomb.h" +#include "pixmapitem.h" +#include "graphicsscene.h" +#include "animationmanager.h" +#include "custompropertyanimation.h" +#include "qanimationstate.h" + +//Qt +#include <QtCore/QPropertyAnimation> +#include <QtCore/QStateMachine> +#include <QtCore/QHistoryState> +#include <QtCore/QFinalState> +#include <QtCore/QState> +#include <QtCore/QSequentialAnimationGroup> + +static QAbstractAnimation *setupDestroyAnimation(Boat *boat) +{ + QSequentialAnimationGroup *group = new QSequentialAnimationGroup(boat); +#if QT_VERSION >=0x040500 + PixmapItem *step1 = new PixmapItem(QString("explosion/boat/step1"),GraphicsScene::Big, boat); + step1->setZValue(6); + PixmapItem *step2 = new PixmapItem(QString("explosion/boat/step2"),GraphicsScene::Big, boat); + step2->setZValue(6); + PixmapItem *step3 = new PixmapItem(QString("explosion/boat/step3"),GraphicsScene::Big, boat); + step3->setZValue(6); + PixmapItem *step4 = new PixmapItem(QString("explosion/boat/step4"),GraphicsScene::Big, boat); + step4->setZValue(6); + step1->setOpacity(0); + step2->setOpacity(0); + step3->setOpacity(0); + step4->setOpacity(0); + CustomPropertyAnimation *anim1 = new CustomPropertyAnimation(boat); + anim1->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim1->setDuration(100); + anim1->setEndValue(1); + CustomPropertyAnimation *anim2 = new CustomPropertyAnimation(boat); + anim2->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim2->setDuration(100); + anim2->setEndValue(1); + CustomPropertyAnimation *anim3 = new CustomPropertyAnimation(boat); + anim3->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim3->setDuration(100); + anim3->setEndValue(1); + CustomPropertyAnimation *anim4 = new CustomPropertyAnimation(boat); + anim4->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim4->setDuration(100); + anim4->setEndValue(1); + CustomPropertyAnimation *anim5 = new CustomPropertyAnimation(boat); + anim5->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim5->setDuration(100); + anim5->setEndValue(0); + CustomPropertyAnimation *anim6 = new CustomPropertyAnimation(boat); + anim6->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim6->setDuration(100); + anim6->setEndValue(0); + CustomPropertyAnimation *anim7 = new CustomPropertyAnimation(boat); + anim7->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim7->setDuration(100); + anim7->setEndValue(0); + CustomPropertyAnimation *anim8 = new CustomPropertyAnimation(boat); + anim8->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim8->setDuration(100); + anim8->setEndValue(0); + group->addAnimation(anim1); + group->addAnimation(anim2); + group->addAnimation(anim3); + group->addAnimation(anim4); + group->addAnimation(anim5); + group->addAnimation(anim6); + group->addAnimation(anim7); + group->addAnimation(anim8); +#else + // work around for a bug where we don't transition if the duration is zero. + QtPauseAnimation *anim = new QtPauseAnimation(group); + anim->setDuration(1); + group->addAnimation(anim); +#endif + AnimationManager::self()->registerAnimation(group); + return group; +} + + + +Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags) + : QGraphicsWidget(parent,wFlags), speed(0), bombsAlreadyLaunched(0), direction(Boat::None), movementAnimation(0) +{ + pixmapItem = new PixmapItem(QString("boat"),GraphicsScene::Big, this); + setZValue(4); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsFocusable); + resize(pixmapItem->boundingRect().size()); + + //The movement animation used to animate the boat + movementAnimation = new QPropertyAnimation(this, "pos"); + + //The movement animation used to animate the boat + destroyAnimation = setupDestroyAnimation(this); + + //We setup the state machien of the boat + machine = new QStateMachine(this); + QState *moving = new QState(machine->rootState()); + StopState *stopState = new StopState(this, moving); + machine->setInitialState(moving); + moving->setInitialState(stopState); + MoveStateRight *moveStateRight = new MoveStateRight(this, moving); + MoveStateLeft *moveStateLeft = new MoveStateLeft(this, moving); + LaunchStateRight *launchStateRight = new LaunchStateRight(this, machine->rootState()); + LaunchStateLeft *launchStateLeft = new LaunchStateLeft(this, machine->rootState()); + + //then setup the transitions for the rightMove state + KeyStopTransition *leftStopRight = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Left); + leftStopRight->setTargetState(stopState); + KeyMoveTransition *leftMoveRight = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Left); + leftMoveRight->setTargetState(moveStateRight); + KeyMoveTransition *rightMoveRight = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right); + rightMoveRight->setTargetState(moveStateRight); + KeyMoveTransition *rightMoveStop = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right); + rightMoveStop->setTargetState(moveStateRight); + + //then setup the transitions for the leftMove state + KeyStopTransition *rightStopLeft = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Right); + rightStopLeft->setTargetState(stopState); + KeyMoveTransition *rightMoveLeft = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right); + rightMoveLeft->setTargetState(moveStateLeft); + KeyMoveTransition *leftMoveLeft = new KeyMoveTransition(this, QEvent::KeyPress,Qt::Key_Left); + leftMoveLeft->setTargetState(moveStateLeft); + KeyMoveTransition *leftMoveStop = new KeyMoveTransition(this, QEvent::KeyPress,Qt::Key_Left); + leftMoveStop->setTargetState(moveStateLeft); + + //We set up the right move state + moveStateRight->addTransition(leftStopRight); + moveStateRight->addTransition(leftMoveRight); + moveStateRight->addTransition(rightMoveRight); + stopState->addTransition(rightMoveStop); + + //We set up the left move state + moveStateLeft->addTransition(rightStopLeft); + moveStateLeft->addTransition(leftMoveLeft); + moveStateLeft->addTransition(rightMoveLeft); + stopState->addTransition(leftMoveStop); + + //The animation is finished, it means we reached the border of the screen, the boat is stopped so we move to the stop state + moveStateLeft->addTransition(movementAnimation, SIGNAL(finished()), stopState); + moveStateRight->addTransition(movementAnimation, SIGNAL(finished()), stopState); + + //We set up the keys for dropping bombs + KeyLaunchTransition *upFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up); + upFireLeft->setTargetState(launchStateRight); + KeyLaunchTransition *upFireRight = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up); + upFireRight->setTargetState(launchStateRight); + KeyLaunchTransition *upFireStop = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up); + upFireStop->setTargetState(launchStateRight); + KeyLaunchTransition *downFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down); + downFireLeft->setTargetState(launchStateLeft); + KeyLaunchTransition *downFireRight = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down); + downFireRight->setTargetState(launchStateLeft); + KeyLaunchTransition *downFireMove = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down); + downFireMove->setTargetState(launchStateLeft); + + //We set up transitions for fire up + moveStateRight->addTransition(upFireRight); + moveStateLeft->addTransition(upFireLeft); + stopState->addTransition(upFireStop); + + //We set up transitions for fire down + moveStateRight->addTransition(downFireRight); + moveStateLeft->addTransition(downFireLeft); + stopState->addTransition(downFireMove); + + //Finally the launch state should come back to its original state + QHistoryState *historyState = new QHistoryState(moving); + launchStateLeft->addTransition(historyState); + launchStateRight->addTransition(historyState); + + QFinalState *final = new QFinalState(machine->rootState()); + + //This state play the destroyed animation + QAnimationState *destroyedState = new QAnimationState(machine->rootState()); + destroyedState->setAnimation(destroyAnimation); + + //Play a nice animation when the boat is destroyed + moving->addTransition(this, SIGNAL(boatDestroyed()),destroyedState); + + //Transition to final state when the destroyed animation is finished + destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final); + + //The machine has finished to be executed, then the boat is dead + connect(machine,SIGNAL(finished()),this, SIGNAL(boatExecutionFinished())); + +} + +void Boat::run() +{ + //We register animations + AnimationManager::self()->registerAnimation(movementAnimation); + AnimationManager::self()->registerAnimation(destroyAnimation); + machine->start(); +} + +void Boat::stop() +{ + movementAnimation->stop(); + machine->stop(); +} + +void Boat::updateBoatMovement() +{ + if (speed == 0 || direction == Boat::None) { + movementAnimation->stop(); + return; + } + + movementAnimation->stop(); + movementAnimation->setStartValue(pos()); + + if (direction == Boat::Left) { + movementAnimation->setEndValue(QPointF(0,y())); + movementAnimation->setDuration(x()/speed*15); + } + else /*if (direction == Boat::Right)*/ { + movementAnimation->setEndValue(QPointF(scene()->width()-size().width(),y())); + movementAnimation->setDuration((scene()->width()-size().width()-x())/speed*15); + } + movementAnimation->start(); +} + +void Boat::destroy() +{ + movementAnimation->stop(); + emit boatDestroyed(); +} + +int Boat::bombsLaunched() const +{ + return bombsAlreadyLaunched; +} + +void Boat::setBombsLaunched(int number) +{ + if (number > MAX_BOMB) { + qWarning("Boat::setBombsLaunched : It impossible to launch that number of bombs"); + return; + } + bombsAlreadyLaunched = number; +} + +int Boat::currentSpeed() const +{ + return speed; +} + +void Boat::setCurrentSpeed(int speed) +{ + if (speed > 3 || speed < 0) { + qWarning("Boat::setCurrentSpeed: The boat can't run on that speed"); + return; + } + this->speed = speed; +} + +enum Boat::Movement Boat::currentDirection() const +{ + return direction; +} + +void Boat::setCurrentDirection(Movement direction) +{ + this->direction = direction; +} + +int Boat::type() const +{ + return Type; +} diff --git a/examples/animation/sub-attaq/boat.h b/examples/animation/sub-attaq/boat.h new file mode 100644 index 0000000..b412739 --- /dev/null +++ b/examples/animation/sub-attaq/boat.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __BOAT__H__ +#define __BOAT__H__ + +//Qt +#include <QtCore/QObject> +#include <QtGui/QKeyEvent> + +#include <QtGui/QGraphicsWidget> + +class PixmapItem; +class Bomb; +QT_BEGIN_NAMESPACE +class QVariantAnimation; +class QAbstractAnimation; +class QStateMachine; +QT_END_NAMESPACE + +class Boat : public QGraphicsWidget +{ +Q_OBJECT +public: + enum Movement { + None = 0, + Left, + Right + }; + enum { Type = UserType + 2 }; + Boat(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); + void destroy(); + void run(); + void stop(); + + int bombsLaunched() const; + void setBombsLaunched(int number); + + int currentSpeed() const; + void setCurrentSpeed(int speed); + + enum Movement currentDirection() const; + void setCurrentDirection(Movement direction); + + void updateBoatMovement(); + + virtual int type() const; + +signals: + void boatDestroyed(); + void boatExecutionFinished(); + +private: + int speed; + int bombsAlreadyLaunched; + Movement direction; + QVariantAnimation *movementAnimation; + QAbstractAnimation *destroyAnimation; + QStateMachine *machine; + PixmapItem *pixmapItem; +}; + +#endif //__BOAT__H__ diff --git a/examples/animation/sub-attaq/boat_p.h b/examples/animation/sub-attaq/boat_p.h new file mode 100644 index 0000000..a8a24a6 --- /dev/null +++ b/examples/animation/sub-attaq/boat_p.h @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BOAT_P_H +#define BOAT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +//Own +#include "bomb.h" +#include "graphicsscene.h" + +// Qt +#include <QtGui/QKeyEventTransition> + +static const int MAX_BOMB = 5; + + +//These transtion test if we have to stop the boat (i.e current speed is 1) +class KeyStopTransition : public QKeyEventTransition +{ +public: + KeyStopTransition(Boat *boat, QEvent::Type type, int key) + : QKeyEventTransition(boat, type, key) + { + this->boat = boat; + this->key = key; + } +protected: + virtual bool eventTest(QEvent *event) + { + Q_UNUSED(event); + if (!QKeyEventTransition::eventTest(event)) + return false; + if (boat->currentSpeed() == 1) + return true; + else + return false; + } +private: + Boat * boat; + int key; +}; + +//These transtion test if we have to move the boat (i.e current speed was 0 or another value) + class KeyMoveTransition : public QKeyEventTransition +{ +public: + KeyMoveTransition(Boat *boat, QEvent::Type type, int key) + : QKeyEventTransition(boat, type, key) + { + this->boat = boat; + this->key = key; + } +protected: + virtual bool eventTest(QEvent *event) + { + Q_UNUSED(event); + if (!QKeyEventTransition::eventTest(event)) + return false; + if (boat->currentSpeed() >= 0) + return true; + else + return false; + + } + void onTransition(QEvent *) + { + //We decrease the speed if needed + if (key == Qt::Key_Left && boat->currentDirection() == Boat::Right) + boat->setCurrentSpeed(boat->currentSpeed() - 1); + else if (key == Qt::Key_Right && boat->currentDirection() == Boat::Left) + boat->setCurrentSpeed(boat->currentSpeed() - 1); + else if (boat->currentSpeed() < 3) + boat->setCurrentSpeed(boat->currentSpeed() + 1); + boat->updateBoatMovement(); + } +private: + Boat * boat; + int key; +}; + +//This transition trigger the bombs launch + class KeyLaunchTransition : public QKeyEventTransition +{ +public: + KeyLaunchTransition(Boat *boat, QEvent::Type type, int key) + : QKeyEventTransition(boat, type, key) + { + this->boat = boat; + this->key = key; + } +protected: + virtual bool eventTest(QEvent *event) + { + Q_UNUSED(event); + if (!QKeyEventTransition::eventTest(event)) + return false; + //We have enough bomb? + if (boat->bombsLaunched() < MAX_BOMB) + return true; + else + return false; + } +private: + Boat * boat; + int key; +}; + +//This state is describing when the boat is moving right +class MoveStateRight : public QState +{ +public: + MoveStateRight(Boat *boat,QState *parent = 0) : QState(parent) + { + this->boat = boat; + } +protected: + void onEntry(QEvent *) + { + boat->setCurrentDirection(Boat::Right); + boat->updateBoatMovement(); + } +private: + Boat * boat; +}; + + //This state is describing when the boat is moving left +class MoveStateLeft : public QState +{ +public: + MoveStateLeft(Boat *boat,QState *parent = 0) : QState(parent) + { + this->boat = boat; + } +protected: + void onEntry(QEvent *) + { + boat->setCurrentDirection(Boat::Left); + boat->updateBoatMovement(); + } +private: + Boat * boat; +}; + +//This state is describing when the boat is in a stand by position +class StopState : public QState +{ +public: + StopState(Boat *boat,QState *parent = 0) : QState(parent) + { + this->boat = boat; + } +protected: + void onEntry(QEvent *) + { + boat->setCurrentSpeed(0); + boat->setCurrentDirection(Boat::None); + boat->updateBoatMovement(); + } +private: + Boat * boat; +}; + +//This state is describing the launch of the torpedo on the right +class LaunchStateRight : public QState +{ +public: + LaunchStateRight(Boat *boat,QState *parent = 0) : QState(parent) + { + this->boat = boat; + } +protected: + void onEntry(QEvent *) + { + Bomb *b = new Bomb(); + b->setPos(boat->x()+boat->size().width(),boat->y()); + GraphicsScene *scene = static_cast<GraphicsScene *>(boat->scene()); + scene->addItem(b); + b->launch(Bomb::Right); + boat->setBombsLaunched(boat->bombsLaunched() + 1); + } +private: + Boat * boat; +}; + +//This state is describing the launch of the torpedo on the left +class LaunchStateLeft : public QState +{ +public: + LaunchStateLeft(Boat *boat,QState *parent = 0) : QState(parent) + { + this->boat = boat; + } +protected: + void onEntry(QEvent *) + { + Bomb *b = new Bomb(); + b->setPos(boat->x() - b->size().width(), boat->y()); + GraphicsScene *scene = static_cast<GraphicsScene *>(boat->scene()); + scene->addItem(b); + b->launch(Bomb::Left); + boat->setBombsLaunched(boat->bombsLaunched() + 1); + } +private: + Boat * boat; +}; + +#endif // BOAT_P_H diff --git a/examples/animation/sub-attaq/bomb.cpp b/examples/animation/sub-attaq/bomb.cpp new file mode 100644 index 0000000..f1f5324 --- /dev/null +++ b/examples/animation/sub-attaq/bomb.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "bomb.h" +#include "submarine.h" +#include "pixmapitem.h" +#include "animationmanager.h" +#include "qanimationstate.h" + +//Qt +#include <QtCore/QSequentialAnimationGroup> +#include <QtCore/QPropertyAnimation> +#include <QtCore/QStateMachine> +#include <QtCore/QFinalState> + +Bomb::Bomb(QGraphicsItem * parent, Qt::WindowFlags wFlags) + : QGraphicsWidget(parent,wFlags), launchAnimation(0) +{ + pixmapItem = new PixmapItem(QString("bomb"),GraphicsScene::Big, this); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFlags(QGraphicsItem::ItemIsMovable); + setZValue(2); + resize(pixmapItem->boundingRect().size()); +} + +void Bomb::launch(Bomb::Direction direction) +{ + launchAnimation = new QSequentialAnimationGroup(); + AnimationManager::self()->registerAnimation(launchAnimation); + qreal delta = direction == Right ? 20 : - 20; + QPropertyAnimation *anim = new QPropertyAnimation(this, "pos"); + anim->setEndValue(QPointF(x() + delta,y() - 20)); + anim->setDuration(150); + launchAnimation->addAnimation(anim); + anim = new QPropertyAnimation(this, "pos"); + anim->setEndValue(QPointF(x() + delta*2, y() )); + anim->setDuration(150); + launchAnimation->addAnimation(anim); + anim = new QPropertyAnimation(this, "pos"); + anim->setEndValue(QPointF(x() + delta*2,scene()->height())); + anim->setDuration(y()/2*60); + launchAnimation->addAnimation(anim); + connect(anim,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationLaunchValueChanged(const QVariant &))); + + //We setup the state machine of the bomb + QStateMachine *machine = new QStateMachine(this); + + //This state is when the launch animation is playing + QAnimationState *launched = new QAnimationState(machine->rootState()); + launched->setAnimation(launchAnimation); + + //End + QFinalState *final = new QFinalState(machine->rootState()); + + machine->setInitialState(launched); + + //### Add a nice animation when the bomb is destroyed + launched->addTransition(this, SIGNAL(bombExplosed()),final); + + //If the animation is finished, then we move to the final state + launched->addTransition(launched, SIGNAL(animationFinished()), final); + + //The machine has finished to be executed, then the boat is dead + connect(machine,SIGNAL(finished()),this, SIGNAL(bombExecutionFinished())); + + machine->start(); + +} + +void Bomb::onAnimationLaunchValueChanged(const QVariant &) +{ + foreach (QGraphicsItem * item , collidingItems(Qt::IntersectsItemBoundingRect)) { + if (item->type() == SubMarine::Type) { + SubMarine *s = static_cast<SubMarine *>(item); + destroy(); + s->destroy(); + } + } +} + +void Bomb::destroy() +{ + launchAnimation->stop(); + emit bombExplosed(); +} diff --git a/examples/animation/sub-attaq/bomb.h b/examples/animation/sub-attaq/bomb.h new file mode 100644 index 0000000..cfd42e5 --- /dev/null +++ b/examples/animation/sub-attaq/bomb.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __BOMB__H__ +#define __BOMB__H__ + +//Qt +#include <QtGui/QGraphicsWidget> +#include <QtCore/QAnimationGroup> + +class PixmapItem; + +class Bomb : public QGraphicsWidget +{ +Q_OBJECT +public: + enum Direction { + Left = 0, + Right + }; + Bomb(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0); + void launch(Direction direction); + void destroy(); + +signals: + void bombExplosed(); + void bombExecutionFinished(); + +private slots: + void onAnimationLaunchValueChanged(const QVariant &); + +private: + QAnimationGroup *launchAnimation; + PixmapItem *pixmapItem; +}; + +#endif //__BOMB__H__ diff --git a/examples/animation/sub-attaq/custompropertyanimation.cpp b/examples/animation/sub-attaq/custompropertyanimation.cpp new file mode 100644 index 0000000..8226cca --- /dev/null +++ b/examples/animation/sub-attaq/custompropertyanimation.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "custompropertyanimation.h" + +// Qt +#include <QtCore/qdebug.h> + +CustomPropertyAnimation::CustomPropertyAnimation(QObject *parent) : + QVariantAnimation(parent), animProp(0) +{ +} + +CustomPropertyAnimation::~CustomPropertyAnimation() +{ +} + +void CustomPropertyAnimation::setProperty(AbstractProperty *_animProp) +{ + if (animProp == _animProp) + return; + delete animProp; + animProp = _animProp; +} + +/*! + \reimp + */ +void CustomPropertyAnimation::updateCurrentValue(const QVariant &value) +{ + if (!animProp || state() == QAbstractAnimation::Stopped) + return; + + animProp->write(value); +} + + +/*! + \reimp +*/ +void CustomPropertyAnimation::updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState) +{ + // Initialize start value + if (oldState == QAbstractAnimation::Stopped) { + if (!animProp) + return; + QVariant def = animProp->read(); + if (def.isValid()) { + const int t = def.userType(); + KeyValues values = keyValues(); + //this ensures that all the keyValues are of type t + for (int i = 0; i < values.count(); ++i) { + QVariantAnimation::KeyValue &pair = values[i]; + if (pair.second.userType() != t) + pair.second.convert(static_cast<QVariant::Type>(t)); + } + //let's now update the key values + setKeyValues(values); + } + + if (animProp && !startValue().isValid() && currentTime() == 0 + || (currentTime() == duration() && currentLoop() == (loopCount() - 1))) { + setStartValue(def); + } + } + + QVariantAnimation::updateState(oldState, newState); +} + +#include "moc_custompropertyanimation.cpp" diff --git a/examples/animation/sub-attaq/custompropertyanimation.h b/examples/animation/sub-attaq/custompropertyanimation.h new file mode 100644 index 0000000..8654aeb --- /dev/null +++ b/examples/animation/sub-attaq/custompropertyanimation.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CUSTOMPROPERTYANIMATION_H +#define CUSTOMPROPERTYANIMATION_H + +#include <QtCore/qvariantanimation.h> + +QT_BEGIN_NAMESPACE +class QGraphicsItem; +QT_END_NAMESPACE + +struct AbstractProperty +{ + virtual QVariant read() const = 0; + virtual void write(const QVariant &value) = 0; +}; + + +class CustomPropertyAnimation : public QVariantAnimation +{ + Q_OBJECT + + template <typename Target, typename T, typename T2 = T> + class MemberFunctionProperty : public AbstractProperty + { + public: + typedef T (Target::*Getter)(void) const; + typedef void (Target::*Setter)(T2); + + MemberFunctionProperty(Target* target, Getter getter, Setter setter) + : m_target(target), m_getter(getter), m_setter(setter) {} + + virtual void write(const QVariant &value) + { + if (m_setter) (m_target->*m_setter)(qVariantValue<T>(value)); + } + + virtual QVariant read() const + { + if (m_getter) return qVariantFromValue<T>((m_target->*m_getter)()); + return QVariant(); + } + + private: + Target *m_target; + Getter m_getter; + Setter m_setter; + }; + +public: + CustomPropertyAnimation(QObject *parent = 0); + ~CustomPropertyAnimation(); + + template<class Target, typename T> + void setMemberFunctions(Target* target, T (Target::*getter)() const, void (Target::*setter)(const T& )) + { + setProperty(new MemberFunctionProperty<Target, T, const T&>(target, getter, setter)); + } + + template<class Target, typename T> + void setMemberFunctions(Target* target, T (Target::*getter)() const, void (Target::*setter)(T)) + { + setProperty(new MemberFunctionProperty<Target, T>(target, getter, setter)); + } + + void updateCurrentValue(const QVariant &value); + void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState); + void setProperty(AbstractProperty *animProp); + +private: + Q_DISABLE_COPY(CustomPropertyAnimation); + AbstractProperty *animProp; +}; + +#endif // CUSTOMPROPERTYANIMATION_H diff --git a/examples/animation/sub-attaq/data.xml b/examples/animation/sub-attaq/data.xml new file mode 100644 index 0000000..41d4754 --- /dev/null +++ b/examples/animation/sub-attaq/data.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<subattaq> + <submarines> + <submarine type="0" points="10" name="Q1" /> + <submarine type="1" points="20" name="Q2" /> + </submarines> + <levels> + <level id="0" name="Seaman recruit"> + <subinstance type="0" nb="2"/> + </level> + <level id="1" name="Seaman apprentice"> + <subinstance type="0" nb="4"/> + </level> + </levels> +</subattaq> diff --git a/examples/animation/sub-attaq/graphicsscene.cpp b/examples/animation/sub-attaq/graphicsscene.cpp new file mode 100644 index 0000000..e773dae --- /dev/null +++ b/examples/animation/sub-attaq/graphicsscene.cpp @@ -0,0 +1,374 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "graphicsscene.h" +#include "states.h" +#include "boat.h" +#include "submarine.h" +#include "torpedo.h" +#include "bomb.h" +#include "pixmapitem.h" +#include "custompropertyanimation.h" +#include "animationmanager.h" +#include "qanimationstate.h" +#include "progressitem.h" + +//Qt +#include <QtCore/QPropertyAnimation> +#include <QtCore/QSequentialAnimationGroup> +#include <QtCore/QParallelAnimationGroup> +#include <QtCore/QStateMachine> +#include <QtCore/QFinalState> +#include <QtCore/QPauseAnimation> +#include <QtGui/QAction> +#include <QtCore/QDir> +#include <QtGui/QApplication> +#include <QtGui/QMessageBox> +#include <QtGui/QGraphicsView> +#include <QtGui/QGraphicsSceneMouseEvent> +#include <QtCore/QXmlStreamReader> + +//helper function that creates an animation for position and inserts it into group +static CustomPropertyAnimation *addGraphicsItemPosAnimation(QSequentialAnimationGroup *group, + QGraphicsItem *item, const QPointF &endPos) +{ + CustomPropertyAnimation *ret = new CustomPropertyAnimation(group); + ret->setMemberFunctions(item, &QGraphicsItem::pos, &QGraphicsItem::setPos); + ret->setEndValue(endPos); + ret->setDuration(200); + ret->setEasingCurve(QEasingCurve::OutElastic); + group->addPause(50); + return ret; +} + +//helper function that creates an animation for opacity and inserts it into group +static void addGraphicsItemFadeoutAnimation(QAnimationGroup *group, QGraphicsItem *item) +{ +#if QT_VERSION >=0x040500 + CustomPropertyAnimation *anim = new CustomPropertyAnimation(group); + anim->setMemberFunctions(item, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim->setDuration(800); + anim->setEndValue(0); + anim->setEasingCurve(QEasingCurve::OutQuad); +#else + // work around for a bug where we don't transition if the duration is zero. + QtPauseAnimation *anim = new QtPauseAnimation(group); + anim->setDuration(1); +#endif +} + +GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode) + : QGraphicsScene(x,y,width,height), mode(mode), newAction(0), quitAction(0), boat(0) +{ + backgroundItem = new PixmapItem(QString("background"),mode); + backgroundItem->setZValue(1); + backgroundItem->setPos(0,0); + addItem(backgroundItem); + + PixmapItem *surfaceItem = new PixmapItem(QString("surface"),mode); + surfaceItem->setZValue(3); + surfaceItem->setPos(0,sealLevel() - surfaceItem->boundingRect().height()/2); + addItem(surfaceItem); + + //The item that display score and level + progressItem = new ProgressItem(backgroundItem); + + //We create the boat + boat = new Boat(); + addItem(boat); + boat->setPos(this->width()/2, sealLevel() - boat->size().height()); + boat->hide(); + + //parse the xml that contain all data of the game + QXmlStreamReader reader; + QFile file(":data.xml"); + file.open(QIODevice::ReadOnly); + reader.setDevice(&file); + LevelDescription currentLevel; + while (!reader.atEnd()) { + reader.readNext(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { + if (reader.name() == "submarine") + { + SubmarineDescription desc; + desc.name = reader.attributes().value("name").toString(); + desc.points = reader.attributes().value("points").toString().toInt(); + desc.type = reader.attributes().value("type").toString().toInt(); + submarinesData.append(desc); + } + if (reader.name() == "level") + { + currentLevel.id = reader.attributes().value("id").toString().toInt(); + currentLevel.name = reader.attributes().value("name").toString(); + } + if (reader.name() == "subinstance") + { + currentLevel.submarines.append(qMakePair(reader.attributes().value("type").toString().toInt(),reader.attributes().value("nb").toString().toInt())); + } + } + if (reader.tokenType() == QXmlStreamReader::EndElement) { + if (reader.name() == "level") + { + levelsData.insert(currentLevel.id,currentLevel); + currentLevel.submarines.clear(); + } + } + } +} + +qreal GraphicsScene::sealLevel() const +{ + if (mode == Big) + return 220; + else + return 160; +} + +void GraphicsScene::setupScene(const QList<QAction *> &actions) +{ + newAction = actions.at(0); + quitAction = actions.at(1); + + QGraphicsItem *logo_s = addWelcomeItem(QPixmap(":/logo-s")); + QGraphicsItem *logo_u = addWelcomeItem(QPixmap(":/logo-u")); + QGraphicsItem *logo_b = addWelcomeItem(QPixmap(":/logo-b")); + QGraphicsItem *logo_dash = addWelcomeItem(QPixmap(":/logo-dash")); + QGraphicsItem *logo_a = addWelcomeItem(QPixmap(":/logo-a")); + QGraphicsItem *logo_t = addWelcomeItem(QPixmap(":/logo-t")); + QGraphicsItem *logo_t2 = addWelcomeItem(QPixmap(":/logo-t2")); + QGraphicsItem *logo_a2 = addWelcomeItem(QPixmap(":/logo-a2")); + QGraphicsItem *logo_q = addWelcomeItem(QPixmap(":/logo-q")); + QGraphicsItem *logo_excl = addWelcomeItem(QPixmap(":/logo-excl")); + logo_s->setZValue(3); + logo_u->setZValue(4); + logo_b->setZValue(5); + logo_dash->setZValue(6); + logo_a->setZValue(7); + logo_t->setZValue(8); + logo_t2->setZValue(9); + logo_a2->setZValue(10); + logo_q->setZValue(11); + logo_excl->setZValue(12); + logo_s->setPos(QPointF(-1000, -1000)); + logo_u->setPos(QPointF(-800, -1000)); + logo_b->setPos(QPointF(-600, -1000)); + logo_dash->setPos(QPointF(-400, -1000)); + logo_a->setPos(QPointF(1000, 2000)); + logo_t->setPos(QPointF(800, 2000)); + logo_t2->setPos(QPointF(600, 2000)); + logo_a2->setPos(QPointF(400, 2000)); + logo_q->setPos(QPointF(200, 2000)); + logo_excl->setPos(QPointF(0, 2000)); + + QSequentialAnimationGroup * lettersGroupMoving = new QSequentialAnimationGroup(this); + QParallelAnimationGroup * lettersGroupFading = new QParallelAnimationGroup(this); + + //creation of the animations for moving letters + addGraphicsItemPosAnimation(lettersGroupMoving, logo_s, QPointF(300, 150)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_u, QPointF(350, 150)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_b, QPointF(400, 120)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_dash, QPointF(460, 150)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_a, QPointF(350, 250)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_t, QPointF(400, 250)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_t2, QPointF(430, 250)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_a2, QPointF(465, 250)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_q, QPointF(510, 250)); + addGraphicsItemPosAnimation(lettersGroupMoving, logo_excl, QPointF(570, 220)); + + //creation of the animations for fading out the letters + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_s); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_u); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_b); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_dash); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_a); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_t); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_t2); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_a2); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_q); + addGraphicsItemFadeoutAnimation(lettersGroupFading, logo_excl); + connect(lettersGroupFading, SIGNAL(finished()), this, SLOT(onIntroAnimationFinished())); + + QStateMachine *machine = new QStateMachine(this); + + //This state is when the player is playing + PlayState *gameState = new PlayState(this,machine->rootState()); + + //Final state + QFinalState *final = new QFinalState(machine->rootState()); + + //Animation when the player enter in the game + QAnimationState *lettersMovingState = new QAnimationState(machine->rootState()); + lettersMovingState->setAnimation(lettersGroupMoving); + + //Animation when the welcome screen disappear + QAnimationState *lettersFadingState = new QAnimationState(machine->rootState()); + 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); + + //New Game is triggered then player start playing + 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); + + //Welcome screen is the initial state + machine->setInitialState(lettersMovingState); + + machine->start(); + + //We reach the final state, then we quit + connect(machine,SIGNAL(finished()),this, SLOT(onQuitGameTriggered())); +} + +void GraphicsScene::addItem(Bomb *bomb) +{ + bombs.insert(bomb); + connect(bomb,SIGNAL(bombExecutionFinished()),this, SLOT(onBombExecutionFinished())); + QGraphicsScene::addItem(bomb); +} + +void GraphicsScene::addItem(Torpedo *torpedo) +{ + torpedos.insert(torpedo); + connect(torpedo,SIGNAL(torpedoExecutionFinished()),this, SLOT(onTorpedoExecutionFinished())); + QGraphicsScene::addItem(torpedo); +} + +void GraphicsScene::addItem(SubMarine *submarine) +{ + submarines.insert(submarine); + connect(submarine,SIGNAL(subMarineExecutionFinished()),this, SLOT(onSubMarineExecutionFinished())); + QGraphicsScene::addItem(submarine); +} + +void GraphicsScene::addItem(QGraphicsItem *item) +{ + QGraphicsScene::addItem(item); +} + +void GraphicsScene::mousePressEvent (QGraphicsSceneMouseEvent * event) +{ + event->ignore(); +} + +void GraphicsScene::onQuitGameTriggered() +{ + qApp->closeAllWindows(); +} + +void GraphicsScene::onBombExecutionFinished() +{ + Bomb *bomb = qobject_cast<Bomb *>(sender()); + bombs.remove(bomb); + bomb->deleteLater(); + if (boat) + boat->setBombsLaunched(boat->bombsLaunched() - 1); +} + +void GraphicsScene::onTorpedoExecutionFinished() +{ + Torpedo *torpedo = qobject_cast<Torpedo *>(sender()); + torpedos.remove(torpedo); + torpedo->deleteLater(); +} + +void GraphicsScene::onSubMarineExecutionFinished() +{ + SubMarine *submarine = qobject_cast<SubMarine *>(sender()); + submarines.remove(submarine); + if (submarines.count() == 0) { + emit allSubMarineDestroyed(submarine->points()); + } else { + emit subMarineDestroyed(submarine->points()); + } + submarine->deleteLater(); +} + +int GraphicsScene::remainingSubMarines() const +{ + return submarines.count(); +} + +void GraphicsScene::clearScene() +{ + foreach (SubMarine *sub,submarines) { + sub->destroy(); + sub->deleteLater(); + } + + foreach (Torpedo *torpedo,torpedos) { + torpedo->destroy(); + torpedo->deleteLater(); + } + + foreach (Bomb *bomb,bombs) { + bomb->destroy(); + bomb->deleteLater(); + } + + submarines.clear(); + bombs.clear(); + torpedos.clear(); + + AnimationManager::self()->unregisterAllAnimations(); + + boat->stop(); + boat->hide(); +} + +QGraphicsPixmapItem *GraphicsScene::addWelcomeItem(const QPixmap &pm) +{ + QGraphicsPixmapItem *item = addPixmap(pm); + welcomeItems << item; + return item; +} + +void GraphicsScene::onIntroAnimationFinished() +{ + qDeleteAll(welcomeItems); + welcomeItems.clear(); +} + diff --git a/examples/animation/sub-attaq/graphicsscene.h b/examples/animation/sub-attaq/graphicsscene.h new file mode 100644 index 0000000..1e6618a --- /dev/null +++ b/examples/animation/sub-attaq/graphicsscene.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __GRAPHICSSCENE__H__ +#define __GRAPHICSSCENE__H__ + +//Qt +#include <QtGui/QGraphicsScene> +#include <QtCore/QSet> +#include <QtCore/QState> + + +class Boat; +class SubMarine; +class Torpedo; +class Bomb; +class PixmapItem; +class ProgressItem; +QT_BEGIN_NAMESPACE +class QAction; +QT_END_NAMESPACE + +class GraphicsScene : public QGraphicsScene +{ +Q_OBJECT +public: + enum Mode { + Big = 0, + Small + }; + + struct SubmarineDescription { + int type; + int points; + QString name; + }; + + struct LevelDescription { + int id; + QString name; + QList<QPair<int,int> > submarines; + }; + + GraphicsScene(int x, int y, int width, int height, Mode mode = Big); + qreal sealLevel() const; + void setupScene(const QList<QAction *> &actions); + void addItem(Bomb *bomb); + void addItem(Torpedo *torpedo); + void addItem(SubMarine *submarine); + void addItem(QGraphicsItem *item); + int remainingSubMarines() const; + void clearScene(); + QGraphicsPixmapItem *addWelcomeItem(const QPixmap &pm); + +signals: + void subMarineDestroyed(int); + void allSubMarineDestroyed(int); + +protected: + void mousePressEvent (QGraphicsSceneMouseEvent * event); + +private slots: + void onQuitGameTriggered(); + void onBombExecutionFinished(); + void onTorpedoExecutionFinished(); + void onSubMarineExecutionFinished(); + void onIntroAnimationFinished(); + +private: + Mode mode; + PixmapItem *backgroundItem; + ProgressItem *progressItem; + QAction * newAction; + QAction * quitAction; + Boat *boat; + QSet<SubMarine *> submarines; + QSet<Bomb *> bombs; + QSet<Torpedo *> torpedos; + QVector<QGraphicsPixmapItem *> welcomeItems; + QVector<SubmarineDescription> submarinesData; + QHash<int, LevelDescription> levelsData; + + friend class PauseState; + friend class PlayState; + friend class LevelState; + friend class LostState; + friend class WinState; + friend class WinTransition; + friend class UpdateScoreTransition; +}; + +#endif //__GRAPHICSSCENE__H__ + diff --git a/examples/animation/sub-attaq/main.cpp b/examples/animation/sub-attaq/main.cpp new file mode 100644 index 0000000..ffaa86f --- /dev/null +++ b/examples/animation/sub-attaq/main.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + Q_INIT_RESOURCE(subattaq); + + qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); + + MainWindow w; + w.show(); + + return app.exec(); +} diff --git a/examples/animation/sub-attaq/mainwindow.cpp b/examples/animation/sub-attaq/mainwindow.cpp new file mode 100644 index 0000000..123363b --- /dev/null +++ b/examples/animation/sub-attaq/mainwindow.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "mainwindow.h" +#include "graphicsscene.h" + +//Qt +#include <QGraphicsView> + +#ifdef QT_NO_OPENGL + #include <QtGui/QMenuBar> + #include <QtGui/QLayout> + #include <QtGui/QApplication> +#else + #include <QtOpenGL/QtOpenGL> +#endif + +MainWindow::MainWindow() : QMainWindow(0) +{ + QMenuBar *menuBar = new QMenuBar; + QMenu *file = new QMenu(tr("&File"),menuBar); + + QAction *newAction = new QAction(tr("New Game"),file); + newAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); + file->addAction(newAction); + QAction *quitAction = new QAction(tr("Quit"),file); + quitAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q)); + file->addAction(quitAction); + + menuBar->addMenu(file); + setMenuBar(menuBar); + + QStringList list = QApplication::arguments(); + if (list.contains("-fullscreen")) { + scene = new GraphicsScene(0, 0, 750, 400,GraphicsScene::Small); + setWindowState(Qt::WindowFullScreen); + } else { + scene = new GraphicsScene(0, 0, 880, 630); + layout()->setSizeConstraint(QLayout::SetFixedSize); + } + + view = new QGraphicsView(scene,this); + view->setAlignment(Qt::AlignLeft | Qt::AlignTop); + QList<QAction *> actions; + actions << newAction << quitAction; + scene->setupScene(actions); +#ifndef QT_NO_OPENGL + view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); +#endif + + setCentralWidget(view); + +} + +MainWindow::~MainWindow() +{ +} + diff --git a/examples/animation/sub-attaq/mainwindow.h b/examples/animation/sub-attaq/mainwindow.h new file mode 100644 index 0000000..87f194a --- /dev/null +++ b/examples/animation/sub-attaq/mainwindow.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __MAINWINDOW__H__ +#define __MAINWINDOW__H__ + +//Qt +#include <QtGui/QMainWindow> +class GraphicsScene; +QT_BEGIN_NAMESPACE +class QGraphicsView; +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ +Q_OBJECT +public: + MainWindow(); + ~MainWindow(); + +private: + GraphicsScene *scene; + QGraphicsView *view; +}; + +#endif //__MAINWINDOW__H__ diff --git a/examples/animation/sub-attaq/pics/big/background.png b/examples/animation/sub-attaq/pics/big/background.png Binary files differnew file mode 100644 index 0000000..9f58157 --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/background.png diff --git a/examples/animation/sub-attaq/pics/big/boat.png b/examples/animation/sub-attaq/pics/big/boat.png Binary files differnew file mode 100644 index 0000000..be82dff --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/boat.png diff --git a/examples/animation/sub-attaq/pics/big/bomb.png b/examples/animation/sub-attaq/pics/big/bomb.png Binary files differnew file mode 100644 index 0000000..3af5f2f --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/bomb.png diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step1.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step1.png Binary files differnew file mode 100644 index 0000000..c9fd8b0 --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/explosion/boat/step1.png diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step2.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step2.png Binary files differnew file mode 100644 index 0000000..7528f2d --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/explosion/boat/step2.png diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step3.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step3.png Binary files differnew file mode 100644 index 0000000..aae9c9c --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/explosion/boat/step3.png diff --git a/examples/animation/sub-attaq/pics/big/explosion/boat/step4.png b/examples/animation/sub-attaq/pics/big/explosion/boat/step4.png Binary files differnew file mode 100644 index 0000000..d697c1b --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/explosion/boat/step4.png diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step1.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step1.png Binary files differnew file mode 100644 index 0000000..88ca514 --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/explosion/submarine/step1.png diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step2.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step2.png Binary files differnew file mode 100644 index 0000000..524f589 --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/explosion/submarine/step2.png diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step3.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step3.png Binary files differnew file mode 100644 index 0000000..2cca1e8 --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/explosion/submarine/step3.png diff --git a/examples/animation/sub-attaq/pics/big/explosion/submarine/step4.png b/examples/animation/sub-attaq/pics/big/explosion/submarine/step4.png Binary files differnew file mode 100644 index 0000000..82100a8 --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/explosion/submarine/step4.png diff --git a/examples/animation/sub-attaq/pics/big/submarine.png b/examples/animation/sub-attaq/pics/big/submarine.png Binary files differnew file mode 100644 index 0000000..df435dc --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/submarine.png diff --git a/examples/animation/sub-attaq/pics/big/surface.png b/examples/animation/sub-attaq/pics/big/surface.png Binary files differnew file mode 100644 index 0000000..4eba29e --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/surface.png diff --git a/examples/animation/sub-attaq/pics/big/torpedo.png b/examples/animation/sub-attaq/pics/big/torpedo.png Binary files differnew file mode 100644 index 0000000..f9c2687 --- /dev/null +++ b/examples/animation/sub-attaq/pics/big/torpedo.png diff --git a/examples/animation/sub-attaq/pics/scalable/background-n810.svg b/examples/animation/sub-attaq/pics/scalable/background-n810.svg new file mode 100644 index 0000000..ece9f7a --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/background-n810.svg @@ -0,0 +1,171 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.0" + width="744.09448" + height="1052.3622" + id="svg2588" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="background-n810.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape"> + <metadata + id="metadata28"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <sodipodi:namedview + inkscape:window-height="1141" + inkscape:window-width="1920" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + guidetolerance="10.0" + gridtolerance="10.0" + objecttolerance="10.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + showgrid="false" + inkscape:zoom="1.2399902" + inkscape:cx="375" + inkscape:cy="461.074" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:current-layer="layer1" /> + <defs + id="defs2590"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective30" /> + <linearGradient + id="linearGradient3746"> + <stop + id="stop3748" + style="stop-color:#ffffff;stop-opacity:1" + offset="0" /> + <stop + id="stop3750" + style="stop-color:#0074b7;stop-opacity:1" + offset="1" /> + </linearGradient> + <radialGradient + cx="82.966125" + cy="-178.42453" + r="526.79456" + fx="82.966125" + fy="-178.42453" + id="radialGradient3880" + xlink:href="#linearGradient3746" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.4952094,0.2388475,-0.1040669,0.3734391,-208.61982,418.216)" /> + <linearGradient + id="linearGradient3624"> + <stop + id="stop3626" + style="stop-color:#3a8daf;stop-opacity:1" + offset="0" /> + <stop + id="stop3636" + style="stop-color:#252525;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="552.98486" + y1="390.56842" + x2="549.39465" + y2="702.3479" + id="linearGradient3630" + xlink:href="#linearGradient3624" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(2.3373776,0,0,1.186038,-986.88716,67.776416)" /> + <linearGradient + id="linearGradient3816"> + <stop + id="stop3818" + style="stop-color:#ad8b00;stop-opacity:1" + offset="0" /> + <stop + id="stop3820" + style="stop-color:#ad8b00;stop-opacity:0" + offset="1" /> + </linearGradient> + <linearGradient + x1="573" + y1="755.46222" + x2="573" + y2="700.13464" + id="linearGradient3826" + xlink:href="#linearGradient3816" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1,0,0,1.2561681,-151.5,-34.518664)" /> + <linearGradient + id="linearGradient5097"> + <stop + id="stop5099" + style="stop-color:#19a2db;stop-opacity:0" + offset="0" /> + <stop + id="stop5109" + style="stop-color:#1379a7;stop-opacity:0.49803922" + offset="0.30000001" /> + <stop + id="stop5101" + style="stop-color:#0e5173;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="590.84674" + y1="274.57559" + x2="590.84674" + y2="334.01376" + id="linearGradient5103" + xlink:href="#linearGradient5097" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-151.5,156.75229)" + spreadMethod="pad" /> + </defs> + <g + id="layer1"> + <rect + width="1053.5891" + height="206.64989" + x="-151.79456" + y="330.16019" + id="rect3638" + style="opacity:1;fill:url(#radialGradient3880);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.1880002;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + width="1054.4708" + height="364.81519" + x="-152.23541" + y="533.48895" + id="rect3622" + style="opacity:1;fill:url(#linearGradient3630);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.13464069;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M -152.5,877.11847 C 120.5,865.81296 -202.86309,769.3663 109.5,871.29717 C 172.96247,892.00636 243.5,872.55334 297.5,871.29717 C 351.5,870.041 311.5,859.80335 358.5,876.13354 C 405.5,892.46372 553.5,861.09903 598.5,854.8182 C 643.5,848.53736 756.5,841.79698 795.5,853.10249 C 834.5,864.408 904.5,866.2725 904.5,866.2725 L 901.5,903.95754 L -154.5,902.70137 L -152.5,877.11847 z" + id="path3814" + style="fill:url(#linearGradient3826);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + <path + d="M 902.20121,894.16261 C 632.01828,889.43035 756.73005,860.2801 614.20403,894.1311 C 596.58819,898.315 408.23621,883.21212 400.43291,894.1311 C 376.86263,927.11261 75.265447,868.1243 34.250926,886.79082 C 31.281885,888.14209 12.514878,884.22134 -12.264082,889.72008 C -48.555335,897.77353 -64.717178,885.62471 -103.31472,890.35697 C -141.91229,895.08922 -145.87102,891.93439 -145.87102,891.93439 L -152.79879,903.10131 L 892.3044,902.5755 L 902.20121,894.16261 z" + id="path3828" + style="fill:#ad8b00;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/scalable/background.svg b/examples/animation/sub-attaq/pics/scalable/background.svg new file mode 100644 index 0000000..0be2680 --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/background.svg @@ -0,0 +1,171 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.0" + width="744.09448" + height="1052.3622" + id="svg2588" + sodipodi:version="0.32" + inkscape:version="0.46" + sodipodi:docname="background.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape"> + <metadata + id="metadata28"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <sodipodi:namedview + inkscape:window-height="1141" + inkscape:window-width="1920" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + guidetolerance="10.0" + gridtolerance="10.0" + objecttolerance="10.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + showgrid="false" + inkscape:zoom="0.93884027" + inkscape:cx="473.72605" + inkscape:cy="538.63678" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:current-layer="layer1" /> + <defs + id="defs2590"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective30" /> + <linearGradient + id="linearGradient3746"> + <stop + id="stop3748" + style="stop-color:#ffffff;stop-opacity:1" + offset="0" /> + <stop + id="stop3750" + style="stop-color:#0074b7;stop-opacity:1" + offset="1" /> + </linearGradient> + <radialGradient + cx="82.966125" + cy="-178.42453" + r="526.79456" + fx="82.966125" + fy="-178.42453" + id="radialGradient3880" + xlink:href="#linearGradient3746" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.4952094,0.3367191,-0.1040669,0.5264617,-208.61982,282.52272)" /> + <linearGradient + id="linearGradient3624"> + <stop + id="stop3626" + style="stop-color:#3a8daf;stop-opacity:1" + offset="0" /> + <stop + id="stop3636" + style="stop-color:#252525;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="552.98486" + y1="390.56842" + x2="549.39465" + y2="702.3479" + id="linearGradient3630" + xlink:href="#linearGradient3624" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(2.3373776,0,0,1.5004634,-986.88716,-154.07447)" /> + <linearGradient + id="linearGradient3816"> + <stop + id="stop3818" + style="stop-color:#ad8b00;stop-opacity:1" + offset="0" /> + <stop + id="stop3820" + style="stop-color:#ad8b00;stop-opacity:0" + offset="1" /> + </linearGradient> + <linearGradient + x1="573" + y1="755.46222" + x2="573" + y2="700.13464" + id="linearGradient3826" + xlink:href="#linearGradient3816" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1,0,0,1.6033628,-151.5,-294.0167)" /> + <linearGradient + id="linearGradient5097"> + <stop + id="stop5099" + style="stop-color:#19a2db;stop-opacity:0" + offset="0" /> + <stop + id="stop5109" + style="stop-color:#1379a7;stop-opacity:0.49803922" + offset="0.30000001" /> + <stop + id="stop5101" + style="stop-color:#0e5173;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="590.84674" + y1="274.57559" + x2="590.84674" + y2="334.01376" + id="linearGradient5103" + xlink:href="#linearGradient5097" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-151.5,156.75229)" + spreadMethod="pad" /> + </defs> + <g + id="layer1"> + <rect + width="1053.5891" + height="291.32797" + x="-151.79456" + y="158.38464" + id="rect3638" + style="opacity:1;fill:url(#radialGradient3880);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.1880002;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + width="1054.4708" + height="461.52972" + x="-152.23541" + y="435.10107" + id="rect3622" + style="opacity:1;fill:url(#linearGradient3630);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.13464069;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M -152.5,869.5896 C 120.5,855.15934 -202.86309,732.0556 109.5,862.15934 C 172.96247,888.59238 243.5,863.7627 297.5,862.15934 C 351.5,860.55598 311.5,847.48872 358.5,868.33244 C 405.5,889.17615 553.5,849.14252 598.5,841.12571 C 643.5,833.1089 756.5,824.50553 795.5,838.9358 C 834.5,853.36606 904.5,855.74589 904.5,855.74589 L 901.5,903.84677 L -154.5,902.24341 L -152.5,869.5896 z" + id="path3814" + style="fill:url(#linearGradient3826);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + <path + d="M 902.20121,891.3446 C 632.01828,885.30439 756.73005,848.09724 614.20403,891.30439 C 596.58819,896.64468 408.23621,877.36748 400.43291,891.30439 C 376.86263,933.40172 75.265447,858.10952 34.250926,881.93531 C 31.281885,883.66006 12.514878,878.65564 -12.264082,885.67419 C -48.555335,895.95355 -64.717178,880.4469 -103.31472,886.48711 C -141.91229,892.52732 -145.87102,888.50052 -145.87102,888.50052 L -152.79879,902.75389 L 892.3044,902.08275 L 902.20121,891.3446 z" + id="path3828" + style="fill:#ad8b00;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/scalable/boat.svg b/examples/animation/sub-attaq/pics/scalable/boat.svg new file mode 100644 index 0000000..5298821b --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/boat.svg @@ -0,0 +1,279 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + version="1.0" + width="744.09448" + height="1052.3622" + id="svg2584"> + <defs + id="defs2666"> + <linearGradient + x1="542.5" + y1="222.59448" + x2="559" + y2="222.59448" + id="linearGradient3387" + xlink:href="#linearGradient3746" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-110.6791,190.19124)" /> + <linearGradient + id="linearGradient3167"> + <stop + id="stop3169" + style="stop-color:#464646;stop-opacity:1" + offset="0" /> + <stop + id="stop3345" + style="stop-color:#848788;stop-opacity:1" + offset="0.44021741" /> + <stop + id="stop3347" + style="stop-color:#9ca0a2;stop-opacity:1" + offset="0.56799388" /> + <stop + id="stop3171" + style="stop-color:#b5babd;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="474.23065" + y1="229.92336" + x2="474.1944" + y2="218.27365" + id="linearGradient3416" + xlink:href="#linearGradient3167" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-125.98032,185.95625)" /> + <linearGradient + id="linearGradient3692"> + <stop + id="stop3694" + style="stop-color:#ffffff;stop-opacity:1" + offset="0" /> + <stop + id="stop3696" + style="stop-color:#b6b6b6;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="573.5" + y1="244.2056" + x2="578.25" + y2="216.9556" + id="linearGradient3972" + xlink:href="#linearGradient3692" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-126.5541,188.56624)" /> + <linearGradient + id="linearGradient3438"> + <stop + id="stop3440" + style="stop-color:#939393;stop-opacity:1" + offset="0" /> + <stop + id="stop3444" + style="stop-color:#d6d6d6;stop-opacity:1" + offset="0.12354442" /> + <stop + id="stop3446" + style="stop-color:#dadada;stop-opacity:1" + offset="0.74055624" /> + <stop + id="stop3442" + style="stop-color:#ffffff;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="660.29303" + y1="256.53284" + x2="444.79303" + y2="255.62085" + id="linearGradient3948" + xlink:href="#linearGradient3438" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-126.5541,185.56624)" /> + <linearGradient + x1="542.5" + y1="222.59448" + x2="559" + y2="222.59448" + id="linearGradient3990" + xlink:href="#linearGradient3746" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-132.8041,190.19124)" /> + <linearGradient + id="linearGradient3746"> + <stop + id="stop3748" + style="stop-color:#ffffff;stop-opacity:1" + offset="0" /> + <stop + id="stop3750" + style="stop-color:#0074b7;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="542.5" + y1="222.59448" + x2="559" + y2="222.59448" + id="linearGradient3994" + xlink:href="#linearGradient3746" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-88.054101,190.19124)" /> + <linearGradient + id="linearGradient3428"> + <stop + id="stop3430" + style="stop-color:#464646;stop-opacity:1" + offset="0" /> + <stop + id="stop3432" + style="stop-color:#848788;stop-opacity:1" + offset="0.18306103" /> + <stop + id="stop3434" + style="stop-color:#9ca0a2;stop-opacity:1" + offset="0.66368055" /> + <stop + id="stop3436" + style="stop-color:#b5babd;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="592.92798" + y1="199.43727" + x2="557.05743" + y2="196.5448" + id="linearGradient3426" + xlink:href="#linearGradient3428" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-102.5217,149.09845)" /> + </defs> + <g + id="layer1"> + <g + id="boat"> + <path + d="M 296.669,434.15623 C 376.12538,436.50959 448.282,436.46711 542.42304,434.15623 C 542.42304,434.15623 544.22253,425.03531 542.42304,422.57953 C 432.90655,403.86953 296.669,418.12547 296.669,422.57953 L 296.669,434.15623 z" + id="path3469" + style="fill:#a9a9a9;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3.4975698;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" /> + <rect + width="3.4280596" + height="29.611124" + x="647.59613" + y="173.91156" + transform="matrix(0.9327494,0.3605254,-0.3633626,0.9316478,0,0)" + id="rect3408" + style="opacity:1;fill:#333333;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + width="48.499989" + height="8.5" + x="318.48221" + y="405.82172" + transform="matrix(0.9999952,3.0887777e-3,-3.0887777e-3,0.9999952,0,0)" + id="rect3376" + style="opacity:1;fill:url(#linearGradient3416);fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:2.99999928;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 382.4459,430.66072 C 382.4459,430.66072 420.85999,388.74829 397.4459,385.66072 L 488.4459,397.66072 L 488.4459,432.66072 L 382.4459,430.66072 z" + id="path3952" + style="fill:url(#linearGradient3972);fill-opacity:1;fill-rule:evenodd;stroke:#323232;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 301.4459,429.66072 C 301.4459,429.66072 330.46329,468.66072 343.4459,468.66072 C 355.42851,471.91072 507.57644,473.70653 525.4459,465.91072 C 534.58031,461.59104 537.90602,455.58662 539.4459,429.66072 C 473.70193,439.43306 371.2651,439.78219 301.4459,429.66072 z" + id="path3938" + style="fill:url(#linearGradient3948);fill-opacity:1;fill-rule:evenodd;stroke:#545454;stroke-width:3.0999999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 339.44863,416.12222 L 357.69854,416.17859 L 368.1622,427.96097 L 339.41234,427.87217 L 339.44863,416.12222 z" + id="rect3378" + style="fill:#dedede;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" /> + <rect + width="13.5" + height="17" + x="411.19589" + y="404.28574" + id="rect3974" + style="opacity:1;fill:url(#linearGradient3990);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + width="13.5" + height="17" + x="455.94589" + y="404.28574" + id="rect3992" + style="opacity:1;fill:url(#linearGradient3994);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 295.6959,421.91072 C 360.77923,430.41072 446.61257,432.91072 541.9459,421.91072 C 541.9459,421.91072 543.74902,428.6076 541.9459,430.41072 C 432.20839,444.14823 295.6959,433.68104 295.6959,430.41072 L 295.6959,421.91072 z" + id="rect2558" + style="fill:#dedede;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" /> + <rect + width="94.427879" + height="7.236649" + x="437.10614" + y="342.2645" + transform="matrix(0.9947793,0.1020501,-0.1079723,0.9941539,0,0)" + id="rect2569" + style="opacity:1;fill:#c1c1c1;fill-opacity:1;fill-rule:nonzero;stroke:#404040;stroke-width:3.0365274;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + width="13.5" + height="17" + x="433.32089" + y="404.28574" + id="rect3385" + style="opacity:1;fill:url(#linearGradient3387);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 402.86916,380.21847 L 489.80407,388.85485 L 491.52271,394.54919 L 397.58781,384.91281 L 402.86916,380.21847 z" + id="rect3466" + style="fill:#dcdcdc;fill-opacity:1;fill-rule:nonzero;stroke:#404040;stroke-width:3.03650045;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" /> + <rect + width="34.5" + height="14.5" + x="456.4783" + y="336.94293" + transform="matrix(0.997157,7.5351915e-2,-7.5351915e-2,0.997157,0,0)" + id="rect3418" + style="opacity:1;fill:url(#linearGradient3426);fill-opacity:1;fill-rule:nonzero;stroke:#494949;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <g + transform="matrix(0.9246214,0.3808874,-0.3808874,0.9246214,-13.252851,-40.129692)" + id="flag"> + <rect + width="19.75" + height="27.75" + x="193.34448" + y="-709" + transform="matrix(0,1,-1,0,0,0)" + id="rect3389" + style="opacity:1;fill:#b20000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + width="27.25" + height="5.75" + x="681.5" + y="200.59448" + id="rect3393" + style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + width="5.75" + height="19.5" + x="691.25" + y="193.59448" + id="rect3395" + style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + width="27.75" + height="2.5" + x="681.5" + y="202.34448" + id="rect3397" + style="opacity:1;fill:#000080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + width="3" + height="19.25" + x="692.5" + y="193.59448" + id="rect3399" + style="opacity:1;fill:#000080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </g> + </g> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/scalable/bomb.svg b/examples/animation/sub-attaq/pics/scalable/bomb.svg new file mode 100644 index 0000000..294771a --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/bomb.svg @@ -0,0 +1,138 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + version="1.0" + width="744.09448" + height="1052.3622" + id="svg3121"> + <defs + id="defs3123"> + <radialGradient + cx="-135.625" + cy="148.71948" + r="7.625" + fx="-135.625" + fy="148.71948" + id="radialGradient3439" + xlink:href="#linearGradient3366" + gradientUnits="userSpaceOnUse" /> + <linearGradient + x1="-132.85063" + y1="173.6969" + x2="-145.3662" + y2="177.59828" + id="linearGradient3418" + xlink:href="#linearGradient3366" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(-0.2134297,-0.5943658,0.6658882,-0.2391126,-274.53441,123.00067)" /> + <linearGradient + x1="-141.85466" + y1="181.49153" + x2="-144.95044" + y2="175.90179" + id="linearGradient3414" + xlink:href="#linearGradient3366" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.2134297,-0.5943658,-0.6658882,-0.2391126,-15.893355,122.67824)" /> + <linearGradient + x1="-149.5" + y1="177.59448" + x2="-145.7928" + y2="180.05936" + id="linearGradient3410" + xlink:href="#linearGradient3366" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(-0.6315243,0,0,0.7075182,-227.03781,54.321514)" /> + <linearGradient + x1="-140.46242" + y1="177.40488" + x2="-147.04802" + y2="172.66473" + id="linearGradient3406" + xlink:href="#linearGradient3366" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(-0.6315243,0,0,-0.7075182,-226.40365,274.91611)" /> + <linearGradient + x1="-147.2406" + y1="180.95567" + x2="-140.01878" + y2="175.57777" + id="linearGradient3402" + xlink:href="#linearGradient3366" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.6315243,0,0,-0.7075182,-64.045217,275.07466)" /> + <linearGradient + x1="-146.98956" + y1="174.00922" + x2="-142.60332" + y2="179.38712" + id="linearGradient3398" + xlink:href="#linearGradient3366" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.6315243,0,0,0.7075182,-62.683611,54.187362)" /> + <linearGradient + id="linearGradient3366"> + <stop + id="stop3368" + style="stop-color:#bcbcbc;stop-opacity:1" + offset="0" /> + <stop + id="stop3370" + style="stop-color:#191b1c;stop-opacity:1" + offset="1" /> + </linearGradient> + <radialGradient + cx="-208.95004" + cy="173.10576" + r="31.667252" + fx="-208.95004" + fy="173.10576" + id="radialGradient3364" + xlink:href="#linearGradient3366" + gradientUnits="userSpaceOnUse" /> + </defs> + <g + id="layer1"> + <g + transform="translate(419.4996,488.13454)" + id="mine"> + <path + d="M -167.5843,186.54079 A 31.466251,31.466251 0 1 1 -230.5168,186.54079 A 31.466251,31.466251 0 1 1 -167.5843,186.54079 z" + transform="matrix(0.6341613,0,0,0.6341613,-18.521242,45.718192)" + id="path2586" + style="opacity:1;fill:url(#radialGradient3364);fill-opacity:1;stroke:#131313;stroke-width:3.54799318;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M -155.20193,175.4167 C -157.60085,176.6451 -156.78074,184.26068 -156.78074,184.26068 C -156.78074,184.26068 -148.33787,181.58301 -148.57092,178.60053 C -148.74283,176.40051 -153.23774,174.41092 -155.20193,175.4167 z" + id="path3382" + style="fill:url(#linearGradient3398);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M -156.56354,153.84532 C -158.96246,152.61693 -158.14235,145.00135 -158.14235,145.00135 C -158.14235,145.00135 -149.69948,147.67902 -149.93253,150.66149 C -150.10444,152.86151 -154.59935,154.85111 -156.56354,153.84532 z" + id="path3400" + style="fill:url(#linearGradient3402);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M -133.88532,153.68678 C -131.48641,152.45838 -132.30652,144.8428 -132.30652,144.8428 C -132.30652,144.8428 -140.74938,147.52047 -140.51633,150.50295 C -140.34442,152.70297 -135.84951,154.69256 -133.88532,153.68678 z" + id="path3404" + style="fill:url(#linearGradient3406);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M -134.51948,175.55085 C -132.12057,176.77925 -132.94068,184.39483 -132.94068,184.39483 C -132.94068,184.39483 -141.38355,181.71716 -141.15049,178.73469 C -140.97858,176.53467 -136.48367,174.54507 -134.51948,175.55085 z" + id="path3408" + style="fill:url(#linearGradient3410);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M -161.25709,168.78221 C -163.22395,170.62484 -170.11427,165.85236 -170.11427,165.85236 C -170.11427,165.85236 -164.7408,160.23808 -162.01257,161.46538 C -160.00011,162.37068 -159.64667,167.27352 -161.25709,168.78221 z" + id="path3412" + style="fill:url(#linearGradient3414);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M -129.17068,169.10464 C -127.20382,170.94727 -120.3135,166.17478 -120.3135,166.17478 C -120.3135,166.17478 -125.68697,160.5605 -128.41519,161.7878 C -130.42766,162.69311 -130.7811,167.59595 -129.17068,169.10464 z" + id="path3416" + style="fill:url(#linearGradient3418);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M -126,151.21948 A 6.625,6.625 0 1 1 -139.25,151.21948 A 6.625,6.625 0 1 1 -126,151.21948 z" + transform="matrix(0.6341613,0,0,0.6341613,-61.039517,68.324922)" + id="path3426" + style="opacity:1;fill:url(#radialGradient3439);fill-opacity:1;stroke:#131313;stroke-width:3.54799318;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </g> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/scalable/sand.svg b/examples/animation/sub-attaq/pics/scalable/sand.svg new file mode 100644 index 0000000..8af11b7 --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/sand.svg @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + version="1.0" + width="744.09448" + height="1052.3622" + id="svg2596"> + <defs + id="defs2598"> + <linearGradient + id="linearGradient3708"> + <stop + id="stop3710" + style="stop-color:#202020;stop-opacity:1" + offset="0" /> + <stop + id="stop3712" + style="stop-color:#ffffff;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="518.26996" + y1="497.31476" + x2="533.02924" + y2="497.31476" + id="linearGradient3794" + xlink:href="#linearGradient3708" + gradientUnits="userSpaceOnUse" /> + <linearGradient + id="linearGradient3718"> + <stop + id="stop3720" + style="stop-color:#bcbcbc;stop-opacity:0.28169015" + offset="0" /> + <stop + id="stop3722" + style="stop-color:#bcbcbc;stop-opacity:0" + offset="1" /> + </linearGradient> + <linearGradient + x1="516.89508" + y1="503.50137" + x2="516.89508" + y2="543.80646" + id="linearGradient3792" + xlink:href="#linearGradient3718" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.9947644,0,0,1.3346457,2.7877039,-166.60153)" /> + <linearGradient + id="linearGradient3692"> + <stop + id="stop3694" + style="stop-color:#ffffff;stop-opacity:1" + offset="0" /> + <stop + id="stop3696" + style="stop-color:#b6b6b6;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="506.95975" + y1="469.73706" + x2="525.41608" + y2="469.73706" + id="linearGradient3790" + xlink:href="#linearGradient3692" + gradientUnits="userSpaceOnUse" /> + <linearGradient + id="linearGradient3816"> + <stop + id="stop3818" + style="stop-color:#ad8b00;stop-opacity:1" + offset="0" /> + <stop + id="stop3820" + style="stop-color:#ad8b00;stop-opacity:0" + offset="1" /> + </linearGradient> + <linearGradient + x1="573" + y1="755.46222" + x2="573" + y2="700.13464" + id="linearGradient3826" + xlink:href="#linearGradient3816" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1,0,0,1.6033628,-150.63569,-350.3846)" /> + </defs> + <g + id="layer1"> + <path + d="M -151.63569,813.2217 C 121.3643,798.79144 -201.99878,675.6877 110.3643,805.79144 C 173.82677,832.22448 244.3643,807.3948 298.3643,805.79144 C 352.3643,804.18808 312.3643,791.12082 359.3643,811.96454 C 406.3643,832.80825 554.3643,792.77462 599.3643,784.75781 C 644.3643,776.741 757.36426,768.13763 796.36426,782.5679 C 835.36426,796.99816 905.36426,799.37799 905.36426,799.37799 L 902.36426,847.47887 L -153.63569,845.87551 L -151.63569,813.2217 z" + id="path3814" + style="fill:url(#linearGradient3826);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + <path + d="M 908.86426,836.95812 C 635.8643,830.91791 761.87636,793.71076 617.8643,836.91791 C 600.0648,842.2582 409.74894,822.981 401.8643,836.91791 C 378.04825,879.01524 73.306465,803.72304 31.864305,827.54883 C 28.864305,829.27358 9.9016246,824.26916 -15.135695,831.28771 C -51.805335,841.56707 -68.135695,826.06042 -107.1357,832.10063 C -146.1357,838.14084 -150.13569,834.11404 -150.13569,834.11404 L -157.13569,848.36741 L 898.86426,847.69627 L 908.86426,836.95812 z" + id="path3828" + style="fill:#ad8b00;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/scalable/see.svg b/examples/animation/sub-attaq/pics/scalable/see.svg new file mode 100644 index 0000000..0666691 --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/see.svg @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + version="1.0" + width="744.09448" + height="1052.3622" + id="svg2650"> + <defs + id="defs2652"> + <linearGradient + id="linearGradient3624"> + <stop + id="stop3626" + style="stop-color:#3a8daf;stop-opacity:1" + offset="0" /> + <stop + id="stop3636" + style="stop-color:#252525;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="552.98486" + y1="390.56842" + x2="549.39465" + y2="702.3479" + id="linearGradient3630" + xlink:href="#linearGradient3624" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(2.3373776,0,0,1.5004634,-996.17287,-279.00679)" /> + </defs> + <g + id="layer1"> + <rect + width="1054.4708" + height="461.52972" + x="-161.52115" + y="310.16876" + id="rect3622" + style="opacity:1;fill:url(#linearGradient3630);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.13464069;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/scalable/sky.svg b/examples/animation/sub-attaq/pics/scalable/sky.svg new file mode 100644 index 0000000..1546c08 --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/sky.svg @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + version="1.0" + width="744.09448" + height="1052.3622" + id="svg2721"> + <defs + id="defs2723"> + <linearGradient + id="linearGradient3746"> + <stop + id="stop3748" + style="stop-color:#ffffff;stop-opacity:1" + offset="0" /> + <stop + id="stop3750" + style="stop-color:#0074b7;stop-opacity:1" + offset="1" /> + </linearGradient> + <radialGradient + cx="82.966125" + cy="-178.42453" + r="526.79456" + fx="82.966125" + fy="-178.42453" + id="radialGradient3880" + xlink:href="#linearGradient3746" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.4952094,0.3367191,-0.1040669,0.5264617,-235.04839,425.12197)" /> + </defs> + <g + id="layer1"> + <rect + width="1053.5891" + height="291.32797" + x="-178.22313" + y="300.98392" + id="rect3638" + style="opacity:1;fill:url(#radialGradient3880);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.1880002;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/scalable/sub-attaq.svg b/examples/animation/sub-attaq/pics/scalable/sub-attaq.svg new file mode 100644 index 0000000..b075179 --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/sub-attaq.svg @@ -0,0 +1,1473 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="1052.3622" + height="744.09448" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + version="1.0" + sodipodi:docname="sub-attaq.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape"> + <defs + id="defs4"> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3366" + id="radialGradient3439" + cx="-135.625" + cy="148.71948" + fx="-135.625" + fy="148.71948" + r="7.625" + gradientUnits="userSpaceOnUse" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3366" + id="linearGradient3418" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(-0.2134297,-0.5943658,0.6658882,-0.2391126,-274.53441,123.00067)" + x1="-132.85063" + y1="173.6969" + x2="-145.3662" + y2="177.59828" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3366" + id="linearGradient3414" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.2134297,-0.5943658,-0.6658882,-0.2391126,-15.893355,122.67824)" + x1="-141.85466" + y1="181.49153" + x2="-144.95044" + y2="175.90179" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3366" + id="linearGradient3410" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(-0.6315243,0,0,0.7075182,-227.03781,54.321514)" + x1="-149.5" + y1="177.59448" + x2="-145.7928" + y2="180.05936" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3366" + id="linearGradient3406" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(-0.6315243,0,0,-0.7075182,-226.40365,274.91611)" + x1="-140.46242" + y1="177.40488" + x2="-147.04802" + y2="172.66473" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3366" + id="linearGradient3402" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.6315243,0,0,-0.7075182,-64.045217,275.07466)" + x1="-147.2406" + y1="180.95567" + x2="-140.01878" + y2="175.57777" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3366" + id="linearGradient3398" + x1="-146.98956" + y1="174.00922" + x2="-142.60332" + y2="179.38712" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.6315243,0,0,0.7075182,-62.683611,54.187362)" /> + <linearGradient + id="linearGradient3366"> + <stop + id="stop3368" + offset="0" + style="stop-color:#bcbcbc;stop-opacity:1;" /> + <stop + id="stop3370" + offset="1" + style="stop-color:#191b1c;stop-opacity:1;" /> + </linearGradient> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3366" + id="radialGradient3364" + cx="-208.95004" + cy="173.10576" + fx="-208.95004" + fy="173.10576" + r="31.667252" + gradientUnits="userSpaceOnUse" /> + <linearGradient + id="linearGradient5097"> + <stop + style="stop-color:#19a2db;stop-opacity:0;" + offset="0" + id="stop5099" /> + <stop + id="stop5109" + offset="0.30000001" + style="stop-color:#1379a7;stop-opacity:0.49803922;" /> + <stop + style="stop-color:#0e5173;stop-opacity:1;" + offset="1" + id="stop5101" /> + </linearGradient> + <linearGradient + id="linearGradient3523" + inkscape:collect="always"> + <stop + id="stop3525" + offset="0" + style="stop-color:#b9b9b9;stop-opacity:1" /> + <stop + id="stop3527" + offset="1" + style="stop-color:#444444;stop-opacity:0;" /> + </linearGradient> + <linearGradient + id="linearGradient3438"> + <stop + style="stop-color:#939393;stop-opacity:1;" + offset="0" + id="stop3440" /> + <stop + id="stop3444" + offset="0.12354442" + style="stop-color:#d6d6d6;stop-opacity:1;" /> + <stop + style="stop-color:#dadada;stop-opacity:1;" + offset="0.74055624" + id="stop3446" /> + <stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="1" + id="stop3442" /> + </linearGradient> + <linearGradient + id="linearGradient3428"> + <stop + id="stop3430" + offset="0" + style="stop-color:#464646;stop-opacity:1;" /> + <stop + style="stop-color:#848788;stop-opacity:1;" + offset="0.18306103" + id="stop3432" /> + <stop + id="stop3434" + offset="0.66368055" + style="stop-color:#9ca0a2;stop-opacity:1;" /> + <stop + id="stop3436" + offset="1" + style="stop-color:#b5babd;stop-opacity:1;" /> + </linearGradient> + <linearGradient + id="linearGradient4034"> + <stop + id="stop4036" + offset="0" + style="stop-color:#ffffff;stop-opacity:1;" /> + <stop + style="stop-color:#ffffff;stop-opacity:0.49803922;" + offset="0.5" + id="stop4038" /> + <stop + id="stop4040" + offset="0.63705367" + style="stop-color:#ffffff;stop-opacity:0.24705882;" /> + <stop + style="stop-color:#ffffff;stop-opacity:0.12156863;" + offset="0.79425853" + id="stop4042" /> + <stop + id="stop4044" + offset="1" + style="stop-color:#a0a0a0;stop-opacity:1;" /> + </linearGradient> + <linearGradient + inkscape:collect="always" + id="linearGradient4016"> + <stop + style="stop-color:#283e6a;stop-opacity:1;" + offset="0" + id="stop4018" /> + <stop + style="stop-color:#283e6a;stop-opacity:0;" + offset="1" + id="stop4020" /> + </linearGradient> + <linearGradient + id="linearGradient4004"> + <stop + style="stop-color:#dbdbdb;stop-opacity:1;" + offset="0" + id="stop4010" /> + <stop + style="stop-color:#c4c9cb;stop-opacity:1;" + offset="1" + id="stop4012" /> + </linearGradient> + <linearGradient + id="linearGradient3998"> + <stop + id="stop4000" + offset="0" + style="stop-color:#adadad;stop-opacity:1;" /> + <stop + id="stop4002" + offset="1" + style="stop-color:#ffffff;stop-opacity:1;" /> + </linearGradient> + <linearGradient + id="linearGradient3864"> + <stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="0" + id="stop3866" /> + <stop + id="stop4028" + offset="0.5" + style="stop-color:#ffffff;stop-opacity:0.49803922;" /> + <stop + style="stop-color:#ffffff;stop-opacity:0.24705882;" + offset="0.75" + id="stop4030" /> + <stop + id="stop4032" + offset="0.875" + style="stop-color:#ffffff;stop-opacity:0.12156863;" /> + <stop + style="stop-color:#a0a0a0;stop-opacity:1;" + offset="1" + id="stop3868" /> + </linearGradient> + <linearGradient + inkscape:collect="always" + id="linearGradient3816"> + <stop + style="stop-color:#ad8b00;stop-opacity:1;" + offset="0" + id="stop3818" /> + <stop + style="stop-color:#ad8b00;stop-opacity:0;" + offset="1" + id="stop3820" /> + </linearGradient> + <linearGradient + id="linearGradient3746"> + <stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="0" + id="stop3748" /> + <stop + style="stop-color:#0074b7;stop-opacity:1;" + offset="1" + id="stop3750" /> + </linearGradient> + <linearGradient + id="linearGradient3718"> + <stop + style="stop-color:#bcbcbc;stop-opacity:0.28169015;" + offset="0" + id="stop3720" /> + <stop + style="stop-color:#bcbcbc;stop-opacity:0;" + offset="1" + id="stop3722" /> + </linearGradient> + <linearGradient + id="linearGradient3708"> + <stop + style="stop-color:#202020;stop-opacity:1;" + offset="0" + id="stop3710" /> + <stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="1" + id="stop3712" /> + </linearGradient> + <linearGradient + id="linearGradient3692"> + <stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="0" + id="stop3694" /> + <stop + style="stop-color:#b6b6b6;stop-opacity:1;" + offset="1" + id="stop3696" /> + </linearGradient> + <linearGradient + id="linearGradient3656"> + <stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="0" + id="stop3658" /> + <stop + style="stop-color:#ffffff;stop-opacity:0;" + offset="1" + id="stop3660" /> + </linearGradient> + <linearGradient + id="linearGradient3624"> + <stop + style="stop-color:#3a8daf;stop-opacity:1;" + offset="0" + id="stop3626" /> + <stop + id="stop3636" + offset="1" + style="stop-color:#252525;stop-opacity:1;" /> + </linearGradient> + <linearGradient + id="linearGradient3532"> + <stop + id="stop3534" + offset="0" + style="stop-color:#545454;stop-opacity:1;" /> + <stop + style="stop-color:#848788;stop-opacity:1;" + offset="0.44021741" + id="stop3536" /> + <stop + id="stop3538" + offset="0.56799388" + style="stop-color:#9ca0a2;stop-opacity:1;" /> + <stop + id="stop3540" + offset="1" + style="stop-color:#565d60;stop-opacity:1" /> + </linearGradient> + <linearGradient + id="linearGradient3345"> + <stop + id="stop3348" + offset="0" + style="stop-color:#898989;stop-opacity:1;" /> + <stop + style="stop-color:#9ea1a2;stop-opacity:1;" + offset="0.44021741" + id="stop3350" /> + <stop + id="stop3352" + offset="0.56799388" + style="stop-color:#bbbdbf;stop-opacity:1;" /> + <stop + id="stop3354" + offset="1" + style="stop-color:#f0f1f2;stop-opacity:1;" /> + </linearGradient> + <linearGradient + id="linearGradient3227"> + <stop + style="stop-color:#444444;stop-opacity:1;" + offset="0" + id="stop3229" /> + <stop + style="stop-color:#b0b0b0;stop-opacity:1;" + offset="1" + id="stop3232" /> + </linearGradient> + <linearGradient + id="linearGradient3435"> + <stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="0" + id="stop3437" /> + <stop + style="stop-color:#c0c0c0;stop-opacity:0;" + offset="1" + id="stop3439" /> + </linearGradient> + <linearGradient + inkscape:collect="always" + id="linearGradient3421"> + <stop + style="stop-color:#444444;stop-opacity:1;" + offset="0" + id="stop3423" /> + <stop + style="stop-color:#444444;stop-opacity:0;" + offset="1" + id="stop3425" /> + </linearGradient> + <linearGradient + id="linearGradient3293"> + <stop + style="stop-color:#c4b434;stop-opacity:1;" + offset="0" + id="stop3295" /> + <stop + style="stop-color:#9b5500;stop-opacity:1;" + offset="1" + id="stop3297" /> + </linearGradient> + <linearGradient + id="linearGradient3229"> + <stop + style="stop-color:#125a7a;stop-opacity:1;" + offset="0" + id="stop3231" /> + <stop + style="stop-color:#308fc0;stop-opacity:1;" + offset="1" + id="stop3233" /> + </linearGradient> + <linearGradient + id="linearGradient3219"> + <stop + id="stop3221" + offset="0" + style="stop-color:#a55b00;stop-opacity:1;" /> + <stop + id="stop3223" + offset="1" + style="stop-color:#f4e45e;stop-opacity:1;" /> + </linearGradient> + <linearGradient + id="linearGradient3189"> + <stop + style="stop-color:#000000;stop-opacity:1;" + offset="0" + id="stop3191" /> + <stop + style="stop-color:#000000;stop-opacity:0;" + offset="1" + id="stop3193" /> + </linearGradient> + <linearGradient + id="linearGradient3167"> + <stop + style="stop-color:#464646;stop-opacity:1;" + offset="0" + id="stop3169" /> + <stop + id="stop3345" + offset="0.44021741" + style="stop-color:#848788;stop-opacity:1;" /> + <stop + style="stop-color:#9ca0a2;stop-opacity:1;" + offset="0.56799388" + id="stop3347" /> + <stop + style="stop-color:#b5babd;stop-opacity:1;" + offset="1" + id="stop3171" /> + </linearGradient> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3167" + id="linearGradient3175" + x1="443.95602" + y1="315.31854" + x2="443.95602" + y2="247.85609" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.4908502,0,0,0.4579593,350.98557,542.12189)" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3219" + id="linearGradient3253" + gradientUnits="userSpaceOnUse" + x1="325.57214" + y1="280.13632" + x2="312.84424" + y2="257.60013" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3229" + id="linearGradient3255" + gradientUnits="userSpaceOnUse" + x1="310.01578" + y1="255.47881" + x2="325.92572" + y2="280.13632" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3219" + id="linearGradient3321" + gradientUnits="userSpaceOnUse" + x1="325.57214" + y1="280.13632" + x2="312.84424" + y2="257.60013" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3229" + id="linearGradient3323" + gradientUnits="userSpaceOnUse" + x1="310.01578" + y1="255.47881" + x2="325.92572" + y2="280.13632" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3219" + id="linearGradient3331" + gradientUnits="userSpaceOnUse" + x1="325.57214" + y1="280.13632" + x2="312.84424" + y2="257.60013" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3229" + id="linearGradient3333" + gradientUnits="userSpaceOnUse" + x1="310.01578" + y1="255.47881" + x2="325.92572" + y2="280.13632" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3293" + id="linearGradient3343" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.3292883,0,0,1.10796,1.5038593,-24.232315)" + x1="359.5589" + y1="258.84247" + x2="370.88239" + y2="258.84247" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3219" + id="linearGradient3365" + gradientUnits="userSpaceOnUse" + x1="325.57214" + y1="280.13632" + x2="312.84424" + y2="257.60013" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3229" + id="linearGradient3367" + gradientUnits="userSpaceOnUse" + x1="310.01578" + y1="255.47881" + x2="325.92572" + y2="280.13632" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3219" + id="linearGradient3369" + gradientUnits="userSpaceOnUse" + x1="325.57214" + y1="280.13632" + x2="312.84424" + y2="257.60013" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3229" + id="linearGradient3371" + gradientUnits="userSpaceOnUse" + x1="310.01578" + y1="255.47881" + x2="325.92572" + y2="280.13632" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3219" + id="linearGradient3379" + gradientUnits="userSpaceOnUse" + x1="325.57214" + y1="280.13632" + x2="312.84424" + y2="257.60013" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3229" + id="linearGradient3381" + gradientUnits="userSpaceOnUse" + x1="310.01578" + y1="255.47881" + x2="325.92572" + y2="280.13632" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3293" + id="linearGradient3385" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.3267302,0,0,1.1332782,-1.5786343,-29.194748)" + x1="371.79858" + y1="258.84247" + x2="364.49646" + y2="258.84247" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3293" + id="linearGradient3401" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.9807835,0,0,1.1280701,-361.45126,-28.553769)" + x1="371.79858" + y1="258.84247" + x2="364.49646" + y2="258.84247" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3421" + id="radialGradient3431" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.1862613,0,0,0.3638703,-186.86143,179.02055)" + cx="432.3343" + cy="233.80295" + fx="432.3343" + fy="233.80295" + r="59.056834" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3435" + id="radialGradient3441" + cx="290.5" + cy="244.34448" + fx="290.5" + fy="244.34448" + r="37.5" + gradientTransform="matrix(0.8202102,0.8202102,-0.7960458,0.7960458,246.73838,-189.686)" + gradientUnits="userSpaceOnUse" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3345" + id="linearGradient3311" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.466978,0,0,0.4500435,352.00841,540.25044)" + x1="510.99884" + y1="161.99408" + x2="396.48914" + y2="161.99408" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3421" + id="radialGradient3339" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.4181493,0,0,0.1282619,386.09461,620.15777)" + cx="432.3343" + cy="233.80295" + fx="432.3343" + fy="233.80295" + r="59.056834" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3219" + id="linearGradient3434" + gradientUnits="userSpaceOnUse" + x1="325.57214" + y1="280.13632" + x2="312.84424" + y2="257.60013" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3229" + id="linearGradient3436" + gradientUnits="userSpaceOnUse" + x1="310.01578" + y1="255.47881" + x2="325.92572" + y2="280.13632" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3532" + id="linearGradient3520" + x1="525" + y1="371.09448" + x2="525" + y2="395.09448" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.5865192,0,0,0.2518015,339.73218,572.99479)" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3624" + id="linearGradient3630" + x1="552.98486" + y1="390.56842" + x2="549.39465" + y2="702.3479" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(2.3373776,0,0,1.5004634,-835.38716,-310.82676)" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3656" + id="radialGradient3662" + cx="656.19507" + cy="534.45917" + fx="656.19507" + fy="534.45917" + r="13.227922" + gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)" + gradientUnits="userSpaceOnUse" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3656" + id="radialGradient3668" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)" + cx="656.19507" + cy="534.45917" + fx="656.19507" + fy="534.45917" + r="13.227922" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3656" + id="radialGradient3672" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)" + cx="656.19507" + cy="534.45917" + fx="656.19507" + fy="534.45917" + r="13.227922" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3656" + id="radialGradient3676" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)" + cx="656.19507" + cy="534.45917" + fx="656.19507" + fy="534.45917" + r="13.227922" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3692" + id="linearGradient3772" + gradientUnits="userSpaceOnUse" + x1="506.95975" + y1="469.73706" + x2="525.41608" + y2="469.73706" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3718" + id="linearGradient3774" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.9947644,0,0,1.3346457,2.7877039,-166.60153)" + x1="516.89508" + y1="503.50137" + x2="516.89508" + y2="543.80646" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3708" + id="linearGradient3776" + gradientUnits="userSpaceOnUse" + x1="518.26993" + y1="497.31477" + x2="533.02923" + y2="497.31477" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3692" + id="linearGradient3790" + gradientUnits="userSpaceOnUse" + x1="506.95975" + y1="469.73706" + x2="525.41608" + y2="469.73706" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3718" + id="linearGradient3792" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.9947644,0,0,1.3346457,2.7877039,-166.60153)" + x1="516.89508" + y1="503.50137" + x2="516.89508" + y2="543.80646" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3708" + id="linearGradient3794" + gradientUnits="userSpaceOnUse" + x1="518.26993" + y1="497.31477" + x2="533.02923" + y2="497.31477" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3656" + id="radialGradient3804" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)" + cx="656.19507" + cy="534.45917" + fx="656.19507" + fy="534.45917" + r="13.227922" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3656" + id="radialGradient3808" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1,0,0,1.2672781,0,-144.63884)" + cx="656.19507" + cy="534.45917" + fx="656.19507" + fy="534.45917" + r="13.227922" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3227" + id="linearGradient3812" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.1223608,0,0,0.3849769,-17.516054,565.40983)" + x1="543.5" + y1="205.19257" + x2="587.52001" + y2="205.19257" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3816" + id="linearGradient3826" + x1="573" + y1="755.46222" + x2="573" + y2="700.13464" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1,0,0,1.6033628,0,-450.76899)" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3864" + id="radialGradient3874" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(2.9674693,0.8647541,-0.8726553,1.0212484,-15.308759,-74.232772)" + cx="94.273849" + cy="89.893486" + fx="94.273849" + fy="89.893486" + r="74.397521" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3746" + id="radialGradient3880" + cx="82.966125" + cy="-178.42453" + fx="82.966125" + fy="-178.42453" + r="526.79456" + gradientTransform="matrix(1.4952094,0.3367191,-0.1040669,0.5264617,-57.119818,125.77043)" + gradientUnits="userSpaceOnUse" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3438" + id="linearGradient3948" + x1="660.29303" + y1="256.53284" + x2="444.79303" + y2="255.62085" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(0,32.526912)" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3692" + id="linearGradient3972" + x1="573.5" + y1="244.2056" + x2="578.25" + y2="216.9556" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(0,35.526912)" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3746" + id="linearGradient3990" + x1="542.5" + y1="222.59448" + x2="559" + y2="222.59448" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-6.25,37.151912)" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3746" + id="linearGradient3994" + gradientUnits="userSpaceOnUse" + x1="542.5" + y1="222.59448" + x2="559" + y2="222.59448" + gradientTransform="translate(38.5,37.151912)" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient4016" + id="linearGradient4022" + x1="639" + y1="262.09448" + x2="667" + y2="262.09448" + gradientUnits="userSpaceOnUse" /> + <inkscape:perspective + id="perspective2578" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 526.18109 : 1" + sodipodi:type="inkscape:persp3d" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3746" + id="linearGradient3387" + gradientUnits="userSpaceOnUse" + x1="542.5" + y1="222.59448" + x2="559" + y2="222.59448" + gradientTransform="translate(15.875,37.151912)" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3167" + id="linearGradient3416" + x1="474.23065" + y1="229.92336" + x2="474.1944" + y2="218.27365" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(0.1004684,32.526757)" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3428" + id="linearGradient3426" + x1="592.92798" + y1="199.43727" + x2="557.05743" + y2="196.5448" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(12.140805,-13.041887)" /> + <filter + inkscape:collect="always" + id="filter3507"> + <feGaussianBlur + inkscape:collect="always" + stdDeviation="3.0523171" + id="feGaussianBlur3509" /> + </filter> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3523" + id="linearGradient3521" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1,0,0,-0.7291751,0,521.83983)" + x1="562.55634" + y1="285.89896" + x2="562.55634" + y2="244.09448" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient5097" + id="linearGradient5103" + x1="590.84674" + y1="274.57559" + x2="590.84674" + y2="334.01376" + gradientUnits="userSpaceOnUse" + spreadMethod="pad" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3864" + id="radialGradient5107" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(2.9674693,0.8647541,-0.8726553,1.0212484,-15.308759,-74.232772)" + cx="94.273849" + cy="89.893486" + fx="94.273849" + fy="89.893486" + r="74.397521" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + gridtolerance="10000" + guidetolerance="10" + objecttolerance="10" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="0.70710678" + inkscape:cx="532.91407" + inkscape:cy="457.84365" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1674" + inkscape:window-height="1000" + inkscape:window-x="2" + inkscape:window-y="14" + showguides="false" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <rect + style="opacity:1;fill:url(#radialGradient3880);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.1880002;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect3638" + width="1053.5891" + height="291.32797" + x="-0.29455566" + y="1.6323624" /> + <path + style="fill:url(#radialGradient3874);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;filter:url(#filter3507)" + d="M 158.37853,75.817898 C 130.95894,49.483192 82.14552,74.615971 85.85382,95.15981 C 49.691853,94.8009 50.214842,139.36083 83.29101,132.16343 C 144.66465,163.16454 159.26268,129.80212 164.6863,136.51386 C 225.60448,157.97672 246.34362,130.65438 265.24417,127.0714 C 294.43981,137.91859 337.16986,121.78798 297.03636,102.77604 C 331.73096,64.597047 277.96882,60.229366 253.07028,70.400868 C 191.09597,33.610112 168.89234,63.292037 158.37853,75.817898 z" + id="path3872" + sodipodi:nodetypes="cccccccc" + transform="matrix(1.5062893,0,0,1.1720951,618.04001,132.36768)" /> + <rect + style="opacity:1;fill:url(#linearGradient3630);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:4.13464069;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect3622" + width="1054.4708" + height="461.52972" + x="-0.7354126" + y="278.34879" /> + <path + style="fill:url(#linearGradient3826);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="M -0.99999999,712.83731 C 272,698.40705 -51.363087,575.30331 261,705.40705 C 324.46247,731.84009 395,707.01041 449,705.40705 C 503,703.80369 463,690.73643 510,711.58015 C 557,732.42386 705,692.39023 750,684.37342 C 795,676.35661 908,667.75324 947,682.18351 C 986,696.61377 1056,698.9936 1056,698.9936 L 1053,747.09448 L -3,745.49112 L -0.99999999,712.83731 z" + id="path3814" + sodipodi:nodetypes="cssssscccc" /> + <rect + style="opacity:1;fill:url(#linearGradient3520);fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:0.56879884;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect3512" + width="10.557344" + height="6.0432386" + x="642.3761" + y="666.43695" /> + <use + x="0" + y="0" + xlink:href="#path2455" + id="use3258" + transform="matrix(0.869168,0,0,-0.869168,81.98751,1246.5374)" + width="1052.3622" + height="744.09448" /> + <path + style="fill:url(#linearGradient3812);fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.77744257;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 593.04822,651.68104 C 593.04822,651.68104 653.65569,615.49321 639.065,637.05192 C 624.47431,658.61061 624.47431,658.61061 624.47431,658.61061 L 593.04822,651.68104 z" + id="path2455" /> + <path + style="fill:url(#linearGradient3175);fill-opacity:1;fill-rule:evenodd;stroke:#393939;stroke-width:1.90693891;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 485.26939,643.71814 C 443.15507,651.66437 458.5319,680.53556 502.21486,686.27814 C 551.68229,692.78115 568.45042,691.0115 605.34827,686.27814 C 657.60843,679.57406 657.68143,651.78445 605.34827,643.25553 C 553.98131,634.88408 516.10913,637.89923 485.26939,643.71814 z" + id="path2385" + sodipodi:nodetypes="cssss" /> + <path + style="fill:url(#radialGradient3339);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="M 542.18031,648.1112 C 548.56327,665.42741 608.42397,656.72745 586.93551,642.57104 C 586.93551,642.57104 543.33293,648.61096 542.18031,648.1112 z" + id="path3403" + sodipodi:nodetypes="ccc" /> + <path + style="fill:url(#linearGradient3311);fill-opacity:1;fill-rule:evenodd;stroke:#2d2d2d;stroke-width:2.07042313;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 537.39402,641.90906 C 537.39402,656.7605 583.62247,656.30589 583.62247,641.45445 L 583.62247,636.06071 C 583.62247,621.21003 537.39402,613.87461 537.39402,628.72529 L 537.39402,641.90906 z" + id="path3291" + sodipodi:nodetypes="cssss" /> + <g + id="g3235" + transform="matrix(1.4016868,0,0,1.1319742,112.22001,-99.678822)" /> + <path + sodipodi:type="arc" + style="opacity:1;fill:url(#radialGradient3441);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.227;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path3433" + sodipodi:cx="303.5" + sodipodi:cy="263.09448" + sodipodi:rx="37.5" + sodipodi:ry="40" + d="M 341,263.09448 A 37.5,40 0 1 1 266,263.09448 A 37.5,40 0 1 1 341,263.09448 z" + transform="matrix(0.692163,0,1.4106583e-2,0.289185,275.31394,582.37251)" /> + <path + sodipodi:type="arc" + style="opacity:1;fill:#444444;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.06500006;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path3458" + sodipodi:cx="369.5" + sodipodi:cy="316.09448" + sodipodi:rx="27.5" + sodipodi:ry="7" + d="M 397,316.09448 A 27.5,7 0 1 1 342,316.09448 A 27.5,7 0 1 1 397,316.09448 z" + transform="matrix(0.5642633,0,0,0.5642633,348.03095,450.47113)" /> + <path + sodipodi:type="arc" + style="opacity:1;fill:#444444;fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:4.23126984;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path3510" + sodipodi:cx="369.5" + sodipodi:cy="316.09448" + sodipodi:rx="27.5" + sodipodi:ry="7" + d="M 397,316.09448 A 27.5,7 0 1 1 342,316.09448 A 27.5,7 0 1 1 397,316.09448 z" + transform="matrix(0,0.30778,-0.5642633,0,828.66499,563.5944)" /> + <use + x="0" + y="0" + xlink:href="#path3510" + id="use3544" + transform="translate(0.5000005,-17.23511)" + width="1052.3622" + height="744.09448" /> + <path + sodipodi:type="arc" + style="opacity:1;fill:#787878;fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:2.38492584;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path3584" + sodipodi:cx="237.5" + sodipodi:cy="366.09448" + sodipodi:rx="8.5" + sodipodi:ry="8" + d="M 246,366.09448 A 8.5,8 0 1 1 229,366.09448 A 8.5,8 0 1 1 246,366.09448 z" + transform="matrix(1.7798114,-4.2997512e-2,1.3318941e-2,0.5513151,196.65666,476.1443)" /> + <path + style="fill:#a9a9a9;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3.49756980000000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" + d="M 423.2231,281.1169 C 502.67948,283.47026 574.8361,283.42778 668.97714,281.1169 C 668.97714,281.1169 670.77663,271.99598 668.97714,269.5402 C 559.46065,250.8302 423.2231,265.08614 423.2231,269.5402 L 423.2231,281.1169 z" + id="path3469" + sodipodi:nodetypes="cccsc" /> + <rect + style="opacity:1;fill:#333333;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect3408" + width="3.4280596" + height="29.611124" + x="709.89148" + y="-14.462622" + transform="matrix(0.9327494,0.3605254,-0.3633626,0.9316478,0,0)" /> + <rect + style="opacity:1;fill:url(#linearGradient3416);fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:2.99999928;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect3376" + width="48.499989" + height="8.5" + x="444.56302" + y="252.39224" + transform="matrix(0.9999952,3.0887776e-3,-3.0887776e-3,0.9999952,0,0)" /> + <path + style="fill:url(#linearGradient3972);fill-opacity:1;fill-rule:evenodd;stroke:#323232;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 509,277.62139 C 509,277.62139 547.41409,235.70896 524,232.62139 L 615,244.62139 L 615,279.62139 L 509,277.62139 z" + id="path3952" + sodipodi:nodetypes="csccc" /> + <path + sodipodi:type="arc" + style="opacity:1;fill:url(#radialGradient3662);fill-opacity:1;fill-rule:nonzero;stroke:#41526b;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path3654" + sodipodi:cx="656.19507" + sodipodi:cy="541.15485" + sodipodi:rx="12.727922" + sodipodi:ry="16.263456" + d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z" + transform="matrix(0.5187874,0,0,0.3968421,374.8524,387.30025)" /> + <path + sodipodi:type="arc" + style="opacity:1;fill:url(#radialGradient3668);fill-opacity:1;fill-rule:nonzero;stroke:#41526b;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path3666" + sodipodi:cx="656.19507" + sodipodi:cy="541.15485" + sodipodi:rx="12.727922" + sodipodi:ry="16.263456" + d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z" + transform="matrix(0.5734968,0,0,0.4386917,316.52295,315.62837)" /> + <path + transform="matrix(0.8598866,0,0,0.5637407,192.52282,220.77351)" + d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z" + sodipodi:ry="16.263456" + sodipodi:rx="12.727922" + sodipodi:cy="541.15485" + sodipodi:cx="656.19507" + id="path3670" + style="opacity:1;fill:url(#radialGradient3672);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.90000010000000020;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + <path + sodipodi:type="arc" + style="opacity:1;fill:url(#radialGradient3676);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.90000010000000020;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path3674" + sodipodi:cx="656.19507" + sodipodi:cy="541.15485" + sodipodi:rx="12.727922" + sodipodi:ry="16.263456" + d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z" + transform="matrix(0.7435991,0,0,0.6264519,225.8301,127.83701)" /> + <g + id="g3759" + transform="matrix(0.8830571,0,0,0.8830571,104.83144,103.2985)"> + <path + d="M 523.9661,469.73706 A 7.7781744,34.648232 0 1 1 508.40975,469.73706 A 7.7781744,34.648232 0 1 1 523.9661,469.73706 z" + sodipodi:ry="34.648232" + sodipodi:rx="7.7781744" + sodipodi:cy="469.73706" + sodipodi:cx="516.18793" + id="path3682" + style="opacity:1;fill:url(#linearGradient3772);fill-opacity:1;fill-rule:nonzero;stroke:#272727;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + <g + id="g3754"> + <rect + style="opacity:1;fill:url(#linearGradient3774);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.20000005;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect3716" + width="33.58757" + height="59.927299" + x="498.86386" + y="497.84454" /> + <path + style="fill:url(#linearGradient3776);fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 523.35045,482.89424 C 523.35045,482.89424 532.31256,488.20203 532.02344,500.14638 C 531.73431,512.09072 531.73431,511.73417 531.73431,511.73417 C 531.73431,511.73417 520.70627,493.83104 519.26887,499.77636 L 523.35045,482.89424 z" + id="path3704" + sodipodi:nodetypes="cscsc" /> + <path + sodipodi:nodetypes="cscsc" + id="path3706" + d="M 508.50327,482.89424 C 508.50327,482.89424 499.54116,488.20203 499.83028,500.14638 C 500.11941,512.09072 500.11941,511.73417 500.11941,511.73417 C 500.11941,511.73417 511.14745,493.83104 512.58485,499.77636 L 508.50327,482.89424 z" + style="fill:#bcbcbc;fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </g> + </g> + <g + transform="matrix(0.8830571,0,0,0.8830571,192.45885,-66.370546)" + id="g3778"> + <path + sodipodi:type="arc" + style="opacity:1;fill:url(#linearGradient3790);fill-opacity:1;fill-rule:nonzero;stroke:#272727;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path3780" + sodipodi:cx="516.18793" + sodipodi:cy="469.73706" + sodipodi:rx="7.7781744" + sodipodi:ry="34.648232" + d="M 523.9661,469.73706 A 7.7781744,34.648232 0 1 1 508.40975,469.73706 A 7.7781744,34.648232 0 1 1 523.9661,469.73706 z" /> + <g + id="g3782"> + <rect + y="497.84454" + x="498.86386" + height="59.927299" + width="33.58757" + id="rect3784" + style="opacity:1;fill:url(#linearGradient3792);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.20000005;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + sodipodi:nodetypes="cscsc" + id="path3786" + d="M 523.35045,482.89424 C 523.35045,482.89424 532.31256,488.20203 532.02344,500.14638 C 531.73431,512.09072 531.73431,511.73417 531.73431,511.73417 C 531.73431,511.73417 520.70627,493.83104 519.26887,499.77636 L 523.35045,482.89424 z" + style="fill:url(#linearGradient3794);fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + style="fill:#bcbcbc;fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 508.50327,482.89424 C 508.50327,482.89424 499.54116,488.20203 499.83028,500.14638 C 500.11941,512.09072 500.11941,511.73417 500.11941,511.73417 C 500.11941,511.73417 511.14745,493.83104 512.58485,499.77636 L 508.50327,482.89424 z" + id="path3788" + sodipodi:nodetypes="cscsc" /> + </g> + </g> + <path + transform="matrix(0.4292897,0,0,0.3283816,384.32775,481.20689)" + d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z" + sodipodi:ry="16.263456" + sodipodi:rx="12.727922" + sodipodi:cy="541.15485" + sodipodi:cx="656.19507" + id="path3802" + style="opacity:1;fill:url(#radialGradient3804);fill-opacity:1;fill-rule:nonzero;stroke:#41526b;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + <path + sodipodi:type="arc" + style="opacity:1;fill:url(#radialGradient3808);fill-opacity:1;fill-rule:nonzero;stroke:#41526b;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path3806" + sodipodi:cx="656.19507" + sodipodi:cy="541.15485" + sodipodi:rx="12.727922" + sodipodi:ry="16.263456" + d="M 668.92299,541.15485 A 12.727922,16.263456 0 1 1 643.46715,541.15485 A 12.727922,16.263456 0 1 1 668.92299,541.15485 z" + transform="matrix(0.5842998,0,0,0.4469553,299.7804,369.91514)" /> + <path + style="fill:#ad8b00;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="M 1059.5,736.57373 C 786.5,730.53352 912.51207,693.32637 768.5,736.53352 C 750.7005,741.87381 560.38464,722.59661 552.5,736.53352 C 528.68395,778.63085 223.94216,703.33865 182.5,727.16444 C 179.5,728.88919 160.53732,723.88477 135.5,730.90332 C 98.830356,741.18268 82.5,725.67603 43.5,731.71624 C 4.5,737.75645 0.5,733.72965 0.5,733.72965 L -6.5,747.98302 L 1049.5,747.31188 L 1059.5,736.57373 z" + id="path3828" + sodipodi:nodetypes="cssssscccc" /> + <rect + style="opacity:1;fill:url(#linearGradient5103);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect3448" + width="1053.5891" + height="67.882248" + x="-0.29455566" + y="274.57559" /> + <path + sodipodi:nodetypes="ccccc" + id="path3519" + d="M 428,343.85222 C 428,343.85222 457.01739,315.41439 470,315.41439 C 481.98261,313.04457 634.13054,311.73511 652,317.41962 C 661.13441,320.56943 664.46012,324.9477 666,343.85222 C 600.25603,336.72647 497.8192,336.4719 428,343.85222 z" + style="opacity:0.43933058;fill:url(#linearGradient3521);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:3.0999999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + style="fill:url(#linearGradient3948);fill-opacity:1;fill-rule:evenodd;stroke:#545454;stroke-width:3.0999999;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 428,276.62139 C 428,276.62139 457.01739,315.62139 470,315.62139 C 481.98261,318.87139 634.13054,320.6672 652,312.87139 C 661.13441,308.55171 664.46012,302.54729 666,276.62139 C 600.25603,286.39373 497.8192,286.74286 428,276.62139 z" + id="path3938" + sodipodi:nodetypes="ccccc" /> + <path + style="fill:#dedede;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" + d="M 466.00273,263.08289 L 484.25264,263.13926 L 494.7163,274.92164 L 465.96644,274.83284 L 466.00273,263.08289 z" + id="rect3378" + sodipodi:nodetypes="ccccc" /> + <rect + style="opacity:1;fill:url(#linearGradient3990);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect3974" + width="13.5" + height="17" + x="537.75" + y="251.2464" + inkscape:transform-center-x="30" /> + <rect + inkscape:transform-center-x="30" + y="251.2464" + x="582.5" + height="17" + width="13.5" + id="rect3992" + style="opacity:1;fill:url(#linearGradient3994);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + style="fill:#dedede;fill-opacity:1;fill-rule:nonzero;stroke:#484848;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" + d="M 422.25,268.87139 C 487.33333,277.37139 573.16667,279.87139 668.5,268.87139 C 668.5,268.87139 670.30312,275.56827 668.5,277.37139 C 558.76249,291.1089 422.25,280.64171 422.25,277.37139 L 422.25,268.87139 z" + id="rect2558" + sodipodi:nodetypes="cccsc" /> + <rect + style="opacity:1;fill:#c1c1c1;fill-opacity:1;fill-rule:nonzero;stroke:#404040;stroke-width:3.0365274;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect2569" + width="94.427879" + height="7.236649" + x="546.39832" + y="177.10637" + transform="matrix(0.9947793,0.1020501,-0.1079723,0.9941539,0,0)" /> + <rect + inkscape:transform-center-x="30" + y="251.2464" + x="559.875" + height="17" + width="13.5" + id="rect3385" + style="opacity:1;fill:url(#linearGradient3387);fill-opacity:1;fill-rule:nonzero;stroke:#323232;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <g + id="g3401" + transform="matrix(0.9246214,0.3808874,-0.3808874,0.9246214,113.30125,-193.16902)" + inkscape:transform-center-x="17.590385" + inkscape:transform-center-y="-15.415449"> + <rect + inkscape:transform-center-y="-43.888889" + transform="matrix(0,1,-1,0,0,0)" + style="opacity:1;fill:#b20000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect3389" + width="19.75" + height="27.75" + x="193.34448" + y="-709" /> + <rect + y="200.59448" + x="681.5" + height="5.75" + width="27.25" + id="rect3393" + style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + y="193.59448" + x="691.25" + height="19.5" + width="5.75" + id="rect3395" + style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + y="202.34448" + x="681.5" + height="2.5" + width="27.75" + id="rect3397" + style="opacity:1;fill:#000080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + y="193.59448" + x="692.5" + height="19.25" + width="3" + id="rect3399" + style="opacity:1;fill:#000080;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </g> + <path + style="fill:#dcdcdc;fill-opacity:1;fill-rule:nonzero;stroke:#404040;stroke-width:3.03650045;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" + d="M 529.42326,227.17914 L 616.35817,235.81552 L 618.07681,241.50986 L 524.14191,231.87348 L 529.42326,227.17914 z" + id="rect3466" + sodipodi:nodetypes="ccccc" /> + <rect + style="opacity:1;fill:url(#linearGradient3426);fill-opacity:1;fill-rule:nonzero;stroke:#494949;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect3418" + width="34.5" + height="14.5" + x="571.14081" + y="174.8026" + transform="matrix(0.997157,7.5351915e-2,-7.5351915e-2,0.997157,0,0)" + inkscape:transform-center-x="-8" + inkscape:transform-center-y="2" /> + <g + id="mine" + transform="translate(971.11461,237.62715)" + inkscape:label="#g3441"> + <path + transform="matrix(0.6341613,0,0,0.6341613,-18.521242,45.718192)" + d="M -167.5843,186.54079 A 31.466251,31.466251 0 1 1 -230.5168,186.54079 A 31.466251,31.466251 0 1 1 -167.5843,186.54079 z" + sodipodi:ry="31.466251" + sodipodi:rx="31.466251" + sodipodi:cy="186.54079" + sodipodi:cx="-199.05055" + id="path2586" + style="opacity:1;fill:url(#radialGradient3364);fill-opacity:1;stroke:#131313;stroke-width:3.54799318;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + <path + sodipodi:nodetypes="ccss" + id="path3382" + d="M -155.20193,175.4167 C -157.60085,176.6451 -156.78074,184.26068 -156.78074,184.26068 C -156.78074,184.26068 -148.33787,181.58301 -148.57092,178.60053 C -148.74283,176.40051 -153.23774,174.41092 -155.20193,175.4167 z" + style="fill:url(#linearGradient3398);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + sodipodi:nodetypes="ccss" + id="path3400" + d="M -156.56354,153.84532 C -158.96246,152.61693 -158.14235,145.00135 -158.14235,145.00135 C -158.14235,145.00135 -149.69948,147.67902 -149.93253,150.66149 C -150.10444,152.86151 -154.59935,154.85111 -156.56354,153.84532 z" + style="fill:url(#linearGradient3402);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + sodipodi:nodetypes="ccss" + id="path3404" + d="M -133.88532,153.68678 C -131.48641,152.45838 -132.30652,144.8428 -132.30652,144.8428 C -132.30652,144.8428 -140.74938,147.52047 -140.51633,150.50295 C -140.34442,152.70297 -135.84951,154.69256 -133.88532,153.68678 z" + style="fill:url(#linearGradient3406);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + sodipodi:nodetypes="ccss" + id="path3408" + d="M -134.51948,175.55085 C -132.12057,176.77925 -132.94068,184.39483 -132.94068,184.39483 C -132.94068,184.39483 -141.38355,181.71716 -141.15049,178.73469 C -140.97858,176.53467 -136.48367,174.54507 -134.51948,175.55085 z" + style="fill:url(#linearGradient3410);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + sodipodi:nodetypes="ccss" + id="path3412" + d="M -161.25709,168.78221 C -163.22395,170.62484 -170.11427,165.85236 -170.11427,165.85236 C -170.11427,165.85236 -164.7408,160.23808 -162.01257,161.46538 C -160.00011,162.37068 -159.64667,167.27352 -161.25709,168.78221 z" + style="fill:url(#linearGradient3414);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + sodipodi:nodetypes="ccss" + id="path3416" + d="M -129.17068,169.10464 C -127.20382,170.94727 -120.3135,166.17478 -120.3135,166.17478 C -120.3135,166.17478 -125.68697,160.5605 -128.41519,161.7878 C -130.42766,162.69311 -130.7811,167.59595 -129.17068,169.10464 z" + style="fill:url(#linearGradient3418);fill-opacity:1;fill-rule:evenodd;stroke:#131313;stroke-width:2.25;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + transform="matrix(0.6341613,0,0,0.6341613,-61.039517,68.324922)" + d="M -126,151.21948 A 6.625,6.625 0 1 1 -139.25,151.21948 A 6.625,6.625 0 1 1 -126,151.21948 z" + sodipodi:ry="6.625" + sodipodi:rx="6.625" + sodipodi:cy="151.21948" + sodipodi:cx="-132.625" + id="path3426" + style="opacity:1;fill:url(#radialGradient3439);fill-opacity:1;stroke:#131313;stroke-width:3.54799318;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + </g> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/scalable/submarine.svg b/examples/animation/sub-attaq/pics/scalable/submarine.svg new file mode 100644 index 0000000..8a0ffdd --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/submarine.svg @@ -0,0 +1,214 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + version="1.0" + width="744.09448" + height="1052.3622" + id="svg2594"> + <defs + id="defs2596"> + <linearGradient + id="linearGradient3345"> + <stop + id="stop3348" + style="stop-color:#898989;stop-opacity:1" + offset="0" /> + <stop + id="stop3350" + style="stop-color:#9ea1a2;stop-opacity:1" + offset="0.44021741" /> + <stop + id="stop3352" + style="stop-color:#bbbdbf;stop-opacity:1" + offset="0.56799388" /> + <stop + id="stop3354" + style="stop-color:#f0f1f2;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="510.99884" + y1="161.99408" + x2="396.48914" + y2="161.99408" + id="linearGradient3311" + xlink:href="#linearGradient3345" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.466978,0,0,0.4500435,231.58508,159.95135)" /> + <linearGradient + id="linearGradient3532"> + <stop + id="stop3534" + style="stop-color:#545454;stop-opacity:1" + offset="0" /> + <stop + id="stop3536" + style="stop-color:#848788;stop-opacity:1" + offset="0.44021741" /> + <stop + id="stop3538" + style="stop-color:#9ca0a2;stop-opacity:1" + offset="0.56799388" /> + <stop + id="stop3540" + style="stop-color:#565d60;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="525" + y1="371.09448" + x2="525" + y2="395.09448" + id="linearGradient3520" + xlink:href="#linearGradient3532" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.5865192,0,0,0.2518015,219.30885,192.6957)" /> + <linearGradient + id="linearGradient3227"> + <stop + id="stop3229" + style="stop-color:#444444;stop-opacity:1" + offset="0" /> + <stop + id="stop3232" + style="stop-color:#b0b0b0;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="543.5" + y1="205.19257" + x2="587.52002" + y2="205.19257" + id="linearGradient3812" + xlink:href="#linearGradient3227" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.1223608,0,0,0.3849769,-137.93938,185.11074)" /> + <linearGradient + id="linearGradient3167"> + <stop + id="stop3169" + style="stop-color:#464646;stop-opacity:1" + offset="0" /> + <stop + id="stop3345" + style="stop-color:#848788;stop-opacity:1" + offset="0.44021741" /> + <stop + id="stop3347" + style="stop-color:#9ca0a2;stop-opacity:1" + offset="0.56799388" /> + <stop + id="stop3171" + style="stop-color:#b5babd;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="443.95602" + y1="315.31854" + x2="443.95602" + y2="247.85609" + id="linearGradient3175" + xlink:href="#linearGradient3167" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.4908502,0,0,0.4579593,230.56224,161.8228)" /> + <linearGradient + id="linearGradient3421"> + <stop + id="stop3423" + style="stop-color:#444444;stop-opacity:1" + offset="0" /> + <stop + id="stop3425" + style="stop-color:#444444;stop-opacity:0" + offset="1" /> + </linearGradient> + <radialGradient + cx="432.33429" + cy="233.80295" + r="59.056835" + fx="432.33429" + fy="233.80295" + id="radialGradient3339" + xlink:href="#linearGradient3421" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.4181493,0,0,0.1282619,265.67128,239.85868)" /> + <linearGradient + id="linearGradient3435"> + <stop + id="stop3437" + style="stop-color:#ffffff;stop-opacity:1" + offset="0" /> + <stop + id="stop3439" + style="stop-color:#c0c0c0;stop-opacity:0" + offset="1" /> + </linearGradient> + <radialGradient + cx="290.5" + cy="244.34448" + r="37.5" + fx="290.5" + fy="244.34448" + id="radialGradient3441" + xlink:href="#linearGradient3435" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.8202102,0.8202102,-0.7960458,0.7960458,246.73838,-189.686)" /> + </defs> + <g + id="submarine"> + <rect + width="10.557344" + height="6.0432386" + x="521.95276" + y="286.13785" + id="rect3512" + style="opacity:1;fill:url(#linearGradient3520);fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:0.56879884;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 472.62489,271.38195 C 472.62489,271.38195 533.23236,235.19412 518.64167,256.75283 C 504.05098,278.31152 504.05098,278.31152 504.05098,278.31152 L 472.62489,271.38195 z" + id="path2455" + style="fill:url(#linearGradient3812);fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.77744257;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 364.84606,263.41905 C 322.73174,271.36528 338.10857,300.23647 381.79153,305.97905 C 431.25896,312.48206 448.02709,310.71241 484.92494,305.97905 C 537.1851,299.27497 537.2581,271.48536 484.92494,262.95644 C 433.55798,254.58499 395.6858,257.60014 364.84606,263.41905 z" + id="path2385" + style="fill:url(#linearGradient3175);fill-opacity:1;fill-rule:evenodd;stroke:#393939;stroke-width:1.90693891;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 421.75698,267.81211 C 428.13994,285.12832 488.00064,276.42836 466.51218,262.27195 C 466.51218,262.27195 422.9096,268.31187 421.75698,267.81211 z" + id="path3403" + style="fill:url(#radialGradient3339);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + <path + d="M 416.97069,261.60997 C 416.97069,276.46141 463.19914,276.0068 463.19914,261.15536 L 463.19914,255.76162 C 463.19914,240.91094 416.97069,233.57552 416.97069,248.4262 L 416.97069,261.60997 z" + id="path3291" + style="fill:url(#linearGradient3311);fill-opacity:1;fill-rule:evenodd;stroke:#2d2d2d;stroke-width:2.07042313;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 341,263.09448 A 37.5,40 0 1 1 266,263.09448 A 37.5,40 0 1 1 341,263.09448 z" + transform="matrix(0.692163,0,1.4106583e-2,0.289185,154.89061,202.07342)" + id="path3433" + style="opacity:1;fill:url(#radialGradient3441);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.227;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 397,316.09448 A 27.5,7 0 1 1 342,316.09448 A 27.5,7 0 1 1 397,316.09448 z" + transform="matrix(0.5642633,0,0,0.5642633,227.60762,70.172035)" + id="path3458" + style="opacity:1;fill:#444444;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.06500006;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 397,316.09448 A 27.5,7 0 1 1 342,316.09448 A 27.5,7 0 1 1 397,316.09448 z" + transform="matrix(0,0.30778,-0.5642633,0,708.24166,183.29531)" + id="path3510" + style="opacity:1;fill:#444444;fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:4.23126984;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <use + transform="translate(0.5000044,-17.235115)" + id="use3544" + x="0" + y="0" + width="1052.3622" + height="744.09448" + xlink:href="#path3510" /> + <path + d="M 246,366.09448 A 8.5,8 0 1 1 229,366.09448 A 8.5,8 0 1 1 246,366.09448 z" + transform="matrix(1.7798114,-4.2997512e-2,1.3318941e-2,0.5513151,76.233334,95.845205)" + id="path3584" + style="opacity:1;fill:#787878;fill-opacity:1;fill-rule:nonzero;stroke:#1b1e1f;stroke-width:2.38492584;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/scalable/surface.svg b/examples/animation/sub-attaq/pics/scalable/surface.svg new file mode 100644 index 0000000..40ed239 --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/surface.svg @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + version="1.0" + width="744.09448" + height="1052.3622" + id="svg2685"> + <defs + id="defs2687"> + <linearGradient + id="linearGradient5097"> + <stop + id="stop5099" + style="stop-color:#19a2db;stop-opacity:0" + offset="0" /> + <stop + id="stop5109" + style="stop-color:#1379a7;stop-opacity:0.49803922" + offset="0.30000001" /> + <stop + id="stop5101" + style="stop-color:#0e5173;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="590.84674" + y1="274.57559" + x2="590.84674" + y2="334.01376" + id="linearGradient5103" + xlink:href="#linearGradient5097" + gradientUnits="userSpaceOnUse" + gradientTransform="translate(-172.21428,209.55976)" + spreadMethod="pad" /> + </defs> + <g + id="layer1"> + <rect + width="1053.5891" + height="67.882248" + x="-172.50883" + y="484.13535" + id="rect3448" + style="opacity:1;fill:url(#linearGradient5103);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/scalable/torpedo.svg b/examples/animation/sub-attaq/pics/scalable/torpedo.svg new file mode 100644 index 0000000..48e429d --- /dev/null +++ b/examples/animation/sub-attaq/pics/scalable/torpedo.svg @@ -0,0 +1,127 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + version="1.0" + width="744.09448" + height="1052.3622" + id="svg2584"> + <defs + id="defs2586"> + <linearGradient + id="linearGradient3708"> + <stop + id="stop3710" + style="stop-color:#202020;stop-opacity:1" + offset="0" /> + <stop + id="stop3712" + style="stop-color:#ffffff;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="518.26996" + y1="497.31476" + x2="533.02924" + y2="497.31476" + id="linearGradient3776" + xlink:href="#linearGradient3708" + gradientUnits="userSpaceOnUse" /> + <linearGradient + id="linearGradient3718"> + <stop + id="stop3720" + style="stop-color:#bcbcbc;stop-opacity:0.28169015" + offset="0" /> + <stop + id="stop3722" + style="stop-color:#bcbcbc;stop-opacity:0" + offset="1" /> + </linearGradient> + <linearGradient + x1="516.89508" + y1="503.50137" + x2="516.89508" + y2="543.80646" + id="linearGradient3774" + xlink:href="#linearGradient3718" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.9947644,0,0,1.3346457,2.7877039,-166.60153)" /> + <linearGradient + id="linearGradient3692"> + <stop + id="stop3694" + style="stop-color:#ffffff;stop-opacity:1" + offset="0" /> + <stop + id="stop3696" + style="stop-color:#b6b6b6;stop-opacity:1" + offset="1" /> + </linearGradient> + <linearGradient + x1="506.95975" + y1="469.73706" + x2="525.41608" + y2="469.73706" + id="linearGradient3772" + xlink:href="#linearGradient3692" + gradientUnits="userSpaceOnUse" /> + <linearGradient + x1="506.95975" + y1="469.73706" + x2="525.41608" + y2="469.73706" + id="linearGradient2403" + xlink:href="#linearGradient3692" + gradientUnits="userSpaceOnUse" /> + <linearGradient + x1="516.89508" + y1="503.50137" + x2="516.89508" + y2="543.80646" + id="linearGradient2405" + xlink:href="#linearGradient3718" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.9947644,0,0,1.3346457,2.7877039,-166.60153)" /> + <linearGradient + x1="518.26996" + y1="497.31476" + x2="533.02924" + y2="497.31476" + id="linearGradient2407" + xlink:href="#linearGradient3708" + gradientUnits="userSpaceOnUse" /> + </defs> + <g + transform="translate(-128.69958,6.6568748)" + id="torpedo"> + <g + transform="matrix(0.8830571,0,0,0.8830571,-119.78327,177.67947)" + id="g3525"> + <path + d="M 523.9661,469.73706 A 7.7781744,34.648232 0 1 1 508.40975,469.73706 A 7.7781744,34.648232 0 1 1 523.9661,469.73706 z" + id="path3682" + style="opacity:1;fill:url(#linearGradient2403);fill-opacity:1;fill-rule:nonzero;stroke:#272727;stroke-width:2.9000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <g + id="g3754"> + <rect + width="33.58757" + height="59.927299" + x="498.86386" + y="497.84454" + id="rect3716" + style="opacity:1;fill:url(#linearGradient2405);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.20000005;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 523.35045,482.89424 C 523.35045,482.89424 532.31256,488.20203 532.02344,500.14638 C 531.73431,512.09072 531.73431,511.73417 531.73431,511.73417 C 531.73431,511.73417 520.70627,493.83104 519.26887,499.77636 L 523.35045,482.89424 z" + id="path3704" + style="fill:url(#linearGradient2407);fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 508.50327,482.89424 C 508.50327,482.89424 499.54116,488.20203 499.83028,500.14638 C 500.11941,512.09072 500.11941,511.73417 500.11941,511.73417 C 500.11941,511.73417 511.14745,493.83104 512.58485,499.77636 L 508.50327,482.89424 z" + id="path3706" + style="fill:#bcbcbc;fill-opacity:1;fill-rule:evenodd;stroke:#1f1f1f;stroke-width:1.99788344;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </g> + </g> + </g> +</svg> diff --git a/examples/animation/sub-attaq/pics/small/background.png b/examples/animation/sub-attaq/pics/small/background.png Binary files differnew file mode 100644 index 0000000..5ad3db6 --- /dev/null +++ b/examples/animation/sub-attaq/pics/small/background.png diff --git a/examples/animation/sub-attaq/pics/small/boat.png b/examples/animation/sub-attaq/pics/small/boat.png Binary files differnew file mode 100644 index 0000000..114ccc3 --- /dev/null +++ b/examples/animation/sub-attaq/pics/small/boat.png diff --git a/examples/animation/sub-attaq/pics/small/bomb.png b/examples/animation/sub-attaq/pics/small/bomb.png Binary files differnew file mode 100644 index 0000000..3af5f2f --- /dev/null +++ b/examples/animation/sub-attaq/pics/small/bomb.png diff --git a/examples/animation/sub-attaq/pics/small/submarine.png b/examples/animation/sub-attaq/pics/small/submarine.png Binary files differnew file mode 100644 index 0000000..0c0c350 --- /dev/null +++ b/examples/animation/sub-attaq/pics/small/submarine.png diff --git a/examples/animation/sub-attaq/pics/small/surface.png b/examples/animation/sub-attaq/pics/small/surface.png Binary files differnew file mode 100644 index 0000000..06d0e47 --- /dev/null +++ b/examples/animation/sub-attaq/pics/small/surface.png diff --git a/examples/animation/sub-attaq/pics/small/torpedo.png b/examples/animation/sub-attaq/pics/small/torpedo.png Binary files differnew file mode 100644 index 0000000..f9c2687 --- /dev/null +++ b/examples/animation/sub-attaq/pics/small/torpedo.png diff --git a/examples/animation/sub-attaq/pics/welcome/logo-a.png b/examples/animation/sub-attaq/pics/welcome/logo-a.png Binary files differnew file mode 100644 index 0000000..67dd76d --- /dev/null +++ b/examples/animation/sub-attaq/pics/welcome/logo-a.png diff --git a/examples/animation/sub-attaq/pics/welcome/logo-a2.png b/examples/animation/sub-attaq/pics/welcome/logo-a2.png Binary files differnew file mode 100644 index 0000000..17668b0 --- /dev/null +++ b/examples/animation/sub-attaq/pics/welcome/logo-a2.png diff --git a/examples/animation/sub-attaq/pics/welcome/logo-b.png b/examples/animation/sub-attaq/pics/welcome/logo-b.png Binary files differnew file mode 100644 index 0000000..cf6c045 --- /dev/null +++ b/examples/animation/sub-attaq/pics/welcome/logo-b.png diff --git a/examples/animation/sub-attaq/pics/welcome/logo-dash.png b/examples/animation/sub-attaq/pics/welcome/logo-dash.png Binary files differnew file mode 100644 index 0000000..219233c --- /dev/null +++ b/examples/animation/sub-attaq/pics/welcome/logo-dash.png diff --git a/examples/animation/sub-attaq/pics/welcome/logo-excl.png b/examples/animation/sub-attaq/pics/welcome/logo-excl.png Binary files differnew file mode 100644 index 0000000..8dd0a2e --- /dev/null +++ b/examples/animation/sub-attaq/pics/welcome/logo-excl.png diff --git a/examples/animation/sub-attaq/pics/welcome/logo-q.png b/examples/animation/sub-attaq/pics/welcome/logo-q.png Binary files differnew file mode 100644 index 0000000..86e588d --- /dev/null +++ b/examples/animation/sub-attaq/pics/welcome/logo-q.png diff --git a/examples/animation/sub-attaq/pics/welcome/logo-s.png b/examples/animation/sub-attaq/pics/welcome/logo-s.png Binary files differnew file mode 100644 index 0000000..7b6a36e --- /dev/null +++ b/examples/animation/sub-attaq/pics/welcome/logo-s.png diff --git a/examples/animation/sub-attaq/pics/welcome/logo-t.png b/examples/animation/sub-attaq/pics/welcome/logo-t.png Binary files differnew file mode 100644 index 0000000..b2e3526 --- /dev/null +++ b/examples/animation/sub-attaq/pics/welcome/logo-t.png diff --git a/examples/animation/sub-attaq/pics/welcome/logo-t2.png b/examples/animation/sub-attaq/pics/welcome/logo-t2.png Binary files differnew file mode 100644 index 0000000..b11a778 --- /dev/null +++ b/examples/animation/sub-attaq/pics/welcome/logo-t2.png diff --git a/examples/animation/sub-attaq/pics/welcome/logo-u.png b/examples/animation/sub-attaq/pics/welcome/logo-u.png Binary files differnew file mode 100644 index 0000000..24eede8 --- /dev/null +++ b/examples/animation/sub-attaq/pics/welcome/logo-u.png diff --git a/examples/animation/sub-attaq/pixmapitem.cpp b/examples/animation/sub-attaq/pixmapitem.cpp new file mode 100644 index 0000000..22a363f --- /dev/null +++ b/examples/animation/sub-attaq/pixmapitem.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "pixmapitem.h" + +//Qt +#include <QtCore/QDir> + +PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphicsItem * parent) : QGraphicsPixmapItem(parent),name(fileName) +{ + loadPixmap(mode); +} + +void PixmapItem::loadPixmap(GraphicsScene::Mode mode) +{ + if (mode == GraphicsScene::Big) + setPixmap(":/big/" + name); + else + setPixmap(":/small/" + name); +} diff --git a/examples/animation/sub-attaq/pixmapitem.h b/examples/animation/sub-attaq/pixmapitem.h new file mode 100644 index 0000000..31022c1 --- /dev/null +++ b/examples/animation/sub-attaq/pixmapitem.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __PIXMAPITEM__H__ +#define __PIXMAPITEM__H__ + +//Own +#include "graphicsscene.h" + +//Qt +#include <QtGui/QGraphicsPixmapItem> + +class PixmapItem : public QGraphicsPixmapItem +{ +public: + PixmapItem(const QString &fileName, GraphicsScene::Mode mode, QGraphicsItem * parent = 0); + +private: + void loadPixmap(GraphicsScene::Mode mode); + + QString name; + QPixmap pixmap; +}; + +#endif //__PIXMAPITEM__H__ diff --git a/examples/animation/sub-attaq/progressitem.cpp b/examples/animation/sub-attaq/progressitem.cpp new file mode 100644 index 0000000..59ccb9a --- /dev/null +++ b/examples/animation/sub-attaq/progressitem.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "progressitem.h" +#include "pixmapitem.h" + +ProgressItem::ProgressItem (QGraphicsItem * parent) + : QGraphicsTextItem(parent), currentLevel(1), currentScore(0) +{ + setFont(QFont("Comic Sans MS")); + setPos(parentItem()->boundingRect().topRight() - QPointF(180, -5)); +} + +void ProgressItem::setLevel(int level) +{ + currentLevel = level; + updateProgress(); +} + +void ProgressItem::setScore(int score) +{ + currentScore = score; + updateProgress(); +} + +void ProgressItem::updateProgress() +{ + setHtml(QString("Level : %1 Score : %2").arg(currentLevel).arg(currentScore)); +} diff --git a/examples/animation/sub-attaq/progressitem.h b/examples/animation/sub-attaq/progressitem.h new file mode 100644 index 0000000..7b8db4d --- /dev/null +++ b/examples/animation/sub-attaq/progressitem.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PROGRESSITEM_H +#define PROGRESSITEM_H + +//Qt +#include <QtGui/QGraphicsTextItem> + +class ProgressItem : public QGraphicsTextItem +{ +public: + ProgressItem(QGraphicsItem * parent = 0); + void setLevel(int level); + void setScore(int score); + +private: + void updateProgress(); + int currentLevel; + int currentScore; +}; + +#endif // PROGRESSITEM_H diff --git a/examples/animation/sub-attaq/qanimationstate.cpp b/examples/animation/sub-attaq/qanimationstate.cpp new file mode 100644 index 0000000..d4d109c --- /dev/null +++ b/examples/animation/sub-attaq/qanimationstate.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qanimationstate.h" + +#include <QtCore/qstate.h> + +QT_BEGIN_NAMESPACE + +/*! +\class QAnimationState + +\brief The QAnimationState class provides state that handle an animation and emit +a signal when this animation is finished. + +\ingroup statemachine + +QAnimationState provides a state that handle an animation. It will start this animation +when the state is entered and stop it when it is leaved. When the animation has finished the +state emit animationFinished signal. +QAnimationState is part of \l{The State Machine Framework}. + +\code +QStateMachine machine; +QAnimationState *s = new QAnimationState(machine->rootState()); +QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos"); +s->setAnimation(animation); +QState *s2 = new QState(machine->rootState()); +s->addTransition(s, SIGNAL(animationFinished()), s2); +machine.start(); +\endcode + +\sa QState, {The Animation Framework} +*/ + + +#ifndef QT_NO_ANIMATION + +/*! + Constructs a new state with the given \a parent state. +*/ +QAnimationState::QAnimationState(QState *parent) + : QState(parent), m_animation(0) +{ +} + +/*! + Destroys the animation state. +*/ +QAnimationState::~QAnimationState() +{ +} + +/*! + Set an \a animation for this QAnimationState. If an animation was previously handle by this + state then it won't emit animationFinished for the old animation. The QAnimationState doesn't + take the ownership of the animation. +*/ +void QAnimationState::setAnimation(QAbstractAnimation *animation) +{ + if (animation == m_animation) + return; + + //Disconnect from the previous animation if exist + if(m_animation) + disconnect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished())); + + m_animation = animation; + + if (m_animation) { + //connect the new animation + connect(m_animation, SIGNAL(finished()), this, SIGNAL(animationFinished())); + } +} + +/*! + Returns the animation handle by this animation state, or 0 if there is no animation. +*/ +QAbstractAnimation* QAnimationState::animation() const +{ + return m_animation; +} + +/*! + \reimp +*/ +void QAnimationState::onEntry(QEvent *) +{ + if (m_animation) + m_animation->start(); +} + +/*! + \reimp +*/ +void QAnimationState::onExit(QEvent *) +{ + if (m_animation) + m_animation->stop(); +} + +/*! + \reimp +*/ +bool QAnimationState::event(QEvent *e) +{ + return QState::event(e); +} + +QT_END_NAMESPACE + +#endif diff --git a/examples/animation/sub-attaq/qanimationstate.h b/examples/animation/sub-attaq/qanimationstate.h new file mode 100644 index 0000000..72bb2d9 --- /dev/null +++ b/examples/animation/sub-attaq/qanimationstate.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the QtGui 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANIMATIONSTATE_H +#define QANIMATIONSTATE_H + +#ifndef QT_STATEMACHINE_SOLUTION +# include <QtCore/qstate.h> +# include <QtCore/qabstractanimation.h> +#else +# include "qstate.h" +# include "qabstractanimation.h" +#endif + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +#ifndef QT_NO_ANIMATION + +class QAbstractAnimation; + +class QAnimationState : public QState +{ + Q_OBJECT +public: + QAnimationState(QState *parent = 0); + ~QAnimationState(); + + void setAnimation(QAbstractAnimation *animation); + QAbstractAnimation* animation() const; + +signals: + void animationFinished(); + +protected: + void onEntry(QEvent *); + void onExit(QEvent *); + bool event(QEvent *e); + +private: + Q_DISABLE_COPY(QAnimationState) + QAbstractAnimation *m_animation; +}; + +#endif + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QANIMATIONSTATE_H diff --git a/examples/animation/sub-attaq/states.cpp b/examples/animation/sub-attaq/states.cpp new file mode 100644 index 0000000..adc8bd0 --- /dev/null +++ b/examples/animation/sub-attaq/states.cpp @@ -0,0 +1,325 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "states.h" +#include "graphicsscene.h" +#include "boat.h" +#include "submarine.h" +#include "torpedo.h" +#include "animationmanager.h" +#include "progressitem.h" + +//Qt +#include <QtGui/QMessageBox> +#include <QtGui/QGraphicsView> +#include <QtCore/QStateMachine> +#include <QtGui/QKeyEventTransition> +#include <QtCore/QSignalEvent> +#include <QtCore/QFinalState> + +PlayState::PlayState(GraphicsScene *scene, QState *parent) + : QState(parent), + scene(scene), + machine(0), + currentLevel(0), + score(0) +{ +} + +PlayState::~PlayState() +{ +} + +void PlayState::onEntry(QEvent *) +{ + //We are now playing? + if (machine) { + machine->stop(); + scene->clearScene(); + currentLevel = 0; + score = 0; + delete machine; + } + + machine = new QStateMachine(this); + + //This state is when player is playing + LevelState *levelState = new LevelState(scene, this, machine->rootState()); + + //This state is when the player is actually playing but the game is not paused + QState *playingState = new QState(levelState); + levelState->setInitialState(playingState); + + //This state is when the game is paused + PauseState *pauseState = new PauseState(scene, levelState); + + //We have one view, it receive the key press event + QKeyEventTransition *pressPplay = new QKeyEventTransition(scene->views().at(0), QEvent::KeyPress, Qt::Key_P); + pressPplay->setTargetState(pauseState); + QKeyEventTransition *pressPpause = new QKeyEventTransition(scene->views().at(0), QEvent::KeyPress, Qt::Key_P); + pressPpause->setTargetState(playingState); + + //Pause "P" is triggered, the player pause the game + playingState->addTransition(pressPplay); + + //To get back playing when the game has been paused + pauseState->addTransition(pressPpause); + + //This state is when player have lost + LostState *lostState = new LostState(scene, this, machine->rootState()); + + //This state is when player have won + WinState *winState = new WinState(scene, this, machine->rootState()); + + //The boat has been destroyed then the game is finished + levelState->addTransition(scene->boat, SIGNAL(boatExecutionFinished()),lostState); + + //This transition check if we won or not + WinTransition *winTransition = new WinTransition(scene, this, winState); + + //The boat has been destroyed then the game is finished + levelState->addTransition(winTransition); + + //This state is an animation when the score changed + UpdateScoreState *scoreState = new UpdateScoreState(this, levelState); + + //This transition update the score when a submarine die + UpdateScoreTransition *scoreTransition = new UpdateScoreTransition(scene, this, levelState); + scoreTransition->setTargetState(scoreState); + + //The boat has been destroyed then the game is finished + playingState->addTransition(scoreTransition); + + //We go back to play state + scoreState->addTransition(playingState); + + //We start playing!!! + machine->setInitialState(levelState); + + //Final state + QFinalState *final = new QFinalState(machine->rootState()); + + //This transition is triggered when the player press space after completing a level + CustomSpaceTransition *spaceTransition = new CustomSpaceTransition(scene->views().at(0), this, QEvent::KeyPress, Qt::Key_Space); + spaceTransition->setTargetState(levelState); + winState->addTransition(spaceTransition); + + //We lost we should reach the final state + lostState->addTransition(lostState, SIGNAL(finished()), final); + + machine->start(); +} + +LevelState::LevelState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game) +{ +} +void LevelState::onEntry(QEvent *) +{ + initializeLevel(); +} + +void LevelState::initializeLevel() +{ + //we re-init the boat + scene->boat->setPos(scene->width()/2, scene->sealLevel() - scene->boat->size().height()); + scene->boat->setCurrentSpeed(0); + scene->boat->setCurrentDirection(Boat::None); + scene->boat->setBombsLaunched(0); + scene->boat->show(); + scene->setFocusItem(scene->boat,Qt::OtherFocusReason); + scene->boat->run(); + + scene->progressItem->setScore(game->score); + scene->progressItem->setLevel(game->currentLevel + 1); + + GraphicsScene::LevelDescription currentLevelDescription = scene->levelsData.value(game->currentLevel); + + for (int i = 0; i < currentLevelDescription.submarines.size(); ++i ) { + + QPair<int,int> subContent = currentLevelDescription.submarines.at(i); + GraphicsScene::SubmarineDescription submarineDesc = scene->submarinesData.at(subContent.first); + + for (int j = 0; j < subContent.second; ++j ) { + SubMarine *sub = new SubMarine(submarineDesc.type, submarineDesc.name, submarineDesc.points); + scene->addItem(sub); + int random = (qrand() % 15 + 1); + qreal x = random == 13 || random == 5 ? 0 : scene->width() - sub->size().width(); + qreal y = scene->height() -(qrand() % 150 + 1) - sub->size().height(); + sub->setPos(x,y); + sub->setCurrentDirection(x == 0 ? SubMarine::Right : SubMarine::Left); + sub->setCurrentSpeed(qrand() % 3 + 1); + } + } +} + +/** Pause State */ +PauseState::PauseState(GraphicsScene *scene, QState *parent) : QState(parent),scene(scene) +{ +} +void PauseState::onEntry(QEvent *) +{ + AnimationManager::self()->pauseAll(); + scene->boat->setEnabled(false); +} +void PauseState::onExit(QEvent *) +{ + AnimationManager::self()->resumeAll(); + scene->boat->setEnabled(true); + scene->boat->setFocus(); +} + +/** Lost State */ +LostState::LostState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game) +{ +} + +void LostState::onEntry(QEvent *) +{ + //The message to display + QString message = QString("You lose on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); + + //We set the level back to 0 + game->currentLevel = 0; + + //We set the score back to 0 + game->score = 0; + + //We clear the scene + scene->clearScene(); + + //we have only one view + QMessageBox::information(scene->views().at(0),"You lose",message); +} + +/** Win State */ +WinState::WinState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game) +{ +} + +void WinState::onEntry(QEvent *) +{ + //We clear the scene + scene->clearScene(); + + 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); + //We increment the level number + game->currentLevel++; + } else { + message = QString("You finish the game on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); + //We set the level back to 0 + game->currentLevel = 0; + //We set the score back to 0 + game->score = 0; + } + + //we have only one view + QMessageBox::information(scene->views().at(0),"You win",message); +} + +/** UpdateScore State */ +UpdateScoreState::UpdateScoreState(PlayState *game, QState *parent) : QState(parent) +{ + this->game = game; +} +void UpdateScoreState::onEntry(QEvent *e) +{ + QState::onEntry(e); +} + +/** Win transition */ +UpdateScoreTransition::UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target) + : QSignalTransition(scene,SIGNAL(subMarineDestroyed(int)), QList<QAbstractState*>() << target), + game(game), scene(scene) +{ +} + +bool UpdateScoreTransition::eventTest(QEvent *event) +{ + if (!QSignalTransition::eventTest(event)) + return false; + else { + QSignalEvent *se = static_cast<QSignalEvent*>(event); + game->score += se->arguments().at(0).toInt(); + scene->progressItem->setScore(game->score); + return true; + } +} + +/** Win transition */ +WinTransition::WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target) + : QSignalTransition(scene,SIGNAL(allSubMarineDestroyed(int)), QList<QAbstractState*>() << target), + game(game), scene(scene) +{ +} + +bool WinTransition::eventTest(QEvent *event) +{ + if (!QSignalTransition::eventTest(event)) + return false; + else { + QSignalEvent *se = static_cast<QSignalEvent*>(event); + game->score += se->arguments().at(0).toInt(); + scene->progressItem->setScore(game->score); + return true; + } +} + +/** Space transition */ +CustomSpaceTransition::CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key) + : QKeyEventTransition(widget, type, key), + game(game) +{ +} + +bool CustomSpaceTransition::eventTest(QEvent *event) +{ + Q_UNUSED(event); + if (!QKeyEventTransition::eventTest(event)) + return false; + if (game->currentLevel != 0) + return true; + else + return false; + +} diff --git a/examples/animation/sub-attaq/states.h b/examples/animation/sub-attaq/states.h new file mode 100644 index 0000000..71375e0 --- /dev/null +++ b/examples/animation/sub-attaq/states.h @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef STATES_H +#define STATES_H + +//Qt +#include <QtCore/QState> +#include <QtCore/QSignalTransition> +#include <QtCore/QPropertyAnimation> +#include <QtGui/QKeyEventTransition> +#include <QtCore/QSet> + +class GraphicsScene; +class Boat; +class SubMarine; +QT_BEGIN_NAMESPACE +class QStateMachine; +QT_END_NAMESPACE + +class PlayState : public QState +{ +public: + PlayState(GraphicsScene *scene, QState *parent = 0); + ~PlayState(); + + protected: + void onEntry(QEvent *); + +private : + GraphicsScene *scene; + QStateMachine *machine; + int currentLevel; + int score; + QState *parallelChild; + + friend class UpdateScoreState; + friend class UpdateScoreTransition; + friend class WinTransition; + friend class CustomSpaceTransition; + friend class WinState; + friend class LostState; + friend class LevelState; +}; + +class LevelState : public QState +{ +public: + LevelState(GraphicsScene *scene, PlayState *game, QState *parent = 0); +protected: + void onEntry(QEvent *); +private : + void initializeLevel(); + GraphicsScene *scene; + PlayState *game; +}; + +class PauseState : public QState +{ +public: + PauseState(GraphicsScene *scene, QState *parent = 0); + +protected: + void onEntry(QEvent *); + void onExit(QEvent *); +private : + GraphicsScene *scene; + Boat *boat; +}; + +class LostState : public QState +{ +public: + LostState(GraphicsScene *scene, PlayState *game, QState *parent = 0); + +protected: + void onEntry(QEvent *); +private : + GraphicsScene *scene; + PlayState *game; +}; + +class WinState : public QState +{ +public: + WinState(GraphicsScene *scene, PlayState *game, QState *parent = 0); + +protected: + void onEntry(QEvent *); +private : + GraphicsScene *scene; + PlayState *game; +}; + +class UpdateScoreState : public QState +{ +public: + UpdateScoreState(PlayState *game, QState *parent); +protected: + void onEntry(QEvent *); +private: + QPropertyAnimation *scoreAnimation; + PlayState *game; +}; + +//These transtion is used to update the score +class UpdateScoreTransition : public QSignalTransition +{ +public: + UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target); +protected: + virtual bool eventTest(QEvent *event); +private: + PlayState * game; + GraphicsScene *scene; +}; + +//These transtion test if we have won the game +class WinTransition : public QSignalTransition +{ +public: + WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target); +protected: + virtual bool eventTest(QEvent *event); +private: + PlayState * game; + GraphicsScene *scene; +}; + +//These transtion is true if one level has been completed and the player want to continue + class CustomSpaceTransition : public QKeyEventTransition +{ +public: + CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key); +protected: + virtual bool eventTest(QEvent *event); +private: + PlayState *game; + int key; +}; + +#endif // STATES_H diff --git a/examples/animation/sub-attaq/sub-attaq.pro b/examples/animation/sub-attaq/sub-attaq.pro new file mode 100644 index 0000000..d13a099 --- /dev/null +++ b/examples/animation/sub-attaq/sub-attaq.pro @@ -0,0 +1,36 @@ +contains(QT_CONFIG, opengl):QT += opengl + +HEADERS += boat.h \ + bomb.h \ + mainwindow.h \ + submarine.h \ + torpedo.h \ + pixmapitem.h \ + graphicsscene.h \ + animationmanager.h \ + states.h \ + boat_p.h \ + submarine_p.h \ + custompropertyanimation.h \ + qanimationstate.h \ + progressitem.h +SOURCES += boat.cpp \ + bomb.cpp \ + main.cpp \ + mainwindow.cpp \ + submarine.cpp \ + torpedo.cpp \ + pixmapitem.cpp \ + graphicsscene.cpp \ + animationmanager.cpp \ + states.cpp \ + custompropertyanimation.cpp \ + qanimationstate.cpp \ + progressitem.cpp +RESOURCES += subattaq.qrc + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/animation/sub-attaq +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS sub-attaq.pro pics +sources.path = $$[QT_INSTALL_EXAMPLES]/animation/sub-attaq +INSTALLS += target sources diff --git a/examples/animation/sub-attaq/subattaq.qrc b/examples/animation/sub-attaq/subattaq.qrc new file mode 100644 index 0000000..80a3af1 --- /dev/null +++ b/examples/animation/sub-attaq/subattaq.qrc @@ -0,0 +1,39 @@ +<RCC> + <qresource prefix="/" > + <file alias="all" >pics/scalable/sub-attaq.svg</file> + <file alias="submarine" >pics/scalable/submarine.svg</file> + <file alias="boat" >pics/scalable/boat.svg</file> + <file alias="torpedo" >pics/scalable/torpedo.svg</file> + <file alias="logo-s" >pics/welcome/logo-s.png</file> + <file alias="logo-u" >pics/welcome/logo-u.png</file> + <file alias="logo-b" >pics/welcome/logo-b.png</file> + <file alias="logo-dash" >pics/welcome/logo-dash.png</file> + <file alias="logo-a" >pics/welcome/logo-a.png</file> + <file alias="logo-t" >pics/welcome/logo-t.png</file> + <file alias="logo-t2" >pics/welcome/logo-t2.png</file> + <file alias="logo-a2" >pics/welcome/logo-a2.png</file> + <file alias="logo-q" >pics/welcome/logo-q.png</file> + <file alias="logo-excl" >pics/welcome/logo-excl.png</file> + <file alias="big/background" >pics/big/background.png</file> + <file alias="big/boat" >pics/big/boat.png</file> + <file alias="big/bomb" >pics/big/bomb.png</file> + <file alias="big/submarine" >pics/big/submarine.png</file> + <file alias="big/surface" >pics/big/surface.png</file> + <file alias="big/torpedo" >pics/big/torpedo.png</file> + <file alias="small/background" >pics/small/background.png</file> + <file alias="small/boat" >pics/small/boat.png</file> + <file alias="small/bomb" >pics/small/bomb.png</file> + <file alias="small/submarine" >pics/small/submarine.png</file> + <file alias="small/surface" >pics/small/surface.png</file> + <file alias="small/torpedo" >pics/small/torpedo.png</file> + <file alias="big/explosion/boat/step1" >pics/big/explosion/boat/step1.png</file> + <file alias="big/explosion/boat/step2" >pics/big/explosion/boat/step2.png</file> + <file alias="big/explosion/boat/step3" >pics/big/explosion/boat/step3.png</file> + <file alias="big/explosion/boat/step4" >pics/big/explosion/boat/step4.png</file> + <file alias="big/explosion/submarine/step1" >pics/big/explosion/submarine/step1.png</file> + <file alias="big/explosion/submarine/step2" >pics/big/explosion/submarine/step2.png</file> + <file alias="big/explosion/submarine/step3" >pics/big/explosion/submarine/step3.png</file> + <file alias="big/explosion/submarine/step4" >pics/big/explosion/submarine/step4.png</file> + <file>data.xml</file> + </qresource> +</RCC> diff --git a/examples/animation/sub-attaq/submarine.cpp b/examples/animation/sub-attaq/submarine.cpp new file mode 100644 index 0000000..d8cf1da --- /dev/null +++ b/examples/animation/sub-attaq/submarine.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "submarine.h" +#include "submarine_p.h" +#include "torpedo.h" +#include "pixmapitem.h" +#include "graphicsscene.h" +#include "animationmanager.h" +#include "custompropertyanimation.h" +#include "qanimationstate.h" + +#include <QtCore/QPropertyAnimation> +#include <QtCore/QStateMachine> +#include <QtCore/QFinalState> +#include <QtCore/QSequentialAnimationGroup> + +static QAbstractAnimation *setupDestroyAnimation(SubMarine *sub) +{ + QSequentialAnimationGroup *group = new QSequentialAnimationGroup(sub); +#if QT_VERSION >=0x040500 + PixmapItem *step1 = new PixmapItem(QString("explosion/submarine/step1"),GraphicsScene::Big, sub); + step1->setZValue(6); + PixmapItem *step2 = new PixmapItem(QString("explosion/submarine/step2"),GraphicsScene::Big, sub); + step2->setZValue(6); + PixmapItem *step3 = new PixmapItem(QString("explosion/submarine/step3"),GraphicsScene::Big, sub); + step3->setZValue(6); + PixmapItem *step4 = new PixmapItem(QString("explosion/submarine/step4"),GraphicsScene::Big, sub); + step4->setZValue(6); + step1->setOpacity(0); + step2->setOpacity(0); + step3->setOpacity(0); + step4->setOpacity(0); + CustomPropertyAnimation *anim1 = new CustomPropertyAnimation(sub); + anim1->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim1->setDuration(100); + anim1->setEndValue(1); + CustomPropertyAnimation *anim2 = new CustomPropertyAnimation(sub); + anim2->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim2->setDuration(100); + anim2->setEndValue(1); + CustomPropertyAnimation *anim3 = new CustomPropertyAnimation(sub); + anim3->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim3->setDuration(100); + anim3->setEndValue(1); + CustomPropertyAnimation *anim4 = new CustomPropertyAnimation(sub); + anim4->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity); + anim4->setDuration(100); + anim4->setEndValue(1); + group->addAnimation(anim1); + group->addAnimation(anim2); + group->addAnimation(anim3); + group->addAnimation(anim4); +#else + // work around for a bug where we don't transition if the duration is zero. + QtPauseAnimation *anim = new QtPauseAnimation(group); + anim->setDuration(1); + group->addAnimation(anim); +#endif + AnimationManager::self()->registerAnimation(group); + return group; +} + + +SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * parent, Qt::WindowFlags wFlags) + : QGraphicsWidget(parent,wFlags), subType(type), subName(name), subPoints(points), speed(0), direction(SubMarine::None) +{ + pixmapItem = new PixmapItem(QString("submarine"),GraphicsScene::Big, this); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setZValue(5); + setFlags(QGraphicsItem::ItemIsMovable); + resize(pixmapItem->boundingRect().width(),pixmapItem->boundingRect().height()); + setTransformOrigin(boundingRect().center()); + + //We setup the state machine of the submarine + QStateMachine *machine = new QStateMachine(this); + + //This state is when the boat is moving/rotating + QState *moving = new QState(machine->rootState()); + + //This state is when the boat is moving from left to right + MovementState *movement = new MovementState(this, moving); + + //This state is when the boat is moving from left to right + ReturnState *rotation = new ReturnState(this, moving); + + //This is the initial state of the moving root state + moving->setInitialState(movement); + + movement->addTransition(this, SIGNAL(subMarineStateChanged()), moving); + + //This is the initial state of the machine + machine->setInitialState(moving); + + //End + QFinalState *final = new QFinalState(machine->rootState()); + + //If the moving animation is finished we move to the return state + movement->addTransition(movement, SIGNAL(animationFinished()), rotation); + + //If the return animation is finished we move to the moving state + rotation->addTransition(rotation, SIGNAL(animationFinished()), movement); + + //This state play the destroyed animation + QAnimationState *destroyedState = new QAnimationState(machine->rootState()); + destroyedState->setAnimation(setupDestroyAnimation(this)); + + //Play a nice animation when the submarine is destroyed + moving->addTransition(this, SIGNAL(subMarineDestroyed()), destroyedState); + + //Transition to final state when the destroyed animation is finished + destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final); + + //The machine has finished to be executed, then the submarine is dead + connect(machine,SIGNAL(finished()),this, SIGNAL(subMarineExecutionFinished())); + + machine->start(); +} + +int SubMarine::points() +{ + return subPoints; +} + +void SubMarine::setCurrentDirection(SubMarine::Movement direction) +{ + if (this->direction == direction) + return; + if (direction == SubMarine::Right && this->direction == SubMarine::None) { + setYRotation(180); + } + this->direction = direction; +} + +enum SubMarine::Movement SubMarine::currentDirection() const +{ + return direction; +} + +void SubMarine::setCurrentSpeed(int speed) +{ + if (speed < 0 || speed > 3) { + qWarning("SubMarine::setCurrentSpeed : The speed is invalid"); + } + this->speed = speed; + emit subMarineStateChanged(); +} + +int SubMarine::currentSpeed() const +{ + return speed; +} + +void SubMarine::launchTorpedo(int speed) +{ + Torpedo * torp = new Torpedo(); + GraphicsScene *scene = static_cast<GraphicsScene *>(this->scene()); + scene->addItem(torp); + torp->setPos(x(), y()); + torp->setCurrentSpeed(speed); + torp->launch(); +} + +void SubMarine::destroy() +{ + emit subMarineDestroyed(); +} + +int SubMarine::type() const +{ + return Type; +} diff --git a/examples/animation/sub-attaq/submarine.h b/examples/animation/sub-attaq/submarine.h new file mode 100644 index 0000000..b8dd2da --- /dev/null +++ b/examples/animation/sub-attaq/submarine.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __SUBMARINE__H__ +#define __SUBMARINE__H__ + +//Qt +#include <QtCore/QVariantAnimation> +#include <QtGui/QGraphicsWidget> + +class PixmapItem; + +class Torpedo; + +class SubMarine : public QGraphicsWidget +{ +Q_OBJECT +public: + enum Movement { + None = 0, + Left, + Right + }; + enum { Type = UserType + 1 }; + SubMarine(int type, const QString &name, int points, QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0); + + int points(); + + void setCurrentDirection(Movement direction); + enum Movement currentDirection() const; + + void setCurrentSpeed(int speed); + int currentSpeed() const; + + void launchTorpedo(int speed); + void destroy(); + + virtual int type() const; + +signals: + void subMarineDestroyed(); + void subMarineExecutionFinished(); + void subMarineStateChanged(); + +private: + int subType; + QString subName; + int subPoints; + int speed; + Movement direction; + PixmapItem *pixmapItem; +}; + +#endif //__SUBMARINE__H__ diff --git a/examples/animation/sub-attaq/submarine_p.h b/examples/animation/sub-attaq/submarine_p.h new file mode 100644 index 0000000..8c31eb7 --- /dev/null +++ b/examples/animation/sub-attaq/submarine_p.h @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SUBMARINE_P_H +#define SUBMARINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +//Own +#include "animationmanager.h" +#include "submarine.h" +#include "qanimationstate.h" + +//Qt +#include <QtCore/QPropertyAnimation> +#include <QtGui/QGraphicsScene> + +//This state is describing when the boat is moving right +class MovementState : public QAnimationState +{ +Q_OBJECT +public: + MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent) + { + movementAnimation = new QPropertyAnimation(submarine, "pos"); + connect(movementAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationMovementValueChanged(const QVariant &))); + setAnimation(movementAnimation); + AnimationManager::self()->registerAnimation(movementAnimation); + this->submarine = submarine; + } + +protected slots: + void onAnimationMovementValueChanged(const QVariant &) + { + if (qrand() % 200 + 1 == 3) + submarine->launchTorpedo(qrand() % 3 + 1); + } + +protected: + void onEntry(QEvent *e) + { + if (submarine->currentDirection() == SubMarine::Left) { + movementAnimation->setEndValue(QPointF(0,submarine->y())); + movementAnimation->setDuration(submarine->x()/submarine->currentSpeed()*12); + } + else /*if (submarine->currentDirection() == SubMarine::Right)*/ { + movementAnimation->setEndValue(QPointF(submarine->scene()->width()-submarine->size().width(),submarine->y())); + movementAnimation->setDuration((submarine->scene()->width()-submarine->size().width()-submarine->x())/submarine->currentSpeed()*12); + } + movementAnimation->setStartValue(submarine->pos()); + QAnimationState::onEntry(e); + } + +private: + SubMarine *submarine; + QPropertyAnimation *movementAnimation; +}; + +//This state is describing when the boat is moving right +class ReturnState : public QAnimationState +{ +public: + ReturnState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent) + { + returnAnimation = new QPropertyAnimation(submarine, "yRotation"); + AnimationManager::self()->registerAnimation(returnAnimation); + setAnimation(returnAnimation); + this->submarine = submarine; + } + +protected: + void onEntry(QEvent *e) + { + returnAnimation->stop(); + returnAnimation->setStartValue(submarine->yRotation()); + returnAnimation->setEndValue(submarine->currentDirection() == SubMarine::Right ? 360. : 180.); + returnAnimation->setDuration(500); + QAnimationState::onEntry(e); + } + + void onExit(QEvent *e) + { + submarine->currentDirection() == SubMarine::Right ? submarine->setCurrentDirection(SubMarine::Left) : submarine->setCurrentDirection(SubMarine::Right); + QAnimationState::onExit(e); + } + +private: + SubMarine *submarine; + QPropertyAnimation *returnAnimation; +}; + +#endif // SUBMARINE_P_H diff --git a/examples/animation/sub-attaq/torpedo.cpp b/examples/animation/sub-attaq/torpedo.cpp new file mode 100644 index 0000000..02a54fc --- /dev/null +++ b/examples/animation/sub-attaq/torpedo.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//Own +#include "torpedo.h" +#include "pixmapitem.h" +#include "boat.h" +#include "graphicsscene.h" +#include "animationmanager.h" +#include "qanimationstate.h" + +#include <QtCore/QPropertyAnimation> +#include <QtCore/QStateMachine> +#include <QtCore/QFinalState> + +Torpedo::Torpedo(QGraphicsItem * parent, Qt::WindowFlags wFlags) + : QGraphicsWidget(parent,wFlags), currentSpeed(0), launchAnimation(0) +{ + pixmapItem = new PixmapItem(QString::fromLatin1("torpedo"),GraphicsScene::Big, this); + setZValue(2); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFlags(QGraphicsItem::ItemIsMovable); + resize(pixmapItem->boundingRect().size()); +} + +void Torpedo::launch() +{ + launchAnimation = new QPropertyAnimation(this, "pos"); + AnimationManager::self()->registerAnimation(launchAnimation); + launchAnimation->setEndValue(QPointF(x(),qobject_cast<GraphicsScene *>(scene())->sealLevel() - 15)); + launchAnimation->setEasingCurve(QEasingCurve::InQuad); + launchAnimation->setDuration(y()/currentSpeed*10); + connect(launchAnimation,SIGNAL(valueChanged(const QVariant &)),this,SLOT(onAnimationLaunchValueChanged(const QVariant &))); + + //We setup the state machine of the torpedo + QStateMachine *machine = new QStateMachine(this); + + //This state is when the launch animation is playing + QAnimationState *launched = new QAnimationState(machine->rootState()); + launched->setAnimation(launchAnimation); + + //End + QFinalState *final = new QFinalState(machine->rootState()); + + machine->setInitialState(launched); + + //### Add a nice animation when the torpedo is destroyed + launched->addTransition(this, SIGNAL(torpedoExplosed()),final); + + //If the animation is finished, then we move to the final state + launched->addTransition(launched, SIGNAL(animationFinished()), final); + + //The machine has finished to be executed, then the boat is dead + connect(machine,SIGNAL(finished()),this, SIGNAL(torpedoExecutionFinished())); + + machine->start(); +} + +void Torpedo::setCurrentSpeed(int speed) +{ + if (speed < 0) { + qWarning("Torpedo::setCurrentSpeed : The speed is invalid"); + return; + } + currentSpeed = speed; +} + +void Torpedo::onAnimationLaunchValueChanged(const QVariant &) +{ + foreach (QGraphicsItem *item , collidingItems(Qt::IntersectsItemBoundingRect)) { + if (item->type() == Boat::Type) { + Boat *b = static_cast<Boat *>(item); + b->destroy(); + } + } +} + +void Torpedo::destroy() +{ + launchAnimation->stop(); + emit torpedoExplosed(); +} diff --git a/examples/animation/sub-attaq/torpedo.h b/examples/animation/sub-attaq/torpedo.h new file mode 100644 index 0000000..f5ab614 --- /dev/null +++ b/examples/animation/sub-attaq/torpedo.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __TORPEDO__H__ +#define __TORPEDO__H__ + +//Qt +#include <QtCore/QObject> + +#include <QtCore/QVariantAnimation> +#include <QtGui/QGraphicsWidget> + +class PixmapItem; + +class Torpedo : public QGraphicsWidget +{ +Q_OBJECT +public: + Torpedo(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0); + void launch(); + void setCurrentSpeed(int speed); + void destroy(); + +signals: + void torpedoExplosed(); + void torpedoExecutionFinished(); + +private slots: + void onAnimationLaunchValueChanged(const QVariant &); + +private: + int currentSpeed; + PixmapItem *pixmapItem; + QVariantAnimation *launchAnimation; +}; + +#endif //__TORPEDO__H__ diff --git a/examples/dialogs/sipdialog/dialog.cpp b/examples/dialogs/sipdialog/dialog.cpp index 9f1b9ad..653b518 100644 --- a/examples/dialogs/sipdialog/dialog.cpp +++ b/examples/dialogs/sipdialog/dialog.cpp @@ -90,7 +90,7 @@ Dialog::Dialog() //! [Dialog constructor part4] //! [Dialog constructor part5] - connect(button, SIGNAL(pressed()), + connect(button, SIGNAL(clicked()), qApp, SLOT(closeAllWindows())); connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), this, SLOT(desktopResized(int))); @@ -111,14 +111,13 @@ void Dialog::reactToSIP() { QRect availableGeometry = QApplication::desktop()->availableGeometry(0); - if (desktopGeometry.width() == availableGeometry.width()) { - if (desktopGeometry.height() > availableGeometry.height()) { + if (desktopGeometry != availableGeometry) { + if (windowState() | Qt::WindowMaximized) setWindowState(windowState() & ~Qt::WindowMaximized); - setGeometry(availableGeometry); - } else { - setWindowState(windowState() | Qt::WindowMaximized); - } + + setGeometry(availableGeometry); } + desktopGeometry = availableGeometry; } //! [reactToSIP() function] diff --git a/examples/dialogs/sipdialog/main.cpp b/examples/dialogs/sipdialog/main.cpp index 5fcbfd8..fec6de2 100644 --- a/examples/dialogs/sipdialog/main.cpp +++ b/examples/dialogs/sipdialog/main.cpp @@ -48,6 +48,6 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); Dialog dialog; - dialog.exec(); + return dialog.exec(); } //! [main() function] diff --git a/examples/examples.pro b/examples/examples.pro index 41501a0..bfcf9b4 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs SUBDIRS = \ + animation \ desktop \ dialogs \ draganddrop \ @@ -14,6 +15,7 @@ SUBDIRS = \ qtconcurrent \ richtext \ sql \ + statemachine \ threads \ tools \ tutorials \ diff --git a/examples/itemviews/puzzle/puzzle.pro b/examples/itemviews/puzzle/puzzle.pro index deed112..4f5aaad 100644 --- a/examples/itemviews/puzzle/puzzle.pro +++ b/examples/itemviews/puzzle/puzzle.pro @@ -12,3 +12,8 @@ target.path = $$[QT_INSTALL_EXAMPLES]/itemviews/puzzle sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.jpg sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/puzzle INSTALLS += target sources + +wince* { + DEPLOYMENT_PLUGIN += qjpeg qgif qtiff +} + diff --git a/examples/network/googlesuggest/googlesuggest.pro b/examples/network/googlesuggest/googlesuggest.pro index afd600f..33b79de 100644 --- a/examples/network/googlesuggest/googlesuggest.pro +++ b/examples/network/googlesuggest/googlesuggest.pro @@ -3,7 +3,7 @@ SOURCES = main.cpp searchbox.cpp googlesuggest.cpp HEADERS = searchbox.h googlesuggest.h # install -target.path = $$[QT_INSTALL_EXAMPLES]/webkit/googlesuggest +target.path = $$[QT_INSTALL_EXAMPLES]/network/googlesuggest sources.files = $$SOURCES $$HEADERS *.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/googlesuggest +sources.path = $$[QT_INSTALL_EXAMPLES]/network/googlesuggest INSTALLS += target sources diff --git a/examples/opengl/framebufferobject/glwidget.cpp b/examples/opengl/framebufferobject/glwidget.cpp index d3591d6..3cb3929 100644 --- a/examples/opengl/framebufferobject/glwidget.cpp +++ b/examples/opengl/framebufferobject/glwidget.cpp @@ -53,7 +53,18 @@ GLWidget::GLWidget(QWidget *parent) { setWindowTitle(tr("OpenGL framebuffer objects")); makeCurrent(); - fbo = new QGLFramebufferObject(1024, 1024); + + if (QGLFramebufferObject::hasOpenGLFramebufferBlit()) { + QGLFramebufferObjectFormat format; + format.setSamples(4); + + render_fbo = new QGLFramebufferObject(512, 512, format); + texture_fbo = new QGLFramebufferObject(512, 512); + } else { + render_fbo = new QGLFramebufferObject(1024, 1024); + texture_fbo = render_fbo; + } + rot_x = rot_y = rot_z = 0.0f; scale = 0.1f; anim = new QTimeLine(750, this); @@ -113,7 +124,9 @@ GLWidget::~GLWidget() { delete[] wave; glDeleteLists(tile_list, 1); - delete fbo; + delete texture_fbo; + if (render_fbo != texture_fbo) + delete render_fbo; } void GLWidget::paintEvent(QPaintEvent *) @@ -129,10 +142,16 @@ void GLWidget::draw() saveGLState(); // render the 'bubbles.svg' file into our framebuffer object - QPainter fbo_painter(fbo); + QPainter fbo_painter(render_fbo); svg_renderer->render(&fbo_painter); fbo_painter.end(); + if (render_fbo != texture_fbo) { + QRect rect(0, 0, render_fbo->width(), render_fbo->height()); + QGLFramebufferObject::blitFramebuffer(texture_fbo, rect, + render_fbo, rect); + } + // draw into the GL widget glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); @@ -145,8 +164,9 @@ void GLWidget::draw() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBindTexture(GL_TEXTURE_2D, fbo->texture()); + glBindTexture(GL_TEXTURE_2D, texture_fbo->texture()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glEnable(GL_TEXTURE_2D); glEnable(GL_MULTISAMPLE); glEnable(GL_CULL_FACE); diff --git a/examples/opengl/framebufferobject/glwidget.h b/examples/opengl/framebufferobject/glwidget.h index b64cfa8..d97ef78 100644 --- a/examples/opengl/framebufferobject/glwidget.h +++ b/examples/opengl/framebufferobject/glwidget.h @@ -77,6 +77,7 @@ private: QImage logo; QTimeLine *anim; QSvgRenderer *svg_renderer; - QGLFramebufferObject *fbo; + QGLFramebufferObject *render_fbo; + QGLFramebufferObject *texture_fbo; }; diff --git a/examples/opengl/hellogl_es2/glwidget.cpp b/examples/opengl/hellogl_es2/glwidget.cpp index 213c5b2..cb4a48d 100644 --- a/examples/opengl/hellogl_es2/glwidget.cpp +++ b/examples/opengl/hellogl_es2/glwidget.cpp @@ -48,124 +48,10 @@ const int bubbleNum = 8; -inline void CrossProduct(qreal &xOut, qreal &yOut, qreal &zOut, qreal x1, qreal y1, qreal z1, qreal x2, qreal y2, qreal z2) -{ - xOut = y1 * z2 - z1 * y2; - yOut = z1 * x2 - x1 * z2; - zOut = x1 * y2 - y1 * x2; -} - -inline void Normalize(qreal &x, qreal &y, qreal &z) -{ - qreal l = sqrt(x*x + y*y + z*z); - x = x / l; - y = y / l; - z = z / l; -} - -inline void IdentityMatrix(GLfloat *m) -{ - m[0 * 4 + 0] = 1.0f; - m[1 * 4 + 0] = 0.0f; - m[2 * 4 + 0] = 0.0f; - m[3 * 4 + 0] = 0.0f; - m[0 * 4 + 1] = 0.0f; - m[1 * 4 + 1] = 1.0f; - m[2 * 4 + 1] = 0.0f; - m[3 * 4 + 1] = 0.0f; - m[0 * 4 + 2] = 0.0f; - m[1 * 4 + 2] = 0.0f; - m[2 * 4 + 2] = 1.0f; - m[3 * 4 + 2] = 0.0f; - m[0 * 4 + 3] = 0.0f; - m[1 * 4 + 3] = 0.0f; - m[2 * 4 + 3] = 0.0f; - m[3 * 4 + 3] = 1.0f; -} - -// Adjust a 4x4 matrix to apply a scale. -inline void ScaleMatrix(GLfloat *m, GLfloat scalex, GLfloat scaley, GLfloat scalez) -{ - m[0 * 4 + 0] *= scalex; - m[0 * 4 + 1] *= scalex; - m[0 * 4 + 2] *= scalex; - m[0 * 4 + 3] *= scalex; - m[1 * 4 + 0] *= scaley; - m[1 * 4 + 1] *= scaley; - m[1 * 4 + 2] *= scaley; - m[1 * 4 + 3] *= scaley; - m[2 * 4 + 0] *= scalez; - m[2 * 4 + 1] *= scalez; - m[2 * 4 + 2] *= scalez; - m[2 * 4 + 3] *= scalez; -} - -// Adjust a 4x4 matrix to apply a translation. -inline void TranslateMatrix(GLfloat *m, GLfloat translatex, GLfloat translatey, GLfloat translatez) -{ - m[3 * 4 + 0] += m[0 * 4 + 0] * translatex + m[1 * 4 + 0] * translatey + m[2 * 4 + 0] * translatez; - m[3 * 4 + 1] += m[0 * 4 + 1] * translatex + m[1 * 4 + 1] * translatey + m[2 * 4 + 1] * translatez; - m[3 * 4 + 2] += m[0 * 4 + 2] * translatex + m[1 * 4 + 2] * translatey + m[2 * 4 + 2] * translatez; - m[3 * 4 + 3] += m[0 * 4 + 3] * translatex + m[1 * 4 + 3] * translatey + m[2 * 4 + 3] * translatez; -} - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -// Adjust a 4x4 matrix to apply a rotation. -inline void RotateMatrix(GLfloat *m, GLfloat angle, GLfloat vx, GLfloat vy, GLfloat vz) -{ - GLfloat len = sqrt(vx * vx + vy * vy + vz * vz); - if (len != 0) { - vx /= len; - vy /= len; - vz /= len; - } - - GLfloat c, s, ic; - c = cos(angle * M_PI / 180.0); - s = sin(angle * M_PI / 180.0); - ic = 1.0f - c; - - GLfloat rot[16]; - rot[0 * 4 + 0] = vx * vx * ic + c; - rot[1 * 4 + 0] = vx * vy * ic - vz * s; - rot[2 * 4 + 0] = vx * vz * ic + vy * s; - rot[3 * 4 + 0] = 0.0f; - rot[0 * 4 + 1] = vy * vx * ic + vz * s; - rot[1 * 4 + 1] = vy * vy * ic + c; - rot[2 * 4 + 1] = vy * vz * ic - vx * s; - rot[3 * 4 + 1] = 0.0f; - rot[0 * 4 + 2] = vx * vz * ic - vy * s; - rot[1 * 4 + 2] = vy * vz * ic + vx * s; - rot[2 * 4 + 2] = vz * vz * ic + c; - rot[3 * 4 + 2] = 0.0f; - rot[0 * 4 + 3] = 0.0f; - rot[1 * 4 + 3] = 0.0f; - rot[2 * 4 + 3] = 0.0f; - rot[3 * 4 + 3] = 1.0f; - - GLfloat temp[16]; - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) { - temp[j * 4 + i] = 0.0f; - for (int k = 0; k < 4; ++k) { - temp[j * 4 + i] += m[k * 4 + i] * rot[j * 4 + k]; - } - } - } - - qMemCopy(m, temp, sizeof(temp)); -} - GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) { qtLogo = true; - createdVertices = 0; - createdNormals = 0; - m_vertexNumber = 0; frames = 0; setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_NoSystemBackground); @@ -178,10 +64,6 @@ GLWidget::GLWidget(QWidget *parent) GLWidget::~GLWidget() { - if (createdVertices) - delete[] createdVertices; - if (createdNormals) - delete[] createdNormals; } void GLWidget::setScaling(int scale) { @@ -210,13 +92,11 @@ void GLWidget::showBubbles(bool bubbles) void GLWidget::paintQtLogo() { glDisable(GL_TEXTURE_2D); - glVertexAttribPointer(vertexAttr1, 3, GL_FLOAT, GL_FALSE, 0, createdVertices); - glEnableVertexAttribArray(vertexAttr1); - glVertexAttribPointer(normalAttr1, 3, GL_FLOAT, GL_FALSE, 0, createdNormals); - glEnableVertexAttribArray(normalAttr1); - glDrawArrays(GL_TRIANGLES, 0, m_vertexNumber / 3); - glDisableVertexAttribArray(normalAttr1); - glDisableVertexAttribArray(vertexAttr1); + program1.setAttributeArray(vertexAttr1, vertices.constData()); + program1.setAttributeArray(normalAttr1, normals.constData()); + glDrawArrays(GL_TRIANGLES, 0, vertices.size()); + program1.disableAttributeArray(normalAttr1); + program1.disableAttributeArray(vertexAttr1); } void GLWidget::paintTexturedCube() @@ -239,8 +119,7 @@ void GLWidget::paintTexturedCube() -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5 }; - glVertexAttribPointer(vertexAttr2, 3, GL_FLOAT, GL_FALSE, 0, afVertices); - glEnableVertexAttribArray(vertexAttr2); + program2.setAttributeArray(vertexAttr2, afVertices, 3); GLfloat afTexCoord[] = { 0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f, @@ -258,8 +137,7 @@ void GLWidget::paintTexturedCube() 1.0f,0.0f, 1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f, 0.0f,0.0f, 1.0f,1.0f }; - glVertexAttribPointer(texCoordAttr2, 2, GL_FLOAT, GL_FALSE, 0, afTexCoord); - glEnableVertexAttribArray(texCoordAttr2); + program2.setAttributeArray(texCoordAttr2, afTexCoord, 2); GLfloat afNormals[] = { @@ -278,50 +156,15 @@ void GLWidget::paintTexturedCube() 0,1,0, 0,1,0, 0,1,0, 0,1,0, 0,1,0, 0,1,0 }; - glVertexAttribPointer(normalAttr2, 3, GL_FLOAT, GL_FALSE, 0, afNormals); - glEnableVertexAttribArray(normalAttr2); + program2.setAttributeArray(normalAttr2, afNormals, 3); - glUniform1i(textureUniform2, 0); // use texture unit 0 + program2.setUniformValue(textureUniform2, 0); // use texture unit 0 glDrawArrays(GL_TRIANGLES, 0, 36); - glDisableVertexAttribArray(vertexAttr2); - glDisableVertexAttribArray(normalAttr2); - glDisableVertexAttribArray(texCoordAttr2); -} - -static void reportCompileErrors(GLuint shader, const char *src) -{ - GLint value = 0; - glGetShaderiv(shader, GL_COMPILE_STATUS, &value); - bool compiled = (value != 0); - value = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &value); - if (!compiled && value > 1) { - char *log = new char [value]; - GLint len; - glGetShaderInfoLog(shader, value, &len, log); - qWarning("%s\n", log); - qWarning("when compiling:\n%s\n", src); - delete [] log; - } -} - -static void reportLinkErrors(GLuint program, const char *vsrc, const char *fsrc) -{ - GLint value = 0; - glGetProgramiv(program, GL_LINK_STATUS, &value); - bool linked = (value != 0); - value = 0; - glGetProgramiv(program, GL_INFO_LOG_LENGTH, &value); - if (!linked && value > 1) { - char *log = new char [value]; - GLint len; - glGetProgramInfoLog(program, value, &len, log); - qWarning("%s\n", log); - qWarning("when linking:\n%s\nwith:\n%s\n", vsrc, fsrc); - delete [] log; - } + program2.disableAttributeArray(vertexAttr2); + program2.disableAttributeArray(normalAttr2); + program2.disableAttributeArray(texCoordAttr2); } void GLWidget::initializeGL () @@ -332,8 +175,8 @@ void GLWidget::initializeGL () glGenTextures(1, &m_uiTexture); m_uiTexture = bindTexture(QImage(":/qt.png")); - GLuint vshader1 = glCreateShader(GL_VERTEX_SHADER); - const char *vsrc1[1] = { + QGLShader *vshader1 = new QGLShader(QGLShader::VertexShader, this); + const char *vsrc1 = "attribute highp vec4 vertex;\n" "attribute mediump vec3 normal;\n" "uniform mediump mat4 matrix;\n" @@ -346,36 +189,28 @@ void GLWidget::initializeGL () " color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);\n" " color = clamp(color, 0.0, 1.0);\n" " gl_Position = matrix * vertex;\n" - "}\n" - }; - glShaderSource(vshader1, 1, vsrc1, 0); - glCompileShader(vshader1); - reportCompileErrors(vshader1, vsrc1[0]); + "}\n"; + vshader1->compile(vsrc1); - GLuint fshader1 = glCreateShader(GL_FRAGMENT_SHADER); - const char *fsrc1[1] = { + QGLShader *fshader1 = new QGLShader(QGLShader::FragmentShader, this); + const char *fsrc1 = "varying mediump vec4 color;\n" "void main(void)\n" "{\n" " gl_FragColor = color;\n" - "}\n" - }; - glShaderSource(fshader1, 1, fsrc1, 0); - glCompileShader(fshader1); - reportCompileErrors(fshader1, fsrc1[0]); - - program1 = glCreateProgram(); - glAttachShader(program1, vshader1); - glAttachShader(program1, fshader1); - glLinkProgram(program1); - reportLinkErrors(program1, vsrc1[0], fsrc1[0]); - - vertexAttr1 = glGetAttribLocation(program1, "vertex"); - normalAttr1 = glGetAttribLocation(program1, "normal"); - matrixUniform1 = glGetUniformLocation(program1, "matrix"); - - GLuint vshader2 = glCreateShader(GL_VERTEX_SHADER); - const char *vsrc2[1] = { + "}\n"; + fshader1->compile(fsrc1); + + program1.addShader(vshader1); + program1.addShader(fshader1); + program1.link(); + + vertexAttr1 = program1.attributeLocation("vertex"); + normalAttr1 = program1.attributeLocation("normal"); + matrixUniform1 = program1.uniformLocation("matrix"); + + QGLShader *vshader2 = new QGLShader(QGLShader::VertexShader); + const char *vsrc2 = "attribute highp vec4 vertex;\n" "attribute highp vec4 texCoord;\n" "attribute mediump vec3 normal;\n" @@ -388,14 +223,11 @@ void GLWidget::initializeGL () " angle = max(dot(normal, toLight), 0.0);\n" " gl_Position = matrix * vertex;\n" " texc = texCoord;\n" - "}\n" - }; - glShaderSource(vshader2, 1, vsrc2, 0); - glCompileShader(vshader2); - reportCompileErrors(vshader2, vsrc2[0]); + "}\n"; + vshader2->compile(vsrc2); - GLuint fshader2 = glCreateShader(GL_FRAGMENT_SHADER); - const char *fsrc2[1] = { + QGLShader *fshader2 = new QGLShader(QGLShader::FragmentShader); + const char *fsrc2 = "varying highp vec4 texc;\n" "uniform sampler2D tex;\n" "varying mediump float angle;\n" @@ -404,23 +236,18 @@ void GLWidget::initializeGL () " highp vec3 color = texture2D(tex, texc.st).rgb;\n" " color = color * 0.2 + color * 0.8 * angle;\n" " gl_FragColor = vec4(clamp(color, 0.0, 1.0), 1.0);\n" - "}\n" - }; - glShaderSource(fshader2, 1, fsrc2, 0); - glCompileShader(fshader2); - reportCompileErrors(fshader2, fsrc2[0]); - - program2 = glCreateProgram(); - glAttachShader(program2, vshader2); - glAttachShader(program2, fshader2); - glLinkProgram(program2); - reportLinkErrors(program2, vsrc2[0], fsrc2[0]); - - vertexAttr2 = glGetAttribLocation(program2, "vertex"); - normalAttr2 = glGetAttribLocation(program2, "normal"); - texCoordAttr2 = glGetAttribLocation(program2, "texCoord"); - matrixUniform2 = glGetUniformLocation(program2, "matrix"); - textureUniform2 = glGetUniformLocation(program2, "tex"); + "}\n"; + fshader2->compile(fsrc2); + + program2.addShader(vshader2); + program2.addShader(fshader2); + program2.link(); + + vertexAttr2 = program2.attributeLocation("vertex"); + normalAttr2 = program2.attributeLocation("normal"); + texCoordAttr2 = program2.attributeLocation("texCoord"); + matrixUniform2 = program2.uniformLocation("matrix"); + textureUniform2 = program2.uniformLocation("tex"); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); @@ -450,24 +277,23 @@ void GLWidget::paintGL() glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); - GLfloat modelview[16]; - IdentityMatrix(modelview); - RotateMatrix(modelview, m_fAngle, 0.0, 1.0, 0.0); - RotateMatrix(modelview, m_fAngle, 1.0, 0.0, 0.0); - RotateMatrix(modelview, m_fAngle, 0.0, 0.0, 1.0); - ScaleMatrix(modelview, m_fScale, m_fScale, m_fScale); - TranslateMatrix(modelview, 0, -0.2, 0); + QMatrix4x4 modelview; + modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f); + modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f); + modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f); + modelview.scale(m_fScale); + modelview.translate(0.0f, -0.2f, 0.0f); if (qtLogo) { - glUseProgram(program1); - glUniformMatrix4fv(matrixUniform1, 1, GL_FALSE, modelview); + program1.enable(); + program1.setUniformValue(matrixUniform1, modelview); paintQtLogo(); - glUseProgram(0); + program1.disable(); } else { - glUseProgram(program2); - glUniformMatrix4fv(matrixUniform2, 1, GL_FALSE, modelview); + program2.enable(); + program1.setUniformValue(matrixUniform2, modelview); paintTexturedCube(); - glUseProgram(0); + program2.disable(); } glDisable(GL_DEPTH_TEST); @@ -563,80 +389,69 @@ void GLWidget::createGeometry() extrude(x8, y8, x5, y5); } - m_vertexNumber = vertices.size(); - createdVertices = new GLfloat[m_vertexNumber]; - createdNormals = new GLfloat[m_vertexNumber]; - for (int i = 0;i < m_vertexNumber;i++) { - createdVertices[i] = vertices.at(i) * 2; - createdNormals[i] = normals.at(i); - } - vertices.clear(); - normals.clear(); + for (int i = 0;i < vertices.size();i++) + vertices[i] *= 2.0f; } void GLWidget::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4) { - qreal nx, ny, nz; + vertices << QVector3D(x1, y1, -0.05f); + vertices << QVector3D(x2, y2, -0.05f); + vertices << QVector3D(x4, y4, -0.05f); - vertices << x1 << y1 << -0.05f; - vertices << x2 << y2 << -0.05f; - vertices << x4 << y4 << -0.05f; + vertices << QVector3D(x3, y3, -0.05f); + vertices << QVector3D(x4, y4, -0.05f); + vertices << QVector3D(x2, y2, -0.05f); - vertices << x3 << y3 << -0.05f; - vertices << x4 << y4 << -0.05f; - vertices << x2 << y2 << -0.05f; + QVector3D n = QVector3D::normal + (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f)); - CrossProduct(nx, ny, nz, x2 - x1, y2 - y1, 0, x4 - x1, y4 - y1, 0); - Normalize(nx, ny, nz); + normals << n; + normals << n; + normals << n; - normals << nx << ny << nz; - normals << nx << ny << nz; - normals << nx << ny << nz; + normals << n; + normals << n; + normals << n; - normals << nx << ny << nz; - normals << nx << ny << nz; - normals << nx << ny << nz; + vertices << QVector3D(x4, y4, 0.05f); + vertices << QVector3D(x2, y2, 0.05f); + vertices << QVector3D(x1, y1, 0.05f); - vertices << x4 << y4 << 0.05f; - vertices << x2 << y2 << 0.05f; - vertices << x1 << y1 << 0.05f; + vertices << QVector3D(x2, y2, 0.05f); + vertices << QVector3D(x4, y4, 0.05f); + vertices << QVector3D(x3, y3, 0.05f); - vertices << x2 << y2 << 0.05f; - vertices << x4 << y4 << 0.05f; - vertices << x3 << y3 << 0.05f; + n = QVector3D::normal + (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f)); - CrossProduct(nx, ny, nz, x2 - x4, y2 - y4, 0, x1 - x4, y1 - y4, 0); - Normalize(nx, ny, nz); + normals << n; + normals << n; + normals << n; - normals << nx << ny << nz; - normals << nx << ny << nz; - normals << nx << ny << nz; - - normals << nx << ny << nz; - normals << nx << ny << nz; - normals << nx << ny << nz; + normals << n; + normals << n; + normals << n; } void GLWidget::extrude(qreal x1, qreal y1, qreal x2, qreal y2) { - qreal nx, ny, nz; - - vertices << x1 << y1 << +0.05f; - vertices << x2 << y2 << +0.05f; - vertices << x1 << y1 << -0.05f; + vertices << QVector3D(x1, y1, +0.05f); + vertices << QVector3D(x2, y2, +0.05f); + vertices << QVector3D(x1, y1, -0.05f); - vertices << x2 << y2 << -0.05f; - vertices << x1 << y1 << -0.05f; - vertices << x2 << y2 << +0.05f; + vertices << QVector3D(x2, y2, -0.05f); + vertices << QVector3D(x1, y1, -0.05f); + vertices << QVector3D(x2, y2, +0.05f); - CrossProduct(nx, ny, nz, x2 - x1, y2 - y1, 0.0f, 0.0f, 0.0f, -0.1f); - Normalize(nx, ny, nz); + QVector3D n = QVector3D::normal + (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f)); - normals << nx << ny << nz; - normals << nx << ny << nz; - normals << nx << ny << nz; + normals << n; + normals << n; + normals << n; - normals << nx << ny << nz; - normals << nx << ny << nz; - normals << nx << ny << nz; + normals << n; + normals << n; + normals << n; } diff --git a/examples/opengl/hellogl_es2/glwidget.h b/examples/opengl/hellogl_es2/glwidget.h index 9a7823a..596e1cc 100644 --- a/examples/opengl/hellogl_es2/glwidget.h +++ b/examples/opengl/hellogl_es2/glwidget.h @@ -43,7 +43,11 @@ #define GLWIDGET_H #include <QGLWidget> +#include <QtGui/qvector3d.h> +#include <QtGui/qmatrix4x4.h> +#include <QtOpenGL/qglshaderprogram.h> #include <QTime> +#include <QVector> class Bubble; class GLWidget : public QGLWidget { @@ -71,24 +75,21 @@ private: void createBubbles(int number); void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4); void extrude(qreal x1, qreal y1, qreal x2, qreal y2); - QList<qreal> vertices; - QList<qreal> normals; - GLfloat *createdVertices; - GLfloat *createdNormals; - int m_vertexNumber; + QVector<QVector3D> vertices; + QVector<QVector3D> normals; bool qtLogo; QList<Bubble*> bubbles; int frames; QTime time; - GLuint program1; - GLuint program2; - GLuint vertexAttr1; - GLuint normalAttr1; - GLuint matrixUniform1; - GLuint vertexAttr2; - GLuint normalAttr2; - GLuint texCoordAttr2; - GLuint matrixUniform2; - GLuint textureUniform2; + QGLShaderProgram program1; + QGLShaderProgram program2; + int vertexAttr1; + int normalAttr1; + int matrixUniform1; + int vertexAttr2; + int normalAttr2; + int texCoordAttr2; + int matrixUniform2; + int textureUniform2; }; #endif diff --git a/examples/qtconcurrent/imagescaling/imagescaling.pro b/examples/qtconcurrent/imagescaling/imagescaling.pro index fbf864a..0a25efb 100644 --- a/examples/qtconcurrent/imagescaling/imagescaling.pro +++ b/examples/qtconcurrent/imagescaling/imagescaling.pro @@ -11,3 +11,5 @@ target.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent/imagescaling sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png sources.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent/imagescaling INSTALLS += target sources + +wince*: DEPLOYMENT_PLUGIN += qgif qjpeg qtiff diff --git a/examples/qtconcurrent/qtconcurrent.pro b/examples/qtconcurrent/qtconcurrent.pro index 53008f0..5d73533 100644 --- a/examples/qtconcurrent/qtconcurrent.pro +++ b/examples/qtconcurrent/qtconcurrent.pro @@ -1,10 +1,13 @@ TEMPLATE = subdirs SUBDIRS = imagescaling \ map \ - progressdialog \ runfunction \ wordcount +!wince* { + SUBDIRS += progressdialog +} + # install target.path = $$[QT_INSTALL_EXAMPLES]/qtconcurrent sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS qtconcurrent.pro README diff --git a/examples/sql/sqlwidgetmapper/sqlwidgetmapper.pro b/examples/sql/sqlwidgetmapper/sqlwidgetmapper.pro index 1881fce..c216a30 100644 --- a/examples/sql/sqlwidgetmapper/sqlwidgetmapper.pro +++ b/examples/sql/sqlwidgetmapper/sqlwidgetmapper.pro @@ -8,3 +8,6 @@ target.path = $$[QT_INSTALL_EXAMPLES]/sql/sqlwidgetmapper sources.files = $$SOURCES $$HEADERS *.pro sources.path = $$[QT_INSTALL_EXAMPLES]/sql/sqlwidgetmapper INSTALLS += target sources + +wince*: DEPLOYMENT_PLUGIN += qsqlite + diff --git a/examples/statemachine/README b/examples/statemachine/README new file mode 100644 index 0000000..2879e67 --- /dev/null +++ b/examples/statemachine/README @@ -0,0 +1,36 @@ +Qt is provided with a powerful hierchical finite state machine through +the Qt State Machine classes. + +The example launcher provided with Qt can be used to explore each of the +examples in this directory. + +Documentation for these examples can be found via the Tutorial and Examples +link in the main Qt documentation. + + +Finding the Qt Examples and Demos launcher +========================================== + +On Windows: + +The launcher can be accessed via the Windows Start menu. Select the menu +entry entitled "Qt Examples and Demos" entry in the submenu containing +the Qt tools. + +On Mac OS X: + +For the binary distribution, the qtdemo executable is installed in the +/Developer/Applications/Qt directory. For the source distribution, it is +installed alongside the other Qt tools on the path specified when Qt is +configured. + +On Unix/Linux: + +The qtdemo executable is installed alongside the other Qt tools on the path +specified when Qt is configured. + +On all platforms: + +The source code for the launcher can be found in the demos/qtdemo directory +in the Qt package. This example is built at the same time as the Qt libraries, +tools, examples, and demonstrations. diff --git a/examples/statemachine/eventtransitions/eventtransitions.pro b/examples/statemachine/eventtransitions/eventtransitions.pro new file mode 100644 index 0000000..7e92cf2 --- /dev/null +++ b/examples/statemachine/eventtransitions/eventtransitions.pro @@ -0,0 +1,7 @@ +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/eventtransitions +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS eventtransitions.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/eventtransitions +INSTALLS += target sources diff --git a/examples/statemachine/eventtransitions/main.cpp b/examples/statemachine/eventtransitions/main.cpp new file mode 100644 index 0000000..aba0c73 --- /dev/null +++ b/examples/statemachine/eventtransitions/main.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#ifdef QT_STATEMACHINE_SOLUTION +#include <qstatemachine.h> +#include <qstate.h> +#include <qeventtransition.h> +#endif + +//! [0] +class Window : public QWidget +{ +public: + Window(QWidget *parent = 0) + : QWidget(parent) + { + QPushButton *button = new QPushButton(this); + button->setGeometry(QRect(100, 100, 100, 100)); +//! [0] + +//! [1] + QStateMachine *machine = new QStateMachine(this); + + QState *s1 = new QState(); + s1->assignProperty(button, "text", "Outside"); + + QState *s2 = new QState(); + s2->assignProperty(button, "text", "Inside"); +//! [1] + +//! [2] + QEventTransition *enterTransition = new QEventTransition(button, QEvent::Enter); + enterTransition->setTargetState(s2); + s1->addTransition(enterTransition); +//! [2] + +//! [3] + QEventTransition *leaveTransition = new QEventTransition(button, QEvent::Leave); + leaveTransition->setTargetState(s1); + s2->addTransition(leaveTransition); +//! [3] + +//! [4] + QState *s3 = new QState(); + s3->assignProperty(button, "text", "Pressing..."); + + QEventTransition *pressTransition = new QEventTransition(button, QEvent::MouseButtonPress); + pressTransition->setTargetState(s3); + s2->addTransition(pressTransition); + + QEventTransition *releaseTransition = new QEventTransition(button, QEvent::MouseButtonRelease); + releaseTransition->setTargetState(s2); + s3->addTransition(releaseTransition); +//! [4] + +//! [5] + machine->addState(s1); + machine->addState(s2); + machine->addState(s3); + + machine->setInitialState(s1); + machine->start(); + } +}; +//! [5] + +//! [6] +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + Window window; + window.resize(300, 300); + window.show(); + + return app.exec(); +} +//! [6] diff --git a/examples/statemachine/factorial/factorial.pro b/examples/statemachine/factorial/factorial.pro new file mode 100644 index 0000000..14a6833 --- /dev/null +++ b/examples/statemachine/factorial/factorial.pro @@ -0,0 +1,11 @@ +QT = core +win32: CONFIG += console +mac:CONFIG -= app_bundle + +SOURCES += main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/factorial +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS factorial.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/factorial +INSTALLS += target sources diff --git a/examples/statemachine/factorial/main.cpp b/examples/statemachine/factorial/main.cpp new file mode 100644 index 0000000..1065eb8 --- /dev/null +++ b/examples/statemachine/factorial/main.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <stdio.h> +#ifdef QT_STATEMACHINE_SOLUTION +#include <qstatemachine.h> +#include <qstate.h> +#include <qsignaltransition.h> +#include <qfinalstate.h> +#endif + +//! [0] +class Factorial : public QObject +{ + Q_OBJECT + Q_PROPERTY(int x READ x WRITE setX) + Q_PROPERTY(int fac READ fac WRITE setFac) +public: + Factorial(QObject *parent = 0) + : QObject(parent), m_x(-1), m_fac(1) + { + } + + int x() const + { + return m_x; + } + + void setX(int x) + { + if (x == m_x) + return; + m_x = x; + emit xChanged(x); + } + + int fac() const + { + return m_fac; + } + + void setFac(int fac) + { + m_fac = fac; + } + +Q_SIGNALS: + void xChanged(int value); + +private: + int m_x; + int m_fac; +}; +//! [0] + +//! [1] +class FactorialLoopTransition : public QSignalTransition +{ +public: + FactorialLoopTransition(Factorial *fact) + : QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact) + {} + + virtual bool eventTest(QEvent *e) + { + if (!QSignalTransition::eventTest(e)) + return false; + QSignalEvent *se = static_cast<QSignalEvent*>(e); + return se->arguments().at(0).toInt() > 1; + } + + virtual void onTransition(QEvent *e) + { + QSignalEvent *se = static_cast<QSignalEvent*>(e); + int x = se->arguments().at(0).toInt(); + int fac = m_fact->property("fac").toInt(); + m_fact->setProperty("fac", x * fac); + m_fact->setProperty("x", x - 1); + } + +private: + Factorial *m_fact; +}; +//! [1] + +//! [2] +class FactorialDoneTransition : public QSignalTransition +{ +public: + FactorialDoneTransition(Factorial *fact) + : QSignalTransition(fact, SIGNAL(xChanged(int))), m_fact(fact) + {} + + virtual bool eventTest(QEvent *e) + { + if (!QSignalTransition::eventTest(e)) + return false; + QSignalEvent *se = static_cast<QSignalEvent*>(e); + return se->arguments().at(0).toInt() <= 1; + } + + virtual void onTransition(QEvent *) + { + fprintf(stdout, "%d\n", m_fact->property("fac").toInt()); + } + +private: + Factorial *m_fact; +}; +//! [2] + +//! [3] +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + Factorial factorial; + QStateMachine machine; +//! [3] + +//! [4] + QState *compute = new QState(machine.rootState()); + compute->assignProperty(&factorial, "fac", 1); + compute->assignProperty(&factorial, "x", 6); + compute->addTransition(new FactorialLoopTransition(&factorial)); +//! [4] + +//! [5] + QFinalState *done = new QFinalState(machine.rootState()); + FactorialDoneTransition *doneTransition = new FactorialDoneTransition(&factorial); + doneTransition->setTargetState(done); + compute->addTransition(doneTransition); +//! [5] + +//! [6] + machine.setInitialState(compute); + QObject::connect(&machine, SIGNAL(finished()), &app, SLOT(quit())); + machine.start(); + + return app.exec(); +} +//! [6] + +#include "main.moc" diff --git a/examples/statemachine/pingpong/main.cpp b/examples/statemachine/pingpong/main.cpp new file mode 100644 index 0000000..331627e --- /dev/null +++ b/examples/statemachine/pingpong/main.cpp @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <stdio.h> +#ifdef QT_STATEMACHINE_SOLUTION +#include <qstate.h> +#include <qstatemachine.h> +#include <qabstracttransition.h> +#endif + +//! [0] +class PingEvent : public QEvent +{ +public: + PingEvent() : QEvent(QEvent::Type(QEvent::User+2)) + {} +}; + +class PongEvent : public QEvent +{ +public: + PongEvent() : QEvent(QEvent::Type(QEvent::User+3)) + {} +}; +//! [0] + +//! [1] +class Pinger : public QState +{ +public: + Pinger(QState *parent) + : QState(parent) {} + +protected: + virtual void onEntry(QEvent *) + { + machine()->postEvent(new PingEvent()); + fprintf(stdout, "ping?\n"); + } +}; +//! [1] + +//! [3] +class PongTransition : public QAbstractTransition +{ +public: + PongTransition() {} + +protected: + virtual bool eventTest(QEvent *e) { + return (e->type() == QEvent::User+3); + } + virtual void onTransition(QEvent *) + { + machine()->postEvent(new PingEvent(), 500); + fprintf(stdout, "ping?\n"); + } +}; +//! [3] + +//! [2] +class PingTransition : public QAbstractTransition +{ +public: + PingTransition() {} + +protected: + virtual bool eventTest(QEvent *e) { + return (e->type() == QEvent::User+2); + } + virtual void onTransition(QEvent *) + { + machine()->postEvent(new PongEvent(), 500); + fprintf(stdout, "pong!\n"); + } +}; +//! [2] + +//! [4] +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + QStateMachine machine; + QState *group = new QState(QState::ParallelStates); + group->setObjectName("group"); +//! [4] + +//! [5] + Pinger *pinger = new Pinger(group); + pinger->setObjectName("pinger"); + pinger->addTransition(new PongTransition()); + + QState *ponger = new QState(group); + ponger->setObjectName("ponger"); + ponger->addTransition(new PingTransition()); +//! [5] + +//! [6] + machine.addState(group); + machine.setInitialState(group); + machine.start(); + + return app.exec(); +} +//! [6] diff --git a/examples/statemachine/pingpong/pingpong.pro b/examples/statemachine/pingpong/pingpong.pro new file mode 100644 index 0000000..42eab6c --- /dev/null +++ b/examples/statemachine/pingpong/pingpong.pro @@ -0,0 +1,11 @@ +QT = core +win32: CONFIG += console +mac:CONFIG -= app_bundle + +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/pingpong +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS pingpong.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/pingpong +INSTALLS += target sources diff --git a/examples/statemachine/statemachine.pro b/examples/statemachine/statemachine.pro new file mode 100644 index 0000000..5074a3c --- /dev/null +++ b/examples/statemachine/statemachine.pro @@ -0,0 +1,15 @@ +TEMPLATE = subdirs +SUBDIRS = \ + eventtransitions \ + factorial \ + pingpong \ + trafficlight \ + twowaybutton \ + tankgame \ + tankgameplugins + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS statemachine.pro README +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine +INSTALLS += target sources diff --git a/examples/statemachine/tankgame/gameitem.cpp b/examples/statemachine/tankgame/gameitem.cpp new file mode 100644 index 0000000..ad8b37c --- /dev/null +++ b/examples/statemachine/tankgame/gameitem.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "gameitem.h" + +#include <QGraphicsScene> +#include <QDebug> + +GameItem::GameItem(QObject *parent) : QObject(parent) +{ +} + +QPointF GameItem::tryMove(const QPointF &requestedPosition, QLineF *collidedLine, + QGraphicsItem **collidedItem) const +{ + QLineF movementPath(pos(), requestedPosition); + + qreal cannonLength = 0.0; + { + QPointF p1 = boundingRect().center(); + QPointF p2 = QPointF(boundingRect().right() + 10.0, p1.y()); + + cannonLength = QLineF(mapToScene(p1), mapToScene(p2)).length(); + } + + movementPath.setLength(movementPath.length() + cannonLength); + + QRectF boundingRectPath(QPointF(qMin(movementPath.x1(), movementPath.x2()), qMin(movementPath.y1(), movementPath.y2())), + QPointF(qMax(movementPath.x1(), movementPath.x2()), qMax(movementPath.y1(), movementPath.y2()))); + + QList<QGraphicsItem *> itemsInRect = scene()->items(boundingRectPath, Qt::IntersectsItemBoundingRect); + + QPointF nextPoint = requestedPosition; + QRectF sceneRect = scene()->sceneRect(); + + foreach (QGraphicsItem *item, itemsInRect) { + if (item == static_cast<const QGraphicsItem *>(this)) + continue; + + QPolygonF mappedBoundingRect = item->mapToScene(item->boundingRect()); + for (int i=0; i<mappedBoundingRect.size(); ++i) { + QPointF p1 = mappedBoundingRect.at(i == 0 ? mappedBoundingRect.size()-1 : i-1); + QPointF p2 = mappedBoundingRect.at(i); + + QLineF rectLine(p1, p2); + QPointF intersectionPoint; + QLineF::IntersectType intersectType = movementPath.intersect(rectLine, &intersectionPoint); + + if (intersectType == QLineF::BoundedIntersection) { + movementPath.setP2(intersectionPoint); + movementPath.setLength(movementPath.length() - cannonLength); + nextPoint = movementPath.p2(); + + if (collidedLine != 0) + *collidedLine = rectLine; + + if (collidedItem != 0) + *collidedItem = item; + } + } + } + + + // Don't go outside of map + if (nextPoint.x() < sceneRect.left()) { + nextPoint.rx() = sceneRect.left(); + if (collidedLine != 0) + *collidedLine = QLineF(scene()->sceneRect().topLeft(), scene()->sceneRect().bottomLeft()); + } + + if (nextPoint.x() > sceneRect.right()) { + nextPoint.rx() = sceneRect.right(); + if (collidedLine != 0) + *collidedLine = QLineF(scene()->sceneRect().topRight(), scene()->sceneRect().bottomRight()); + } + + if (nextPoint.y() < sceneRect.top()) { + nextPoint.ry() = sceneRect.top(); + if (collidedLine != 0) + *collidedLine = QLineF(scene()->sceneRect().topLeft(), scene()->sceneRect().topRight()); + } + + if (nextPoint.y() > sceneRect.bottom()) { + nextPoint.ry() = sceneRect.bottom(); + if (collidedLine != 0) + *collidedLine = QLineF(scene()->sceneRect().bottomLeft(), scene()->sceneRect().bottomRight()); + } + + return nextPoint; +} + diff --git a/examples/statemachine/tankgame/gameitem.h b/examples/statemachine/tankgame/gameitem.h new file mode 100644 index 0000000..90b0a6c --- /dev/null +++ b/examples/statemachine/tankgame/gameitem.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GAMEITEM_H +#define GAMEITEM_H + +#include <QGraphicsItem> + +QT_BEGIN_NAMESPACE +class QLineF; +QT_END_NAMESPACE +class GameItem: public QObject, public QGraphicsItem +{ + Q_OBJECT +public: + enum { Type = UserType + 1 }; + int type() const { return Type; } + + GameItem(QObject *parent = 0); + + virtual void idle(qreal elapsed) = 0; + +protected: + QPointF tryMove(const QPointF &requestedPosition, QLineF *collidedLine = 0, + QGraphicsItem **collidedItem = 0) const; +}; + +#endif diff --git a/examples/statemachine/tankgame/gameovertransition.cpp b/examples/statemachine/tankgame/gameovertransition.cpp new file mode 100644 index 0000000..360e902 --- /dev/null +++ b/examples/statemachine/tankgame/gameovertransition.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "gameovertransition.h" +#include "tankitem.h" + +#include <QSignalEvent> +#include <QSignalMapper> + +GameOverTransition::GameOverTransition(QAbstractState *targetState) + : QSignalTransition(new QSignalMapper(), SIGNAL(mapped(QObject*))) +{ + setTargetState(targetState); + + QSignalMapper *mapper = qobject_cast<QSignalMapper *>(senderObject()); + mapper->setParent(this); +} + +void GameOverTransition::addTankItem(TankItem *tankItem) +{ + m_tankItems.append(tankItem); + + QSignalMapper *mapper = qobject_cast<QSignalMapper *>(senderObject()); + mapper->setMapping(tankItem, tankItem); + connect(tankItem, SIGNAL(aboutToBeDestroyed()), mapper, SLOT(map())); +} + +bool GameOverTransition::eventTest(QEvent *e) +{ + bool ret = QSignalTransition::eventTest(e); + + if (ret) { + QSignalEvent *signalEvent = static_cast<QSignalEvent *>(e); + QObject *sender = qvariant_cast<QObject *>(signalEvent->arguments().at(0)); + TankItem *tankItem = qobject_cast<TankItem *>(sender); + m_tankItems.removeAll(tankItem); + + return m_tankItems.size() <= 1; + } else { + return false; + } +} diff --git a/examples/statemachine/tankgame/gameovertransition.h b/examples/statemachine/tankgame/gameovertransition.h new file mode 100644 index 0000000..5e99a75 --- /dev/null +++ b/examples/statemachine/tankgame/gameovertransition.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GAMEOVERTRANSITION_H +#define GAMEOVERTRANSITION_H + +#include <QSignalTransition> + +class TankItem; +class GameOverTransition: public QSignalTransition +{ + Q_OBJECT +public: + GameOverTransition(QAbstractState *targetState); + + void addTankItem(TankItem *tankItem); + +protected: + bool eventTest(QEvent *event); + +private: + QList<TankItem *> m_tankItems; +}; + +#endif diff --git a/examples/statemachine/tankgame/main.cpp b/examples/statemachine/tankgame/main.cpp new file mode 100644 index 0000000..185ad68 --- /dev/null +++ b/examples/statemachine/tankgame/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include "mainwindow.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + MainWindow mainWindow; + mainWindow.show(); + + return app.exec(); +} diff --git a/examples/statemachine/tankgame/mainwindow.cpp b/examples/statemachine/tankgame/mainwindow.cpp new file mode 100644 index 0000000..46e0db3 --- /dev/null +++ b/examples/statemachine/tankgame/mainwindow.cpp @@ -0,0 +1,342 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "mainwindow.h" +#include "tankitem.h" +#include "rocketitem.h" +#include "plugin.h" +#include "gameovertransition.h" + +#include <QStateMachine> +#include <QGraphicsView> +#include <QAction> +#include <QMenuBar> +#include <QState> +#include <QHistoryState> +#include <QTimer> +#include <QFileDialog> +#include <QPluginLoader> +#include <QApplication> +#include <QInputDialog> +#include <QMessageBox> + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent), m_scene(0), m_machine(0), m_runningState(0), m_started(false) +{ + init(); +} + +MainWindow::~MainWindow() +{ +} + +void MainWindow::addWall(const QRectF &wall) +{ + QGraphicsRectItem *item = new QGraphicsRectItem; + item->setRect(wall); + item->setBrush(Qt::darkGreen); + item->setPen(QPen(Qt::black, 0)); + + m_scene->addItem(item); +} + +void MainWindow::init() +{ + setWindowTitle("Pluggable Tank Game"); + + QGraphicsView *view = new QGraphicsView(this); + view->setRenderHints(QPainter::Antialiasing); + setCentralWidget(view); + + m_scene = new QGraphicsScene(this); + view->setScene(m_scene); + + QRectF sceneRect = QRectF(-200.0, -200.0, 400.0, 400.0); + m_scene->setSceneRect(sceneRect); + + { + TankItem *item = new TankItem(this); + + item->setPos(m_scene->sceneRect().topLeft() + QPointF(30.0, 30.0)); + item->setDirection(45.0); + item->setColor(Qt::red); + + m_spawns.append(item); + } + + { + TankItem *item = new TankItem(this); + + item->setPos(m_scene->sceneRect().topRight() + QPointF(-30.0, 30.0)); + item->setDirection(135.0); + item->setColor(Qt::green); + + m_spawns.append(item); + } + + { + TankItem *item = new TankItem(this); + + item->setPos(m_scene->sceneRect().bottomRight() + QPointF(-30.0, -30.0)); + item->setDirection(225.0); + item->setColor(Qt::blue); + + m_spawns.append(item); + } + + { + TankItem *item = new TankItem(this); + + item->setPos(m_scene->sceneRect().bottomLeft() + QPointF(30.0, -30.0)); + item->setDirection(315.0); + item->setColor(Qt::yellow); + + m_spawns.append(item); + } + + QPointF centerOfMap = sceneRect.center(); + + addWall(QRectF(centerOfMap + QPointF(-50.0, -60.0), centerOfMap + QPointF(50.0, -50.0))); + addWall(QRectF(centerOfMap - QPointF(-50.0, -60.0), centerOfMap - QPointF(50.0, -50.0))); + addWall(QRectF(centerOfMap + QPointF(-50.0, -50.0), centerOfMap + QPointF(-40.0, 50.0))); + addWall(QRectF(centerOfMap - QPointF(-50.0, -50.0), centerOfMap - QPointF(-40.0, 50.0))); + + addWall(QRectF(sceneRect.topLeft() + QPointF(sceneRect.width() / 2.0 - 5.0, -10.0), + sceneRect.topLeft() + QPointF(sceneRect.width() / 2.0 + 5.0, 100.0))); + addWall(QRectF(sceneRect.bottomLeft() + QPointF(sceneRect.width() / 2.0 - 5.0, 10.0), + sceneRect.bottomLeft() + QPointF(sceneRect.width() / 2.0 + 5.0, -100.0))); + addWall(QRectF(sceneRect.topLeft() + QPointF(-10.0, sceneRect.height() / 2.0 - 5.0), + sceneRect.topLeft() + QPointF(100.0, sceneRect.height() / 2.0 + 5.0))); + addWall(QRectF(sceneRect.topRight() + QPointF(10.0, sceneRect.height() / 2.0 - 5.0), + sceneRect.topRight() + QPointF(-100.0, sceneRect.height() / 2.0 + 5.0))); + + + QAction *addTankAction = menuBar()->addAction("&Add tank"); + QAction *runGameAction = menuBar()->addAction("&Run game"); + runGameAction->setObjectName("runGameAction"); + QAction *stopGameAction = menuBar()->addAction("&Stop game"); + menuBar()->addSeparator(); + QAction *quitAction = menuBar()->addAction("&Quit"); + + connect(addTankAction, SIGNAL(triggered()), this, SLOT(addTank())); + connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + + m_machine = new QStateMachine(this); + QState *stoppedState = new QState(m_machine->rootState()); + stoppedState->setObjectName("stoppedState"); + stoppedState->assignProperty(runGameAction, "enabled", true); + stoppedState->assignProperty(stopGameAction, "enabled", false); + stoppedState->assignProperty(this, "started", false); + m_machine->setInitialState(stoppedState); + +//! [5] + QState *spawnsAvailable = new QState(stoppedState); + spawnsAvailable->assignProperty(addTankAction, "enabled", true); + + QState *noSpawnsAvailable = new QState(stoppedState); + noSpawnsAvailable->assignProperty(addTankAction, "enabled", false); +//! [5] + spawnsAvailable->setObjectName("spawnsAvailable"); + noSpawnsAvailable->setObjectName("noSpawnsAvailable"); + + spawnsAvailable->addTransition(this, SIGNAL(mapFull()), noSpawnsAvailable); + +//! [3] + QHistoryState *hs = new QHistoryState(stoppedState); + hs->setDefaultState(spawnsAvailable); +//! [3] + hs->setObjectName("hs"); + + stoppedState->setInitialState(hs); + +//! [0] + m_runningState = new QState(QState::ParallelStates, m_machine->rootState()); +//! [0] + m_runningState->setObjectName("runningState"); + m_runningState->assignProperty(addTankAction, "enabled", false); + m_runningState->assignProperty(runGameAction, "enabled", false); + m_runningState->assignProperty(stopGameAction, "enabled", true); + + QState *gameOverState = new QState(m_machine->rootState()); + gameOverState->setObjectName("gameOverState"); + gameOverState->assignProperty(stopGameAction, "enabled", false); + connect(gameOverState, SIGNAL(entered()), this, SLOT(gameOver())); + + stoppedState->addTransition(runGameAction, SIGNAL(triggered()), m_runningState); + m_runningState->addTransition(stopGameAction, SIGNAL(triggered()), stoppedState); + + m_gameOverTransition = new GameOverTransition(gameOverState); + m_runningState->addTransition(m_gameOverTransition); + + QTimer *timer = new QTimer(this); + timer->setInterval(100); + connect(timer, SIGNAL(timeout()), this, SLOT(runStep())); + connect(m_runningState, SIGNAL(entered()), timer, SLOT(start())); + connect(m_runningState, SIGNAL(exited()), timer, SLOT(stop())); + + m_machine->start(); + m_time.start(); +} + +void MainWindow::runStep() +{ + if (!m_started) { + m_time.restart(); + m_started = true; + } else { + int elapsed = m_time.elapsed(); + if (elapsed > 0) { + m_time.restart(); + qreal elapsedSecs = elapsed / 1000.0; + QList<QGraphicsItem *> items = m_scene->items(); + foreach (QGraphicsItem *item, items) { + if (GameItem *gameItem = qgraphicsitem_cast<GameItem *>(item)) + gameItem->idle(elapsedSecs); + } + } + } +} + +void MainWindow::gameOver() +{ + QList<QGraphicsItem *> items = m_scene->items(); + + TankItem *lastTankStanding = 0; + foreach (QGraphicsItem *item, items) { + if (GameItem *gameItem = qgraphicsitem_cast<GameItem *>(item)) { + if ((lastTankStanding = qobject_cast<TankItem *>(gameItem)) != 0) + break; + } + } + + QMessageBox::information(this, "Game over!", + QString::fromLatin1("The tank played by '%1' has won!").arg(lastTankStanding->objectName())); +} + +void MainWindow::addRocket() +{ + TankItem *tankItem = qobject_cast<TankItem *>(sender()); + if (tankItem != 0) { + RocketItem *rocketItem = new RocketItem; + + QPointF s = tankItem->mapToScene(QPointF(tankItem->boundingRect().right() + 10.0, + tankItem->boundingRect().center().y())); + rocketItem->setPos(s); + rocketItem->setDirection(tankItem->direction()); + m_scene->addItem(rocketItem); + } +} + +void MainWindow::addTank() +{ + Q_ASSERT(!m_spawns.isEmpty()); + + QDir pluginsDir(qApp->applicationDirPath()); +#if defined(Q_OS_WIN) + if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release") + pluginsDir.cdUp(); +#elif defined(Q_OS_MAC) + if (pluginsDir.dirName() == "MacOS") { + pluginsDir.cdUp(); + pluginsDir.cdUp(); + pluginsDir.cdUp(); + } +#endif + + pluginsDir.cd("plugins"); + + QStringList itemNames; + QList<Plugin *> items; + foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { + QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); + QObject *possiblePlugin = loader.instance(); + if (Plugin *plugin = qobject_cast<Plugin *>(possiblePlugin)) { + QString objectName = possiblePlugin->objectName(); + if (objectName.isEmpty()) + objectName = fileName; + + itemNames.append(objectName); + items.append(plugin); + } + } + + if (items.isEmpty()) { + QMessageBox::information(this, "No tank types found", "Please build the errorstateplugins directory"); + return; + } + + bool ok; +//! [1] + QString selectedName = QInputDialog::getItem(this, "Select a tank type", "Tank types", + itemNames, 0, false, &ok); +//! [1] + + if (ok && !selectedName.isEmpty()) { + int idx = itemNames.indexOf(selectedName); + if (Plugin *plugin = idx >= 0 ? items.at(idx) : 0) { + TankItem *tankItem = m_spawns.takeLast(); + tankItem->setObjectName(selectedName); + tankItem->setToolTip(selectedName); + m_scene->addItem(tankItem); + connect(tankItem, SIGNAL(cannonFired()), this, SLOT(addRocket())); + if (m_spawns.isEmpty()) + emit mapFull(); + + m_gameOverTransition->addTankItem(tankItem); + + QState *region = new QState(m_runningState); + region->setObjectName(QString::fromLatin1("region%1").arg(m_spawns.size())); +//! [2] + QState *pluginState = plugin->create(region, tankItem); +//! [2] + region->setInitialState(pluginState); + + // If the plugin has an error it is disabled +//! [4] + QState *errorState = new QState(region); + errorState->setObjectName(QString::fromLatin1("errorState%1").arg(m_spawns.size())); + errorState->assignProperty(tankItem, "enabled", false); + pluginState->setErrorState(errorState); +//! [4] + } + } +} + diff --git a/examples/statemachine/tankgame/mainwindow.h b/examples/statemachine/tankgame/mainwindow.h new file mode 100644 index 0000000..4ae8f7a --- /dev/null +++ b/examples/statemachine/tankgame/mainwindow.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <QTime> + +QT_BEGIN_NAMESPACE +class QGraphicsScene; +class QStateMachine; +class QState; +QT_END_NAMESPACE +class GameOverTransition; +class TankItem; + +class MainWindow: public QMainWindow +{ + Q_OBJECT + Q_PROPERTY(bool started READ started WRITE setStarted) +public: + MainWindow(QWidget *parent = 0); + ~MainWindow(); + + void setStarted(bool b) { m_started = b; } + bool started() const { return m_started; } + +public slots: + void addTank(); + void addRocket(); + void runStep(); + void gameOver(); + +signals: + void mapFull(); + +private: + void init(); + void addWall(const QRectF &wall); + + QGraphicsScene *m_scene; + + QStateMachine *m_machine; + QState *m_runningState; + GameOverTransition *m_gameOverTransition; + + QList<TankItem *> m_spawns; + QTime m_time; + + bool m_started : 1; +}; + +#endif + diff --git a/examples/statemachine/tankgame/plugin.h b/examples/statemachine/tankgame/plugin.h new file mode 100644 index 0000000..ddd10b7 --- /dev/null +++ b/examples/statemachine/tankgame/plugin.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PLUGIN_H +#define PLUGIN_H + +#include <QtPlugin> + +QT_BEGIN_NAMESPACE +class QState; +QT_END_NAMESPACE +class Plugin +{ +public: + virtual ~Plugin() {} + + virtual QState *create(QState *parentState, QObject *tank) = 0; +}; + +QT_BEGIN_NAMESPACE +Q_DECLARE_INTERFACE(Plugin, "TankPlugin") +QT_END_NAMESPACE + +#endif diff --git a/examples/statemachine/tankgame/rocketitem.cpp b/examples/statemachine/tankgame/rocketitem.cpp new file mode 100644 index 0000000..3ace8e8 --- /dev/null +++ b/examples/statemachine/tankgame/rocketitem.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "rocketitem.h" +#include "tankitem.h" + +#include <QPainter> +#include <QGraphicsScene> + +#include <math.h> + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +RocketItem::RocketItem(QObject *parent) + : GameItem(parent), m_direction(0.0), m_distance(300.0) +{ +} + +QRectF RocketItem::boundingRect() const +{ + return QRectF(-1.0, -1.0, 2.0, 2.0); +} + +void RocketItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + painter->setBrush(Qt::black); + painter->drawEllipse(boundingRect()); +} + +void RocketItem::idle(qreal elapsed) +{ + qreal dist = elapsed * speed(); + + m_distance -= dist; + if (m_distance < 0.0) { + scene()->removeItem(this); + delete this; + return; + } + + qreal a = m_direction * M_PI / 180.0; + + qreal yd = dist * sin(a); + qreal xd = dist * sin(M_PI / 2.0 - a); + + QPointF requestedPosition = pos() + QPointF(xd, yd); + QGraphicsItem *collidedItem = 0; + QPointF nextPosition = tryMove(requestedPosition, 0, &collidedItem); + if (requestedPosition == nextPosition) { + setPos(nextPosition); + } else { + if (GameItem *gameItem = qgraphicsitem_cast<GameItem *>(collidedItem)) { + TankItem *tankItem = qobject_cast<TankItem *>(gameItem); + if (tankItem != 0) + tankItem->hitByRocket(); + } + + scene()->removeItem(this); + delete this; + } +} diff --git a/examples/statemachine/tankgame/rocketitem.h b/examples/statemachine/tankgame/rocketitem.h new file mode 100644 index 0000000..31146a6 --- /dev/null +++ b/examples/statemachine/tankgame/rocketitem.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ROCKETITEM_H +#define ROCKETITEM_H + +#include "gameitem.h" + +class RocketItem: public GameItem +{ + Q_OBJECT +public: + RocketItem(QObject *parent = 0); + + virtual void idle(qreal elapsed); + qreal speed() const { return 100.0; } + void setDirection(qreal direction) { m_direction = direction; } + +protected: + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + QRectF boundingRect() const; + +private: + qreal m_direction; + qreal m_distance; +}; + +#endif diff --git a/examples/statemachine/tankgame/tankgame.pro b/examples/statemachine/tankgame/tankgame.pro new file mode 100644 index 0000000..59415be --- /dev/null +++ b/examples/statemachine/tankgame/tankgame.pro @@ -0,0 +1,19 @@ +HEADERS += mainwindow.h \ + plugin.h \ + tankitem.h \ + rocketitem.h \ + gameitem.h \ + gameovertransition.h +SOURCES += main.cpp \ + mainwindow.cpp \ + tankitem.cpp \ + rocketitem.cpp \ + gameitem.cpp \ + gameovertransition.cpp +CONFIG += console + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tankgame.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame +INSTALLS += target sources diff --git a/examples/statemachine/tankgame/tankitem.cpp b/examples/statemachine/tankgame/tankitem.cpp new file mode 100644 index 0000000..393d65f --- /dev/null +++ b/examples/statemachine/tankgame/tankitem.cpp @@ -0,0 +1,302 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "tankitem.h" + +#include <QPainter> +#include <QGraphicsScene> +#include <QDebug> + +#include <math.h> + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +class Action +{ +public: + Action(TankItem *item) : m_item(item) + { + } + + TankItem *item() const { return m_item; } + void setItem(TankItem *item) { m_item = item; } + + virtual bool apply(qreal timeDelta) = 0; + +private: + TankItem *m_item; +}; + +class MoveAction: public Action +{ +public: + MoveAction(TankItem *item, qreal distance) + : Action(item), m_distance(distance) + { + m_reverse = m_distance < 0.0; + } + + bool apply(qreal timeDelta) + { + qreal dist = timeDelta * item()->speed() * (m_reverse ? -1.0 : 1.0); + + bool done = false; + if (qAbs(m_distance) < qAbs(dist)) { + done = true; + dist = m_distance; + } + m_distance -= dist; + + qreal a = item()->direction() * M_PI / 180.0; + + qreal yd = dist * sin(a); + qreal xd = dist * sin(M_PI / 2.0 - a); + + item()->setPos(item()->pos() + QPointF(xd, yd)); + return !done; + } + +private: + qreal m_distance; + bool m_reverse; +}; + +class TurnAction: public Action +{ +public: + TurnAction(TankItem *item, qreal distance) + : Action(item), m_distance(distance) + { + m_reverse = m_distance < 0.0; + } + + bool apply(qreal timeDelta) + { + qreal dist = timeDelta * item()->angularSpeed() * (m_reverse ? -1.0 : 1.0); + bool done = false; + if (qAbs(m_distance) < qAbs(dist)) { + done = true; + dist = m_distance; + } + m_distance -= dist; + + item()->setDirection(item()->direction() + dist); + return !done; + } + +private: + qreal m_distance; + bool m_reverse; +}; + +TankItem::TankItem(QObject *parent) + : GameItem(parent), m_currentAction(0), m_currentDirection(0.0), m_enabled(true) +{ + connect(this, SIGNAL(cannonFired()), this, SIGNAL(actionCompleted())); +} + +void TankItem::idle(qreal elapsed) +{ + if (m_enabled) { + if (m_currentAction != 0) { + if (!m_currentAction->apply(elapsed)) { + setAction(0); + emit actionCompleted(); + } + + QGraphicsItem *item = 0; + qreal distance = distanceToObstacle(&item); + if (TankItem *tankItem = qgraphicsitem_cast<TankItem *>(item)) + emit tankSpotted(tankItem->direction(), distance); + } + } +} + +void TankItem::hitByRocket() +{ + emit aboutToBeDestroyed(); + deleteLater(); +} + +void TankItem::setAction(Action *newAction) +{ + if (m_currentAction != 0) + delete m_currentAction; + + m_currentAction = newAction; +} + +void TankItem::fireCannon() +{ + emit cannonFired(); +} + +void TankItem::moveForwards(qreal length) +{ + setAction(new MoveAction(this, length)); +} + +void TankItem::moveBackwards(qreal length) +{ + setAction(new MoveAction(this, -length)); +} + +void TankItem::turn(qreal degrees) +{ + setAction(new TurnAction(this, degrees)); +} + +void TankItem::turnTo(qreal degrees) +{ + setAction(new TurnAction(this, degrees - direction())); +} + +void TankItem::stop() +{ + setAction(0); +} + +QVariant TankItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemPositionChange && scene()) { + QPointF requestedPosition = value.toPointF(); + QLineF collidedLine; + QPointF nextPoint = tryMove(requestedPosition, &collidedLine); + if (nextPoint != requestedPosition) + emit collision(collidedLine); + return nextPoint; + } else { + return QGraphicsItem::itemChange(change, value); + } +} + + +void TankItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + QRectF brect = boundingRect(); + + painter->setBrush(m_color); + painter->setPen(Qt::black); + + // body + painter->drawRect(brect.adjusted(0.0, 4.0, -2.0, -4.0)); + + // cannon + QRectF cannonBase = brect.adjusted(10.0, 6.0, -12.0, -6.0); + painter->drawEllipse(cannonBase); + + painter->drawRect(QRectF(QPointF(cannonBase.center().x(), cannonBase.center().y() - 2.0), + QPointF(brect.right(), cannonBase.center().y() + 2.0))); + + // left track + painter->setBrush(QBrush(Qt::black, Qt::VerPattern)); + QRectF leftTrackRect = QRectF(brect.topLeft(), QPointF(brect.right() - 2.0, brect.top() + 4.0)); + painter->fillRect(leftTrackRect, Qt::darkYellow); + painter->drawRect(leftTrackRect); + + // right track + QRectF rightTrackRect = QRectF(QPointF(brect.left(), brect.bottom() - 4.0), + QPointF(brect.right() - 2.0, brect.bottom())); + painter->fillRect(rightTrackRect, Qt::darkYellow); + painter->drawRect(rightTrackRect); + + if (!m_enabled) { + painter->setPen(QPen(Qt::red, 5)); + + painter->drawEllipse(brect); + + QPainterPath path; + path.addEllipse(brect); + painter->setClipPath(path); + painter->drawLine(brect.topRight(), brect.bottomLeft()); + } +} + +QRectF TankItem::boundingRect() const +{ + return QRectF(-20.0, -10.0, 40.0, 20.0); +} + +qreal TankItem::direction() const +{ + return m_currentDirection; +} + +void TankItem::setDirection(qreal newDirection) +{ + int fullRotations = int(newDirection) / 360; + newDirection -= fullRotations * 360.0; + + qreal diff = newDirection - m_currentDirection; + m_currentDirection = newDirection; + rotate(diff); +} + +qreal TankItem::distanceToObstacle(QGraphicsItem **obstacle) const +{ + qreal dist = sqrt(pow(scene()->sceneRect().width(), 2) + pow(scene()->sceneRect().height(), 2)); + + qreal a = m_currentDirection * M_PI / 180.0; + + qreal yd = dist * sin(a); + qreal xd = dist * sin(M_PI / 2.0 - a); + + QPointF requestedPosition = pos() + QPointF(xd, yd); + QGraphicsItem *collidedItem = 0; + QPointF nextPosition = tryMove(requestedPosition, 0, &collidedItem); + if (collidedItem != 0) { + if (obstacle != 0) + *obstacle = collidedItem; + + QPointF d = nextPosition - pos(); + return sqrt(pow(d.x(), 2) + pow(d.y(), 2)); + } else { + return 0.0; + } +} + +qreal TankItem::distanceToObstacle() const +{ + return distanceToObstacle(0); +} + diff --git a/examples/statemachine/tankgame/tankitem.h b/examples/statemachine/tankgame/tankitem.h new file mode 100644 index 0000000..942fca8 --- /dev/null +++ b/examples/statemachine/tankgame/tankitem.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TANKITEM_H +#define TANKITEM_H + +#include "gameitem.h" + +#include <QColor> + +class Action; +class TankItem: public GameItem +{ + Q_OBJECT + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled) + Q_PROPERTY(qreal direction READ direction WRITE turnTo) + Q_PROPERTY(qreal distanceToObstacle READ distanceToObstacle) +public: + TankItem(QObject *parent = 0); + + void setColor(const QColor &color) { m_color = color; } + QColor color() const { return m_color; } + + void idle(qreal elapsed); + void setDirection(qreal newDirection); + + qreal speed() const { return 90.0; } + qreal angularSpeed() const { return 90.0; } + + QRectF boundingRect() const; + + void hitByRocket(); + + void setEnabled(bool b) { m_enabled = b; } + bool enabled() const { return m_enabled; } + + qreal direction() const; + qreal distanceToObstacle() const; + qreal distanceToObstacle(QGraphicsItem **item) const; + +//! [0] +signals: + void tankSpotted(qreal direction, qreal distance); + void collision(const QLineF &collidedLine); + void actionCompleted(); + void cannonFired(); + void aboutToBeDestroyed(); + +public slots: + void moveForwards(qreal length = 10.0); + void moveBackwards(qreal length = 10.0); + void turn(qreal degrees = 30.0); + void turnTo(qreal degrees = 0.0); + void stop(); + void fireCannon(); +//! [0] + +protected: + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); + +private: + void setAction(Action *newAction); + + Action *m_currentAction; + qreal m_currentDirection; + QColor m_color; + bool m_enabled; +}; + +#endif diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai.pro b/examples/statemachine/tankgameplugins/random_ai/random_ai.pro new file mode 100644 index 0000000..5bc0b26 --- /dev/null +++ b/examples/statemachine/tankgameplugins/random_ai/random_ai.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +CONFIG += plugin +INCLUDEPATH += ../.. +HEADERS = random_ai_plugin.h +SOURCES = random_ai_plugin.cpp +TARGET = $$qtLibraryTarget(random_ai) +DESTDIR = ../../tankgame/plugins + +#! [0] +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS random_ai.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/random_ai
\ No newline at end of file diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp new file mode 100644 index 0000000..d360de9 --- /dev/null +++ b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "random_ai_plugin.h" + +#include <QState> +#include <QtPlugin> + +#include <time.h> + +QState *RandomAiPlugin::create(QState *parentState, QObject *tank) +{ + qsrand(uint(time(NULL))); + + QState *topLevel = new QState(parentState); + + QState *selectNextActionState = new SelectActionState(topLevel); + topLevel->setInitialState(selectNextActionState); + + QState *fireState = new RandomDistanceState(topLevel); + connect(fireState, SIGNAL(distanceComputed(qreal)), tank, SLOT(fireCannon())); + selectNextActionState->addTransition(selectNextActionState, SIGNAL(fireSelected()), fireState); + + QState *moveForwardsState = new RandomDistanceState(topLevel); + connect(moveForwardsState, SIGNAL(distanceComputed(qreal)), tank, SLOT(moveForwards(qreal))); + selectNextActionState->addTransition(selectNextActionState, SIGNAL(moveForwardsSelected()), moveForwardsState); + + QState *moveBackwardsState = new RandomDistanceState(topLevel); + connect(moveBackwardsState, SIGNAL(distanceComputed(qreal)), tank, SLOT(moveBackwards(qreal))); + selectNextActionState->addTransition(selectNextActionState, SIGNAL(moveBackwardsSelected()), moveBackwardsState); + + QState *turnState = new RandomDistanceState(topLevel); + connect(turnState, SIGNAL(distanceComputed(qreal)), tank, SLOT(turn(qreal))); + selectNextActionState->addTransition(selectNextActionState, SIGNAL(turnSelected()), turnState); + + topLevel->addTransition(tank, SIGNAL(actionCompleted()), selectNextActionState); + + return topLevel; +} + +Q_EXPORT_PLUGIN2(random_ai, RandomAiPlugin) diff --git a/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h new file mode 100644 index 0000000..9faeeac --- /dev/null +++ b/examples/statemachine/tankgameplugins/random_ai/random_ai_plugin.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef RANDOM_AI_PLUGIN_H +#define RANDOM_AI_PLUGIN_H + +#include <QObject> +#include <QState> + +#include <tankgame/plugin.h> + +class SelectActionState: public QState +{ + Q_OBJECT +public: + SelectActionState(QState *parent = 0) : QState(parent) + { + } + +signals: + void fireSelected(); + void moveForwardsSelected(); + void moveBackwardsSelected(); + void turnSelected(); + +protected: + void onEntry(QEvent *) + { + int rand = qrand() % 4; + switch (rand) { + case 0: emit fireSelected(); break; + case 1: emit moveForwardsSelected(); break; + case 2: emit moveBackwardsSelected(); break; + case 3: emit turnSelected(); break; + }; + } +}; + +class RandomDistanceState: public QState +{ + Q_OBJECT +public: + RandomDistanceState(QState *parent = 0) : QState(parent) + { + } + +signals: + void distanceComputed(qreal distance); + +protected: + void onEntry(QEvent *) + { + emit distanceComputed(qreal(qrand() % 180)); + } +}; + +class RandomAiPlugin: public QObject, public Plugin +{ + Q_OBJECT + Q_INTERFACES(Plugin) +public: + RandomAiPlugin() { setObjectName("Random"); } + + virtual QState *create(QState *parentState, QObject *tank); +}; + +#endif // RANDOM_AI_PLUGIN_H diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp new file mode 100644 index 0000000..6aae015 --- /dev/null +++ b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "seek_ai.h" + +QState *SeekAi::create(QState *parentState, QObject *tank) +{ + QState *topLevel = new QState(parentState); + topLevel->setObjectName("topLevel"); + + QState *seek = new QState(topLevel); + seek->setObjectName("seek"); + topLevel->setInitialState(seek); + + QState *lookForNearestWall = new SearchState(tank, seek); + lookForNearestWall->setObjectName("lookForNearestWall"); + seek->setInitialState(lookForNearestWall); + + QState *driveToFirstObstacle = new QState(seek); + driveToFirstObstacle->setObjectName("driveToFirstObstacle"); + lookForNearestWall->addTransition(lookForNearestWall, SIGNAL(nearestObstacleStraightAhead()), + driveToFirstObstacle); + + QState *drive = new QState(driveToFirstObstacle); + drive->setObjectName("drive"); + driveToFirstObstacle->setInitialState(drive); + connect(drive, SIGNAL(entered()), tank, SLOT(moveForwards())); + connect(drive, SIGNAL(exited()), tank, SLOT(stop())); + + // Go in loop + QState *finishedDriving = new QState(driveToFirstObstacle); + finishedDriving->setObjectName("finishedDriving"); + drive->addTransition(tank, SIGNAL(actionCompleted()), finishedDriving); + finishedDriving->addTransition(drive); + + QState *turnTo = new QState(seek); + turnTo->setObjectName("turnTo"); + driveToFirstObstacle->addTransition(new CollisionTransition(tank, turnTo)); + + turnTo->addTransition(tank, SIGNAL(actionCompleted()), driveToFirstObstacle); + + ChaseState *chase = new ChaseState(tank, topLevel); + chase->setObjectName("chase"); + seek->addTransition(new TankSpottedTransition(tank, chase)); + chase->addTransition(chase, SIGNAL(finished()), driveToFirstObstacle); + chase->addTransition(new TankSpottedTransition(tank, chase)); + + return topLevel; +} + +Q_EXPORT_PLUGIN2(seek_ai, SeekAi) diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h new file mode 100644 index 0000000..e44ad07 --- /dev/null +++ b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.h @@ -0,0 +1,249 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SEEK_AI_H +#define SEEK_AI_H + +#include <tankgame/plugin.h> + +#include <QState> +#include <QFinalState> +#include <QSignalTransition> +#include <QSignalEvent> +#include <QVariant> +#include <QLineF> +#include <QDebug> + +class SearchState: public QState +{ + Q_OBJECT +public: + SearchState(QObject *tank, QState *parentState = 0) + : QState(parentState), + m_tank(tank), + m_distanceToTurn(360.0), + m_nearestDistance(-1.0), + m_directionOfNearestObstacle(0.0) + { + } + +public slots: + void turnAlittle() + { + qreal dist = m_tank->property("distanceToObstacle").toDouble(); + + if (m_nearestDistance < 0.0 || dist < m_nearestDistance) { + m_nearestDistance = dist; + m_directionOfNearestObstacle = m_tank->property("direction").toDouble(); + } + + m_distanceToTurn -= 10.0; + if (m_distanceToTurn < 0.0) { + disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle())); + connect(m_tank, SIGNAL(actionCompleted()), this, SIGNAL(nearestObstacleStraightAhead())); + m_tank->setProperty("direction", m_directionOfNearestObstacle); + } + + qreal currentDirection = m_tank->property("direction").toDouble(); + m_tank->setProperty("direction", currentDirection + 10.0); + } + +signals: + void nearestObstacleStraightAhead(); + +protected: + void onEntry(QEvent *) + { + connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle())); + turnAlittle(); + } + + void onExit(QEvent *) + { + disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle())); + disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(nearestObstacleStraightAhead())); + } + +private: + QObject *m_tank; + + qreal m_distanceToTurn; + qreal m_nearestDistance; + qreal m_directionOfNearestObstacle; +}; + +class CollisionTransition: public QSignalTransition +{ +public: + CollisionTransition(QObject *tank, QState *turnTo) + : QSignalTransition(tank, SIGNAL(collision(QLineF))), + m_tank(tank), + m_turnTo(turnTo) + { + setTargetState(turnTo); + } + +protected: + bool eventTest(QEvent *event) + { + bool b = QSignalTransition::eventTest(event); + if (b) { + QSignalEvent *se = static_cast<QSignalEvent *>(event); + m_lastLine = se->arguments().at(0).toLineF(); + } + return b; + } + + void onTransition(QEvent *) + { + qreal angleOfWall = m_lastLine.angle(); + + qreal newDirection; + if (qrand() % 2 == 0) + newDirection = angleOfWall; + else + newDirection = angleOfWall - 180.0; + + m_turnTo->assignProperty(m_tank, "direction", newDirection); + } + +private: + QLineF m_lastLine; + QObject *m_tank; + QState *m_turnTo; +}; + +class ChaseState: public QState +{ + class GoToLocationState: public QState + { + public: + GoToLocationState(QObject *tank, QState *parentState = 0) + : QState(parentState), m_tank(tank), m_distance(0.0) + { + } + + void setDistance(qreal distance) { m_distance = distance; } + + protected: + void onEntry() + { + QMetaObject::invokeMethod(m_tank, "moveForwards", Q_ARG(qreal, m_distance)); + } + + private: + QObject *m_tank; + qreal m_distance; + }; + +public: + ChaseState(QObject *tank, QState *parentState = 0) : QState(parentState), m_tank(tank) + { + QState *fireCannon = new QState(this); + fireCannon->setObjectName("fireCannon"); + connect(fireCannon, SIGNAL(entered()), tank, SLOT(fireCannon())); + setInitialState(fireCannon); + + m_goToLocation = new GoToLocationState(tank, this); + m_goToLocation->setObjectName("goToLocation"); + fireCannon->addTransition(tank, SIGNAL(actionCompleted()), m_goToLocation); + + m_turnToDirection = new QState(this); + m_turnToDirection->setObjectName("turnToDirection"); + m_goToLocation->addTransition(tank, SIGNAL(actionCompleted()), m_turnToDirection); + + QFinalState *finalState = new QFinalState(this); + finalState->setObjectName("finalState"); + m_turnToDirection->addTransition(tank, SIGNAL(actionCompleted()), finalState); + } + + void setDirection(qreal direction) + { + m_turnToDirection->assignProperty(m_tank, "direction", direction); + } + + void setDistance(qreal distance) + { + m_goToLocation->setDistance(distance); + } + +private: + QObject *m_tank; + GoToLocationState *m_goToLocation; + QState *m_turnToDirection; + +}; + +class TankSpottedTransition: public QSignalTransition +{ +public: + TankSpottedTransition(QObject *tank, ChaseState *target) : QSignalTransition(tank, SIGNAL(tankSpotted(qreal,qreal))), m_chase(target) + { + setTargetState(target); + } + +protected: + bool eventTest(QEvent *event) + { + bool b = QSignalTransition::eventTest(event); + if (b) { + QSignalEvent *se = static_cast<QSignalEvent *>(event); + m_chase->setDirection(se->arguments().at(0).toDouble()); + m_chase->setDistance(se->arguments().at(1).toDouble()); + } + return b; + } + +private: + ChaseState *m_chase; +}; + +class SeekAi: public QObject, public Plugin +{ + Q_OBJECT + Q_INTERFACES(Plugin) +public: + SeekAi() { setObjectName("Seek and destroy"); } + + virtual QState *create(QState *parentState, QObject *tank); +}; + +#endif diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro new file mode 100644 index 0000000..0d8bf2e --- /dev/null +++ b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +CONFIG += plugin +INCLUDEPATH += ../.. +HEADERS = seek_ai.h +SOURCES = seek_ai.cpp +TARGET = $$qtLibraryTarget(seek_ai) +DESTDIR = ../../tankgame/plugins + +#! [0] +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS seek_ai.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/seek_ai
\ No newline at end of file diff --git a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp new file mode 100644 index 0000000..581a6b2 --- /dev/null +++ b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "spin_ai.h" + +#include <QtPlugin> + +QState *SpinAi::create(QState *parentState, QObject *tank) +{ + QState *topLevel = new QState(parentState); + QState *spinState = new SpinState(tank, topLevel); + topLevel->setInitialState(spinState); + + // When tank is spotted, fire two times and go back to spin state + QState *fireState = new QState(topLevel); + + QState *fireOnce = new QState(fireState); + fireState->setInitialState(fireOnce); + connect(fireOnce, SIGNAL(entered()), tank, SLOT(fireCannon())); + + QState *fireTwice = new QState(fireState); + connect(fireTwice, SIGNAL(entered()), tank, SLOT(fireCannon())); + + fireOnce->addTransition(tank, SIGNAL(actionCompleted()), fireTwice); + fireTwice->addTransition(tank, SIGNAL(actionCompleted()), spinState); + + spinState->addTransition(tank, SIGNAL(tankSpotted(qreal,qreal)), fireState); + + return topLevel; +} + +Q_EXPORT_PLUGIN2(spin_ai, SpinAi) diff --git a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h new file mode 100644 index 0000000..652e8b8 --- /dev/null +++ b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SPIN_AI_H +#define SPIN_AI_H + +#include <tankgame/plugin.h> + +#include <QObject> +#include <QState> +#include <QVariant> + +class SpinState: public QState +{ + Q_OBJECT +public: + SpinState(QObject *tank, QState *parent) : QState(parent), m_tank(tank) + { + } + +public slots: + void spin() + { + m_tank->setProperty("direction", m_tank->property("direction").toDouble() + 90.0); + } + +protected: + void onEntry(QEvent *) + { + connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); + spin(); + } + + void onExit(QEvent *) + { + disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); + } + +private: + QObject *m_tank; + +}; + +class SpinAi: public QObject, public Plugin +{ + Q_OBJECT + Q_INTERFACES(Plugin) +public: + SpinAi() { setObjectName("Spin and destroy"); } + + virtual QState *create(QState *parentState, QObject *tank); +}; + +#endif diff --git a/examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro new file mode 100644 index 0000000..8ab4da0 --- /dev/null +++ b/examples/statemachine/tankgameplugins/spin_ai/spin_ai.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +CONFIG += plugin +INCLUDEPATH += ../.. +HEADERS = spin_ai.h +SOURCES = spin_ai.cpp +TARGET = $$qtLibraryTarget(spin_ai) +DESTDIR = ../../tankgame/plugins + +#! [0] +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS spin_ai.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/spin_ai
\ No newline at end of file diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp new file mode 100644 index 0000000..19137b2 --- /dev/null +++ b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "spin_ai_with_error.h" + +#include <QtPlugin> + +QState *SpinAiWithError::create(QState *parentState, QObject *tank) +{ + QState *topLevel = new QState(parentState); + QState *spinState = new SpinState(tank, topLevel); + topLevel->setInitialState(spinState); + + // When tank is spotted, fire two times and go back to spin state + // (no initial state set for fireState will lead to run-time error in machine) + QState *fireState = new QState(topLevel); + + QState *fireOnce = new QState(fireState); + connect(fireOnce, SIGNAL(entered()), tank, SLOT(fireCannon())); + + QState *fireTwice = new QState(fireState); + connect(fireTwice, SIGNAL(entered()), tank, SLOT(fireCannon())); + + fireOnce->addTransition(tank, SIGNAL(actionCompleted()), fireTwice); + fireTwice->addTransition(tank, SIGNAL(actionCompleted()), spinState); + + spinState->addTransition(tank, SIGNAL(tankSpotted(qreal,qreal)), fireState); + + return topLevel; +} + +Q_EXPORT_PLUGIN2(spin_ai_with_error, SpinAiWithError) diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h new file mode 100644 index 0000000..e040bf2 --- /dev/null +++ b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SPIN_AI_WITH_ERROR_H +#define SPIN_AI_WITH_ERROR_H + +#include <tankgame/plugin.h> + +#include <QObject> +#include <QState> +#include <QVariant> + +class SpinState: public QState +{ + Q_OBJECT +public: + SpinState(QObject *tank, QState *parent) : QState(parent), m_tank(tank) + { + } + +public slots: + void spin() + { + m_tank->setProperty("direction", m_tank->property("direction").toDouble() + 90.0); + } + +protected: + void onEntry(QEvent *) + { + connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); + spin(); + } + + void onExit(QEvent *) + { + disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); + } + +private: + QObject *m_tank; + +}; + +class SpinAiWithError: public QObject, public Plugin +{ + Q_OBJECT + Q_INTERFACES(Plugin) +public: + SpinAiWithError() { setObjectName("Spin and destroy with runtime error in state machine"); } + + virtual QState *create(QState *parentState, QObject *tank); +}; + +#endif diff --git a/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro new file mode 100644 index 0000000..124cf98 --- /dev/null +++ b/examples/statemachine/tankgameplugins/spin_ai_with_error/spin_ai_with_error.pro @@ -0,0 +1,13 @@ +TEMPLATE = lib +CONFIG += plugin +INCLUDEPATH += ../.. +HEADERS = spin_ai_with_error.h +SOURCES = spin_ai_with_error.cpp +TARGET = $$qtLibraryTarget(spin_ai_with_error) +DESTDIR = ../../tankgame/plugins + +#! [0] +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgame/plugins +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS spin_ai_with_error.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins/spin_ai_with_error
\ No newline at end of file diff --git a/examples/statemachine/tankgameplugins/tankgameplugins.pro b/examples/statemachine/tankgameplugins/tankgameplugins.pro new file mode 100644 index 0000000..a098e03 --- /dev/null +++ b/examples/statemachine/tankgameplugins/tankgameplugins.pro @@ -0,0 +1,11 @@ +TEMPLATE = subdirs +SUBDIRS = random_ai \ + spin_ai_with_error \ + spin_ai \ + seek_ai + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tankgameplugins.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/tankgameplugins +INSTALLS += target sources diff --git a/examples/statemachine/trafficlight/main.cpp b/examples/statemachine/trafficlight/main.cpp new file mode 100644 index 0000000..8a46fff --- /dev/null +++ b/examples/statemachine/trafficlight/main.cpp @@ -0,0 +1,190 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#ifdef QT_STATEMACHINE_SOLUTION +#include <qstate.h> +#include <qstatemachine.h> +#include <qfinalstate.h> +#endif + +//! [0] +class LightWidget : public QWidget +{ + Q_OBJECT + Q_PROPERTY(bool on READ isOn WRITE setOn) +public: + LightWidget(const QColor &color, QWidget *parent = 0) + : QWidget(parent), m_color(color), m_on(false) {} + + bool isOn() const + { return m_on; } + void setOn(bool on) + { + if (on == m_on) + return; + m_on = on; + update(); + } + +public slots: + void turnOff() { setOn(false); } + void turnOn() { setOn(true); } + +protected: + virtual void paintEvent(QPaintEvent *) + { + if (!m_on) + return; + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.setBrush(m_color); + painter.drawEllipse(0, 0, width(), height()); + } + +private: + QColor m_color; + bool m_on; +}; +//! [0] + +//! [1] +class TrafficLightWidget : public QWidget +{ +public: + TrafficLightWidget(QWidget *parent = 0) + : QWidget(parent) + { + QVBoxLayout *vbox = new QVBoxLayout(this); + m_red = new LightWidget(Qt::red); + vbox->addWidget(m_red); + m_yellow = new LightWidget(Qt::yellow); + vbox->addWidget(m_yellow); + m_green = new LightWidget(Qt::green); + vbox->addWidget(m_green); + QPalette pal = palette(); + pal.setColor(QPalette::Background, Qt::black); + setPalette(pal); + setAutoFillBackground(true); + } + + LightWidget *redLight() const + { return m_red; } + LightWidget *yellowLight() const + { return m_yellow; } + LightWidget *greenLight() const + { return m_green; } + +private: + LightWidget *m_red; + LightWidget *m_yellow; + LightWidget *m_green; +}; +//! [1] + +//! [2] +QState *createLightState(LightWidget *light, int duration, QState *parent = 0) +{ + QState *lightState = new QState(parent); + QTimer *timer = new QTimer(lightState); + timer->setInterval(duration); + timer->setSingleShot(true); + QState *timing = new QState(lightState); + QObject::connect(timing, SIGNAL(entered()), light, SLOT(turnOn())); + QObject::connect(timing, SIGNAL(entered()), timer, SLOT(start())); + QObject::connect(timing, SIGNAL(exited()), light, SLOT(turnOff())); + QFinalState *done = new QFinalState(lightState); + timing->addTransition(timer, SIGNAL(timeout()), done); + lightState->setInitialState(timing); + return lightState; +} +//! [2] + +//! [3] +class TrafficLight : public QWidget +{ +public: + TrafficLight(QWidget *parent = 0) + : QWidget(parent) + { + QVBoxLayout *vbox = new QVBoxLayout(this); + TrafficLightWidget *widget = new TrafficLightWidget(); + vbox->addWidget(widget); + vbox->setMargin(0); + + QStateMachine *machine = new QStateMachine(this); + QState *redGoingYellow = createLightState(widget->redLight(), 3000); + redGoingYellow->setObjectName("redGoingYellow"); + QState *yellowGoingGreen = createLightState(widget->yellowLight(), 1000); + yellowGoingGreen->setObjectName("yellowGoingGreen"); + redGoingYellow->addTransition(redGoingYellow, SIGNAL(finished()), yellowGoingGreen); + QState *greenGoingYellow = createLightState(widget->greenLight(), 3000); + greenGoingYellow->setObjectName("greenGoingYellow"); + yellowGoingGreen->addTransition(yellowGoingGreen, SIGNAL(finished()), greenGoingYellow); + QState *yellowGoingRed = createLightState(widget->yellowLight(), 1000); + yellowGoingRed->setObjectName("yellowGoingRed"); + greenGoingYellow->addTransition(greenGoingYellow, SIGNAL(finished()), yellowGoingRed); + yellowGoingRed->addTransition(yellowGoingRed, SIGNAL(finished()), redGoingYellow); + + machine->addState(redGoingYellow); + machine->addState(yellowGoingGreen); + machine->addState(greenGoingYellow); + machine->addState(yellowGoingRed); + machine->setInitialState(redGoingYellow); + machine->start(); + } +}; +//! [3] + +//! [4] +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + TrafficLight widget; + widget.resize(110, 300); + widget.show(); + + return app.exec(); +} +//! [4] + +#include "main.moc" diff --git a/examples/statemachine/trafficlight/trafficlight.pro b/examples/statemachine/trafficlight/trafficlight.pro new file mode 100644 index 0000000..684575a --- /dev/null +++ b/examples/statemachine/trafficlight/trafficlight.pro @@ -0,0 +1,7 @@ +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/trafficlight +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS trafficlight.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/trafficlight +INSTALLS += target sources diff --git a/examples/statemachine/twowaybutton/main.cpp b/examples/statemachine/twowaybutton/main.cpp new file mode 100644 index 0000000..a2c6e45 --- /dev/null +++ b/examples/statemachine/twowaybutton/main.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#ifdef QT_STATEMACHINE_SOLUTION +#include <qstate.h> +#include <qstatemachine.h> +#endif + +//! [0] +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + QPushButton button; + QStateMachine machine; +//! [0] + +//! [1] + QState *off = new QState(); + off->assignProperty(&button, "text", "Off"); + off->setObjectName("off"); + + QState *on = new QState(); + on->setObjectName("on"); + on->assignProperty(&button, "text", "On"); +//! [1] + +//! [2] + off->addTransition(&button, SIGNAL(clicked()), on); + on->addTransition(&button, SIGNAL(clicked()), off); +//! [2] + +//! [3] + machine.addState(off); + machine.addState(on); +//! [3] + +//! [4] + machine.setInitialState(off); + machine.start(); +//! [4] + +//! [5] + button.resize(100, 50); + button.show(); + return app.exec(); +} +//! [5] diff --git a/examples/statemachine/twowaybutton/twowaybutton.pro b/examples/statemachine/twowaybutton/twowaybutton.pro new file mode 100644 index 0000000..f6cbc57 --- /dev/null +++ b/examples/statemachine/twowaybutton/twowaybutton.pro @@ -0,0 +1,7 @@ +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/twowaybutton +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS twowaybutton.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/twowaybutton +INSTALLS += target sources diff --git a/examples/tools/contiguouscache/contiguouscache.pro b/examples/tools/contiguouscache/contiguouscache.pro new file mode 100644 index 0000000..f840514 --- /dev/null +++ b/examples/tools/contiguouscache/contiguouscache.pro @@ -0,0 +1,9 @@ +HEADERS = randomlistmodel.h +SOURCES = randomlistmodel.cpp \ + main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tools/contiguouscache +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS contiguouscache.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tools/contiguouscache +INSTALLS += target sources diff --git a/examples/tools/contiguouscache/main.cpp b/examples/tools/contiguouscache/main.cpp new file mode 100644 index 0000000..291aaf4 --- /dev/null +++ b/examples/tools/contiguouscache/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "randomlistmodel.h" +#include <QListView> +#include <QApplication> + +int main(int c, char **v) +{ + QApplication a(c, v); + + QListView view; + view.setUniformItemSizes(true); + view.setModel(new RandomListModel(&view)); + view.show(); + + return a.exec(); +} diff --git a/examples/tools/contiguouscache/randomlistmodel.cpp b/examples/tools/contiguouscache/randomlistmodel.cpp new file mode 100644 index 0000000..b1c7204 --- /dev/null +++ b/examples/tools/contiguouscache/randomlistmodel.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "randomlistmodel.h" +#include <stdlib.h> + +static const int bufferSize(500); +static const int lookAhead(100); +static const int halfLookAhead(lookAhead/2); + +RandomListModel::RandomListModel(QObject *parent) +: QAbstractListModel(parent), m_rows(bufferSize), m_count(10000) +{ +} + +RandomListModel::~RandomListModel() +{ +} + +int RandomListModel::rowCount(const QModelIndex &) const +{ + return m_count; +} + +//! [0] +QVariant RandomListModel::data(const QModelIndex &index, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + int row = index.row(); + + if (row > m_rows.lastIndex()) { + if (row - m_rows.lastIndex() > lookAhead) + cacheRows(row-halfLookAhead, qMin(m_count, row+halfLookAhead)); + else while (row > m_rows.lastIndex()) + m_rows.append(fetchRow(m_rows.lastIndex()+1)); + } else if (row < m_rows.firstIndex()) { + if (m_rows.firstIndex() - row > lookAhead) + cacheRows(qMax(0, row-halfLookAhead), row+halfLookAhead); + else while (row < m_rows.firstIndex()) + m_rows.prepend(fetchRow(m_rows.firstIndex()-1)); + } + + return m_rows.at(row); +} + +void RandomListModel::cacheRows(int from, int to) const +{ + for (int i = from; i <= to; ++i) + m_rows.insert(i, fetchRow(i)); +} +//![0] + +//![1] +QString RandomListModel::fetchRow(int position) const +{ + return QString::number(rand() % ++position); +} +//![1] diff --git a/examples/tools/contiguouscache/randomlistmodel.h b/examples/tools/contiguouscache/randomlistmodel.h new file mode 100644 index 0000000..d32bf16 --- /dev/null +++ b/examples/tools/contiguouscache/randomlistmodel.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef RANDOMLISTMODEL_H +#define RANDOMLISTMODEL_H + +#include <QContiguousCache> +#include <QAbstractListModel> + +class QTimer; +class RandomListModel : public QAbstractListModel +{ + Q_OBJECT +public: + RandomListModel(QObject *parent = 0); + ~RandomListModel(); + + int rowCount(const QModelIndex & = QModelIndex()) const; + QVariant data(const QModelIndex &, int) const; + +private: + void cacheRows(int, int) const; + QString fetchRow(int) const; + + mutable QContiguousCache<QString> m_rows; + const int m_count; +}; + +#endif diff --git a/examples/tools/tools.pro b/examples/tools/tools.pro index 79f0faa..c694dd8 100644 --- a/examples/tools/tools.pro +++ b/examples/tools/tools.pro @@ -5,6 +5,7 @@ SUBDIRS = codecs \ customcompleter \ echoplugin \ i18n \ + contiguouscache \ plugandpaintplugins \ plugandpaint \ regexp \ diff --git a/examples/tutorials/addressbook-fr/part1/main.cpp b/examples/tutorials/addressbook-fr/part1/main.cpp index 22bfd3e..9c96882 100644 --- a/examples/tutorials/addressbook-fr/part1/main.cpp +++ b/examples/tutorials/addressbook-fr/part1/main.cpp @@ -47,8 +47,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook-fr/part2/main.cpp b/examples/tutorials/addressbook-fr/part2/main.cpp index 22bfd3e..9c96882 100644 --- a/examples/tutorials/addressbook-fr/part2/main.cpp +++ b/examples/tutorials/addressbook-fr/part2/main.cpp @@ -47,8 +47,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook-fr/part3/main.cpp b/examples/tutorials/addressbook-fr/part3/main.cpp index b25d656..46f6f03 100644 --- a/examples/tutorials/addressbook-fr/part3/main.cpp +++ b/examples/tutorials/addressbook-fr/part3/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook-fr/part4/main.cpp b/examples/tutorials/addressbook-fr/part4/main.cpp index b25d656..46f6f03 100644 --- a/examples/tutorials/addressbook-fr/part4/main.cpp +++ b/examples/tutorials/addressbook-fr/part4/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook-fr/part5/main.cpp b/examples/tutorials/addressbook-fr/part5/main.cpp index b25d656..46f6f03 100644 --- a/examples/tutorials/addressbook-fr/part5/main.cpp +++ b/examples/tutorials/addressbook-fr/part5/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook-fr/part6/main.cpp b/examples/tutorials/addressbook-fr/part6/main.cpp index b25d656..46f6f03 100644 --- a/examples/tutorials/addressbook-fr/part6/main.cpp +++ b/examples/tutorials/addressbook-fr/part6/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook-fr/part7/main.cpp b/examples/tutorials/addressbook-fr/part7/main.cpp index b25d656..46f6f03 100644 --- a/examples/tutorials/addressbook-fr/part7/main.cpp +++ b/examples/tutorials/addressbook-fr/part7/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook/part1/main.cpp b/examples/tutorials/addressbook/part1/main.cpp index 22bfd3e..9c96882 100644 --- a/examples/tutorials/addressbook/part1/main.cpp +++ b/examples/tutorials/addressbook/part1/main.cpp @@ -47,8 +47,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook/part2/main.cpp b/examples/tutorials/addressbook/part2/main.cpp index 22bfd3e..9c96882 100644 --- a/examples/tutorials/addressbook/part2/main.cpp +++ b/examples/tutorials/addressbook/part2/main.cpp @@ -47,8 +47,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook/part3/main.cpp b/examples/tutorials/addressbook/part3/main.cpp index b25d656..46f6f03 100644 --- a/examples/tutorials/addressbook/part3/main.cpp +++ b/examples/tutorials/addressbook/part3/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook/part4/main.cpp b/examples/tutorials/addressbook/part4/main.cpp index b25d656..46f6f03 100644 --- a/examples/tutorials/addressbook/part4/main.cpp +++ b/examples/tutorials/addressbook/part4/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook/part5/main.cpp b/examples/tutorials/addressbook/part5/main.cpp index b25d656..46f6f03 100644 --- a/examples/tutorials/addressbook/part5/main.cpp +++ b/examples/tutorials/addressbook/part5/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook/part6/main.cpp b/examples/tutorials/addressbook/part6/main.cpp index b25d656..46f6f03 100644 --- a/examples/tutorials/addressbook/part6/main.cpp +++ b/examples/tutorials/addressbook/part6/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/addressbook/part7/main.cpp b/examples/tutorials/addressbook/part7/main.cpp index b25d656..46f6f03 100644 --- a/examples/tutorials/addressbook/part7/main.cpp +++ b/examples/tutorials/addressbook/part7/main.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - AddressBook *addressBook = new AddressBook; - addressBook->show(); + AddressBook addressBook; + addressBook.show(); return app.exec(); } diff --git a/examples/tutorials/widgets/childwidget/childwidget.pro b/examples/tutorials/widgets/childwidget/childwidget.pro new file mode 100644 index 0000000..37ae98e --- /dev/null +++ b/examples/tutorials/widgets/childwidget/childwidget.pro @@ -0,0 +1,7 @@ +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/widgets/childwidget +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS childwidget.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/widgets/childwidget +INSTALLS += target sources diff --git a/examples/tutorials/widgets/childwidget/main.cpp b/examples/tutorials/widgets/childwidget/main.cpp new file mode 100644 index 0000000..fd50b1d --- /dev/null +++ b/examples/tutorials/widgets/childwidget/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the documentation 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [main program] +#include <QtGui> + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QWidget window; + window.resize(320, 240); + window.setWindowTitle(QApplication::translate("childwidget", "Child widget")); + window.show(); + +//! [create, position and show] + QPushButton *button = new QPushButton( + QApplication::translate("childwidget", "Press me"), &window); + button->move(100, 100); + button->show(); +//! [create, position and show] + return app.exec(); +} +//! [main program] diff --git a/examples/tutorials/widgets/nestedlayouts/main.cpp b/examples/tutorials/widgets/nestedlayouts/main.cpp new file mode 100644 index 0000000..226d0f9 --- /dev/null +++ b/examples/tutorials/widgets/nestedlayouts/main.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the documentation 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [main program] +//! [first part] +#include <QtGui> + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QWidget window; + + QLabel *queryLabel = new QLabel( + QApplication::translate("nestedlayouts", "Query:")); + QLineEdit *queryEdit = new QLineEdit(); + QTableView *resultView = new QTableView(); + + QHBoxLayout *queryLayout = new QHBoxLayout(); + queryLayout->addWidget(queryLabel); + queryLayout->addWidget(queryEdit); + + QVBoxLayout *mainLayout = new QVBoxLayout(); + mainLayout->addLayout(queryLayout); + mainLayout->addWidget(resultView); + window.setLayout(mainLayout); + + // Set up the model and configure the view... +//! [first part] + +//! [set up the model] + QStandardItemModel model; + model.setHorizontalHeaderLabels( + QStringList() << QApplication::translate("nestedlayouts", "Name") + << QApplication::translate("nestedlayouts", "Office")); + + QList<QStringList> rows = QList<QStringList>() + << (QStringList() << "Verne Nilsen" << "123") + << (QStringList() << "Carlos Tang" << "77") + << (QStringList() << "Bronwyn Hawcroft" << "119") + << (QStringList() << "Alessandro Hanssen" << "32") + << (QStringList() << "Andrew John Bakken" << "54") + << (QStringList() << "Vanessa Weatherley" << "85") + << (QStringList() << "Rebecca Dickens" << "17") + << (QStringList() << "David Bradley" << "42") + << (QStringList() << "Knut Walters" << "25") + << (QStringList() << "Andrea Jones" << "34"); + + foreach (QStringList row, rows) { + QList<QStandardItem *> items; + foreach (QString text, row) + items.append(new QStandardItem(text)); + model.appendRow(items); + } + + resultView->setModel(&model); + resultView->verticalHeader()->hide(); + resultView->horizontalHeader()->setStretchLastSection(true); +//! [set up the model] +//! [last part] + window.setWindowTitle( + QApplication::translate("nestedlayouts", "Nested layouts")); + window.show(); + return app.exec(); +} +//! [last part] +//! [main program] diff --git a/examples/tutorials/widgets/nestedlayouts/nestedlayouts.pro b/examples/tutorials/widgets/nestedlayouts/nestedlayouts.pro new file mode 100644 index 0000000..a7f141c --- /dev/null +++ b/examples/tutorials/widgets/nestedlayouts/nestedlayouts.pro @@ -0,0 +1,7 @@ +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/widgets/nestedlayouts +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS nestedlayouts.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/widgets/nestedlayouts +INSTALLS += target sources diff --git a/examples/tutorials/widgets/toplevel/main.cpp b/examples/tutorials/widgets/toplevel/main.cpp new file mode 100644 index 0000000..f18fa6b --- /dev/null +++ b/examples/tutorials/widgets/toplevel/main.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the documentation 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [main program] +#include <QtGui> + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); +//! [create, resize and show] + QWidget window; + window.resize(320, 240); + window.show(); +//! [create, resize and show] + window.setWindowTitle( + QApplication::translate("toplevel", "Top-level widget")); + return app.exec(); +} +//! [main program] diff --git a/examples/tutorials/widgets/toplevel/toplevel.pro b/examples/tutorials/widgets/toplevel/toplevel.pro new file mode 100644 index 0000000..58d59c5 --- /dev/null +++ b/examples/tutorials/widgets/toplevel/toplevel.pro @@ -0,0 +1,7 @@ +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/widgets/toplevel +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS toplevel.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/widgets/toplevel +INSTALLS += target sources diff --git a/examples/tutorials/widgets/widgets.pro b/examples/tutorials/widgets/widgets.pro new file mode 100644 index 0000000..7a870e7 --- /dev/null +++ b/examples/tutorials/widgets/widgets.pro @@ -0,0 +1,8 @@ +TEMPLATE = subdirs +SUBDIRS = toplevel childwidget windowlayout nestedlayouts + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/widgets +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS widgets.pro README +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/widgets +INSTALLS += target sources diff --git a/examples/tutorials/widgets/windowlayout/main.cpp b/examples/tutorials/widgets/windowlayout/main.cpp new file mode 100644 index 0000000..c30d669 --- /dev/null +++ b/examples/tutorials/widgets/windowlayout/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the documentation 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [main program] +#include <QtGui> + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + QWidget window; +//! [create, lay out widgets and show] + QLabel *label = new QLabel(QApplication::translate("windowlayout", "Name:")); + QLineEdit *lineEdit = new QLineEdit(); + + QHBoxLayout *layout = new QHBoxLayout(); + layout->addWidget(label); + layout->addWidget(lineEdit); + window.setLayout(layout); +//! [create, lay out widgets and show] + window.setWindowTitle( + QApplication::translate("windowlayout", "Window layout")); + window.show(); + return app.exec(); +} +//! [main program] diff --git a/examples/tutorials/widgets/windowlayout/windowlayout.pro b/examples/tutorials/widgets/windowlayout/windowlayout.pro new file mode 100644 index 0000000..408f6ef --- /dev/null +++ b/examples/tutorials/widgets/windowlayout/windowlayout.pro @@ -0,0 +1,7 @@ +SOURCES = main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/tutorials/widgets/windowlayout +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS windowlayout.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/tutorials/widgets/windowlayout +INSTALLS += target sources diff --git a/examples/webkit/fancybrowser/mainwindow.cpp b/examples/webkit/fancybrowser/mainwindow.cpp index bf61f9c..e24f6cf 100644 --- a/examples/webkit/fancybrowser/mainwindow.cpp +++ b/examples/webkit/fancybrowser/mainwindow.cpp @@ -43,6 +43,8 @@ #include <QtWebKit> #include "mainwindow.h" +//! [1] + MainWindow::MainWindow() { progress = 0; @@ -52,7 +54,9 @@ MainWindow::MainWindow() file.open(QIODevice::ReadOnly); jQuery = file.readAll(); file.close(); +//! [1] +//! [2] view = new QWebView(this); view->load(QUrl("http://www.google.com/ncr")); connect(view, SIGNAL(loadFinished(bool)), SLOT(adjustLocation())); @@ -70,7 +74,9 @@ MainWindow::MainWindow() toolBar->addAction(view->pageAction(QWebPage::Reload)); toolBar->addAction(view->pageAction(QWebPage::Stop)); toolBar->addWidget(locationEdit); +//! [2] +//! [3] QMenu *effectMenu = menuBar()->addMenu(tr("&Effect")); effectMenu->addAction("Highlight all links", this, SLOT(highlightAllLinks())); @@ -89,7 +95,9 @@ MainWindow::MainWindow() setCentralWidget(view); } +//! [3] +//! [4] void MainWindow::adjustLocation() { locationEdit->setText(view->url().toString()); @@ -98,11 +106,12 @@ void MainWindow::adjustLocation() void MainWindow::changeLocation() { QUrl url = QUrl(locationEdit->text()); - locationEdit->setText(url.toString()); view->load(url); view->setFocus(); } +//! [4] +//! [5] void MainWindow::adjustTitle() { if (progress <= 0 || progress >= 100) @@ -116,20 +125,26 @@ void MainWindow::setProgress(int p) progress = p; adjustTitle(); } +//! [5] +//! [6] void MainWindow::finishLoading(bool) { progress = 100; adjustTitle(); view->page()->mainFrame()->evaluateJavaScript(jQuery); } +//! [6] +//! [7] void MainWindow::highlightAllLinks() { QString code = "$('a').each( function () { $(this).css('background-color', 'yellow') } )"; view->page()->mainFrame()->evaluateJavaScript(code); } +//! [7] +//! [8] void MainWindow::rotateImages(bool toggle) { QString code = "$('img').each( function () { $(this).css('-webkit-transition', '-webkit-transform 2s') } )"; @@ -140,7 +155,9 @@ void MainWindow::rotateImages(bool toggle) code = "$('img').each( function () { $(this).css('-webkit-transform', 'rotate(0deg)') } )"; view->page()->mainFrame()->evaluateJavaScript(code); } +//! [8] +//! [9] void MainWindow::removeGifImages() { QString code = "$('[src*=gif]').remove()"; @@ -164,4 +181,5 @@ void MainWindow::removeEmbeddedElements() QString code = "$('embed').remove()"; view->page()->mainFrame()->evaluateJavaScript(code); } +//! [9] diff --git a/examples/webkit/fancybrowser/mainwindow.h b/examples/webkit/fancybrowser/mainwindow.h index 9362ca7..ba0bede 100644 --- a/examples/webkit/fancybrowser/mainwindow.h +++ b/examples/webkit/fancybrowser/mainwindow.h @@ -39,13 +39,14 @@ ** ****************************************************************************/ -#include <QMainWindow> +#include <QtGui> -QT_BEGIN_NAMESPACE class QWebView; +QT_BEGIN_NAMESPACE class QLineEdit; QT_END_NAMESPACE +//! [1] class MainWindow : public QMainWindow { Q_OBJECT @@ -73,4 +74,5 @@ private: QWebView *view; QLineEdit *locationEdit; int progress; +//! [1] }; diff --git a/examples/widgets/movie/movie.pro b/examples/widgets/movie/movie.pro index 1c7cbae..6aa5780 100644 --- a/examples/widgets/movie/movie.pro +++ b/examples/widgets/movie/movie.pro @@ -7,3 +7,11 @@ target.path = $$[QT_INSTALL_EXAMPLES]/widgets/movie sources.files = $$SOURCES $$HEADERS $$RESOURCES movie.pro animation.mng sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/movie INSTALLS += target sources + +wince*: { + addFiles.sources += *.mng + addFiles.path = . + DEPLOYMENT += addFiles + DEPLOYMENT_PLUGIN += qmng +} + diff --git a/examples/xmlpatterns/trafficinfo/main.cpp b/examples/xmlpatterns/trafficinfo/main.cpp index 97b2bf7..544260d 100644 --- a/examples/xmlpatterns/trafficinfo/main.cpp +++ b/examples/xmlpatterns/trafficinfo/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the examples of the Qt Toolkit. diff --git a/examples/xmlpatterns/trafficinfo/mainwindow.cpp b/examples/xmlpatterns/trafficinfo/mainwindow.cpp index 393e33c..aeb7224 100644 --- a/examples/xmlpatterns/trafficinfo/mainwindow.cpp +++ b/examples/xmlpatterns/trafficinfo/mainwindow.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the examples of the Qt Toolkit. diff --git a/examples/xmlpatterns/trafficinfo/mainwindow.h b/examples/xmlpatterns/trafficinfo/mainwindow.h index d48109d..5362bcd 100644 --- a/examples/xmlpatterns/trafficinfo/mainwindow.h +++ b/examples/xmlpatterns/trafficinfo/mainwindow.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the examples of the Qt Toolkit. diff --git a/examples/xmlpatterns/trafficinfo/stationdialog.cpp b/examples/xmlpatterns/trafficinfo/stationdialog.cpp index 9876bdb..54ed904 100644 --- a/examples/xmlpatterns/trafficinfo/stationdialog.cpp +++ b/examples/xmlpatterns/trafficinfo/stationdialog.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the examples of the Qt Toolkit. diff --git a/examples/xmlpatterns/trafficinfo/stationdialog.h b/examples/xmlpatterns/trafficinfo/stationdialog.h index 5ac1635..0e87f61 100644 --- a/examples/xmlpatterns/trafficinfo/stationdialog.h +++ b/examples/xmlpatterns/trafficinfo/stationdialog.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the examples of the Qt Toolkit. diff --git a/examples/xmlpatterns/trafficinfo/stationquery.cpp b/examples/xmlpatterns/trafficinfo/stationquery.cpp index ab42ad9..3db0fdb 100644 --- a/examples/xmlpatterns/trafficinfo/stationquery.cpp +++ b/examples/xmlpatterns/trafficinfo/stationquery.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the examples of the Qt Toolkit. diff --git a/examples/xmlpatterns/trafficinfo/stationquery.h b/examples/xmlpatterns/trafficinfo/stationquery.h index 5cbf28a..d1e4d2f 100644 --- a/examples/xmlpatterns/trafficinfo/stationquery.h +++ b/examples/xmlpatterns/trafficinfo/stationquery.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the examples of the Qt Toolkit. diff --git a/examples/xmlpatterns/trafficinfo/timequery.cpp b/examples/xmlpatterns/trafficinfo/timequery.cpp index bd63560..d6bf695 100644 --- a/examples/xmlpatterns/trafficinfo/timequery.cpp +++ b/examples/xmlpatterns/trafficinfo/timequery.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the examples of the Qt Toolkit. diff --git a/examples/xmlpatterns/trafficinfo/timequery.h b/examples/xmlpatterns/trafficinfo/timequery.h index f88e62c..2435c71 100644 --- a/examples/xmlpatterns/trafficinfo/timequery.h +++ b/examples/xmlpatterns/trafficinfo/timequery.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the examples of the Qt Toolkit. |