QtBase  v6.3.1
main.cpp
Go to the documentation of this file.
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 test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 #include <QtGui>
29 
30 #include "valgrind/callgrind.h"
31 
32 class ItemMover : public QObject
33 {
34  Q_OBJECT
35 public:
37  : _item(item)
38  {
39  startTimer(0);
40  }
41 
42 protected:
44  {
45  _item->moveBy(-1, 0);
46  }
47 
48 private:
49  QGraphicsItem *_item;
50 };
51 
53 {
54 public:
56  : QGraphicsRectItem(x, y, w, h)
57  {
58  setPen(pen);
59  setBrush(brush);
60  }
61 
63  {
65  path.addRect(rect());
66  return path;
67  }
68 };
69 
70 class CountView : public QGraphicsView
71 {
72 protected:
74  {
75  static int n = 0;
76  if (n)
79  if (n)
81  if (++n == 500)
82  qApp->quit();
83  }
84 };
85 
86 int main(int argc, char *argv[])
87 {
88  QApplication app(argc, argv);
89 
92 
93  ClipItem *clipItem = new ClipItem(0, 0, 100, 100, QPen(), QBrush(Qt::blue));
95  clipItem->setData(0, "clipItem");
96  scene.addItem(clipItem);
97 
98  QGraphicsRectItem *scrollItem = scene.addRect(0, 0, 10, 10, QPen(Qt::NoPen), QBrush(Qt::NoBrush));
99  scrollItem->setParentItem(clipItem);
101  scrollItem->setData(0, "scrollItem");
102 
103  for (int y = 0; y < 25; ++y) {
104  for (int x = 0; x < 25; ++x) {
105  ClipItem *rect = new ClipItem(0, 0, 90, 20, QPen(Qt::NoPen), QBrush(Qt::green));
106  rect->setParentItem(scrollItem);
107  rect->setPos(x * 95, y * 25);
108  rect->setData(0, qPrintable(QString("rect %1 %2").arg(x).arg(y)));
110 
111  QGraphicsEllipseItem *ellipse = new QGraphicsEllipseItem(-5, -5, 10, 10);
115  ellipse->setData(0, qPrintable(QString("ellipse %1 %2").arg(x).arg(y)));
116  }
117  }
118 
119  scrollItem->setRect(scrollItem->childrenBoundingRect());
120 
121 #if 0
122  ItemMover mover(scrollItem);
123 #endif
124 
125  CountView view;
126  view.setScene(&scene);
127  view.setSceneRect(-25, -25, 150, 150);
128  view.resize(300, 300);
129  view.show();
130 
131  return app.exec();
132 }
133 
134 #include "main.moc"
#define CALLGRIND_START_INSTRUMENTATION
Definition: callgrind_p.h:114
#define CALLGRIND_STOP_INSTRUMENTATION
Definition: callgrind_p.h:125
QPainterPath shape() const
Definition: main.cpp:62
ClipItem(qreal x, qreal y, qreal w, qreal h, const QPen &pen, const QBrush &brush)
Definition: main.cpp:55
void paintEvent(QPaintEvent *event)
Definition: main.cpp:73
ItemMover(QGraphicsItem *item)
Definition: main.cpp:36
void timerEvent(QTimerEvent *event)
Definition: main.cpp:43
void setPen(const QPen &pen)
void setBrush(const QBrush &brush)
The QApplication class manages the GUI application's control flow and main settings.
Definition: qapplication.h:68
static int exec()
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:66
The QGraphicsEllipseItem class provides an ellipse item that you can add to a QGraphicsScene.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:83
void setData(int key, const QVariant &value)
void moveBy(qreal dx, qreal dy)
@ ItemClipsChildrenToShape
Definition: qgraphicsitem.h:90
void setParentItem(QGraphicsItem *parent)
QRectF childrenBoundingRect() const
void setFlag(GraphicsItemFlag flag, bool enabled=true)
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
void setRect(const QRectF &rect)
QRectF rect() const
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
void addItem(QGraphicsItem *item)
void setItemIndexMethod(ItemIndexMethod method)
QGraphicsRectItem * addRect(const QRectF &rect, const QPen &pen=QPen(), const QBrush &brush=QBrush())
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:60
void paintEvent(QPaintEvent *event) override
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
int startTimer(int interval, Qt::TimerType timerType=Qt::CoarseTimer)
Definition: qobject.cpp:1765
The QPaintEvent class contains event parameters for paint events. \inmodule QtGui.
Definition: qevent.h:539
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:65
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:61
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:367
int main(int argc, char **argv)
Definition: main.cpp:1
rect
[4]
@ blue
Definition: qnamespace.h:68
@ yellow
Definition: qnamespace.h:71
@ green
Definition: qnamespace.h:67
@ NoPen
Definition: qnamespace.h:1112
@ NoBrush
Definition: qnamespace.h:1140
Definition: brush.cpp:52
#define QString()
Definition: parse-defines.h:51
#define qApp
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLfloat n
GLint y
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
Definition: qopenglext.h:2998
GLsizei const GLchar *const * path
Definition: qopenglext.h:4283
SSL_CTX int(*) void arg)
#define Q_OBJECT
Definition: qtmetamacros.h:158
QGraphicsScene scene
[0]
QGraphicsItem * item
QGraphicsEllipseItem * ellipse
QApplication app(argc, argv)
[0]
QQuickView * view
[0]