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