1 /****************************************************************************
3 ** Copyright (C) 2011 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 QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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>
60 class Q_GUI_EXPORT QPolygon : public QVector<QPoint>
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
72 operator QVariant() const;
74 void translate(int dx, int dy);
75 void translate(const QPoint &offset);
77 QPolygon translated(int dx, int dy) const;
78 inline QPolygon translated(const QPoint &offset) const;
80 QRect boundingRect() const;
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);
92 bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const;
94 QPolygon united(const QPolygon &r) const;
95 QPolygon intersected(const QPolygon &r) const;
96 QPolygon subtracted(const QPolygon &r) const;
99 inline QPolygon::QPolygon(int asize) : QVector<QPoint>(asize) {}
101 #ifndef QT_NO_DEBUG_STREAM
102 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &);
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);
113 /*****************************************************************************
114 Misc. QPolygon functions
115 *****************************************************************************/
117 inline void QPolygon::setPoint(int index, const QPoint &pt)
118 { (*this)[index] = pt; }
120 inline void QPolygon::setPoint(int index, int x, int y)
121 { (*this)[index] = QPoint(x, y); }
123 inline QPoint QPolygon::point(int index) const
124 { return at(index); }
126 inline void QPolygon::translate(const QPoint &offset)
127 { translate(offset.x(), offset.y()); }
129 inline QPolygon QPolygon::translated(const QPoint &offset) const
130 { return translated(offset.x(), offset.y()); }
134 class Q_GUI_EXPORT QPolygonF : public QVector<QPointF>
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
146 inline void translate(qreal dx, qreal dy);
147 void translate(const QPointF &offset);
149 inline QPolygonF translated(qreal dx, qreal dy) const;
150 QPolygonF translated(const QPointF &offset) const;
152 QPolygon toPolygon() const;
154 bool isClosed() const { return !isEmpty() && first() == last(); }
156 QRectF boundingRect() const;
158 bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
160 QPolygonF united(const QPolygonF &r) const;
161 QPolygonF intersected(const QPolygonF &r) const;
162 QPolygonF subtracted(const QPolygonF &r) const;
165 inline QPolygonF::QPolygonF(int asize) : QVector<QPointF>(asize) {}
167 #ifndef QT_NO_DEBUG_STREAM
168 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
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);
179 inline void QPolygonF::translate(qreal dx, qreal dy)
180 { translate(QPointF(dx, dy)); }
182 inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const
183 { return translated(QPointF(dx, dy)); }