[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[556] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
| 8 | **
|
---|
[846] | 9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
| 10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
[556] | 11 | **
|
---|
[846] | 12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
| 13 | ** modification, are permitted provided that the following conditions are
|
---|
| 14 | ** met:
|
---|
| 15 | ** * Redistributions of source code must retain the above copyright
|
---|
| 16 | ** notice, this list of conditions and the following disclaimer.
|
---|
| 17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
| 18 | ** notice, this list of conditions and the following disclaimer in
|
---|
| 19 | ** the documentation and/or other materials provided with the
|
---|
| 20 | ** distribution.
|
---|
| 21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
| 22 | ** the names of its contributors may be used to endorse or promote
|
---|
| 23 | ** products derived from this software without specific prior written
|
---|
| 24 | ** permission.
|
---|
[556] | 25 | **
|
---|
[846] | 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
| 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
| 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
| 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
| 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
| 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
[556] | 37 | ** $QT_END_LICENSE$
|
---|
| 38 | **
|
---|
| 39 | ****************************************************************************/
|
---|
| 40 |
|
---|
| 41 | #include <QtGui>
|
---|
| 42 |
|
---|
| 43 | int main(int argv, char **args)
|
---|
| 44 | {
|
---|
| 45 | QApplication app(argv, args);
|
---|
| 46 | QWidget *button;
|
---|
| 47 |
|
---|
| 48 | {
|
---|
| 49 | //![0]
|
---|
| 50 | QStateMachine machine;
|
---|
| 51 | machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
|
---|
| 52 |
|
---|
| 53 | QState *s1 = new QState();
|
---|
| 54 | s1->assignProperty(object, "fooBar", 1.0);
|
---|
| 55 | machine.addState(s1);
|
---|
| 56 | machine.setInitialState(s1);
|
---|
| 57 |
|
---|
| 58 | QState *s2 = new QState();
|
---|
| 59 | machine.addState(s2);
|
---|
| 60 | //![0]
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | {
|
---|
| 64 |
|
---|
| 65 | //![2]
|
---|
| 66 | QStateMachine machine;
|
---|
| 67 | machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
|
---|
| 68 |
|
---|
| 69 | QState *s1 = new QState();
|
---|
| 70 | s1->assignProperty(object, "fooBar", 1.0);
|
---|
| 71 | machine.addState(s1);
|
---|
| 72 | machine.setInitialState(s1);
|
---|
| 73 |
|
---|
| 74 | QState *s2 = new QState(s1);
|
---|
| 75 | s2->assignProperty(object, "fooBar", 2.0);
|
---|
| 76 | s1->setInitialState(s2);
|
---|
| 77 |
|
---|
| 78 | QState *s3 = new QState(s1);
|
---|
| 79 | //![2]
|
---|
| 80 |
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | {
|
---|
| 84 | //![3]
|
---|
| 85 | QState *s1 = new QState();
|
---|
| 86 | QState *s2 = new QState();
|
---|
| 87 |
|
---|
| 88 | s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
|
---|
| 89 | s2->assignProperty(button, "geometry", QRectF(0, 0, 100, 100));
|
---|
| 90 |
|
---|
| 91 | s1->addTransition(button, SIGNAL(clicked()), s2);
|
---|
| 92 | //![3]
|
---|
| 93 |
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | {
|
---|
| 97 | //![4]
|
---|
| 98 | QState *s1 = new QState();
|
---|
| 99 | QState *s2 = new QState();
|
---|
| 100 |
|
---|
| 101 | s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
|
---|
| 102 | s2->assignProperty(button, "geometry", QRectF(0, 0, 100, 100));
|
---|
| 103 |
|
---|
| 104 | QSignalTransition *transition = s1->addTransition(button, SIGNAL(clicked()), s2);
|
---|
| 105 | transition->addAnimation(new QPropertyAnimation(button, "geometry"));
|
---|
| 106 | //![4]
|
---|
| 107 |
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | {
|
---|
| 111 | QMainWindow *mainWindow = 0;
|
---|
| 112 |
|
---|
| 113 | //![5]
|
---|
| 114 | QMessageBox *messageBox = new QMessageBox(mainWindow);
|
---|
| 115 | messageBox->addButton(QMessageBox::Ok);
|
---|
| 116 | messageBox->setText("Button geometry has been set!");
|
---|
| 117 | messageBox->setIcon(QMessageBox::Information);
|
---|
| 118 |
|
---|
| 119 | QState *s1 = new QState();
|
---|
| 120 |
|
---|
| 121 | QState *s2 = new QState();
|
---|
| 122 | s2->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
|
---|
| 123 | connect(s2, SIGNAL(entered()), messageBox, SLOT(exec()));
|
---|
| 124 |
|
---|
| 125 | s1->addTransition(button, SIGNAL(clicked()), s2);
|
---|
| 126 | //![5]
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | {
|
---|
| 130 | QMainWindow *mainWindow = 0;
|
---|
| 131 |
|
---|
| 132 | //![6]
|
---|
| 133 | QMessageBox *messageBox = new QMessageBox(mainWindow);
|
---|
| 134 | messageBox->addButton(QMessageBox::Ok);
|
---|
| 135 | messageBox->setText("Button geometry has been set!");
|
---|
| 136 | messageBox->setIcon(QMessageBox::Information);
|
---|
| 137 |
|
---|
| 138 | QState *s1 = new QState();
|
---|
| 139 |
|
---|
| 140 | QState *s2 = new QState();
|
---|
| 141 | s2->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
|
---|
| 142 |
|
---|
| 143 | QState *s3 = new QState();
|
---|
| 144 | connect(s3, SIGNAL(entered()), messageBox, SLOT(exec()));
|
---|
| 145 |
|
---|
| 146 | s1->addTransition(button, SIGNAL(clicked()), s2);
|
---|
| 147 | s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3);
|
---|
| 148 | //![6]
|
---|
| 149 |
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | {
|
---|
| 153 |
|
---|
| 154 | //![7]
|
---|
| 155 | QState *s1 = new QState();
|
---|
| 156 | QState *s2 = new QState();
|
---|
| 157 |
|
---|
| 158 | s2->assignProperty(object, "fooBar", 2.0);
|
---|
| 159 | s1->addTransition(s2);
|
---|
| 160 |
|
---|
| 161 | QStateMachine machine;
|
---|
| 162 | machine.setInitialState(s1);
|
---|
| 163 | machine.addDefaultAnimation(new QPropertyAnimation(object, "fooBar"));
|
---|
| 164 | //![7]
|
---|
| 165 |
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 | return app.exec();
|
---|
| 171 | }
|
---|
| 172 |
|
---|