author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:BSD$ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
10 |
** You may use this file under the terms of the BSD license as follows: |
0 | 11 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
12 |
** "Redistribution and use in source and binary forms, with or without |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
13 |
** modification, are permitted provided that the following conditions are |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
14 |
** met: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
15 |
** * Redistributions of source code must retain the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
16 |
** notice, this list of conditions and the following disclaimer. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
17 |
** * Redistributions in binary form must reproduce the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
18 |
** notice, this list of conditions and the following disclaimer in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
19 |
** the documentation and/or other materials provided with the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
20 |
** distribution. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
21 |
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
22 |
** the names of its contributors may be used to endorse or promote |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
23 |
** products derived from this software without specific prior written |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
24 |
** permission. |
0 | 25 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
26 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
27 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
28 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
29 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
30 |
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
31 |
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
32 |
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
33 |
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
34 |
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
35 |
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
36 |
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
0 | 37 |
** $QT_END_LICENSE$ |
38 |
** |
|
39 |
****************************************************************************/ |
|
40 |
||
41 |
#include <QtGui> |
|
42 |
||
43 |
class Pixmap : public QGraphicsObject |
|
44 |
{ |
|
45 |
Q_OBJECT |
|
46 |
public: |
|
47 |
Pixmap(const QPixmap &pix) : QGraphicsObject(), p(pix) |
|
48 |
{ |
|
49 |
} |
|
50 |
||
51 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
52 |
{ |
|
53 |
painter->drawPixmap(QPointF(), p); |
|
54 |
} |
|
55 |
||
56 |
QRectF boundingRect() const |
|
57 |
{ |
|
58 |
return QRectF( QPointF(0, 0), p.size()); |
|
59 |
} |
|
60 |
||
61 |
private: |
|
62 |
QPixmap p; |
|
63 |
}; |
|
64 |
||
65 |
int main(int argc, char *argv[]) |
|
66 |
{ |
|
67 |
Q_INIT_RESOURCE(states); |
|
68 |
||
69 |
QApplication app(argc, argv); |
|
70 |
||
71 |
// Text edit and button |
|
72 |
QTextEdit *edit = new QTextEdit; |
|
73 |
edit->setText("asdf lkjha yuoiqwe asd iuaysd u iasyd uiy " |
|
74 |
"asdf lkjha yuoiqwe asd iuaysd u iasyd uiy " |
|
75 |
"asdf lkjha yuoiqwe asd iuaysd u iasyd uiy " |
|
76 |
"asdf lkjha yuoiqwe asd iuaysd u iasyd uiy!"); |
|
77 |
||
78 |
QPushButton *button = new QPushButton; |
|
79 |
QGraphicsProxyWidget *buttonProxy = new QGraphicsProxyWidget; |
|
80 |
buttonProxy->setWidget(button); |
|
81 |
QGraphicsProxyWidget *editProxy = new QGraphicsProxyWidget; |
|
82 |
editProxy->setWidget(edit); |
|
83 |
||
84 |
QGroupBox *box = new QGroupBox; |
|
85 |
box->setFlat(true); |
|
86 |
box->setTitle("Options"); |
|
87 |
||
88 |
QVBoxLayout *layout2 = new QVBoxLayout; |
|
89 |
box->setLayout(layout2); |
|
90 |
layout2->addWidget(new QRadioButton("Herring")); |
|
91 |
layout2->addWidget(new QRadioButton("Blue Parrot")); |
|
92 |
layout2->addWidget(new QRadioButton("Petunias")); |
|
93 |
layout2->addStretch(); |
|
94 |
||
95 |
QGraphicsProxyWidget *boxProxy = new QGraphicsProxyWidget; |
|
96 |
boxProxy->setWidget(box); |
|
97 |
||
98 |
// Parent widget |
|
99 |
QGraphicsWidget *widget = new QGraphicsWidget; |
|
100 |
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, widget); |
|
101 |
layout->addItem(editProxy); |
|
102 |
layout->addItem(buttonProxy); |
|
103 |
widget->setLayout(layout); |
|
104 |
||
105 |
Pixmap *p1 = new Pixmap(QPixmap(":/digikam.png")); |
|
106 |
Pixmap *p2 = new Pixmap(QPixmap(":/akregator.png")); |
|
107 |
Pixmap *p3 = new Pixmap(QPixmap(":/accessories-dictionary.png")); |
|
108 |
Pixmap *p4 = new Pixmap(QPixmap(":/k3b.png")); |
|
109 |
Pixmap *p5 = new Pixmap(QPixmap(":/help-browser.png")); |
|
110 |
Pixmap *p6 = new Pixmap(QPixmap(":/kchart.png")); |
|
111 |
||
112 |
QGraphicsScene scene(0, 0, 400, 300); |
|
113 |
scene.setBackgroundBrush(scene.palette().window()); |
|
114 |
scene.addItem(widget); |
|
115 |
scene.addItem(boxProxy); |
|
116 |
scene.addItem(p1); |
|
117 |
scene.addItem(p2); |
|
118 |
scene.addItem(p3); |
|
119 |
scene.addItem(p4); |
|
120 |
scene.addItem(p5); |
|
121 |
scene.addItem(p6); |
|
122 |
||
123 |
QStateMachine machine; |
|
124 |
QState *state1 = new QState(&machine); |
|
125 |
QState *state2 = new QState(&machine); |
|
126 |
QState *state3 = new QState(&machine); |
|
127 |
machine.setInitialState(state1); |
|
128 |
||
129 |
// State 1 |
|
130 |
state1->assignProperty(button, "text", "Switch to state 2"); |
|
131 |
state1->assignProperty(widget, "geometry", QRectF(0, 0, 400, 150)); |
|
132 |
state1->assignProperty(box, "geometry", QRect(-200, 150, 200, 150)); |
|
133 |
state1->assignProperty(p1, "pos", QPointF(68, 185)); |
|
134 |
state1->assignProperty(p2, "pos", QPointF(168, 185)); |
|
135 |
state1->assignProperty(p3, "pos", QPointF(268, 185)); |
|
136 |
state1->assignProperty(p4, "pos", QPointF(68-150, 48-150)); |
|
137 |
state1->assignProperty(p5, "pos", QPointF(168, 48-150)); |
|
138 |
state1->assignProperty(p6, "pos", QPointF(268+150, 48-150)); |
|
139 |
state1->assignProperty(p1, "rotation", qreal(0)); |
|
140 |
state1->assignProperty(p2, "rotation", qreal(0)); |
|
141 |
state1->assignProperty(p3, "rotation", qreal(0)); |
|
142 |
state1->assignProperty(p4, "rotation", qreal(-270)); |
|
143 |
state1->assignProperty(p5, "rotation", qreal(-90)); |
|
144 |
state1->assignProperty(p6, "rotation", qreal(270)); |
|
145 |
state1->assignProperty(boxProxy, "opacity", qreal(0)); |
|
146 |
state1->assignProperty(p1, "opacity", qreal(1)); |
|
147 |
state1->assignProperty(p2, "opacity", qreal(1)); |
|
148 |
state1->assignProperty(p3, "opacity", qreal(1)); |
|
149 |
state1->assignProperty(p4, "opacity", qreal(0)); |
|
150 |
state1->assignProperty(p5, "opacity", qreal(0)); |
|
151 |
state1->assignProperty(p6, "opacity", qreal(0)); |
|
152 |
||
153 |
// State 2 |
|
154 |
state2->assignProperty(button, "text", "Switch to state 3"); |
|
155 |
state2->assignProperty(widget, "geometry", QRectF(200, 150, 200, 150)); |
|
156 |
state2->assignProperty(box, "geometry", QRect(9, 150, 190, 150)); |
|
157 |
state2->assignProperty(p1, "pos", QPointF(68-150, 185+150)); |
|
158 |
state2->assignProperty(p2, "pos", QPointF(168, 185+150)); |
|
159 |
state2->assignProperty(p3, "pos", QPointF(268+150, 185+150)); |
|
160 |
state2->assignProperty(p4, "pos", QPointF(64, 48)); |
|
161 |
state2->assignProperty(p5, "pos", QPointF(168, 48)); |
|
162 |
state2->assignProperty(p6, "pos", QPointF(268, 48)); |
|
163 |
state2->assignProperty(p1, "rotation", qreal(-270)); |
|
164 |
state2->assignProperty(p2, "rotation", qreal(90)); |
|
165 |
state2->assignProperty(p3, "rotation", qreal(270)); |
|
166 |
state2->assignProperty(p4, "rotation", qreal(0)); |
|
167 |
state2->assignProperty(p5, "rotation", qreal(0)); |
|
168 |
state2->assignProperty(p6, "rotation", qreal(0)); |
|
169 |
state2->assignProperty(boxProxy, "opacity", qreal(1)); |
|
170 |
state2->assignProperty(p1, "opacity", qreal(0)); |
|
171 |
state2->assignProperty(p2, "opacity", qreal(0)); |
|
172 |
state2->assignProperty(p3, "opacity", qreal(0)); |
|
173 |
state2->assignProperty(p4, "opacity", qreal(1)); |
|
174 |
state2->assignProperty(p5, "opacity", qreal(1)); |
|
175 |
state2->assignProperty(p6, "opacity", qreal(1)); |
|
176 |
||
177 |
// State 3 |
|
178 |
state3->assignProperty(button, "text", "Switch to state 1"); |
|
179 |
state3->assignProperty(p1, "pos", QPointF(0, 5)); |
|
180 |
state3->assignProperty(p2, "pos", QPointF(0, 5 + 64 + 5)); |
|
181 |
state3->assignProperty(p3, "pos", QPointF(5, 5 + (64 + 5) + 64)); |
|
182 |
state3->assignProperty(p4, "pos", QPointF(5 + 64 + 5, 5)); |
|
183 |
state3->assignProperty(p5, "pos", QPointF(5 + 64 + 5, 5 + 64 + 5)); |
|
184 |
state3->assignProperty(p6, "pos", QPointF(5 + 64 + 5, 5 + (64 + 5) + 64)); |
|
185 |
state3->assignProperty(widget, "geometry", QRectF(138, 5, 400 - 138, 200)); |
|
186 |
state3->assignProperty(box, "geometry", QRect(5, 205, 400, 90)); |
|
187 |
state3->assignProperty(p1, "opacity", qreal(1)); |
|
188 |
state3->assignProperty(p2, "opacity", qreal(1)); |
|
189 |
state3->assignProperty(p3, "opacity", qreal(1)); |
|
190 |
state3->assignProperty(p4, "opacity", qreal(1)); |
|
191 |
state3->assignProperty(p5, "opacity", qreal(1)); |
|
192 |
state3->assignProperty(p6, "opacity", qreal(1)); |
|
193 |
||
194 |
QAbstractTransition *t1 = state1->addTransition(button, SIGNAL(clicked()), state2); |
|
195 |
QSequentialAnimationGroup *animation1SubGroup = new QSequentialAnimationGroup; |
|
196 |
animation1SubGroup->addPause(250); |
|
197 |
animation1SubGroup->addAnimation(new QPropertyAnimation(box, "geometry")); |
|
198 |
t1->addAnimation(animation1SubGroup); |
|
199 |
t1->addAnimation(new QPropertyAnimation(widget, "geometry")); |
|
200 |
t1->addAnimation(new QPropertyAnimation(p1, "pos")); |
|
201 |
t1->addAnimation(new QPropertyAnimation(p2, "pos")); |
|
202 |
t1->addAnimation(new QPropertyAnimation(p3, "pos")); |
|
203 |
t1->addAnimation(new QPropertyAnimation(p4, "pos")); |
|
204 |
t1->addAnimation(new QPropertyAnimation(p5, "pos")); |
|
205 |
t1->addAnimation(new QPropertyAnimation(p6, "pos")); |
|
206 |
t1->addAnimation(new QPropertyAnimation(p1, "rotation")); |
|
207 |
t1->addAnimation(new QPropertyAnimation(p2, "rotation")); |
|
208 |
t1->addAnimation(new QPropertyAnimation(p3, "rotation")); |
|
209 |
t1->addAnimation(new QPropertyAnimation(p4, "rotation")); |
|
210 |
t1->addAnimation(new QPropertyAnimation(p5, "rotation")); |
|
211 |
t1->addAnimation(new QPropertyAnimation(p6, "rotation")); |
|
212 |
t1->addAnimation(new QPropertyAnimation(p1, "opacity")); |
|
213 |
t1->addAnimation(new QPropertyAnimation(p2, "opacity")); |
|
214 |
t1->addAnimation(new QPropertyAnimation(p3, "opacity")); |
|
215 |
t1->addAnimation(new QPropertyAnimation(p4, "opacity")); |
|
216 |
t1->addAnimation(new QPropertyAnimation(p5, "opacity")); |
|
217 |
t1->addAnimation(new QPropertyAnimation(p6, "opacity")); |
|
218 |
||
219 |
QAbstractTransition *t2 = state2->addTransition(button, SIGNAL(clicked()), state3); |
|
220 |
t2->addAnimation(new QPropertyAnimation(box, "geometry")); |
|
221 |
t2->addAnimation(new QPropertyAnimation(widget, "geometry")); |
|
222 |
t2->addAnimation(new QPropertyAnimation(p1, "pos")); |
|
223 |
t2->addAnimation(new QPropertyAnimation(p2, "pos")); |
|
224 |
t2->addAnimation(new QPropertyAnimation(p3, "pos")); |
|
225 |
t2->addAnimation(new QPropertyAnimation(p4, "pos")); |
|
226 |
t2->addAnimation(new QPropertyAnimation(p5, "pos")); |
|
227 |
t2->addAnimation(new QPropertyAnimation(p6, "pos")); |
|
228 |
t2->addAnimation(new QPropertyAnimation(p1, "rotation")); |
|
229 |
t2->addAnimation(new QPropertyAnimation(p2, "rotation")); |
|
230 |
t2->addAnimation(new QPropertyAnimation(p3, "rotation")); |
|
231 |
t2->addAnimation(new QPropertyAnimation(p4, "rotation")); |
|
232 |
t2->addAnimation(new QPropertyAnimation(p5, "rotation")); |
|
233 |
t2->addAnimation(new QPropertyAnimation(p6, "rotation")); |
|
234 |
t2->addAnimation(new QPropertyAnimation(p1, "opacity")); |
|
235 |
t2->addAnimation(new QPropertyAnimation(p2, "opacity")); |
|
236 |
t2->addAnimation(new QPropertyAnimation(p3, "opacity")); |
|
237 |
t2->addAnimation(new QPropertyAnimation(p4, "opacity")); |
|
238 |
t2->addAnimation(new QPropertyAnimation(p5, "opacity")); |
|
239 |
t2->addAnimation(new QPropertyAnimation(p6, "opacity")); |
|
240 |
||
241 |
QAbstractTransition *t3 = state3->addTransition(button, SIGNAL(clicked()), state1); |
|
242 |
t3->addAnimation(new QPropertyAnimation(box, "geometry")); |
|
243 |
t3->addAnimation(new QPropertyAnimation(widget, "geometry")); |
|
244 |
t3->addAnimation(new QPropertyAnimation(p1, "pos")); |
|
245 |
t3->addAnimation(new QPropertyAnimation(p2, "pos")); |
|
246 |
t3->addAnimation(new QPropertyAnimation(p3, "pos")); |
|
247 |
t3->addAnimation(new QPropertyAnimation(p4, "pos")); |
|
248 |
t3->addAnimation(new QPropertyAnimation(p5, "pos")); |
|
249 |
t3->addAnimation(new QPropertyAnimation(p6, "pos")); |
|
250 |
t3->addAnimation(new QPropertyAnimation(p1, "rotation")); |
|
251 |
t3->addAnimation(new QPropertyAnimation(p2, "rotation")); |
|
252 |
t3->addAnimation(new QPropertyAnimation(p3, "rotation")); |
|
253 |
t3->addAnimation(new QPropertyAnimation(p4, "rotation")); |
|
254 |
t3->addAnimation(new QPropertyAnimation(p5, "rotation")); |
|
255 |
t3->addAnimation(new QPropertyAnimation(p6, "rotation")); |
|
256 |
t3->addAnimation(new QPropertyAnimation(p1, "opacity")); |
|
257 |
t3->addAnimation(new QPropertyAnimation(p2, "opacity")); |
|
258 |
t3->addAnimation(new QPropertyAnimation(p3, "opacity")); |
|
259 |
t3->addAnimation(new QPropertyAnimation(p4, "opacity")); |
|
260 |
t3->addAnimation(new QPropertyAnimation(p5, "opacity")); |
|
261 |
t3->addAnimation(new QPropertyAnimation(p6, "opacity")); |
|
262 |
||
263 |
machine.start(); |
|
264 |
||
265 |
QGraphicsView view(&scene); |
|
266 |
view.show(); |
|
267 |
||
268 |
return app.exec(); |
|
269 |
} |
|
270 |
||
271 |
#include "main.moc" |