1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtCore/qvector.h>
46 #include <QtCore/qpoint.h>
47 #include <QtCore/qrect.h>
59 class Q_GUI_EXPORT QPolygon : public QVector<QPoint>
64 inline explicit QPolygon(int size);
65 inline QPolygon(const QPolygon &a) : QVector<QPoint>(a) {}
66 inline /*implicit*/ QPolygon(const QVector<QPoint> &v) : QVector<QPoint>(v) {}
67 QPolygon(const QRect &r, bool closed=false);
68 QPolygon(int nPoints, const int *points);
69 inline void swap(QPolygon &other) { QVector<QPoint>::swap(other); } // prevent QVector<QPoint><->QPolygon swaps
71 operator QVariant() const;
73 void translate(int dx, int dy);
74 void translate(const QPoint &offset);
76 QPolygon translated(int dx, int dy) const;
77 inline QPolygon translated(const QPoint &offset) const;
79 QRect boundingRect() const;
81 void point(int i, int *x, int *y) const;
82 QPoint point(int i) const;
83 void setPoint(int index, int x, int y);
84 void setPoint(int index, const QPoint &p);
85 void setPoints(int nPoints, const int *points);
86 void setPoints(int nPoints, int firstx, int firsty, ...);
87 void putPoints(int index, int nPoints, const int *points);
88 void putPoints(int index, int nPoints, int firstx, int firsty, ...);
89 void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex=0);
91 bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const;
93 QPolygon united(const QPolygon &r) const;
94 QPolygon intersected(const QPolygon &r) const;
95 QPolygon subtracted(const QPolygon &r) const;
98 inline QPolygon::QPolygon(int asize) : QVector<QPoint>(asize) {}
100 #ifndef QT_NO_DEBUG_STREAM
101 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &);
104 /*****************************************************************************
105 QPolygon stream functions
106 *****************************************************************************/
107 #ifndef QT_NO_DATASTREAM
108 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon);
109 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon);
112 /*****************************************************************************
113 Misc. QPolygon functions
114 *****************************************************************************/
116 inline void QPolygon::setPoint(int index, const QPoint &pt)
117 { (*this)[index] = pt; }
119 inline void QPolygon::setPoint(int index, int x, int y)
120 { (*this)[index] = QPoint(x, y); }
122 inline QPoint QPolygon::point(int index) const
123 { return at(index); }
125 inline void QPolygon::translate(const QPoint &offset)
126 { translate(offset.x(), offset.y()); }
128 inline QPolygon QPolygon::translated(const QPoint &offset) const
129 { return translated(offset.x(), offset.y()); }
133 class Q_GUI_EXPORT QPolygonF : public QVector<QPointF>
136 inline QPolygonF() {}
137 inline ~QPolygonF() {}
138 inline explicit QPolygonF(int size);
139 inline QPolygonF(const QPolygonF &a) : QVector<QPointF>(a) {}
140 inline /*implicit*/ QPolygonF(const QVector<QPointF> &v) : QVector<QPointF>(v) {}
141 QPolygonF(const QRectF &r);
142 /*implicit*/ QPolygonF(const QPolygon &a);
143 inline void swap(QPolygonF &other) { QVector<QPointF>::swap(other); } // prevent QVector<QPointF><->QPolygonF swaps
145 inline void translate(qreal dx, qreal dy);
146 void translate(const QPointF &offset);
148 inline QPolygonF translated(qreal dx, qreal dy) const;
149 QPolygonF translated(const QPointF &offset) const;
151 QPolygon toPolygon() const;
153 bool isClosed() const { return !isEmpty() && first() == last(); }
155 QRectF boundingRect() const;
157 bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
159 QPolygonF united(const QPolygonF &r) const;
160 QPolygonF intersected(const QPolygonF &r) const;
161 QPolygonF subtracted(const QPolygonF &r) const;
164 inline QPolygonF::QPolygonF(int asize) : QVector<QPointF>(asize) {}
166 #ifndef QT_NO_DEBUG_STREAM
167 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
170 /*****************************************************************************
171 QPolygonF stream functions
172 *****************************************************************************/
173 #ifndef QT_NO_DATASTREAM
174 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array);
175 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array);
178 inline void QPolygonF::translate(qreal dx, qreal dy)
179 { translate(QPointF(dx, dy)); }
181 inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const
182 { return translated(QPointF(dx, dy)); }