| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 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 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QPAINTERPATH_P_H
|
|---|
| 43 | #define QPAINTERPATH_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 49 | // This file is not part of the Qt API. It exists for the convenience
|
|---|
| 50 | // of other Qt classes. This header file may change from version to
|
|---|
| 51 | // version without notice, or even be removed.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #include "QtGui/qpainterpath.h"
|
|---|
| 57 | #include "QtGui/qregion.h"
|
|---|
| 58 | #include "QtCore/qlist.h"
|
|---|
| 59 | #include "QtCore/qvarlengtharray.h"
|
|---|
| 60 |
|
|---|
| 61 | #include <qdebug.h>
|
|---|
| 62 |
|
|---|
| 63 | #include <private/qvectorpath_p.h>
|
|---|
| 64 | #include <private/qstroker_p.h>
|
|---|
| 65 |
|
|---|
| 66 | QT_BEGIN_NAMESPACE
|
|---|
| 67 |
|
|---|
| 68 | class QPainterPathStrokerPrivate
|
|---|
| 69 | {
|
|---|
| 70 | public:
|
|---|
| 71 | QPainterPathStrokerPrivate();
|
|---|
| 72 |
|
|---|
| 73 | QStroker stroker;
|
|---|
| 74 | QVector<qfixed> dashPattern;
|
|---|
| 75 | qreal dashOffset;
|
|---|
| 76 | };
|
|---|
| 77 |
|
|---|
| 78 | class QPolygonF;
|
|---|
| 79 | class QVectorPathConverter;
|
|---|
| 80 |
|
|---|
| 81 | class QVectorPathConverter
|
|---|
| 82 | {
|
|---|
| 83 | public:
|
|---|
| 84 | QVectorPathConverter(const QVector<QPainterPath::Element> &path, uint fillRule, bool convex)
|
|---|
| 85 | : pathData(path, fillRule, convex),
|
|---|
| 86 | path(pathData.points.data(), path.size(),
|
|---|
| 87 | pathData.elements.data(), pathData.flags) {}
|
|---|
| 88 |
|
|---|
| 89 | const QVectorPath &vectorPath() {
|
|---|
| 90 | return path;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | struct QVectorPathData {
|
|---|
| 94 | QVectorPathData(const QVector<QPainterPath::Element> &path, uint fillRule, bool convex)
|
|---|
| 95 | : elements(path.size()),
|
|---|
| 96 | points(path.size() * 2),
|
|---|
| 97 | flags(0)
|
|---|
| 98 | {
|
|---|
| 99 | int ptsPos = 0;
|
|---|
| 100 | for (int i=0; i<path.size(); ++i) {
|
|---|
| 101 | const QPainterPath::Element &e = path.at(i);
|
|---|
| 102 | elements[i] = e.type;
|
|---|
| 103 | points[ptsPos++] = e.x;
|
|---|
| 104 | points[ptsPos++] = e.y;
|
|---|
| 105 | if (e.type == QPainterPath::CurveToElement)
|
|---|
| 106 | flags |= QVectorPath::CurvedShapeMask;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | if (fillRule == Qt::WindingFill)
|
|---|
| 110 | flags |= QVectorPath::WindingFill;
|
|---|
| 111 | else
|
|---|
| 112 | flags |= QVectorPath::OddEvenFill;
|
|---|
| 113 |
|
|---|
| 114 | if (!convex)
|
|---|
| 115 | flags |= QVectorPath::NonConvexShapeMask;
|
|---|
| 116 | }
|
|---|
| 117 | QVarLengthArray<QPainterPath::ElementType> elements;
|
|---|
| 118 | QVarLengthArray<qreal> points;
|
|---|
| 119 | uint flags;
|
|---|
| 120 | };
|
|---|
| 121 |
|
|---|
| 122 | QVectorPathData pathData;
|
|---|
| 123 | QVectorPath path;
|
|---|
| 124 |
|
|---|
| 125 | private:
|
|---|
| 126 | Q_DISABLE_COPY(QVectorPathConverter)
|
|---|
| 127 | };
|
|---|
| 128 |
|
|---|
| 129 | class QPainterPathData : public QPainterPathPrivate
|
|---|
| 130 | {
|
|---|
| 131 | public:
|
|---|
| 132 | QPainterPathData() :
|
|---|
| 133 | cStart(0),
|
|---|
| 134 | fillRule(Qt::OddEvenFill),
|
|---|
| 135 | dirtyBounds(false),
|
|---|
| 136 | dirtyControlBounds(false),
|
|---|
| 137 | pathConverter(0)
|
|---|
| 138 | {
|
|---|
| 139 | ref = 1;
|
|---|
| 140 | require_moveTo = false;
|
|---|
| 141 | convex = false;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | QPainterPathData(const QPainterPathData &other) :
|
|---|
| 145 | QPainterPathPrivate(), cStart(other.cStart), fillRule(other.fillRule),
|
|---|
| 146 | bounds(other.bounds),
|
|---|
| 147 | controlBounds(other.controlBounds),
|
|---|
| 148 | dirtyBounds(other.dirtyBounds),
|
|---|
| 149 | dirtyControlBounds(other.dirtyControlBounds),
|
|---|
| 150 | convex(other.convex),
|
|---|
| 151 | pathConverter(0)
|
|---|
| 152 | {
|
|---|
| 153 | ref = 1;
|
|---|
| 154 | require_moveTo = false;
|
|---|
| 155 | elements = other.elements;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | ~QPainterPathData() {
|
|---|
| 159 | delete pathConverter;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | inline bool isClosed() const;
|
|---|
| 163 | inline void close();
|
|---|
| 164 | inline void maybeMoveTo();
|
|---|
| 165 |
|
|---|
| 166 | const QVectorPath &vectorPath() {
|
|---|
| 167 | if (!pathConverter)
|
|---|
| 168 | pathConverter = new QVectorPathConverter(elements, fillRule, convex);
|
|---|
| 169 | return pathConverter->path;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | int cStart;
|
|---|
| 173 | Qt::FillRule fillRule;
|
|---|
| 174 |
|
|---|
| 175 | QRectF bounds;
|
|---|
| 176 | QRectF controlBounds;
|
|---|
| 177 |
|
|---|
| 178 | uint require_moveTo : 1;
|
|---|
| 179 | uint dirtyBounds : 1;
|
|---|
| 180 | uint dirtyControlBounds : 1;
|
|---|
| 181 | uint convex : 1;
|
|---|
| 182 |
|
|---|
| 183 | QVectorPathConverter *pathConverter;
|
|---|
| 184 | };
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 | inline const QPainterPath QVectorPath::convertToPainterPath() const
|
|---|
| 188 | {
|
|---|
| 189 | QPainterPath path;
|
|---|
| 190 | path.ensureData();
|
|---|
| 191 | QPainterPathData *data = path.d_func();
|
|---|
| 192 | data->elements.reserve(m_count);
|
|---|
| 193 | int index = 0;
|
|---|
| 194 | data->elements[0].x = m_points[index++];
|
|---|
| 195 | data->elements[0].y = m_points[index++];
|
|---|
| 196 |
|
|---|
| 197 | if (m_elements) {
|
|---|
| 198 | data->elements[0].type = m_elements[0];
|
|---|
| 199 | for (int i=1; i<m_count; ++i) {
|
|---|
| 200 | QPainterPath::Element element;
|
|---|
| 201 | element.x = m_points[index++];
|
|---|
| 202 | element.y = m_points[index++];
|
|---|
| 203 | element.type = m_elements[i];
|
|---|
| 204 | data->elements << element;
|
|---|
| 205 | }
|
|---|
| 206 | } else {
|
|---|
| 207 | data->elements[0].type = QPainterPath::MoveToElement;
|
|---|
| 208 | for (int i=1; i<m_count; ++i) {
|
|---|
| 209 | QPainterPath::Element element;
|
|---|
| 210 | element.x = m_points[index++];
|
|---|
| 211 | element.y = m_points[index++];
|
|---|
| 212 | element.type = QPainterPath::LineToElement;
|
|---|
| 213 | data->elements << element;
|
|---|
| 214 | }
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | if (m_hints & OddEvenFill)
|
|---|
| 218 | data->fillRule = Qt::OddEvenFill;
|
|---|
| 219 | else
|
|---|
| 220 | data->fillRule = Qt::WindingFill;
|
|---|
| 221 | return path;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | void Q_GUI_EXPORT qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length,
|
|---|
| 225 | QPointF* startPoint, QPointF *endPoint);
|
|---|
| 226 |
|
|---|
| 227 | inline bool QPainterPathData::isClosed() const
|
|---|
| 228 | {
|
|---|
| 229 | const QPainterPath::Element &first = elements.at(cStart);
|
|---|
| 230 | const QPainterPath::Element &last = elements.last();
|
|---|
| 231 | return first.x == last.x && first.y == last.y;
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | inline void QPainterPathData::close()
|
|---|
| 235 | {
|
|---|
| 236 | Q_ASSERT(ref == 1);
|
|---|
| 237 | require_moveTo = true;
|
|---|
| 238 | const QPainterPath::Element &first = elements.at(cStart);
|
|---|
| 239 | QPainterPath::Element &last = elements.last();
|
|---|
| 240 | if (first.x != last.x || first.y != last.y) {
|
|---|
| 241 | if (qFuzzyCompare(first.x, last.x) && qFuzzyCompare(first.y, last.y)) {
|
|---|
| 242 | last.x = first.x;
|
|---|
| 243 | last.y = first.y;
|
|---|
| 244 | } else {
|
|---|
| 245 | QPainterPath::Element e = { first.x, first.y, QPainterPath::LineToElement };
|
|---|
| 246 | elements << e;
|
|---|
| 247 | }
|
|---|
| 248 | }
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | inline void QPainterPathData::maybeMoveTo()
|
|---|
| 252 | {
|
|---|
| 253 | if (require_moveTo) {
|
|---|
| 254 | QPainterPath::Element e = elements.last();
|
|---|
| 255 | e.type = QPainterPath::MoveToElement;
|
|---|
| 256 | elements.append(e);
|
|---|
| 257 | require_moveTo = false;
|
|---|
| 258 | }
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | #define KAPPA 0.5522847498
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 | QT_END_NAMESPACE
|
|---|
| 265 |
|
|---|
| 266 | #endif // QPAINTERPATH_P_H
|
|---|