QtGui/qpolygon.h Source File

qpolygon.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QPOLYGON_H
43 #define QPOLYGON_H
44 
45 #include <QtCore/qvector.h>
46 #include <QtCore/qpoint.h>
47 #include <QtCore/qrect.h>
48 
50 
52 
53 QT_MODULE(Gui)
54 
55 class QMatrix;
56 class QTransform;
57 class QRect;
58 class QVariant;
59 
60 class Q_GUI_EXPORT QPolygon : public QVector<QPoint>
61 {
62 public:
63  inline QPolygon() {}
64  inline ~QPolygon() {}
65  inline QPolygon(int size);
66  inline QPolygon(const QPolygon &a) : QVector<QPoint>(a) {}
67  inline QPolygon(const QVector<QPoint> &v) : QVector<QPoint>(v) {}
68  QPolygon(const QRect &r, bool closed=false);
69  QPolygon(int nPoints, const int *points);
70  inline void swap(QPolygon &other) { QVector<QPoint>::swap(other); } // prevent QVector<QPoint><->QPolygon swaps
71 
72  operator QVariant() const;
73 
74  void translate(int dx, int dy);
75  void translate(const QPoint &offset);
76 
77  QPolygon translated(int dx, int dy) const;
78  inline QPolygon translated(const QPoint &offset) const;
79 
80  QRect boundingRect() const;
81 
82  void point(int i, int *x, int *y) const;
83  QPoint point(int i) const;
84  void setPoint(int index, int x, int y);
85  void setPoint(int index, const QPoint &p);
86  void setPoints(int nPoints, const int *points);
87  void setPoints(int nPoints, int firstx, int firsty, ...);
88  void putPoints(int index, int nPoints, const int *points);
89  void putPoints(int index, int nPoints, int firstx, int firsty, ...);
90  void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex=0);
91 
92  bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const;
93 
94  QPolygon united(const QPolygon &r) const;
95  QPolygon intersected(const QPolygon &r) const;
96  QPolygon subtracted(const QPolygon &r) const;
97 };
98 
99 inline QPolygon::QPolygon(int asize) : QVector<QPoint>(asize) {}
100 
101 #ifndef QT_NO_DEBUG_STREAM
102 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &);
103 #endif
104 
105 /*****************************************************************************
106  QPolygon stream functions
107  *****************************************************************************/
108 #ifndef QT_NO_DATASTREAM
109 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon);
110 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon);
111 #endif
112 
113 /*****************************************************************************
114  Misc. QPolygon functions
115  *****************************************************************************/
116 
117 inline void QPolygon::setPoint(int index, const QPoint &pt)
118 { (*this)[index] = pt; }
119 
120 inline void QPolygon::setPoint(int index, int x, int y)
121 { (*this)[index] = QPoint(x, y); }
122 
123 inline QPoint QPolygon::point(int index) const
124 { return at(index); }
125 
126 inline void QPolygon::translate(const QPoint &offset)
127 { translate(offset.x(), offset.y()); }
128 
130 { return translated(offset.x(), offset.y()); }
131 
132 class QRectF;
133 
134 class Q_GUI_EXPORT QPolygonF : public QVector<QPointF>
135 {
136 public:
137  inline QPolygonF() {}
138  inline ~QPolygonF() {}
139  inline QPolygonF(int size);
140  inline QPolygonF(const QPolygonF &a) : QVector<QPointF>(a) {}
141  inline QPolygonF(const QVector<QPointF> &v) : QVector<QPointF>(v) {}
142  QPolygonF(const QRectF &r);
143  QPolygonF(const QPolygon &a);
144  inline void swap(QPolygonF &other) { QVector<QPointF>::swap(other); } // prevent QVector<QPointF><->QPolygonF swaps
145 
146  inline void translate(qreal dx, qreal dy);
147  void translate(const QPointF &offset);
148 
149  inline QPolygonF translated(qreal dx, qreal dy) const;
150  QPolygonF translated(const QPointF &offset) const;
151 
152  QPolygon toPolygon() const;
153 
154  bool isClosed() const { return !isEmpty() && first() == last(); }
155 
156  QRectF boundingRect() const;
157 
158  bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
159 
160  QPolygonF united(const QPolygonF &r) const;
161  QPolygonF intersected(const QPolygonF &r) const;
162  QPolygonF subtracted(const QPolygonF &r) const;
163 };
164 
165 inline QPolygonF::QPolygonF(int asize) : QVector<QPointF>(asize) {}
166 
167 #ifndef QT_NO_DEBUG_STREAM
168 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
169 #endif
170 
171 /*****************************************************************************
172  QPolygonF stream functions
173  *****************************************************************************/
174 #ifndef QT_NO_DATASTREAM
175 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array);
176 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array);
177 #endif
178 
179 inline void QPolygonF::translate(qreal dx, qreal dy)
180 { translate(QPointF(dx, dy)); }
181 
182 inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const
183 { return translated(QPointF(dx, dy)); }
184 
186 
188 
189 #endif // QPOLYGON_H
const QPoint & at(int i) const
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
QPolygon translated(int dx, int dy) const
GLenum GLint GLint y
Definition: GLee.h:876
int int int int * dy
Definition: GLee.h:10535
#define QT_END_NAMESPACE
Definition: qglobal.h:128
GLintptr offset
Definition: GLee.h:1562
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
QPolygon(const QVector< QPoint > &v)
Definition: qpolygon.h:67
T & last()
Definition: qvector.h:262
void swap(QPolygon &other)
Definition: qpolygon.h:70
Definition: qdebug.h:62
Definition: qpoint.h:53
void translate(qreal dx, qreal dy)
Definition: qpolygon.h:179
int y() const
Definition: qpoint.h:131
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
~QPolygon()
Definition: qpolygon.h:64
void swap(QVector< T > &other)
Definition: qvector.h:130
void setPoint(int index, int x, int y)
Definition: qpolygon.h:120
QPolygonF(const QPolygonF &a)
Definition: qpolygon.h:140
GLenum GLint x
Definition: GLee.h:876
QPolygon(const QPolygon &a)
Definition: qpolygon.h:66
const GLdouble * v
Definition: GLee.h:1174
void swap(QPolygonF &other)
Definition: qpolygon.h:144
QPolygon()
Definition: qpolygon.h:63
~QPolygonF()
Definition: qpolygon.h:138
Definition: qrect.h:58
QPolygonF(const QVector< QPointF > &v)
Definition: qpolygon.h:141
Definition: qrect.h:511
GLfloat GLfloat p
Definition: GLee.h:5416
void point(int i, int *x, int *y) const
bool isClosed() const
Definition: qpolygon.h:154
QPolygonF()
Definition: qpolygon.h:137
int x() const
Definition: qpoint.h:128
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &)
int int int * dx
Definition: GLee.h:10535
T & first()
Definition: qvector.h:260
GLsizei const GLfloat * points
Definition: GLee.h:3793
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &stream, QPolygon &polygon)
bool isEmpty() const
Definition: qvector.h:139
void translate(int dx, int dy)
FillRule
Definition: qnamespace.h:1485
#define QT_END_HEADER
Definition: qglobal.h:142
QPolygonF translated(qreal dx, qreal dy) const
Definition: qpolygon.h:182
GLsizeiptr size
Definition: GLee.h:1561
GLuint index
Definition: GLee.h:1704