1
/****************************************************************************
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the QtCore module of the Qt Toolkit.
9
** $QT_BEGIN_LICENSE:LGPL$
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file. Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights. These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
40
****************************************************************************/
46
class Pixmap : public QGraphicsWidget
51
Pixmap(const QPixmap &pix, QGraphicsItem *parent = 0)
52
: QGraphicsWidget(parent), orig(pix), p(pix)
56
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
58
painter->drawPixmap(QPointF(), p);
61
virtual void mousePressEvent(QGraphicsSceneMouseEvent * )
66
virtual void setGeometry(const QRectF &rect)
68
QGraphicsWidget::setGeometry(rect);
70
if (rect.size().width() > orig.size().width())
71
p = orig.scaled(rect.size().toSize());
84
void createStates(const QObjectList &objects,
85
const QRect &selectedRect, QState *parent)
87
for (int i = 0; i < objects.size(); ++i) {
88
QState *state = new QState(parent);
89
state->assignProperty(objects.at(i), "geometry", selectedRect);
90
parent->addTransition(objects.at(i), SIGNAL(clicked()), state);
94
void createAnimations(const QObjectList &objects, QStateMachine *machine)
96
for (int i=0; i<objects.size(); ++i)
97
machine->addDefaultAnimation(new QPropertyAnimation(objects.at(i), "geometry"));
100
int main(int argc, char **argv)
102
Q_INIT_RESOURCE(appchooser);
104
QApplication app(argc, argv);
106
Pixmap *p1 = new Pixmap(QPixmap(":/digikam.png"));
107
Pixmap *p2 = new Pixmap(QPixmap(":/akregator.png"));
108
Pixmap *p3 = new Pixmap(QPixmap(":/accessories-dictionary.png"));
109
Pixmap *p4 = new Pixmap(QPixmap(":/k3b.png"));
111
p1->setObjectName("p1");
112
p2->setObjectName("p2");
113
p3->setObjectName("p3");
114
p4->setObjectName("p4");
116
p1->setGeometry(QRectF(0.0, 0.0, 64.0, 64.0));
117
p2->setGeometry(QRectF(236.0, 0.0, 64.0, 64.0));
118
p3->setGeometry(QRectF(236.0, 236.0, 64.0, 64.0));
119
p4->setGeometry(QRectF(0.0, 236.0, 64.0, 64.0));
121
QGraphicsScene scene(0, 0, 300, 300);
122
scene.setBackgroundBrush(Qt::white);
128
QGraphicsView window(&scene);
129
window.setFrameStyle(0);
130
window.setAlignment(Qt::AlignLeft | Qt::AlignTop);
131
window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
132
window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
134
QStateMachine machine;
135
machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
137
QState *group = new QState(&machine);
138
group->setObjectName("group");
139
QRect selectedRect(86, 86, 128, 128);
141
QState *idleState = new QState(group);
142
group->setInitialState(idleState);
145
objects << p1 << p2 << p3 << p4;
146
createStates(objects, selectedRect, group);
147
createAnimations(objects, &machine);
149
machine.setInitialState(group);
152
window.resize(300, 300);