1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtCore module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
11 | **
|
---|
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.
|
---|
25 | **
|
---|
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."
|
---|
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));
|
---|
|
---|