author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
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 test suite of the Qt Toolkit. |
|
8 |
** |
|
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 |
|
14 |
** this package. |
|
15 |
** |
|
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. |
|
23 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
#include <QtGui> |
|
42 |
#include "valgrind/callgrind.h" |
|
43 |
||
44 |
#ifdef Q_WS_X11 |
|
45 |
extern void qt_x11_wait_for_window_manager(QWidget *); |
|
46 |
#endif |
|
47 |
||
48 |
class View : public QGraphicsView |
|
49 |
{ |
|
50 |
Q_OBJECT |
|
51 |
public: |
|
52 |
View(QGraphicsScene *scene, QGraphicsItem *item) |
|
53 |
: QGraphicsView(scene), _item(item) |
|
54 |
{ |
|
55 |
} |
|
56 |
||
57 |
protected: |
|
58 |
void paintEvent(QPaintEvent *event) |
|
59 |
{ |
|
60 |
static int n = 0; |
|
61 |
if (n) |
|
62 |
CALLGRIND_START_INSTRUMENTATION |
|
63 |
QGraphicsView::paintEvent(event); |
|
64 |
_item->moveBy(1, 1); |
|
65 |
if (n) |
|
66 |
CALLGRIND_STOP_INSTRUMENTATION |
|
67 |
if (++n == 200) |
|
68 |
qApp->quit(); |
|
69 |
} |
|
70 |
||
71 |
private: |
|
72 |
QGraphicsItem *_item; |
|
73 |
}; |
|
74 |
||
75 |
int main(int argc, char *argv[]) |
|
76 |
{ |
|
77 |
QApplication app(argc, argv); |
|
78 |
||
79 |
if (argc < 2) { |
|
80 |
qDebug("usage: ./%s <numItems>", argv[0]); |
|
81 |
return 1; |
|
82 |
} |
|
83 |
||
84 |
QGraphicsScene scene(-150, -150, 300, 300); |
|
85 |
scene.setItemIndexMethod(QGraphicsScene::NoIndex); |
|
86 |
||
87 |
QGraphicsRectItem *item = scene.addRect(-50, -50, 100, 100, QPen(Qt::NoPen), QBrush(Qt::blue)); |
|
88 |
item->setFlag(QGraphicsItem::ItemIsMovable); |
|
89 |
||
90 |
for (int i = 0; i < atoi(argv[1]); ++i) { |
|
91 |
QGraphicsRectItem *child = scene.addRect(-5, -5, 10, 10, QPen(Qt::NoPen), QBrush(Qt::blue)); |
|
92 |
child->setPos(-50 + qrand() % 100, -50 + qrand() % 100); |
|
93 |
child->setParentItem(item); |
|
94 |
} |
|
95 |
||
96 |
View view(&scene, item); |
|
97 |
view.resize(300, 300); |
|
98 |
view.show(); |
|
99 |
#ifdef Q_WS_X11 |
|
100 |
qt_x11_wait_for_window_manager(&view); |
|
101 |
#endif |
|
102 |
||
103 |
return app.exec(); |
|
104 |
} |
|
105 |
||
106 |
#include "main.moc" |