diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-04-17 14:06:06 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-04-17 14:06:06 (GMT) |
commit | f15b8a83e2e51955776a3f07cb85ebfc342dd8ef (patch) | |
tree | c5dc684986051654898db11ce73e03b9fec8db99 /examples/animation/example | |
download | Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.zip Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.tar.gz Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.tar.bz2 |
Initial import of statemachine branch from the old kinetic repository
Diffstat (limited to 'examples/animation/example')
-rw-r--r-- | examples/animation/example/example.pro | 12 | ||||
-rw-r--r-- | examples/animation/example/main.cpp | 23 | ||||
-rw-r--r-- | examples/animation/example/mainwindow.cpp | 222 | ||||
-rw-r--r-- | examples/animation/example/mainwindow.h | 45 |
4 files changed, 302 insertions, 0 deletions
diff --git a/examples/animation/example/example.pro b/examples/animation/example/example.pro new file mode 100644 index 0000000..bc79b82 --- /dev/null +++ b/examples/animation/example/example.pro @@ -0,0 +1,12 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Thu Sep 25 14:03:47 2008 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +# Input +HEADERS += mainwindow.h +SOURCES += main.cpp mainwindow.cpp diff --git a/examples/animation/example/main.cpp b/examples/animation/example/main.cpp new file mode 100644 index 0000000..d5f5607 --- /dev/null +++ b/examples/animation/example/main.cpp @@ -0,0 +1,23 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + //Q_INIT_RESOURCE(example); + QApplication app(argc, argv); + MainWindow w; + w.show(); + return app.exec(); +} + diff --git a/examples/animation/example/mainwindow.cpp b/examples/animation/example/mainwindow.cpp new file mode 100644 index 0000000..2b0e035 --- /dev/null +++ b/examples/animation/example/mainwindow.cpp @@ -0,0 +1,222 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include "mainwindow.h" + +MainWindow::MainWindow() : QMainWindow(0) +{ + // Text edit and button + listWidget = new QListWidget; + new QListWidgetItem("Rachel", listWidget); + new QListWidgetItem("Andreas", listWidget); + new QListWidgetItem("David", listWidget); + new QListWidgetItem("Olivier", listWidget); + new QListWidgetItem("Andy", listWidget); + new QListWidgetItem("Martial", listWidget); + new QListWidgetItem("Kazou", listWidget); + new QListWidgetItem("Fred", listWidget); + new QListWidgetItem("Ingrid", listWidget); + QGraphicsProxyWidget *listProxy = new QGraphicsProxyWidget; + listProxy->setWidget(listWidget); + + labelWidget = new QLabel; + QGraphicsProxyWidget *labelProxy = new QGraphicsProxyWidget; + labelProxy->setWidget(labelWidget); + labelWidget->setAttribute(Qt::WA_NoSystemBackground); + + label2Widget = new QLabel; + label2Widget->setAlignment(Qt::AlignCenter); + QGraphicsProxyWidget *label2Proxy = new QGraphicsProxyWidget; + label2Proxy->setWidget(label2Widget); + label2Widget->setAttribute(Qt::WA_NoSystemBackground); + + editWidget = new QLineEdit; + QGraphicsProxyWidget *editProxy = new QGraphicsProxyWidget; + editProxy->setWidget(editWidget); + editWidget->setAttribute(Qt::WA_NoSystemBackground); + + // Parent widget + QGraphicsWidget *widget = new QGraphicsWidget; + // Parent widget + QGraphicsWidget *widget2 = new QGraphicsWidget; + + QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout(Qt::Vertical, widget); + vLayout->addItem(listProxy); + vLayout->addItem(widget2); + widget->setLayout(vLayout); + + QPushButton *button = new QPushButton; + QGraphicsProxyWidget *buttonProxy = new QGraphicsProxyWidget; + buttonProxy->setWidget(button); + + QPushButton *button2 = new QPushButton; + QGraphicsProxyWidget *buttonProxy2 = new QGraphicsProxyWidget; + buttonProxy2->setWidget(button2); + + QPushButton *button3 = new QPushButton; + QGraphicsProxyWidget *buttonProxy3 = new QGraphicsProxyWidget; + buttonProxy3->setWidget(button3); + + QPushButton *button4 = new QPushButton; + QGraphicsProxyWidget *buttonProxy4 = new QGraphicsProxyWidget; + buttonProxy4->setWidget(button4); + + QGraphicsLinearLayout *hLayout = new QGraphicsLinearLayout(Qt::Horizontal, widget2); + hLayout->addItem(buttonProxy); + hLayout->addItem(buttonProxy2); + hLayout->addItem(buttonProxy3); + widget2->setLayout(hLayout); + + scene = new QGraphicsScene(0, 0, 700, 600); + scene->setBackgroundBrush(scene->palette().window()); + scene->addItem(widget); + scene->addItem(editProxy); + scene->addItem(label2Proxy); + scene->addItem(labelProxy); + scene->addItem(buttonProxy4); + + machine = new QStateMachine(); + + group = new QState(machine->rootState()); + state1 = new QState(group); + state2 = new QState(group); + state3 = new QState(group); + group->setInitialState(state1); + + machine->setInitialState(group); + + // State 1 + state1->assignProperty(button, "text", "Edit"); + state1->assignProperty(button2, "text", "Add"); + state1->assignProperty(button3, "text", "Remove"); + state1->assignProperty(button4, "text", "Accept"); + state1->addTransition(button2, SIGNAL(clicked()), state3); + state1->assignProperty(listProxy, "geometry", QRectF(0, 0, 700, 560)); + state1->assignProperty(widget, "geometry", QRectF(0, 0, 700, 600)); + state1->assignProperty(editProxy, "opacity", double(0)); + state1->assignProperty(labelProxy, "opacity", double(0)); + state1->assignProperty(label2Proxy, "opacity", double(0)); + state1->assignProperty(buttonProxy4, "opacity", double(0)); + state1->assignProperty(labelWidget, "text", "Name : "); + state1->assignProperty(label2Widget, "text", "Edit a contact"); + state1->assignProperty(label2Proxy, "geometry", QRectF(375, -50, 300, 30)); + state1->assignProperty(labelProxy, "geometry", QRectF(350, 300, 100, 30)); + state1->assignProperty(editProxy, "geometry", QRectF(750, 300, 250, 30)); + state1->assignProperty(buttonProxy4, "geometry", QRectF(500, 350, 80, 25)); + + // State 2 + state2->assignProperty(button, "text", "Close Editing"); + state2->assignProperty(listProxy, "geometry", QRectF(0, 0, 350, 560)); + state2->addTransition(button2, SIGNAL(clicked()), state3); + state2->addTransition(button4, SIGNAL(clicked()), state1); + + state2->assignProperty(editProxy, "opacity", double(1)); + state2->assignProperty(labelProxy, "opacity", double(1)); + state2->assignProperty(label2Proxy, "opacity", double(1)); + state2->assignProperty(buttonProxy4, "opacity", double(1)); + + state2->assignProperty(label2Proxy, "geometry", QRectF(375, 250, 300, 30)); + state2->assignProperty(editProxy, "geometry", QRectF(440, 300, 260, 30)); + + // State 3 + state3->assignProperty(button4, "text", "Create New"); + state3->assignProperty(listProxy, "geometry", QRectF(0, 0, 350, 560)); + state3->addTransition(button4, SIGNAL(clicked()), state1); + state3->addTransition(button, SIGNAL(clicked()), state1); + state3->assignProperty(editProxy, "opacity", double(1)); + state3->assignProperty(labelProxy, "opacity", double(1)); + state3->assignProperty(label2Proxy, "opacity", double(1)); + state3->assignProperty(buttonProxy4, "opacity", double(1)); + + state3->assignProperty(label2Proxy, "geometry", QRectF(375, 250, 300, 30)); + state3->assignProperty(editProxy, "geometry", QRectF(440, 300, 260, 30)); + + { + QAnimationGroup *animationGroup = new QParallelAnimationGroup; + QVariantAnimation *anim = new QPropertyAnimation(labelProxy, "opacity"); + animationGroup->addAnimation(anim); + anim = new QPropertyAnimation(label2Proxy, "geometry"); + animationGroup->addAnimation(anim); + anim = new QPropertyAnimation(editProxy, "geometry"); + animationGroup->addAnimation(anim); + anim = new QPropertyAnimation(listProxy, "geometry"); + animationGroup->addAnimation(anim); + + QAbstractTransition *trans = state1->addTransition(button, SIGNAL(clicked()), state2); + trans->addAnimation(animationGroup); + } + + { + QVariantAnimation *anim; + QAnimationGroup *animationGroup = new QParallelAnimationGroup; + anim = new QPropertyAnimation(label2Proxy, "geometry"); + animationGroup->addAnimation(anim); + anim = new QPropertyAnimation(editProxy, "geometry"); + animationGroup->addAnimation(anim); + anim = new QPropertyAnimation(listProxy, "geometry"); + animationGroup->addAnimation(anim); + QAbstractTransition *trans = state2->addTransition(button, SIGNAL(clicked()), state1); + trans->addAnimation(animationGroup); + } + + currentState = state1; + + view = new QGraphicsView(scene); + + setCentralWidget(view); + + state3->invokeMethodOnEntry(this, "onEnterState3"); + state2->invokeMethodOnEntry(this, "onEnterState2"); + state1->invokeMethodOnEntry(this, "onEnterState1"); + + connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemClicked(QListWidgetItem*))); + connect(button3, SIGNAL(clicked()), this, SLOT(onRemoveClicked())); + + machine->start(); +} + +void MainWindow::onEnterState2() +{ + currentState = state2; + if (listWidget->currentItem()) + editWidget->setText(listWidget->currentItem()->text()); +} + +void MainWindow::onEnterState1() +{ + if (currentState == state2 && listWidget->currentItem()) + listWidget->currentItem()->setText(editWidget->text()); + if (currentState == state3 && !editWidget->text().isNull()) { + new QListWidgetItem(editWidget->text(), listWidget); + editWidget->clear(); + } + currentState = state1; +} + +void MainWindow::onEnterState3() +{ + currentState = state3; +} + +void MainWindow::onItemClicked(QListWidgetItem*) +{ + if (currentState == state2) + { + editWidget->setText(listWidget->currentItem()->text()); + editWidget->clear(); + } +} + +void MainWindow::onRemoveClicked() +{ + QListWidgetItem *listItem = listWidget->takeItem(listWidget->currentRow()); + delete listItem; +} diff --git a/examples/animation/example/mainwindow.h b/examples/animation/example/mainwindow.h new file mode 100644 index 0000000..6be7463 --- /dev/null +++ b/examples/animation/example/mainwindow.h @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#ifndef __MAINWINDOW__H__ +#define __MAINWINDOW__H__ + +#include <QtGui> + +class MainWindow : public QMainWindow +{ +Q_OBJECT +public: + MainWindow(); + +private slots : + void onEnterState3(); + void onEnterState2(); + void onEnterState1(); + void onItemClicked(QListWidgetItem*); + void onRemoveClicked(); +private: + QListWidget *listWidget; + QLabel *labelWidget; + QLabel *label2Widget; + QLineEdit *editWidget; + QGraphicsScene *scene; + QGraphicsView *view; + QState *state1; + QState *state2; + QState *state3; + QState *currentState; + QState *group; + QStateMachine *machine; +}; + +#endif //__MAINWINDOW__H__ + |