| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qpainterpath.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | struct QPainterPathPrivateDeleter | - | ||||||||||||||||||||||||
| 7 | { | - | ||||||||||||||||||||||||
| 8 | static inline void cleanup(QPainterPathPrivate *d) | - | ||||||||||||||||||||||||
| 9 | { | - | ||||||||||||||||||||||||
| 10 | - | |||||||||||||||||||||||||
| 11 | - | |||||||||||||||||||||||||
| 12 | if (d && !d->ref.deref()) | - | ||||||||||||||||||||||||
| 13 | delete static_cast<QPainterPathData *>(d); | - | ||||||||||||||||||||||||
| 14 | } | - | ||||||||||||||||||||||||
| 15 | }; | - | ||||||||||||||||||||||||
| 16 | QPainterPath qt_stroke_dash(const QPainterPath &path, qreal *dashes, int dashCount); | - | ||||||||||||||||||||||||
| 17 | - | |||||||||||||||||||||||||
| 18 | void qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length, | - | ||||||||||||||||||||||||
| 19 | QPointF* startPoint, QPointF *endPoint) | - | ||||||||||||||||||||||||
| 20 | { | - | ||||||||||||||||||||||||
| 21 | if (r.isNull()) { | - | ||||||||||||||||||||||||
| 22 | if (startPoint) | - | ||||||||||||||||||||||||
| 23 | *startPoint = QPointF(); | - | ||||||||||||||||||||||||
| 24 | if (endPoint) | - | ||||||||||||||||||||||||
| 25 | *endPoint = QPointF(); | - | ||||||||||||||||||||||||
| 26 | return; | - | ||||||||||||||||||||||||
| 27 | } | - | ||||||||||||||||||||||||
| 28 | - | |||||||||||||||||||||||||
| 29 | qreal w2 = r.width() / 2; | - | ||||||||||||||||||||||||
| 30 | qreal h2 = r.height() / 2; | - | ||||||||||||||||||||||||
| 31 | - | |||||||||||||||||||||||||
| 32 | qreal angles[2] = { angle, angle + length }; | - | ||||||||||||||||||||||||
| 33 | QPointF *points[2] = { startPoint, endPoint }; | - | ||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||
| 35 | for (int i = 0; i < 2; ++i) { | - | ||||||||||||||||||||||||
| 36 | if (!points[i]) | - | ||||||||||||||||||||||||
| 37 | continue; | - | ||||||||||||||||||||||||
| 38 | - | |||||||||||||||||||||||||
| 39 | qreal theta = angles[i] - 360 * qFloor(angles[i] / 360); | - | ||||||||||||||||||||||||
| 40 | qreal t = theta / 90; | - | ||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | int quadrant = int(t); | - | ||||||||||||||||||||||||
| 43 | t -= quadrant; | - | ||||||||||||||||||||||||
| 44 | - | |||||||||||||||||||||||||
| 45 | t = qt_t_for_arc_angle(90 * t); | - | ||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||
| 47 | - | |||||||||||||||||||||||||
| 48 | if (quadrant & 1) | - | ||||||||||||||||||||||||
| 49 | t = 1 - t; | - | ||||||||||||||||||||||||
| 50 | - | |||||||||||||||||||||||||
| 51 | qreal a, b, c, d; | - | ||||||||||||||||||||||||
| 52 | QBezier::coefficients(t, a, b, c, d); | - | ||||||||||||||||||||||||
| 53 | QPointF p(a + b + c*0.5522847498, d + c + b*0.5522847498); | - | ||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | if (quadrant == 1 || quadrant == 2) | - | ||||||||||||||||||||||||
| 57 | p.rx() = -p.x(); | - | ||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||
| 60 | if (quadrant == 0 || quadrant == 1) | - | ||||||||||||||||||||||||
| 61 | p.ry() = -p.y(); | - | ||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||
| 63 | *points[i] = r.center() + QPointF(w2 * p.x(), h2 * p.y()); | - | ||||||||||||||||||||||||
| 64 | } | - | ||||||||||||||||||||||||
| 65 | } | - | ||||||||||||||||||||||||
| 66 | int QPainterPath::elementCount() const | - | ||||||||||||||||||||||||
| 67 | { | - | ||||||||||||||||||||||||
| 68 | return d_ptr ? d_ptr->elements.size() : 0; | - | ||||||||||||||||||||||||
| 69 | } | - | ||||||||||||||||||||||||
| 70 | QPainterPath::Element QPainterPath::elementAt(int i) const | - | ||||||||||||||||||||||||
| 71 | { | - | ||||||||||||||||||||||||
| 72 | ((!(d_ptr)) ? qt_assert("d_ptr",__FILE__,490496) : qt_noop()); | - | ||||||||||||||||||||||||
| 73 | ((!(i >= 0 && i < elementCount())) ? qt_assert("i >= 0 && i < elementCount()",__FILE__,491497) : qt_noop()); | - | ||||||||||||||||||||||||
| 74 | return d_ptr->elements.at(i); | - | ||||||||||||||||||||||||
| 75 | } | - | ||||||||||||||||||||||||
| 76 | void QPainterPath::setElementPositionAt(int i, qreal x, qreal y) | - | ||||||||||||||||||||||||
| 77 | { | - | ||||||||||||||||||||||||
| 78 | ((!(d_ptr)) ? qt_assert("d_ptr",__FILE__,505511) : qt_noop()); | - | ||||||||||||||||||||||||
| 79 | ((!(i >= 0 && i < elementCount())) ? qt_assert("i >= 0 && i < elementCount()",__FILE__,506512) : qt_noop()); | - | ||||||||||||||||||||||||
| 80 | detach(); | - | ||||||||||||||||||||||||
| 81 | QPainterPath::Element &e = d_ptr->elements[i]; | - | ||||||||||||||||||||||||
| 82 | e.x = x; | - | ||||||||||||||||||||||||
| 83 | e.y = y; | - | ||||||||||||||||||||||||
| 84 | } | - | ||||||||||||||||||||||||
| 85 | QPainterPath::QPainterPath() noexcept | - | ||||||||||||||||||||||||
| 86 | : d_ptr(0) | - | ||||||||||||||||||||||||
| 87 | { | - | ||||||||||||||||||||||||
| 88 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 89 | QPainterPath::QPainterPath(const QPainterPath &other) | - | ||||||||||||||||||||||||
| 90 | : d_ptr(other.d_ptr.data()) | - | ||||||||||||||||||||||||
| 91 | { | - | ||||||||||||||||||||||||
| 92 | if (d_ptr) | - | ||||||||||||||||||||||||
| 93 | d_ptr->ref.ref(); | - | ||||||||||||||||||||||||
| 94 | } | - | ||||||||||||||||||||||||
| 95 | - | |||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||
| 101 | QPainterPath::QPainterPath(const QPointF &startPoint) | - | ||||||||||||||||||||||||
| 102 | : d_ptr(new QPainterPathData) | - | ||||||||||||||||||||||||
| 103 | { | - | ||||||||||||||||||||||||
| 104 | Element e = { startPoint.x(), startPoint.y(), MoveToElement }; | - | ||||||||||||||||||||||||
| 105 | d_func()->elements << e; | - | ||||||||||||||||||||||||
| 106 | } | - | ||||||||||||||||||||||||
| 107 | - | |||||||||||||||||||||||||
| 108 | void QPainterPath::detach() | - | ||||||||||||||||||||||||
| 109 | { | - | ||||||||||||||||||||||||
| 110 | if (d_ptr->ref.load() != 1) | - | ||||||||||||||||||||||||
| 111 | detach_helper(); | - | ||||||||||||||||||||||||
| 112 | setDirty(true); | - | ||||||||||||||||||||||||
| 113 | } | - | ||||||||||||||||||||||||
| 114 | - | |||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | - | |||||||||||||||||||||||||
| 118 | void QPainterPath::detach_helper() | - | ||||||||||||||||||||||||
| 119 | { | - | ||||||||||||||||||||||||
| 120 | QPainterPathPrivate *data = new QPainterPathData(*d_func()); | - | ||||||||||||||||||||||||
| 121 | d_ptr.reset(data); | - | ||||||||||||||||||||||||
| 122 | } | - | ||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||
| 125 | - | |||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||
| 127 | void QPainterPath::ensureData_helper() | - | ||||||||||||||||||||||||
| 128 | { | - | ||||||||||||||||||||||||
| 129 | QPainterPathPrivate *data = new QPainterPathData; | - | ||||||||||||||||||||||||
| 130 | data->elements.reserve(16); | - | ||||||||||||||||||||||||
| 131 | QPainterPath::Element e = { 0, 0, QPainterPath::MoveToElement }; | - | ||||||||||||||||||||||||
| 132 | data->elements << e; | - | ||||||||||||||||||||||||
| 133 | d_ptr.reset(data); | - | ||||||||||||||||||||||||
| 134 | ((!(d_ptr != 0)) ? qt_assert("d_ptr != 0",__FILE__,581587) : qt_noop()); | - | ||||||||||||||||||||||||
| 135 | } | - | ||||||||||||||||||||||||
| 136 | QPainterPath &QPainterPath::operator=(const QPainterPath &other) | - | ||||||||||||||||||||||||
| 137 | { | - | ||||||||||||||||||||||||
| 138 | if (other.d_func() != d_func()) { | - | ||||||||||||||||||||||||
| 139 | QPainterPathPrivate *data = other.d_func(); | - | ||||||||||||||||||||||||
| 140 | if (data) | - | ||||||||||||||||||||||||
| 141 | data->ref.ref(); | - | ||||||||||||||||||||||||
| 142 | d_ptr.reset(data); | - | ||||||||||||||||||||||||
| 143 | } | - | ||||||||||||||||||||||||
| 144 | return *this; | - | ||||||||||||||||||||||||
| 145 | } | - | ||||||||||||||||||||||||
| 146 | QPainterPath::~QPainterPath() | - | ||||||||||||||||||||||||
| 147 | { | - | ||||||||||||||||||||||||
| 148 | } | - | ||||||||||||||||||||||||
| 149 | void QPainterPath::closeSubpath() | - | ||||||||||||||||||||||||
| 150 | { | - | ||||||||||||||||||||||||
| 151 | - | |||||||||||||||||||||||||
| 152 | - | |||||||||||||||||||||||||
| 153 | - | |||||||||||||||||||||||||
| 154 | if (isEmpty()) | - | ||||||||||||||||||||||||
| 155 | return; | - | ||||||||||||||||||||||||
| 156 | detach(); | - | ||||||||||||||||||||||||
| 157 | - | |||||||||||||||||||||||||
| 158 | d_func()->close(); | - | ||||||||||||||||||||||||
| 159 | } | - | ||||||||||||||||||||||||
| 160 | void QPainterPath::moveTo(const QPointF &p) | - | ||||||||||||||||||||||||
| 161 | { | - | ||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | - | |||||||||||||||||||||||||
| 165 | - | |||||||||||||||||||||||||
| 166 | if (!qt_is_finite(p.x())
| 0 | ||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||
| 168 | QMessageLogger(__FILE__, 674680, __PRETTY_FUNCTION__).warning("QPainterPath::moveTo: Adding point where x or y is NaN or Inf, ignoring call"); | - | ||||||||||||||||||||||||
| 169 | - | |||||||||||||||||||||||||
| 170 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 171 | } | - | ||||||||||||||||||||||||
| 172 | - | |||||||||||||||||||||||||
| 173 | ensureData(); | - | ||||||||||||||||||||||||
| 174 | detach(); | - | ||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | QPainterPathData *d = d_func(); | - | ||||||||||||||||||||||||
| 177 | ((!(!d->elements.isEmpty())) ? qt_assert("!d->elements.isEmpty()",__FILE__,683689) : qt_noop()); | - | ||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||
| 179 | d->require_moveTo = false; | - | ||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||
| 181 | if (d->elements.lastconstLast().type == MoveToElement
| 0 | ||||||||||||||||||||||||
| 182 | d->elements.last().x = p.x(); | - | ||||||||||||||||||||||||
| 183 | d->elements.last().y = p.y(); | - | ||||||||||||||||||||||||
| 184 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 185 | Element elm = { p.x(), p.y(), MoveToElement }; | - | ||||||||||||||||||||||||
| 186 | d->elements.append(elm); | - | ||||||||||||||||||||||||
| 187 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 188 | d->cStart = d->elements.size() - 1; | - | ||||||||||||||||||||||||
| 189 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 190 | void QPainterPath::lineTo(const QPointF &p) | - | ||||||||||||||||||||||||
| 191 | { | - | ||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||
| 193 | - | |||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||
| 195 | - | |||||||||||||||||||||||||
| 196 | if (!qt_is_finite(p.x())
| 0 | ||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||
| 198 | QMessageLogger(__FILE__, 724730, __PRETTY_FUNCTION__).warning("QPainterPath::lineTo: Adding point where x or y is NaN or Inf, ignoring call"); | - | ||||||||||||||||||||||||
| 199 | - | |||||||||||||||||||||||||
| 200 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 201 | } | - | ||||||||||||||||||||||||
| 202 | - | |||||||||||||||||||||||||
| 203 | ensureData(); | - | ||||||||||||||||||||||||
| 204 | detach(); | - | ||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||
| 206 | QPainterPathData *d = d_func(); | - | ||||||||||||||||||||||||
| 207 | ((!(!d->elements.isEmpty())) ? qt_assert("!d->elements.isEmpty()",__FILE__,733739) : qt_noop()); | - | ||||||||||||||||||||||||
| 208 | d->maybeMoveTo(); | - | ||||||||||||||||||||||||
| 209 | if (p == QPointF(d->elements.lastconstLast())
| 0 | ||||||||||||||||||||||||
| 210 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 211 | Element elm = { p.x(), p.y(), LineToElement }; | - | ||||||||||||||||||||||||
| 212 | d->elements.append(elm); | - | ||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | d->convex = d->elements.size() == 3
| 0 | ||||||||||||||||||||||||
| 215 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 216 | void QPainterPath::cubicTo(const QPointF &c1, const QPointF &c2, const QPointF &e) | - | ||||||||||||||||||||||||
| 217 | { | - | ||||||||||||||||||||||||
| 218 | - | |||||||||||||||||||||||||
| 219 | - | |||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||
| 222 | - | |||||||||||||||||||||||||
| 223 | if (!qt_is_finite(c1.x())
| 0 | ||||||||||||||||||||||||
| 224 | || !qt_is_finite(e.x())
| 0 | ||||||||||||||||||||||||
| 225 | - | |||||||||||||||||||||||||
| 226 | QMessageLogger(__FILE__, 784790, __PRETTY_FUNCTION__).warning("QPainterPath::cubicTo: Adding point where x or y is NaN or Inf, ignoring call"); | - | ||||||||||||||||||||||||
| 227 | - | |||||||||||||||||||||||||
| 228 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 229 | } | - | ||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||
| 231 | ensureData(); | - | ||||||||||||||||||||||||
| 232 | detach(); | - | ||||||||||||||||||||||||
| 233 | - | |||||||||||||||||||||||||
| 234 | QPainterPathData *d = d_func(); | - | ||||||||||||||||||||||||
| 235 | ((!(!d->elements.isEmpty())) ? qt_assert("!d->elements.isEmpty()",__FILE__,793799) : qt_noop()); | - | ||||||||||||||||||||||||
| 236 | - | |||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||
| 238 | - | |||||||||||||||||||||||||
| 239 | - | |||||||||||||||||||||||||
| 240 | if (d->elements.lastconstLast() == c1
| 0 | ||||||||||||||||||||||||
| 241 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 242 | - | |||||||||||||||||||||||||
| 243 | d->maybeMoveTo(); | - | ||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||
| 245 | Element ce1 = { c1.x(), c1.y(), CurveToElement }; | - | ||||||||||||||||||||||||
| 246 | Element ce2 = { c2.x(), c2.y(), CurveToDataElement }; | - | ||||||||||||||||||||||||
| 247 | Element ee = { e.x(), e.y(), CurveToDataElement }; | - | ||||||||||||||||||||||||
| 248 | d->elements << ce1 << ce2 << ee; | - | ||||||||||||||||||||||||
| 249 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 250 | void QPainterPath::quadTo(const QPointF &c, const QPointF &e) | - | ||||||||||||||||||||||||
| 251 | { | - | ||||||||||||||||||||||||
| 252 | - | |||||||||||||||||||||||||
| 253 | - | |||||||||||||||||||||||||
| 254 | - | |||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||
| 256 | - | |||||||||||||||||||||||||
| 257 | if (!qt_is_finite(c.x()) || !qt_is_finite(c.y()) || !qt_is_finite(e.x()) || !qt_is_finite(e.y())) { | - | ||||||||||||||||||||||||
| 258 | - | |||||||||||||||||||||||||
| 259 | QMessageLogger(__FILE__, 840846, __PRETTY_FUNCTION__).warning("QPainterPath::quadTo: Adding point where x or y is NaN or Inf, ignoring call"); | - | ||||||||||||||||||||||||
| 260 | - | |||||||||||||||||||||||||
| 261 | return; | - | ||||||||||||||||||||||||
| 262 | } | - | ||||||||||||||||||||||||
| 263 | - | |||||||||||||||||||||||||
| 264 | ensureData(); | - | ||||||||||||||||||||||||
| 265 | detach(); | - | ||||||||||||||||||||||||
| 266 | - | |||||||||||||||||||||||||
| 267 | QPainterPathPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 268 | ((!(!d->elements.isEmpty())) ? qt_assert("!d->elements.isEmpty()",__FILE__,849855) : qt_noop()); | - | ||||||||||||||||||||||||
| 269 | const QPainterPath::Element &elm = d->elements.at(elementCount()-1); | - | ||||||||||||||||||||||||
| 270 | QPointF prev(elm.x, elm.y); | - | ||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||
| 272 | - | |||||||||||||||||||||||||
| 273 | - | |||||||||||||||||||||||||
| 274 | if (prev == c && c == e) | - | ||||||||||||||||||||||||
| 275 | return; | - | ||||||||||||||||||||||||
| 276 | - | |||||||||||||||||||||||||
| 277 | QPointF c1((prev.x() + 2*c.x()) / 3, (prev.y() + 2*c.y()) / 3); | - | ||||||||||||||||||||||||
| 278 | QPointF c2((e.x() + 2*c.x()) / 3, (e.y() + 2*c.y()) / 3); | - | ||||||||||||||||||||||||
| 279 | cubicTo(c1, c2, e); | - | ||||||||||||||||||||||||
| 280 | } | - | ||||||||||||||||||||||||
| 281 | void QPainterPath::arcTo(const QRectF &rect, qreal startAngle, qreal sweepLength) | - | ||||||||||||||||||||||||
| 282 | { | - | ||||||||||||||||||||||||
| 283 | - | |||||||||||||||||||||||||
| 284 | - | |||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||
| 286 | - | |||||||||||||||||||||||||
| 287 | - | |||||||||||||||||||||||||
| 288 | if ((!qt_is_finite(rect.x()) && !qt_is_finite(rect.y())) || !qt_is_finite(rect.width()) || !qt_is_finite(rect.height()) | - | ||||||||||||||||||||||||
| 289 | || !qt_is_finite(startAngle) || !qt_is_finite(sweepLength)) { | - | ||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | QMessageLogger(__FILE__, 912918, __PRETTY_FUNCTION__).warning("QPainterPath::arcTo: Adding arc where a parameter is NaN or Inf, ignoring call"); | - | ||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | return; | - | ||||||||||||||||||||||||
| 294 | } | - | ||||||||||||||||||||||||
| 295 | - | |||||||||||||||||||||||||
| 296 | if (rect.isNull()) | - | ||||||||||||||||||||||||
| 297 | return; | - | ||||||||||||||||||||||||
| 298 | - | |||||||||||||||||||||||||
| 299 | ensureData(); | - | ||||||||||||||||||||||||
| 300 | detach(); | - | ||||||||||||||||||||||||
| 301 | - | |||||||||||||||||||||||||
| 302 | int point_count; | - | ||||||||||||||||||||||||
| 303 | QPointF pts[15]; | - | ||||||||||||||||||||||||
| 304 | QPointF curve_start = qt_curves_for_arc(rect, startAngle, sweepLength, pts, &point_count); | - | ||||||||||||||||||||||||
| 305 | - | |||||||||||||||||||||||||
| 306 | lineTo(curve_start); | - | ||||||||||||||||||||||||
| 307 | for (int i=0; i<point_count; i+=3) { | - | ||||||||||||||||||||||||
| 308 | cubicTo(pts[i].x(), pts[i].y(), | - | ||||||||||||||||||||||||
| 309 | pts[i+1].x(), pts[i+1].y(), | - | ||||||||||||||||||||||||
| 310 | pts[i+2].x(), pts[i+2].y()); | - | ||||||||||||||||||||||||
| 311 | } | - | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | } | - | ||||||||||||||||||||||||
| 314 | void QPainterPath::arcMoveTo(const QRectF &rect, qreal angle) | - | ||||||||||||||||||||||||
| 315 | { | - | ||||||||||||||||||||||||
| 316 | if (rect.isNull()) | - | ||||||||||||||||||||||||
| 317 | return; | - | ||||||||||||||||||||||||
| 318 | - | |||||||||||||||||||||||||
| 319 | QPointF pt; | - | ||||||||||||||||||||||||
| 320 | qt_find_ellipse_coords(rect, angle, 0, &pt, 0); | - | ||||||||||||||||||||||||
| 321 | moveTo(pt); | - | ||||||||||||||||||||||||
| 322 | } | - | ||||||||||||||||||||||||
| 323 | QPointF QPainterPath::currentPosition() const | - | ||||||||||||||||||||||||
| 324 | { | - | ||||||||||||||||||||||||
| 325 | return never executed: !d_ptr || d_func()->elements.isEmpty()return !d_ptr || d_func()->elements.isEmpty() ? QPointF() : QPointF(d_func()->elements.constLast().x, d_func()->elements.constLast().y);never executed: return !d_ptr || d_func()->elements.isEmpty() ? QPointF() : QPointF(d_func()->elements.constLast().x, d_func()->elements.constLast().y); | 0 | ||||||||||||||||||||||||
| 326 | ? QPointF() never executed: return !d_ptr || d_func()->elements.isEmpty() ? QPointF() : QPointF(d_func()->elements.constLast().x, d_func()->elements.constLast().y); | 0 | ||||||||||||||||||||||||
| 327 | : QPointF(d_func()->elements.lastconstLast().x, d_func()->elements.lastconstLast().y); never executed: return !d_ptr || d_func()->elements.isEmpty() ? QPointF() : QPointF(d_func()->elements.constLast().x, d_func()->elements.constLast().y); | 0 | ||||||||||||||||||||||||
| 328 | } | - | ||||||||||||||||||||||||
| 329 | void QPainterPath::addRect(const QRectF &r) | - | ||||||||||||||||||||||||
| 330 | { | - | ||||||||||||||||||||||||
| 331 | if (!qt_is_finite(r.x()) || !qt_is_finite(r.y()) || !qt_is_finite(r.width()) || !qt_is_finite(r.height())) { | - | ||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||
| 333 | QMessageLogger(__FILE__, 10171023, __PRETTY_FUNCTION__).warning("QPainterPath::addRect: Adding rect where a parameter is NaN or Inf, ignoring call"); | - | ||||||||||||||||||||||||
| 334 | - | |||||||||||||||||||||||||
| 335 | return; | - | ||||||||||||||||||||||||
| 336 | } | - | ||||||||||||||||||||||||
| 337 | - | |||||||||||||||||||||||||
| 338 | if (r.isNull()) | - | ||||||||||||||||||||||||
| 339 | return; | - | ||||||||||||||||||||||||
| 340 | - | |||||||||||||||||||||||||
| 341 | ensureData(); | - | ||||||||||||||||||||||||
| 342 | detach(); | - | ||||||||||||||||||||||||
| 343 | - | |||||||||||||||||||||||||
| 344 | bool first = d_func()->elements.size() < 2; | - | ||||||||||||||||||||||||
| 345 | - | |||||||||||||||||||||||||
| 346 | d_func()->elements.reserve(d_func()->elements.size() + 5); | - | ||||||||||||||||||||||||
| 347 | moveTo(r.x(), r.y()); | - | ||||||||||||||||||||||||
| 348 | - | |||||||||||||||||||||||||
| 349 | Element l1 = { r.x() + r.width(), r.y(), LineToElement }; | - | ||||||||||||||||||||||||
| 350 | Element l2 = { r.x() + r.width(), r.y() + r.height(), LineToElement }; | - | ||||||||||||||||||||||||
| 351 | Element l3 = { r.x(), r.y() + r.height(), LineToElement }; | - | ||||||||||||||||||||||||
| 352 | Element l4 = { r.x(), r.y(), LineToElement }; | - | ||||||||||||||||||||||||
| 353 | - | |||||||||||||||||||||||||
| 354 | d_func()->elements << l1 << l2 << l3 << l4; | - | ||||||||||||||||||||||||
| 355 | d_func()->require_moveTo = true; | - | ||||||||||||||||||||||||
| 356 | d_func()->convex = first; | - | ||||||||||||||||||||||||
| 357 | } | - | ||||||||||||||||||||||||
| 358 | void QPainterPath::addPolygon(const QPolygonF &polygon) | - | ||||||||||||||||||||||||
| 359 | { | - | ||||||||||||||||||||||||
| 360 | if (polygon.isEmpty()
| 0 | ||||||||||||||||||||||||
| 361 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 362 | - | |||||||||||||||||||||||||
| 363 | ensureData(); | - | ||||||||||||||||||||||||
| 364 | detach(); | - | ||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||
| 366 | d_func()->elements.reserve(d_func()->elements.size() + polygon.size()); | - | ||||||||||||||||||||||||
| 367 | - | |||||||||||||||||||||||||
| 368 | moveTo(polygon.firstconstFirst()); | - | ||||||||||||||||||||||||
| 369 | for (int i=1; i<polygon.size()
| 0 | ||||||||||||||||||||||||
| 370 | Element elm = { polygon.at(i).x(), polygon.at(i).y(), LineToElement }; | - | ||||||||||||||||||||||||
| 371 | d_func()->elements << elm; | - | ||||||||||||||||||||||||
| 372 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 373 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 374 | void QPainterPath::addEllipse(const QRectF &boundingRect) | - | ||||||||||||||||||||||||
| 375 | { | - | ||||||||||||||||||||||||
| 376 | if (!qt_is_finite(boundingRect.x()) || !qt_is_finite(boundingRect.y()) | - | ||||||||||||||||||||||||
| 377 | || !qt_is_finite(boundingRect.width()) || !qt_is_finite(boundingRect.height())) { | - | ||||||||||||||||||||||||
| 378 | - | |||||||||||||||||||||||||
| 379 | QMessageLogger(__FILE__, 11011107, __PRETTY_FUNCTION__).warning("QPainterPath::addEllipse: Adding ellipse where a parameter is NaN or Inf, ignoring call"); | - | ||||||||||||||||||||||||
| 380 | - | |||||||||||||||||||||||||
| 381 | return; | - | ||||||||||||||||||||||||
| 382 | } | - | ||||||||||||||||||||||||
| 383 | - | |||||||||||||||||||||||||
| 384 | if (boundingRect.isNull()) | - | ||||||||||||||||||||||||
| 385 | return; | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | ensureData(); | - | ||||||||||||||||||||||||
| 388 | detach(); | - | ||||||||||||||||||||||||
| 389 | - | |||||||||||||||||||||||||
| 390 | QPainterPathPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 391 | bool first = d_func()->elements.size() < 2; | - | ||||||||||||||||||||||||
| 392 | d->elements.reserve(d->elements.size() + 13); | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | QPointF pts[12]; | - | ||||||||||||||||||||||||
| 395 | int point_count; | - | ||||||||||||||||||||||||
| 396 | QPointF start = qt_curves_for_arc(boundingRect, 0, -360, pts, &point_count); | - | ||||||||||||||||||||||||
| 397 | - | |||||||||||||||||||||||||
| 398 | moveTo(start); | - | ||||||||||||||||||||||||
| 399 | cubicTo(pts[0], pts[1], pts[2]); | - | ||||||||||||||||||||||||
| 400 | cubicTo(pts[3], pts[4], pts[5]); | - | ||||||||||||||||||||||||
| 401 | cubicTo(pts[6], pts[7], pts[8]); | - | ||||||||||||||||||||||||
| 402 | cubicTo(pts[9], pts[10], pts[11]); | - | ||||||||||||||||||||||||
| 403 | d_func()->require_moveTo = true; | - | ||||||||||||||||||||||||
| 404 | - | |||||||||||||||||||||||||
| 405 | d_func()->convex = first; | - | ||||||||||||||||||||||||
| 406 | } | - | ||||||||||||||||||||||||
| 407 | void QPainterPath::addText(const QPointF &point, const QFont &f, const QString &text) | - | ||||||||||||||||||||||||
| 408 | { | - | ||||||||||||||||||||||||
| 409 | if (text.isEmpty()
| 0 | ||||||||||||||||||||||||
| 410 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 411 | - | |||||||||||||||||||||||||
| 412 | ensureData(); | - | ||||||||||||||||||||||||
| 413 | detach(); | - | ||||||||||||||||||||||||
| 414 | - | |||||||||||||||||||||||||
| 415 | QTextLayout layout(text, f); | - | ||||||||||||||||||||||||
| 416 | layout.setCacheEnabled(true); | - | ||||||||||||||||||||||||
| 417 | QTextEngine *eng = layout.engine(); | - | ||||||||||||||||||||||||
| 418 | layout.beginLayout(); | - | ||||||||||||||||||||||||
| 419 | QTextLine line = layout.createLine(); | - | ||||||||||||||||||||||||
| 420 | (void)line;; | - | ||||||||||||||||||||||||
| 421 | layout.endLayout(); | - | ||||||||||||||||||||||||
| 422 | const QScriptLine &sl = eng->lines[0]; | - | ||||||||||||||||||||||||
| 423 | if (!sl.length
| 0 | ||||||||||||||||||||||||
| 424 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 425 | - | |||||||||||||||||||||||||
| 426 | int nItems = eng->layoutData->items.size(); | - | ||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||
| 428 | qreal x(point.x()); | - | ||||||||||||||||||||||||
| 429 | qreal y(point.y()); | - | ||||||||||||||||||||||||
| 430 | - | |||||||||||||||||||||||||
| 431 | QVarLengthArray<int> visualOrder(nItems); | - | ||||||||||||||||||||||||
| 432 | QVarLengthArray<uchar> levels(nItems); | - | ||||||||||||||||||||||||
| 433 | for (int i = 0; i < nItems
| 0 | ||||||||||||||||||||||||
| 434 | levels[i] = eng->layoutData->items[.at(i].).analysis.bidiLevel; never executed: levels[i] = eng->layoutData->items.at(i).analysis.bidiLevel; | 0 | ||||||||||||||||||||||||
| 435 | QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data()); | - | ||||||||||||||||||||||||
| 436 | - | |||||||||||||||||||||||||
| 437 | for (int i = 0; i < nItems
| 0 | ||||||||||||||||||||||||
| 438 | int item = visualOrder[i]; | - | ||||||||||||||||||||||||
| 439 | const QScriptItem &si = eng->layoutData->items[.at(item];); | - | ||||||||||||||||||||||||
| 440 | - | |||||||||||||||||||||||||
| 441 | if (si.analysis.flags < QScriptAnalysis::TabOrObject
| 0 | ||||||||||||||||||||||||
| 442 | QGlyphLayout glyphs = eng->shapedGlyphs(&si); | - | ||||||||||||||||||||||||
| 443 | QFontEngine *fe = f.d->engineForScript(si.analysis.script); | - | ||||||||||||||||||||||||
| 444 | ((!(fe)) ? qt_assert("fe",__FILE__,11851191) : qt_noop()); | - | ||||||||||||||||||||||||
| 445 | fe->addOutlineToPath(x, y, glyphs, this, | - | ||||||||||||||||||||||||
| 446 | si.analysis.bidiLevel % 2 | - | ||||||||||||||||||||||||
| 447 | ? QTextItem::RenderFlags(QTextItem::RightToLeft) | - | ||||||||||||||||||||||||
| 448 | : QTextItem::RenderFlags(0)); | - | ||||||||||||||||||||||||
| 449 | - | |||||||||||||||||||||||||
| 450 | const qreal lw = fe->lineThickness().toReal(); | - | ||||||||||||||||||||||||
| 451 | if (f.d->underline
| 0 | ||||||||||||||||||||||||
| 452 | qreal pos = fe->underlinePosition().toReal(); | - | ||||||||||||||||||||||||
| 453 | addRect(x, y + pos, si.width.toReal(), lw); | - | ||||||||||||||||||||||||
| 454 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 455 | if (f.d->overline
| 0 | ||||||||||||||||||||||||
| 456 | qreal pos = fe->ascent().toReal() + 1; | - | ||||||||||||||||||||||||
| 457 | addRect(x, y - pos, si.width.toReal(), lw); | - | ||||||||||||||||||||||||
| 458 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 459 | if (f.d->strikeOut
| 0 | ||||||||||||||||||||||||
| 460 | qreal pos = fe->ascent().toReal() / 3; | - | ||||||||||||||||||||||||
| 461 | addRect(x, y - pos, si.width.toReal(), lw); | - | ||||||||||||||||||||||||
| 462 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 463 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 464 | x += si.width.toReal(); | - | ||||||||||||||||||||||||
| 465 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 466 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 467 | void QPainterPath::addPath(const QPainterPath &other) | - | ||||||||||||||||||||||||
| 468 | { | - | ||||||||||||||||||||||||
| 469 | if (other.isEmpty()
| 0 | ||||||||||||||||||||||||
| 470 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 471 | - | |||||||||||||||||||||||||
| 472 | ensureData(); | - | ||||||||||||||||||||||||
| 473 | detach(); | - | ||||||||||||||||||||||||
| 474 | - | |||||||||||||||||||||||||
| 475 | QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func()); | - | ||||||||||||||||||||||||
| 476 | - | |||||||||||||||||||||||||
| 477 | if (d->elements.lastconstLast().type == MoveToElement
| 0 | ||||||||||||||||||||||||
| 478 | d->elements.remove(d->elements.size()-1); never executed: d->elements.remove(d->elements.size()-1); | 0 | ||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | - | |||||||||||||||||||||||||
| 481 | int cStart = d->elements.size() + other.d_func()->cStart; | - | ||||||||||||||||||||||||
| 482 | d->elements += other.d_func()->elements; | - | ||||||||||||||||||||||||
| 483 | d->cStart = cStart; | - | ||||||||||||||||||||||||
| 484 | - | |||||||||||||||||||||||||
| 485 | d->require_moveTo = other.d_func()->isClosed(); | - | ||||||||||||||||||||||||
| 486 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 487 | void QPainterPath::connectPath(const QPainterPath &other) | - | ||||||||||||||||||||||||
| 488 | { | - | ||||||||||||||||||||||||
| 489 | if (other.isEmpty()
| 0 | ||||||||||||||||||||||||
| 490 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 491 | - | |||||||||||||||||||||||||
| 492 | ensureData(); | - | ||||||||||||||||||||||||
| 493 | detach(); | - | ||||||||||||||||||||||||
| 494 | - | |||||||||||||||||||||||||
| 495 | QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func()); | - | ||||||||||||||||||||||||
| 496 | - | |||||||||||||||||||||||||
| 497 | if (d->elements.lastconstLast().type == MoveToElement
| 0 | ||||||||||||||||||||||||
| 498 | d->elements.remove(d->elements.size()-1); never executed: d->elements.remove(d->elements.size()-1); | 0 | ||||||||||||||||||||||||
| 499 | - | |||||||||||||||||||||||||
| 500 | - | |||||||||||||||||||||||||
| 501 | int cStart = d->elements.size() + other.d_func()->cStart; | - | ||||||||||||||||||||||||
| 502 | int first = d->elements.size(); | - | ||||||||||||||||||||||||
| 503 | d->elements += other.d_func()->elements; | - | ||||||||||||||||||||||||
| 504 | - | |||||||||||||||||||||||||
| 505 | if (first != 0
| 0 | ||||||||||||||||||||||||
| 506 | d->elements[first].type = LineToElement; never executed: d->elements[first].type = LineToElement; | 0 | ||||||||||||||||||||||||
| 507 | - | |||||||||||||||||||||||||
| 508 | - | |||||||||||||||||||||||||
| 509 | if (first > 0
| 0 | ||||||||||||||||||||||||
| 510 | d->elements.remove(first--); | - | ||||||||||||||||||||||||
| 511 | --cStart; | - | ||||||||||||||||||||||||
| 512 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | if (cStart != first
| 0 | ||||||||||||||||||||||||
| 515 | d->cStart = cStart; never executed: d->cStart = cStart; | 0 | ||||||||||||||||||||||||
| 516 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 517 | void QPainterPath::addRegion(const QRegion ®ion) | - | ||||||||||||||||||||||||
| 518 | { | - | ||||||||||||||||||||||||
| 519 | ensureData(); | - | ||||||||||||||||||||||||
| 520 | detach(); | - | ||||||||||||||||||||||||
| 521 | - | |||||||||||||||||||||||||
| 522 | QVector<QRect> rects = region.rects(); | - | ||||||||||||||||||||||||
| 523 | d_func()->elements.reserve(rects.size() * 5); | - | ||||||||||||||||||||||||
| 524 | for (int i=0; i<rects.size(); ++i) | - | ||||||||||||||||||||||||
| 525 | addRect(rects.at(i)); | - | ||||||||||||||||||||||||
| 526 | } | - | ||||||||||||||||||||||||
| 527 | - | |||||||||||||||||||||||||
| 528 | - | |||||||||||||||||||||||||
| 529 | - | |||||||||||||||||||||||||
| 530 | - | |||||||||||||||||||||||||
| 531 | - | |||||||||||||||||||||||||
| 532 | - | |||||||||||||||||||||||||
| 533 | - | |||||||||||||||||||||||||
| 534 | Qt::FillRule QPainterPath::fillRule() const | - | ||||||||||||||||||||||||
| 535 | { | - | ||||||||||||||||||||||||
| 536 | return isEmpty() ? Qt::OddEvenFill : d_func()->fillRule; | - | ||||||||||||||||||||||||
| 537 | } | - | ||||||||||||||||||||||||
| 538 | void QPainterPath::setFillRule(Qt::FillRule fillRule) | - | ||||||||||||||||||||||||
| 539 | { | - | ||||||||||||||||||||||||
| 540 | ensureData(); | - | ||||||||||||||||||||||||
| 541 | if (d_func()->fillRule == fillRule) | - | ||||||||||||||||||||||||
| 542 | return; | - | ||||||||||||||||||||||||
| 543 | detach(); | - | ||||||||||||||||||||||||
| 544 | - | |||||||||||||||||||||||||
| 545 | d_func()->fillRule = fillRule; | - | ||||||||||||||||||||||||
| 546 | } | - | ||||||||||||||||||||||||
| 547 | static QRectF qt_painterpath_bezier_extrema(const QBezier &b) | - | ||||||||||||||||||||||||
| 548 | { | - | ||||||||||||||||||||||||
| 549 | qreal minx, miny, maxx, maxy; | - | ||||||||||||||||||||||||
| 550 | - | |||||||||||||||||||||||||
| 551 | - | |||||||||||||||||||||||||
| 552 | if (b.x1 < b.x4) { | - | ||||||||||||||||||||||||
| 553 | minx = b.x1; | - | ||||||||||||||||||||||||
| 554 | maxx = b.x4; | - | ||||||||||||||||||||||||
| 555 | } else { | - | ||||||||||||||||||||||||
| 556 | minx = b.x4; | - | ||||||||||||||||||||||||
| 557 | maxx = b.x1; | - | ||||||||||||||||||||||||
| 558 | } | - | ||||||||||||||||||||||||
| 559 | if (b.y1 < b.y4) { | - | ||||||||||||||||||||||||
| 560 | miny = b.y1; | - | ||||||||||||||||||||||||
| 561 | maxy = b.y4; | - | ||||||||||||||||||||||||
| 562 | } else { | - | ||||||||||||||||||||||||
| 563 | miny = b.y4; | - | ||||||||||||||||||||||||
| 564 | maxy = b.y1; | - | ||||||||||||||||||||||||
| 565 | } | - | ||||||||||||||||||||||||
| 566 | - | |||||||||||||||||||||||||
| 567 | - | |||||||||||||||||||||||||
| 568 | { | - | ||||||||||||||||||||||||
| 569 | qreal ax = 3 * (-b.x1 + 3*b.x2 - 3*b.x3 +b.x4); | - | ||||||||||||||||||||||||
| 570 | qreal bx = 6 * (b.x1 - 2*b.x2 + b.x3); | - | ||||||||||||||||||||||||
| 571 | qreal cx = 3 * (- b.x1 + b.x2); | - | ||||||||||||||||||||||||
| 572 | - | |||||||||||||||||||||||||
| 573 | if (qFuzzyIsNull(ax)) { | - | ||||||||||||||||||||||||
| 574 | - | |||||||||||||||||||||||||
| 575 | - | |||||||||||||||||||||||||
| 576 | if (!qFuzzyIsNull(bx)) { | - | ||||||||||||||||||||||||
| 577 | qreal t = -cx / bx; | - | ||||||||||||||||||||||||
| 578 | if (t >= 0 && t <= 1) { QPointF p(b.pointAt(t)); if (p.x() < minx) minx = p.x(); else if (p.x() > maxx) maxx = p.x(); if (p.y() < miny) miny = p.y(); else if (p.y() > maxy) maxy = p.y(); }; | - | ||||||||||||||||||||||||
| 579 | } | - | ||||||||||||||||||||||||
| 580 | - | |||||||||||||||||||||||||
| 581 | } else { | - | ||||||||||||||||||||||||
| 582 | const qreal tx = bx * bx - 4 * ax * cx; | - | ||||||||||||||||||||||||
| 583 | - | |||||||||||||||||||||||||
| 584 | if (tx >= 0) { | - | ||||||||||||||||||||||||
| 585 | qreal temp = qSqrt(tx); | - | ||||||||||||||||||||||||
| 586 | qreal rcp = 1 / (2 * ax); | - | ||||||||||||||||||||||||
| 587 | qreal t1 = (-bx + temp) * rcp; | - | ||||||||||||||||||||||||
| 588 | if (t1 >= 0 && t1 <= 1) { QPointF p(b.pointAt(t1)); if (p.x() < minx) minx = p.x(); else if (p.x() > maxx) maxx = p.x(); if (p.y() < miny) miny = p.y(); else if (p.y() > maxy) maxy = p.y(); }; | - | ||||||||||||||||||||||||
| 589 | - | |||||||||||||||||||||||||
| 590 | qreal t2 = (-bx - temp) * rcp; | - | ||||||||||||||||||||||||
| 591 | if (t2 >= 0 && t2 <= 1) { QPointF p(b.pointAt(t2)); if (p.x() < minx) minx = p.x(); else if (p.x() > maxx) maxx = p.x(); if (p.y() < miny) miny = p.y(); else if (p.y() > maxy) maxy = p.y(); }; | - | ||||||||||||||||||||||||
| 592 | } | - | ||||||||||||||||||||||||
| 593 | } | - | ||||||||||||||||||||||||
| 594 | } | - | ||||||||||||||||||||||||
| 595 | - | |||||||||||||||||||||||||
| 596 | - | |||||||||||||||||||||||||
| 597 | { | - | ||||||||||||||||||||||||
| 598 | qreal ay = 3 * (-b.y1 + 3*b.y2 - 3*b.y3 +b.y4); | - | ||||||||||||||||||||||||
| 599 | qreal by = 6 * (b.y1 - 2*b.y2 + b.y3); | - | ||||||||||||||||||||||||
| 600 | qreal cy = 3 * (- b.y1 + b.y2); | - | ||||||||||||||||||||||||
| 601 | - | |||||||||||||||||||||||||
| 602 | - | |||||||||||||||||||||||||
| 603 | if (qFuzzyIsNull(ay)) { | - | ||||||||||||||||||||||||
| 604 | - | |||||||||||||||||||||||||
| 605 | - | |||||||||||||||||||||||||
| 606 | if (!qFuzzyIsNull(by)) { | - | ||||||||||||||||||||||||
| 607 | qreal t = -cy / by; | - | ||||||||||||||||||||||||
| 608 | if (t >= 0 && t <= 1) { QPointF p(b.pointAt(t)); if (p.x() < minx) minx = p.x(); else if (p.x() > maxx) maxx = p.x(); if (p.y() < miny) miny = p.y(); else if (p.y() > maxy) maxy = p.y(); }; | - | ||||||||||||||||||||||||
| 609 | } | - | ||||||||||||||||||||||||
| 610 | - | |||||||||||||||||||||||||
| 611 | } else { | - | ||||||||||||||||||||||||
| 612 | const qreal ty = by * by - 4 * ay * cy; | - | ||||||||||||||||||||||||
| 613 | - | |||||||||||||||||||||||||
| 614 | if (ty > 0) { | - | ||||||||||||||||||||||||
| 615 | qreal temp = qSqrt(ty); | - | ||||||||||||||||||||||||
| 616 | qreal rcp = 1 / (2 * ay); | - | ||||||||||||||||||||||||
| 617 | qreal t1 = (-by + temp) * rcp; | - | ||||||||||||||||||||||||
| 618 | if (t1 >= 0 && t1 <= 1) { QPointF p(b.pointAt(t1)); if (p.x() < minx) minx = p.x(); else if (p.x() > maxx) maxx = p.x(); if (p.y() < miny) miny = p.y(); else if (p.y() > maxy) maxy = p.y(); }; | - | ||||||||||||||||||||||||
| 619 | - | |||||||||||||||||||||||||
| 620 | qreal t2 = (-by - temp) * rcp; | - | ||||||||||||||||||||||||
| 621 | if (t2 >= 0 && t2 <= 1) { QPointF p(b.pointAt(t2)); if (p.x() < minx) minx = p.x(); else if (p.x() > maxx) maxx = p.x(); if (p.y() < miny) miny = p.y(); else if (p.y() > maxy) maxy = p.y(); }; | - | ||||||||||||||||||||||||
| 622 | } | - | ||||||||||||||||||||||||
| 623 | } | - | ||||||||||||||||||||||||
| 624 | } | - | ||||||||||||||||||||||||
| 625 | return QRectF(minx, miny, maxx - minx, maxy - miny); | - | ||||||||||||||||||||||||
| 626 | } | - | ||||||||||||||||||||||||
| 627 | - | |||||||||||||||||||||||||
| 628 | - | |||||||||||||||||||||||||
| 629 | - | |||||||||||||||||||||||||
| 630 | - | |||||||||||||||||||||||||
| 631 | - | |||||||||||||||||||||||||
| 632 | - | |||||||||||||||||||||||||
| 633 | - | |||||||||||||||||||||||||
| 634 | QRectF QPainterPath::boundingRect() const | - | ||||||||||||||||||||||||
| 635 | { | - | ||||||||||||||||||||||||
| 636 | if (!d_ptr) | - | ||||||||||||||||||||||||
| 637 | return QRectF(); | - | ||||||||||||||||||||||||
| 638 | QPainterPathData *d = d_func(); | - | ||||||||||||||||||||||||
| 639 | - | |||||||||||||||||||||||||
| 640 | if (d->dirtyBounds) | - | ||||||||||||||||||||||||
| 641 | computeBoundingRect(); | - | ||||||||||||||||||||||||
| 642 | return d->bounds; | - | ||||||||||||||||||||||||
| 643 | } | - | ||||||||||||||||||||||||
| 644 | QRectF QPainterPath::controlPointRect() const | - | ||||||||||||||||||||||||
| 645 | { | - | ||||||||||||||||||||||||
| 646 | if (!d_ptr) | - | ||||||||||||||||||||||||
| 647 | return QRectF(); | - | ||||||||||||||||||||||||
| 648 | QPainterPathData *d = d_func(); | - | ||||||||||||||||||||||||
| 649 | - | |||||||||||||||||||||||||
| 650 | if (d->dirtyControlBounds) | - | ||||||||||||||||||||||||
| 651 | computeControlPointRect(); | - | ||||||||||||||||||||||||
| 652 | return d->controlBounds; | - | ||||||||||||||||||||||||
| 653 | } | - | ||||||||||||||||||||||||
| 654 | bool QPainterPath::isEmpty() const | - | ||||||||||||||||||||||||
| 655 | { | - | ||||||||||||||||||||||||
| 656 | return !d_ptr || (d_ptr->elements.size() == 1 && d_ptr->elements.first().type == MoveToElement); | - | ||||||||||||||||||||||||
| 657 | } | - | ||||||||||||||||||||||||
| 658 | QPainterPath QPainterPath::toReversed() const | - | ||||||||||||||||||||||||
| 659 | { | - | ||||||||||||||||||||||||
| 660 | const QPainterPathPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 661 | QPainterPath rev; | - | ||||||||||||||||||||||||
| 662 | - | |||||||||||||||||||||||||
| 663 | if (isEmpty()) { | - | ||||||||||||||||||||||||
| 664 | rev = *this; | - | ||||||||||||||||||||||||
| 665 | return rev; | - | ||||||||||||||||||||||||
| 666 | } | - | ||||||||||||||||||||||||
| 667 | - | |||||||||||||||||||||||||
| 668 | rev.moveTo(d->elements.at(d->elements.size()-1).x, d->elements.at(d->elements.size()-1).y); | - | ||||||||||||||||||||||||
| 669 | - | |||||||||||||||||||||||||
| 670 | for (int i=d->elements.size()-1; i>=1; --i) { | - | ||||||||||||||||||||||||
| 671 | const QPainterPath::Element &elm = d->elements.at(i); | - | ||||||||||||||||||||||||
| 672 | const QPainterPath::Element &prev = d->elements.at(i-1); | - | ||||||||||||||||||||||||
| 673 | switch (elm.type) { | - | ||||||||||||||||||||||||
| 674 | case LineToElement: | - | ||||||||||||||||||||||||
| 675 | rev.lineTo(prev.x, prev.y); | - | ||||||||||||||||||||||||
| 676 | break; | - | ||||||||||||||||||||||||
| 677 | case MoveToElement: | - | ||||||||||||||||||||||||
| 678 | rev.moveTo(prev.x, prev.y); | - | ||||||||||||||||||||||||
| 679 | break; | - | ||||||||||||||||||||||||
| 680 | case CurveToDataElement: | - | ||||||||||||||||||||||||
| 681 | { | - | ||||||||||||||||||||||||
| 682 | ((!(i>=3)) ? qt_assert("i>=3",__FILE__,15231529) : qt_noop()); | - | ||||||||||||||||||||||||
| 683 | const QPainterPath::Element &cp1 = d->elements.at(i-2); | - | ||||||||||||||||||||||||
| 684 | const QPainterPath::Element &sp = d->elements.at(i-3); | - | ||||||||||||||||||||||||
| 685 | ((!(prev.type == CurveToDataElement)) ? qt_assert("prev.type == CurveToDataElement",__FILE__,15261532) : qt_noop()); | - | ||||||||||||||||||||||||
| 686 | ((!(cp1.type == CurveToElement)) ? qt_assert("cp1.type == CurveToElement",__FILE__,15271533) : qt_noop()); | - | ||||||||||||||||||||||||
| 687 | rev.cubicTo(prev.x, prev.y, cp1.x, cp1.y, sp.x, sp.y); | - | ||||||||||||||||||||||||
| 688 | i -= 2; | - | ||||||||||||||||||||||||
| 689 | break; | - | ||||||||||||||||||||||||
| 690 | } | - | ||||||||||||||||||||||||
| 691 | default: | - | ||||||||||||||||||||||||
| 692 | ((!(!"qt_reversed_path")) ? qt_assert("!\"qt_reversed_path\"",__FILE__,15331539) : qt_noop()); | - | ||||||||||||||||||||||||
| 693 | break; | - | ||||||||||||||||||||||||
| 694 | } | - | ||||||||||||||||||||||||
| 695 | } | - | ||||||||||||||||||||||||
| 696 | - | |||||||||||||||||||||||||
| 697 | return rev; | - | ||||||||||||||||||||||||
| 698 | } | - | ||||||||||||||||||||||||
| 699 | QList<QPolygonF> QPainterPath::toSubpathPolygons(const QTransform &matrix) const | - | ||||||||||||||||||||||||
| 700 | { | - | ||||||||||||||||||||||||
| 701 | - | |||||||||||||||||||||||||
| 702 | const QPainterPathPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 703 | QList<QPolygonF> flatCurves; | - | ||||||||||||||||||||||||
| 704 | if (isEmpty()) | - | ||||||||||||||||||||||||
| 705 | return flatCurves; | - | ||||||||||||||||||||||||
| 706 | - | |||||||||||||||||||||||||
| 707 | QPolygonF current; | - | ||||||||||||||||||||||||
| 708 | for (int i=0; i<elementCount(); ++i) { | - | ||||||||||||||||||||||||
| 709 | const QPainterPath::Element &e = d->elements.at(i); | - | ||||||||||||||||||||||||
| 710 | switch (e.type) { | - | ||||||||||||||||||||||||
| 711 | case QPainterPath::MoveToElement: | - | ||||||||||||||||||||||||
| 712 | if (current.size() > 1) | - | ||||||||||||||||||||||||
| 713 | flatCurves += current; | - | ||||||||||||||||||||||||
| 714 | current.clear(); | - | ||||||||||||||||||||||||
| 715 | current.reserve(16); | - | ||||||||||||||||||||||||
| 716 | current += QPointF(e.x, e.y) * matrix; | - | ||||||||||||||||||||||||
| 717 | break; | - | ||||||||||||||||||||||||
| 718 | case QPainterPath::LineToElement: | - | ||||||||||||||||||||||||
| 719 | current += QPointF(e.x, e.y) * matrix; | - | ||||||||||||||||||||||||
| 720 | break; | - | ||||||||||||||||||||||||
| 721 | case QPainterPath::CurveToElement: { | - | ||||||||||||||||||||||||
| 722 | ((!(d->elements.at(i+1).type == QPainterPath::CurveToDataElement)) ? qt_assert("d->elements.at(i+1).type == QPainterPath::CurveToDataElement",__FILE__,15761582) : qt_noop()); | - | ||||||||||||||||||||||||
| 723 | ((!(d->elements.at(i+2).type == QPainterPath::CurveToDataElement)) ? qt_assert("d->elements.at(i+2).type == QPainterPath::CurveToDataElement",__FILE__,15771583) : qt_noop()); | - | ||||||||||||||||||||||||
| 724 | QBezier bezier = QBezier::fromPoints(QPointF(d->elements.at(i-1).x, d->elements.at(i-1).y) * matrix, | - | ||||||||||||||||||||||||
| 725 | QPointF(e.x, e.y) * matrix, | - | ||||||||||||||||||||||||
| 726 | QPointF(d->elements.at(i+1).x, d->elements.at(i+1).y) * matrix, | - | ||||||||||||||||||||||||
| 727 | QPointF(d->elements.at(i+2).x, d->elements.at(i+2).y) * matrix); | - | ||||||||||||||||||||||||
| 728 | bezier.addToPolygon(¤t); | - | ||||||||||||||||||||||||
| 729 | i+=2; | - | ||||||||||||||||||||||||
| 730 | break; | - | ||||||||||||||||||||||||
| 731 | } | - | ||||||||||||||||||||||||
| 732 | case QPainterPath::CurveToDataElement: | - | ||||||||||||||||||||||||
| 733 | ((!(!"QPainterPath::toSubpathPolygons(), bad element type")) ? qt_assert("!\"QPainterPath::toSubpathPolygons(), bad element type\"",__FILE__,15871593) : qt_noop()); | - | ||||||||||||||||||||||||
| 734 | break; | - | ||||||||||||||||||||||||
| 735 | } | - | ||||||||||||||||||||||||
| 736 | } | - | ||||||||||||||||||||||||
| 737 | - | |||||||||||||||||||||||||
| 738 | if (current.size()>1) | - | ||||||||||||||||||||||||
| 739 | flatCurves += current; | - | ||||||||||||||||||||||||
| 740 | - | |||||||||||||||||||||||||
| 741 | return flatCurves; | - | ||||||||||||||||||||||||
| 742 | } | - | ||||||||||||||||||||||||
| 743 | - | |||||||||||||||||||||||||
| 744 | - | |||||||||||||||||||||||||
| 745 | - | |||||||||||||||||||||||||
| 746 | - | |||||||||||||||||||||||||
| 747 | QList<QPolygonF> QPainterPath::toSubpathPolygons(const QMatrix &matrix) const | - | ||||||||||||||||||||||||
| 748 | { | - | ||||||||||||||||||||||||
| 749 | return toSubpathPolygons(QTransform(matrix)); | - | ||||||||||||||||||||||||
| 750 | } | - | ||||||||||||||||||||||||
| 751 | QList<QPolygonF> QPainterPath::toFillPolygons(const QTransform &matrix) const | - | ||||||||||||||||||||||||
| 752 | { | - | ||||||||||||||||||||||||
| 753 | - | |||||||||||||||||||||||||
| 754 | QList<QPolygonF> polys; | - | ||||||||||||||||||||||||
| 755 | - | |||||||||||||||||||||||||
| 756 | QList<QPolygonF> subpaths = toSubpathPolygons(matrix); | - | ||||||||||||||||||||||||
| 757 | int count = subpaths.size(); | - | ||||||||||||||||||||||||
| 758 | - | |||||||||||||||||||||||||
| 759 | if (count == 0
| 0 | ||||||||||||||||||||||||
| 760 | return never executed: polys;return polys;never executed: return polys; | 0 | ||||||||||||||||||||||||
| 761 | - | |||||||||||||||||||||||||
| 762 | QVector<QRectF> bounds; | - | ||||||||||||||||||||||||
| 763 | bounds.reserve(count); | - | ||||||||||||||||||||||||
| 764 | for (int i=0; i<count
| 0 | ||||||||||||||||||||||||
| 765 | bounds += subpaths.at(i).boundingRect(); never executed: bounds += subpaths.at(i).boundingRect(); | 0 | ||||||||||||||||||||||||
| 766 | - | |||||||||||||||||||||||||
| 767 | - | |||||||||||||||||||||||||
| 768 | - | |||||||||||||||||||||||||
| 769 | - | |||||||||||||||||||||||||
| 770 | - | |||||||||||||||||||||||||
| 771 | - | |||||||||||||||||||||||||
| 772 | - | |||||||||||||||||||||||||
| 773 | QVector< QListQVector<int> > isects; | - | ||||||||||||||||||||||||
| 774 | isects.resize(count); | - | ||||||||||||||||||||||||
| 775 | - | |||||||||||||||||||||||||
| 776 | - | |||||||||||||||||||||||||
| 777 | for (int j=0; j<count
| 0 | ||||||||||||||||||||||||
| 778 | if (subpaths.at(j).size() <= 2
| 0 | ||||||||||||||||||||||||
| 779 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 780 | QRectF cbounds = bounds.at(j); | - | ||||||||||||||||||||||||
| 781 | for (int i=0; i<count
| 0 | ||||||||||||||||||||||||
| 782 | if (cbounds.intersects(bounds.at(i))
| 0 | ||||||||||||||||||||||||
| 783 | isects[j] << i; | - | ||||||||||||||||||||||||
| 784 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 785 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 786 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 787 | for (int i=0; i<count
| 0 | ||||||||||||||||||||||||
| 788 | const QListQVector<int> ¤t_isects = isects.at(i); | - | ||||||||||||||||||||||||
| 789 | for (int j=0; j<current_isects.size()
| 0 | ||||||||||||||||||||||||
| 790 | int isect_j = current_isects.at(j); | - | ||||||||||||||||||||||||
| 791 | if (isect_j == i
| 0 | ||||||||||||||||||||||||
| 792 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 793 | const QVector<int> &isects_j = isects.at(isect_j); | - | ||||||||||||||||||||||||
| 794 | for (int k = 0;, size = isects_j.size(); k < isects[isect_j].size();
| 0 | ||||||||||||||||||||||||
| 795 | int isect_k = isects[isect_j][isects_j.at(k];); | - | ||||||||||||||||||||||||
| 796 | if (isect_k != i
| 0 | ||||||||||||||||||||||||
| 797 | isects[i] += isect_k; | - | ||||||||||||||||||||||||
| 798 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 799 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 800 | isects[isect_j].clear(); | - | ||||||||||||||||||||||||
| 801 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 802 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 803 | for (int i=0; i<count
| 0 | ||||||||||||||||||||||||
| 804 | const QListQVector<int> &subpath_list = isects[.at(i];); | - | ||||||||||||||||||||||||
| 805 | if (!subpath_list.isEmpty()
| 0 | ||||||||||||||||||||||||
| 806 | QPolygonF buildUp; | - | ||||||||||||||||||||||||
| 807 | for (int j=0; j<subpath_list.size()
| 0 | ||||||||||||||||||||||||
| 808 | const QPolygonF &subpath = subpaths.at(subpath_list.at(j)); | - | ||||||||||||||||||||||||
| 809 | buildUp += subpath; | - | ||||||||||||||||||||||||
| 810 | if (!subpath.isClosed()
| 0 | ||||||||||||||||||||||||
| 811 | buildUp += subpath.first(); never executed: buildUp += subpath.first(); | 0 | ||||||||||||||||||||||||
| 812 | if (!buildUp.isClosed()
| 0 | ||||||||||||||||||||||||
| 813 | buildUp += buildUp.firstconstFirst(); never executed: buildUp += buildUp.constFirst(); | 0 | ||||||||||||||||||||||||
| 814 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 815 | polys += buildUp; | - | ||||||||||||||||||||||||
| 816 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 817 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 818 | - | |||||||||||||||||||||||||
| 819 | return never executed: polys;return polys;never executed: return polys; | 0 | ||||||||||||||||||||||||
| 820 | } | - | ||||||||||||||||||||||||
| 821 | - | |||||||||||||||||||||||||
| 822 | - | |||||||||||||||||||||||||
| 823 | - | |||||||||||||||||||||||||
| 824 | - | |||||||||||||||||||||||||
| 825 | QList<QPolygonF> QPainterPath::toFillPolygons(const QMatrix &matrix) const | - | ||||||||||||||||||||||||
| 826 | { | - | ||||||||||||||||||||||||
| 827 | return toFillPolygons(QTransform(matrix)); | - | ||||||||||||||||||||||||
| 828 | } | - | ||||||||||||||||||||||||
| 829 | - | |||||||||||||||||||||||||
| 830 | - | |||||||||||||||||||||||||
| 831 | static void qt_painterpath_isect_line(const QPointF &p1, | - | ||||||||||||||||||||||||
| 832 | const QPointF &p2, | - | ||||||||||||||||||||||||
| 833 | const QPointF &pos, | - | ||||||||||||||||||||||||
| 834 | int *winding) | - | ||||||||||||||||||||||||
| 835 | { | - | ||||||||||||||||||||||||
| 836 | qreal x1 = p1.x(); | - | ||||||||||||||||||||||||
| 837 | qreal y1 = p1.y(); | - | ||||||||||||||||||||||||
| 838 | qreal x2 = p2.x(); | - | ||||||||||||||||||||||||
| 839 | qreal y2 = p2.y(); | - | ||||||||||||||||||||||||
| 840 | qreal y = pos.y(); | - | ||||||||||||||||||||||||
| 841 | - | |||||||||||||||||||||||||
| 842 | int dir = 1; | - | ||||||||||||||||||||||||
| 843 | - | |||||||||||||||||||||||||
| 844 | if (qFuzzyCompare(y1, y2)) { | - | ||||||||||||||||||||||||
| 845 | - | |||||||||||||||||||||||||
| 846 | return; | - | ||||||||||||||||||||||||
| 847 | } else if (y2 < y1) { | - | ||||||||||||||||||||||||
| 848 | qreal x_tmp = x2; x2 = x1; x1 = x_tmp; | - | ||||||||||||||||||||||||
| 849 | qreal y_tmp = y2; y2 = y1; y1 = y_tmp; | - | ||||||||||||||||||||||||
| 850 | dir = -1; | - | ||||||||||||||||||||||||
| 851 | } | - | ||||||||||||||||||||||||
| 852 | - | |||||||||||||||||||||||||
| 853 | if (y >= y1 && y < y2) { | - | ||||||||||||||||||||||||
| 854 | qreal x = x1 + ((x2 - x1) / (y2 - y1)) * (y - y1); | - | ||||||||||||||||||||||||
| 855 | - | |||||||||||||||||||||||||
| 856 | - | |||||||||||||||||||||||||
| 857 | if (x<=pos.x()) { | - | ||||||||||||||||||||||||
| 858 | (*winding) += dir; | - | ||||||||||||||||||||||||
| 859 | } | - | ||||||||||||||||||||||||
| 860 | } | - | ||||||||||||||||||||||||
| 861 | } | - | ||||||||||||||||||||||||
| 862 | - | |||||||||||||||||||||||||
| 863 | static void qt_painterpath_isect_curve(const QBezier &bezier, const QPointF &pt, | - | ||||||||||||||||||||||||
| 864 | int *winding, int depth = 0) | - | ||||||||||||||||||||||||
| 865 | { | - | ||||||||||||||||||||||||
| 866 | qreal y = pt.y(); | - | ||||||||||||||||||||||||
| 867 | qreal x = pt.x(); | - | ||||||||||||||||||||||||
| 868 | QRectF bounds = bezier.bounds(); | - | ||||||||||||||||||||||||
| 869 | - | |||||||||||||||||||||||||
| 870 | - | |||||||||||||||||||||||||
| 871 | - | |||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||
| 873 | - | |||||||||||||||||||||||||
| 874 | if (y >= bounds.y() && y < bounds.y() + bounds.height()) { | - | ||||||||||||||||||||||||
| 875 | - | |||||||||||||||||||||||||
| 876 | - | |||||||||||||||||||||||||
| 877 | - | |||||||||||||||||||||||||
| 878 | const qreal lower_bound = qreal(.001); | - | ||||||||||||||||||||||||
| 879 | if (depth == 32 || (bounds.width() < lower_bound && bounds.height() < lower_bound)) { | - | ||||||||||||||||||||||||
| 880 | - | |||||||||||||||||||||||||
| 881 | - | |||||||||||||||||||||||||
| 882 | - | |||||||||||||||||||||||||
| 883 | if (bezier.pt1().x() <= x) { | - | ||||||||||||||||||||||||
| 884 | (*winding) += (bezier.pt4().y() > bezier.pt1().y() ? 1 : -1); | - | ||||||||||||||||||||||||
| 885 | } | - | ||||||||||||||||||||||||
| 886 | return; | - | ||||||||||||||||||||||||
| 887 | } | - | ||||||||||||||||||||||||
| 888 | - | |||||||||||||||||||||||||
| 889 | - | |||||||||||||||||||||||||
| 890 | QBezier first_half, second_half; | - | ||||||||||||||||||||||||
| 891 | bezier.split(&first_half, &second_half); | - | ||||||||||||||||||||||||
| 892 | qt_painterpath_isect_curve(first_half, pt, winding, depth + 1); | - | ||||||||||||||||||||||||
| 893 | qt_painterpath_isect_curve(second_half, pt, winding, depth + 1); | - | ||||||||||||||||||||||||
| 894 | } | - | ||||||||||||||||||||||||
| 895 | } | - | ||||||||||||||||||||||||
| 896 | bool QPainterPath::contains(const QPointF &pt) const | - | ||||||||||||||||||||||||
| 897 | { | - | ||||||||||||||||||||||||
| 898 | if (isEmpty() || !controlPointRect().contains(pt)) | - | ||||||||||||||||||||||||
| 899 | return false; | - | ||||||||||||||||||||||||
| 900 | - | |||||||||||||||||||||||||
| 901 | QPainterPathData *d = d_func(); | - | ||||||||||||||||||||||||
| 902 | - | |||||||||||||||||||||||||
| 903 | int winding_number = 0; | - | ||||||||||||||||||||||||
| 904 | - | |||||||||||||||||||||||||
| 905 | QPointF last_pt; | - | ||||||||||||||||||||||||
| 906 | QPointF last_start; | - | ||||||||||||||||||||||||
| 907 | for (int i=0; i<d->elements.size(); ++i) { | - | ||||||||||||||||||||||||
| 908 | const Element &e = d->elements.at(i); | - | ||||||||||||||||||||||||
| 909 | - | |||||||||||||||||||||||||
| 910 | switch (e.type) { | - | ||||||||||||||||||||||||
| 911 | - | |||||||||||||||||||||||||
| 912 | case MoveToElement: | - | ||||||||||||||||||||||||
| 913 | if (i > 0) | - | ||||||||||||||||||||||||
| 914 | qt_painterpath_isect_line(last_pt, last_start, pt, &winding_number); | - | ||||||||||||||||||||||||
| 915 | last_start = last_pt = e; | - | ||||||||||||||||||||||||
| 916 | break; | - | ||||||||||||||||||||||||
| 917 | - | |||||||||||||||||||||||||
| 918 | case LineToElement: | - | ||||||||||||||||||||||||
| 919 | qt_painterpath_isect_line(last_pt, e, pt, &winding_number); | - | ||||||||||||||||||||||||
| 920 | last_pt = e; | - | ||||||||||||||||||||||||
| 921 | break; | - | ||||||||||||||||||||||||
| 922 | - | |||||||||||||||||||||||||
| 923 | case CurveToElement: | - | ||||||||||||||||||||||||
| 924 | { | - | ||||||||||||||||||||||||
| 925 | const QPainterPath::Element &cp2 = d->elements.at(++i); | - | ||||||||||||||||||||||||
| 926 | const QPainterPath::Element &ep = d->elements.at(++i); | - | ||||||||||||||||||||||||
| 927 | qt_painterpath_isect_curve(QBezier::fromPoints(last_pt, e, cp2, ep), | - | ||||||||||||||||||||||||
| 928 | pt, &winding_number); | - | ||||||||||||||||||||||||
| 929 | last_pt = ep; | - | ||||||||||||||||||||||||
| 930 | - | |||||||||||||||||||||||||
| 931 | } | - | ||||||||||||||||||||||||
| 932 | break; | - | ||||||||||||||||||||||||
| 933 | - | |||||||||||||||||||||||||
| 934 | default: | - | ||||||||||||||||||||||||
| 935 | break; | - | ||||||||||||||||||||||||
| 936 | } | - | ||||||||||||||||||||||||
| 937 | } | - | ||||||||||||||||||||||||
| 938 | - | |||||||||||||||||||||||||
| 939 | - | |||||||||||||||||||||||||
| 940 | if (last_pt != last_start) | - | ||||||||||||||||||||||||
| 941 | qt_painterpath_isect_line(last_pt, last_start, pt, &winding_number); | - | ||||||||||||||||||||||||
| 942 | - | |||||||||||||||||||||||||
| 943 | return (d->fillRule == Qt::WindingFill | - | ||||||||||||||||||||||||
| 944 | ? (winding_number != 0) | - | ||||||||||||||||||||||||
| 945 | : ((winding_number % 2) != 0)); | - | ||||||||||||||||||||||||
| 946 | } | - | ||||||||||||||||||||||||
| 947 | - | |||||||||||||||||||||||||
| 948 | enum PainterDirections { Left, Right, Top, Bottom }; | - | ||||||||||||||||||||||||
| 949 | - | |||||||||||||||||||||||||
| 950 | static bool qt_painterpath_isect_line_rect(qreal x1, qreal y1, qreal x2, qreal y2, | - | ||||||||||||||||||||||||
| 951 | const QRectF &rect) | - | ||||||||||||||||||||||||
| 952 | { | - | ||||||||||||||||||||||||
| 953 | qreal left = rect.left(); | - | ||||||||||||||||||||||||
| 954 | qreal right = rect.right(); | - | ||||||||||||||||||||||||
| 955 | qreal top = rect.top(); | - | ||||||||||||||||||||||||
| 956 | qreal bottom = rect.bottom(); | - | ||||||||||||||||||||||||
| 957 | - | |||||||||||||||||||||||||
| 958 | - | |||||||||||||||||||||||||
| 959 | enum { Left, Right, Top, Bottom };int p1 = ((x1 < left) << Left) | - | ||||||||||||||||||||||||
| 960 | | ((x1 > right) << Right) | - | ||||||||||||||||||||||||
| 961 | | ((y1 < top) << Top) | - | ||||||||||||||||||||||||
| 962 | | ((y1 > bottom) << Bottom); | - | ||||||||||||||||||||||||
| 963 | int p2 = ((x2 < left) << Left) | - | ||||||||||||||||||||||||
| 964 | | ((x2 > right) << Right) | - | ||||||||||||||||||||||||
| 965 | | ((y2 < top) << Top) | - | ||||||||||||||||||||||||
| 966 | | ((y2 > bottom) << Bottom); | - | ||||||||||||||||||||||||
| 967 | - | |||||||||||||||||||||||||
| 968 | if (p1 & p2
| 0 | ||||||||||||||||||||||||
| 969 | - | |||||||||||||||||||||||||
| 970 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 971 | - | |||||||||||||||||||||||||
| 972 | if (p1 | p2
| 0 | ||||||||||||||||||||||||
| 973 | qreal dx = x2 - x1; | - | ||||||||||||||||||||||||
| 974 | qreal dy = y2 - y1; | - | ||||||||||||||||||||||||
| 975 | - | |||||||||||||||||||||||||
| 976 | - | |||||||||||||||||||||||||
| 977 | if (x1 < left
| 0 | ||||||||||||||||||||||||
| 978 | y1 += dy/dx * (left - x1); | - | ||||||||||||||||||||||||
| 979 | x1 = left; | - | ||||||||||||||||||||||||
| 980 | } never executed: else if (x1 > rightend of block
| 0 | ||||||||||||||||||||||||
| 981 | y1 -= dy/dx * (x1 - right); | - | ||||||||||||||||||||||||
| 982 | x1 = right; | - | ||||||||||||||||||||||||
| 983 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 984 | if (x2 < left
| 0 | ||||||||||||||||||||||||
| 985 | y2 += dy/dx * (left - x2); | - | ||||||||||||||||||||||||
| 986 | x2 = left; | - | ||||||||||||||||||||||||
| 987 | } never executed: else if (x2 > rightend of block
| 0 | ||||||||||||||||||||||||
| 988 | y2 -= dy/dx * (x2 - right); | - | ||||||||||||||||||||||||
| 989 | x2 = right; | - | ||||||||||||||||||||||||
| 990 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 991 | - | |||||||||||||||||||||||||
| 992 | p1 = ((y1 < top) << Top) | - | ||||||||||||||||||||||||
| 993 | | ((y1 > bottom) << Bottom); | - | ||||||||||||||||||||||||
| 994 | p2 = ((y2 < top) << Top) | - | ||||||||||||||||||||||||
| 995 | | ((y2 > bottom) << Bottom); | - | ||||||||||||||||||||||||
| 996 | - | |||||||||||||||||||||||||
| 997 | if (p1 & p2
| 0 | ||||||||||||||||||||||||
| 998 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 999 | - | |||||||||||||||||||||||||
| 1000 | - | |||||||||||||||||||||||||
| 1001 | if (y1 < top
| 0 | ||||||||||||||||||||||||
| 1002 | x1 += dx/dy * (top - y1); | - | ||||||||||||||||||||||||
| 1003 | y1 = top; | - | ||||||||||||||||||||||||
| 1004 | } never executed: else if (y1 > bottomend of block
| 0 | ||||||||||||||||||||||||
| 1005 | x1 -= dx/dy * (y1 - bottom); | - | ||||||||||||||||||||||||
| 1006 | y1 = bottom; | - | ||||||||||||||||||||||||
| 1007 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1008 | if (y2 < top
| 0 | ||||||||||||||||||||||||
| 1009 | x2 += dx/dy * (top - y2); | - | ||||||||||||||||||||||||
| 1010 | y2 = top; | - | ||||||||||||||||||||||||
| 1011 | } never executed: else if (y2 > bottomend of block
| 0 | ||||||||||||||||||||||||
| 1012 | x2 -= dx/dy * (y2 - bottom); | - | ||||||||||||||||||||||||
| 1013 | y2 = bottom; | - | ||||||||||||||||||||||||
| 1014 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1015 | - | |||||||||||||||||||||||||
| 1016 | p1 = ((x1 < left) << Left) | - | ||||||||||||||||||||||||
| 1017 | | ((x1 > right) << Right); | - | ||||||||||||||||||||||||
| 1018 | p2 = ((x2 < left) << Left) | - | ||||||||||||||||||||||||
| 1019 | | ((x2 > right) << Right); | - | ||||||||||||||||||||||||
| 1020 | - | |||||||||||||||||||||||||
| 1021 | if (p1 & p2
| 0 | ||||||||||||||||||||||||
| 1022 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 1023 | - | |||||||||||||||||||||||||
| 1024 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 1025 | } | - | ||||||||||||||||||||||||
| 1026 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 1027 | } | - | ||||||||||||||||||||||||
| 1028 | - | |||||||||||||||||||||||||
| 1029 | static bool qt_isect_curve_horizontal(const QBezier &bezier, qreal y, qreal x1, qreal x2, int depth = 0) | - | ||||||||||||||||||||||||
| 1030 | { | - | ||||||||||||||||||||||||
| 1031 | QRectF bounds = bezier.bounds(); | - | ||||||||||||||||||||||||
| 1032 | - | |||||||||||||||||||||||||
| 1033 | if (y >= bounds.top() && y < bounds.bottom() | - | ||||||||||||||||||||||||
| 1034 | && bounds.right() >= x1 && bounds.left() < x2) { | - | ||||||||||||||||||||||||
| 1035 | const qreal lower_bound = qreal(.01); | - | ||||||||||||||||||||||||
| 1036 | if (depth == 32 || (bounds.width() < lower_bound && bounds.height() < lower_bound)) | - | ||||||||||||||||||||||||
| 1037 | return true; | - | ||||||||||||||||||||||||
| 1038 | - | |||||||||||||||||||||||||
| 1039 | QBezier first_half, second_half; | - | ||||||||||||||||||||||||
| 1040 | bezier.split(&first_half, &second_half); | - | ||||||||||||||||||||||||
| 1041 | if (qt_isect_curve_horizontal(first_half, y, x1, x2, depth + 1) | - | ||||||||||||||||||||||||
| 1042 | || qt_isect_curve_horizontal(second_half, y, x1, x2, depth + 1)) | - | ||||||||||||||||||||||||
| 1043 | return true; | - | ||||||||||||||||||||||||
| 1044 | } | - | ||||||||||||||||||||||||
| 1045 | return false; | - | ||||||||||||||||||||||||
| 1046 | } | - | ||||||||||||||||||||||||
| 1047 | - | |||||||||||||||||||||||||
| 1048 | static bool qt_isect_curve_vertical(const QBezier &bezier, qreal x, qreal y1, qreal y2, int depth = 0) | - | ||||||||||||||||||||||||
| 1049 | { | - | ||||||||||||||||||||||||
| 1050 | QRectF bounds = bezier.bounds(); | - | ||||||||||||||||||||||||
| 1051 | - | |||||||||||||||||||||||||
| 1052 | if (x >= bounds.left() && x < bounds.right() | - | ||||||||||||||||||||||||
| 1053 | && bounds.bottom() >= y1 && bounds.top() < y2) { | - | ||||||||||||||||||||||||
| 1054 | const qreal lower_bound = qreal(.01); | - | ||||||||||||||||||||||||
| 1055 | if (depth == 32 || (bounds.width() < lower_bound && bounds.height() < lower_bound)) | - | ||||||||||||||||||||||||
| 1056 | return true; | - | ||||||||||||||||||||||||
| 1057 | - | |||||||||||||||||||||||||
| 1058 | QBezier first_half, second_half; | - | ||||||||||||||||||||||||
| 1059 | bezier.split(&first_half, &second_half); | - | ||||||||||||||||||||||||
| 1060 | if (qt_isect_curve_vertical(first_half, x, y1, y2, depth + 1) | - | ||||||||||||||||||||||||
| 1061 | || qt_isect_curve_vertical(second_half, x, y1, y2, depth + 1)) | - | ||||||||||||||||||||||||
| 1062 | return true; | - | ||||||||||||||||||||||||
| 1063 | } | - | ||||||||||||||||||||||||
| 1064 | return false; | - | ||||||||||||||||||||||||
| 1065 | } | - | ||||||||||||||||||||||||
| 1066 | - | |||||||||||||||||||||||||
| 1067 | - | |||||||||||||||||||||||||
| 1068 | - | |||||||||||||||||||||||||
| 1069 | - | |||||||||||||||||||||||||
| 1070 | static bool qt_painterpath_check_crossing(const QPainterPath *path, const QRectF &rect) | - | ||||||||||||||||||||||||
| 1071 | { | - | ||||||||||||||||||||||||
| 1072 | QPointF last_pt; | - | ||||||||||||||||||||||||
| 1073 | QPointF last_start; | - | ||||||||||||||||||||||||
| 1074 | for (int i=0; i<path->elementCount(); ++i) { | - | ||||||||||||||||||||||||
| 1075 | const QPainterPath::Element &e = path->elementAt(i); | - | ||||||||||||||||||||||||
| 1076 | - | |||||||||||||||||||||||||
| 1077 | switch (e.type) { | - | ||||||||||||||||||||||||
| 1078 | - | |||||||||||||||||||||||||
| 1079 | case QPainterPath::MoveToElement: | - | ||||||||||||||||||||||||
| 1080 | if (i > 0 | - | ||||||||||||||||||||||||
| 1081 | && qFuzzyCompare(last_pt.x(), last_start.x()) | - | ||||||||||||||||||||||||
| 1082 | && qFuzzyCompare(last_pt.y(), last_start.y()) | - | ||||||||||||||||||||||||
| 1083 | && qt_painterpath_isect_line_rect(last_pt.x(), last_pt.y(), | - | ||||||||||||||||||||||||
| 1084 | last_start.x(), last_start.y(), rect)) | - | ||||||||||||||||||||||||
| 1085 | return true; | - | ||||||||||||||||||||||||
| 1086 | last_start = last_pt = e; | - | ||||||||||||||||||||||||
| 1087 | break; | - | ||||||||||||||||||||||||
| 1088 | - | |||||||||||||||||||||||||
| 1089 | case QPainterPath::LineToElement: | - | ||||||||||||||||||||||||
| 1090 | if (qt_painterpath_isect_line_rect(last_pt.x(), last_pt.y(), e.x, e.y, rect)) | - | ||||||||||||||||||||||||
| 1091 | return true; | - | ||||||||||||||||||||||||
| 1092 | last_pt = e; | - | ||||||||||||||||||||||||
| 1093 | break; | - | ||||||||||||||||||||||||
| 1094 | - | |||||||||||||||||||||||||
| 1095 | case QPainterPath::CurveToElement: | - | ||||||||||||||||||||||||
| 1096 | { | - | ||||||||||||||||||||||||
| 1097 | QPointF cp2 = path->elementAt(++i); | - | ||||||||||||||||||||||||
| 1098 | QPointF ep = path->elementAt(++i); | - | ||||||||||||||||||||||||
| 1099 | QBezier bezier = QBezier::fromPoints(last_pt, e, cp2, ep); | - | ||||||||||||||||||||||||
| 1100 | if (qt_isect_curve_horizontal(bezier, rect.top(), rect.left(), rect.right()) | - | ||||||||||||||||||||||||
| 1101 | || qt_isect_curve_horizontal(bezier, rect.bottom(), rect.left(), rect.right()) | - | ||||||||||||||||||||||||
| 1102 | || qt_isect_curve_vertical(bezier, rect.left(), rect.top(), rect.bottom()) | - | ||||||||||||||||||||||||
| 1103 | || qt_isect_curve_vertical(bezier, rect.right(), rect.top(), rect.bottom())) | - | ||||||||||||||||||||||||
| 1104 | return true; | - | ||||||||||||||||||||||||
| 1105 | last_pt = ep; | - | ||||||||||||||||||||||||
| 1106 | } | - | ||||||||||||||||||||||||
| 1107 | break; | - | ||||||||||||||||||||||||
| 1108 | - | |||||||||||||||||||||||||
| 1109 | default: | - | ||||||||||||||||||||||||
| 1110 | break; | - | ||||||||||||||||||||||||
| 1111 | } | - | ||||||||||||||||||||||||
| 1112 | } | - | ||||||||||||||||||||||||
| 1113 | - | |||||||||||||||||||||||||
| 1114 | - | |||||||||||||||||||||||||
| 1115 | if (last_pt != last_start | - | ||||||||||||||||||||||||
| 1116 | && qt_painterpath_isect_line_rect(last_pt.x(), last_pt.y(), | - | ||||||||||||||||||||||||
| 1117 | last_start.x(), last_start.y(), rect)) | - | ||||||||||||||||||||||||
| 1118 | return true; | - | ||||||||||||||||||||||||
| 1119 | - | |||||||||||||||||||||||||
| 1120 | return false; | - | ||||||||||||||||||||||||
| 1121 | } | - | ||||||||||||||||||||||||
| 1122 | bool QPainterPath::intersects(const QRectF &rect) const | - | ||||||||||||||||||||||||
| 1123 | { | - | ||||||||||||||||||||||||
| 1124 | if (elementCount() == 1 && rect.contains(elementAt(0))) | - | ||||||||||||||||||||||||
| 1125 | return true; | - | ||||||||||||||||||||||||
| 1126 | - | |||||||||||||||||||||||||
| 1127 | if (isEmpty()) | - | ||||||||||||||||||||||||
| 1128 | return false; | - | ||||||||||||||||||||||||
| 1129 | - | |||||||||||||||||||||||||
| 1130 | QRectF cp = controlPointRect(); | - | ||||||||||||||||||||||||
| 1131 | QRectF rn = rect.normalized(); | - | ||||||||||||||||||||||||
| 1132 | - | |||||||||||||||||||||||||
| 1133 | - | |||||||||||||||||||||||||
| 1134 | - | |||||||||||||||||||||||||
| 1135 | - | |||||||||||||||||||||||||
| 1136 | if (qMax(rn.left(), cp.left()) > qMin(rn.right(), cp.right()) | - | ||||||||||||||||||||||||
| 1137 | || qMax(rn.top(), cp.top()) > qMin(rn.bottom(), cp.bottom())) | - | ||||||||||||||||||||||||
| 1138 | return false; | - | ||||||||||||||||||||||||
| 1139 | - | |||||||||||||||||||||||||
| 1140 | - | |||||||||||||||||||||||||
| 1141 | if (qt_painterpath_check_crossing(this, rect)) | - | ||||||||||||||||||||||||
| 1142 | return true; | - | ||||||||||||||||||||||||
| 1143 | - | |||||||||||||||||||||||||
| 1144 | if (contains(rect.center())) | - | ||||||||||||||||||||||||
| 1145 | return true; | - | ||||||||||||||||||||||||
| 1146 | - | |||||||||||||||||||||||||
| 1147 | QPainterPathPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1148 | - | |||||||||||||||||||||||||
| 1149 | - | |||||||||||||||||||||||||
| 1150 | for (int i=0; i<d->elements.size(); ++i) { | - | ||||||||||||||||||||||||
| 1151 | const Element &e = d->elements.at(i); | - | ||||||||||||||||||||||||
| 1152 | if (e.type == QPainterPath::MoveToElement && rect.contains(e)) | - | ||||||||||||||||||||||||
| 1153 | return true; | - | ||||||||||||||||||||||||
| 1154 | } | - | ||||||||||||||||||||||||
| 1155 | - | |||||||||||||||||||||||||
| 1156 | return false; | - | ||||||||||||||||||||||||
| 1157 | } | - | ||||||||||||||||||||||||
| 1158 | - | |||||||||||||||||||||||||
| 1159 | - | |||||||||||||||||||||||||
| 1160 | - | |||||||||||||||||||||||||
| 1161 | - | |||||||||||||||||||||||||
| 1162 | - | |||||||||||||||||||||||||
| 1163 | - | |||||||||||||||||||||||||
| 1164 | - | |||||||||||||||||||||||||
| 1165 | void QPainterPath::translate(qreal dx, qreal dy) | - | ||||||||||||||||||||||||
| 1166 | { | - | ||||||||||||||||||||||||
| 1167 | if (!d_ptr || (dx == 0 && dy == 0)) | - | ||||||||||||||||||||||||
| 1168 | return; | - | ||||||||||||||||||||||||
| 1169 | - | |||||||||||||||||||||||||
| 1170 | int elementsLeft = d_ptr->elements.size(); | - | ||||||||||||||||||||||||
| 1171 | if (elementsLeft <= 0) | - | ||||||||||||||||||||||||
| 1172 | return; | - | ||||||||||||||||||||||||
| 1173 | - | |||||||||||||||||||||||||
| 1174 | detach(); | - | ||||||||||||||||||||||||
| 1175 | QPainterPath::Element *element = d_func()->elements.data(); | - | ||||||||||||||||||||||||
| 1176 | ((!(element)) ? qt_assert("element",__FILE__,21012109) : qt_noop()); | - | ||||||||||||||||||||||||
| 1177 | while (elementsLeft--) { | - | ||||||||||||||||||||||||
| 1178 | element->x += dx; | - | ||||||||||||||||||||||||
| 1179 | element->y += dy; | - | ||||||||||||||||||||||||
| 1180 | ++element; | - | ||||||||||||||||||||||||
| 1181 | } | - | ||||||||||||||||||||||||
| 1182 | } | - | ||||||||||||||||||||||||
| 1183 | QPainterPath QPainterPath::translated(qreal dx, qreal dy) const | - | ||||||||||||||||||||||||
| 1184 | { | - | ||||||||||||||||||||||||
| 1185 | QPainterPath copy(*this); | - | ||||||||||||||||||||||||
| 1186 | copy.translate(dx, dy); | - | ||||||||||||||||||||||||
| 1187 | return copy; | - | ||||||||||||||||||||||||
| 1188 | } | - | ||||||||||||||||||||||||
| 1189 | bool QPainterPath::contains(const QRectF &rect) const | - | ||||||||||||||||||||||||
| 1190 | { | - | ||||||||||||||||||||||||
| 1191 | QPainterPathPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1192 | - | |||||||||||||||||||||||||
| 1193 | - | |||||||||||||||||||||||||
| 1194 | - | |||||||||||||||||||||||||
| 1195 | if (isEmpty() || !controlPointRect().contains(rect)) | - | ||||||||||||||||||||||||
| 1196 | return false; | - | ||||||||||||||||||||||||
| 1197 | - | |||||||||||||||||||||||||
| 1198 | - | |||||||||||||||||||||||||
| 1199 | - | |||||||||||||||||||||||||
| 1200 | - | |||||||||||||||||||||||||
| 1201 | if (qt_painterpath_check_crossing(this, rect)) { | - | ||||||||||||||||||||||||
| 1202 | if (fillRule() == Qt::OddEvenFill) { | - | ||||||||||||||||||||||||
| 1203 | return false; | - | ||||||||||||||||||||||||
| 1204 | } else { | - | ||||||||||||||||||||||||
| 1205 | - | |||||||||||||||||||||||||
| 1206 | - | |||||||||||||||||||||||||
| 1207 | if (!contains(rect.topLeft()) || | - | ||||||||||||||||||||||||
| 1208 | !contains(rect.topRight()) || | - | ||||||||||||||||||||||||
| 1209 | !contains(rect.bottomRight()) || | - | ||||||||||||||||||||||||
| 1210 | !contains(rect.bottomLeft())) | - | ||||||||||||||||||||||||
| 1211 | return false; | - | ||||||||||||||||||||||||
| 1212 | } | - | ||||||||||||||||||||||||
| 1213 | } | - | ||||||||||||||||||||||||
| 1214 | - | |||||||||||||||||||||||||
| 1215 | - | |||||||||||||||||||||||||
| 1216 | - | |||||||||||||||||||||||||
| 1217 | - | |||||||||||||||||||||||||
| 1218 | - | |||||||||||||||||||||||||
| 1219 | if (!contains(rect.center())) | - | ||||||||||||||||||||||||
| 1220 | return false; | - | ||||||||||||||||||||||||
| 1221 | - | |||||||||||||||||||||||||
| 1222 | - | |||||||||||||||||||||||||
| 1223 | - | |||||||||||||||||||||||||
| 1224 | - | |||||||||||||||||||||||||
| 1225 | - | |||||||||||||||||||||||||
| 1226 | - | |||||||||||||||||||||||||
| 1227 | - | |||||||||||||||||||||||||
| 1228 | for (int i=0; i<d->elements.size(); ++i) { | - | ||||||||||||||||||||||||
| 1229 | const Element &e = d->elements.at(i); | - | ||||||||||||||||||||||||
| 1230 | if (e.type == QPainterPath::MoveToElement && rect.contains(e)) { | - | ||||||||||||||||||||||||
| 1231 | if (fillRule() == Qt::OddEvenFill) | - | ||||||||||||||||||||||||
| 1232 | return false; | - | ||||||||||||||||||||||||
| 1233 | - | |||||||||||||||||||||||||
| 1234 | bool stop = false; | - | ||||||||||||||||||||||||
| 1235 | for (; !stop && i<d->elements.size(); ++i) { | - | ||||||||||||||||||||||||
| 1236 | const Element &el = d->elements.at(i); | - | ||||||||||||||||||||||||
| 1237 | switch (el.type) { | - | ||||||||||||||||||||||||
| 1238 | case MoveToElement: | - | ||||||||||||||||||||||||
| 1239 | stop = true; | - | ||||||||||||||||||||||||
| 1240 | break; | - | ||||||||||||||||||||||||
| 1241 | case LineToElement: | - | ||||||||||||||||||||||||
| 1242 | if (!contains(el)) | - | ||||||||||||||||||||||||
| 1243 | return false; | - | ||||||||||||||||||||||||
| 1244 | break; | - | ||||||||||||||||||||||||
| 1245 | case CurveToElement: | - | ||||||||||||||||||||||||
| 1246 | if (!contains(d->elements.at(i+2))) | - | ||||||||||||||||||||||||
| 1247 | return false; | - | ||||||||||||||||||||||||
| 1248 | i += 2; | - | ||||||||||||||||||||||||
| 1249 | break; | - | ||||||||||||||||||||||||
| 1250 | default: | - | ||||||||||||||||||||||||
| 1251 | break; | - | ||||||||||||||||||||||||
| 1252 | } | - | ||||||||||||||||||||||||
| 1253 | } | - | ||||||||||||||||||||||||
| 1254 | - | |||||||||||||||||||||||||
| 1255 | - | |||||||||||||||||||||||||
| 1256 | --i; | - | ||||||||||||||||||||||||
| 1257 | } | - | ||||||||||||||||||||||||
| 1258 | } | - | ||||||||||||||||||||||||
| 1259 | - | |||||||||||||||||||||||||
| 1260 | return true; | - | ||||||||||||||||||||||||
| 1261 | } | - | ||||||||||||||||||||||||
| 1262 | - | |||||||||||||||||||||||||
| 1263 | static inline bool epsilonCompare(const QPointF &a, const QPointF &b, const QSizeF &epsilon) | - | ||||||||||||||||||||||||
| 1264 | { | - | ||||||||||||||||||||||||
| 1265 | return qAbs(a.x() - b.x()) <= epsilon.width() | - | ||||||||||||||||||||||||
| 1266 | && qAbs(a.y() - b.y()) <= epsilon.height(); | - | ||||||||||||||||||||||||
| 1267 | } | - | ||||||||||||||||||||||||
| 1268 | bool QPainterPath::operator==(const QPainterPath &path) const | - | ||||||||||||||||||||||||
| 1269 | { | - | ||||||||||||||||||||||||
| 1270 | QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func()); | - | ||||||||||||||||||||||||
| 1271 | if (path.d_func() == d) | - | ||||||||||||||||||||||||
| 1272 | return true; | - | ||||||||||||||||||||||||
| 1273 | else if (!d || !path.d_func()) | - | ||||||||||||||||||||||||
| 1274 | return false; | - | ||||||||||||||||||||||||
| 1275 | else if (d->fillRule != path.d_func()->fillRule) | - | ||||||||||||||||||||||||
| 1276 | return false; | - | ||||||||||||||||||||||||
| 1277 | else if (d->elements.size() != path.d_func()->elements.size()) | - | ||||||||||||||||||||||||
| 1278 | return false; | - | ||||||||||||||||||||||||
| 1279 | - | |||||||||||||||||||||||||
| 1280 | const qreal qt_epsilon = sizeof(qreal) == sizeof(double) ? 1e-12 : qreal(1e-5); | - | ||||||||||||||||||||||||
| 1281 | - | |||||||||||||||||||||||||
| 1282 | QSizeF epsilon = boundingRect().size(); | - | ||||||||||||||||||||||||
| 1283 | epsilon.rwidth() *= qt_epsilon; | - | ||||||||||||||||||||||||
| 1284 | epsilon.rheight() *= qt_epsilon; | - | ||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||
| 1286 | for (int i = 0; i < d->elements.size(); ++i) | - | ||||||||||||||||||||||||
| 1287 | if (d->elements.at(i).type != path.d_func()->elements.at(i).type | - | ||||||||||||||||||||||||
| 1288 | || !epsilonCompare(d->elements.at(i), path.d_func()->elements.at(i), epsilon)) | - | ||||||||||||||||||||||||
| 1289 | return false; | - | ||||||||||||||||||||||||
| 1290 | - | |||||||||||||||||||||||||
| 1291 | return true; | - | ||||||||||||||||||||||||
| 1292 | } | - | ||||||||||||||||||||||||
| 1293 | bool QPainterPath::operator!=(const QPainterPath &path) const | - | ||||||||||||||||||||||||
| 1294 | { | - | ||||||||||||||||||||||||
| 1295 | return !(*this==path); | - | ||||||||||||||||||||||||
| 1296 | } | - | ||||||||||||||||||||||||
| 1297 | QPainterPath QPainterPath::operator&(const QPainterPath &other) const | - | ||||||||||||||||||||||||
| 1298 | { | - | ||||||||||||||||||||||||
| 1299 | return intersected(other); | - | ||||||||||||||||||||||||
| 1300 | } | - | ||||||||||||||||||||||||
| 1301 | QPainterPath QPainterPath::operator|(const QPainterPath &other) const | - | ||||||||||||||||||||||||
| 1302 | { | - | ||||||||||||||||||||||||
| 1303 | return united(other); | - | ||||||||||||||||||||||||
| 1304 | } | - | ||||||||||||||||||||||||
| 1305 | QPainterPath QPainterPath::operator+(const QPainterPath &other) const | - | ||||||||||||||||||||||||
| 1306 | { | - | ||||||||||||||||||||||||
| 1307 | return united(other); | - | ||||||||||||||||||||||||
| 1308 | } | - | ||||||||||||||||||||||||
| 1309 | QPainterPath QPainterPath::operator-(const QPainterPath &other) const | - | ||||||||||||||||||||||||
| 1310 | { | - | ||||||||||||||||||||||||
| 1311 | return subtracted(other); | - | ||||||||||||||||||||||||
| 1312 | } | - | ||||||||||||||||||||||||
| 1313 | QPainterPath &QPainterPath::operator&=(const QPainterPath &other) | - | ||||||||||||||||||||||||
| 1314 | { | - | ||||||||||||||||||||||||
| 1315 | return *this = (*this & other); | - | ||||||||||||||||||||||||
| 1316 | } | - | ||||||||||||||||||||||||
| 1317 | QPainterPath &QPainterPath::operator|=(const QPainterPath &other) | - | ||||||||||||||||||||||||
| 1318 | { | - | ||||||||||||||||||||||||
| 1319 | return *this = (*this | other); | - | ||||||||||||||||||||||||
| 1320 | } | - | ||||||||||||||||||||||||
| 1321 | QPainterPath &QPainterPath::operator+=(const QPainterPath &other) | - | ||||||||||||||||||||||||
| 1322 | { | - | ||||||||||||||||||||||||
| 1323 | return *this = (*this + other); | - | ||||||||||||||||||||||||
| 1324 | } | - | ||||||||||||||||||||||||
| 1325 | QPainterPath &QPainterPath::operator-=(const QPainterPath &other) | - | ||||||||||||||||||||||||
| 1326 | { | - | ||||||||||||||||||||||||
| 1327 | return *this = (*this - other); | - | ||||||||||||||||||||||||
| 1328 | } | - | ||||||||||||||||||||||||
| 1329 | QDataStream &operator<<(QDataStream &s, const QPainterPath &p) | - | ||||||||||||||||||||||||
| 1330 | { | - | ||||||||||||||||||||||||
| 1331 | if (p.isEmpty()) { | - | ||||||||||||||||||||||||
| 1332 | s << 0; | - | ||||||||||||||||||||||||
| 1333 | return s; | - | ||||||||||||||||||||||||
| 1334 | } | - | ||||||||||||||||||||||||
| 1335 | - | |||||||||||||||||||||||||
| 1336 | s << p.elementCount(); | - | ||||||||||||||||||||||||
| 1337 | for (int i=0; i < p.d_func()->elements.size(); ++i) { | - | ||||||||||||||||||||||||
| 1338 | const QPainterPath::Element &e = p.d_func()->elements.at(i); | - | ||||||||||||||||||||||||
| 1339 | s << int(e.type); | - | ||||||||||||||||||||||||
| 1340 | s << double(e.x) << double(e.y); | - | ||||||||||||||||||||||||
| 1341 | } | - | ||||||||||||||||||||||||
| 1342 | s << p.d_func()->cStart; | - | ||||||||||||||||||||||||
| 1343 | s << int(p.d_func()->fillRule); | - | ||||||||||||||||||||||||
| 1344 | return s; | - | ||||||||||||||||||||||||
| 1345 | } | - | ||||||||||||||||||||||||
| 1346 | QDataStream &operator>>(QDataStream &s, QPainterPath &p) | - | ||||||||||||||||||||||||
| 1347 | { | - | ||||||||||||||||||||||||
| 1348 | int size; | - | ||||||||||||||||||||||||
| 1349 | s >> size; | - | ||||||||||||||||||||||||
| 1350 | - | |||||||||||||||||||||||||
| 1351 | if (size == 0) | - | ||||||||||||||||||||||||
| 1352 | return s; | - | ||||||||||||||||||||||||
| 1353 | - | |||||||||||||||||||||||||
| 1354 | p.ensureData(); | - | ||||||||||||||||||||||||
| 1355 | if (p.d_func()->elements.size() == 1) { | - | ||||||||||||||||||||||||
| 1356 | ((!(p.d_func()->elements.at(0).type == QPainterPath::MoveToElement)) ? qt_assert("p.d_func()->elements.at(0).type == QPainterPath::MoveToElement",__FILE__,24232431) : qt_noop()); | - | ||||||||||||||||||||||||
| 1357 | p.d_func()->elements.clear(); | - | ||||||||||||||||||||||||
| 1358 | } | - | ||||||||||||||||||||||||
| 1359 | p.d_func()->elements.reserve(p.d_func()->elements.size() + size); | - | ||||||||||||||||||||||||
| 1360 | for (int i=0; i<size; ++i) { | - | ||||||||||||||||||||||||
| 1361 | int type; | - | ||||||||||||||||||||||||
| 1362 | double x, y; | - | ||||||||||||||||||||||||
| 1363 | s >> type; | - | ||||||||||||||||||||||||
| 1364 | s >> x; | - | ||||||||||||||||||||||||
| 1365 | s >> y; | - | ||||||||||||||||||||||||
| 1366 | ((!(type >= 0 && type <= 3)) ? qt_assert("type >= 0 && type <= 3",__FILE__,24332441) : qt_noop()); | - | ||||||||||||||||||||||||
| 1367 | if (!qt_is_finite(x) || !qt_is_finite(y)) { | - | ||||||||||||||||||||||||
| 1368 | - | |||||||||||||||||||||||||
| 1369 | QMessageLogger(__FILE__, 24362444, __PRETTY_FUNCTION__).warning("QDataStream::operator>>: NaN or Inf element found in path, skipping it"); | - | ||||||||||||||||||||||||
| 1370 | - | |||||||||||||||||||||||||
| 1371 | continue; | - | ||||||||||||||||||||||||
| 1372 | } | - | ||||||||||||||||||||||||
| 1373 | QPainterPath::Element elm = { qreal(x), qreal(y), QPainterPath::ElementType(type) }; | - | ||||||||||||||||||||||||
| 1374 | p.d_func()->elements.append(elm); | - | ||||||||||||||||||||||||
| 1375 | } | - | ||||||||||||||||||||||||
| 1376 | s >> p.d_func()->cStart; | - | ||||||||||||||||||||||||
| 1377 | int fillRule; | - | ||||||||||||||||||||||||
| 1378 | s >> fillRule; | - | ||||||||||||||||||||||||
| 1379 | ((!(fillRule == Qt::OddEvenFill || Qt::WindingFill)) ? qt_assert("fillRule == Qt::OddEvenFill || Qt::WindingFill",__FILE__,24462454) : qt_noop()); | - | ||||||||||||||||||||||||
| 1380 | p.d_func()->fillRule = Qt::FillRule(fillRule); | - | ||||||||||||||||||||||||
| 1381 | p.d_func()->dirtyBounds = true; | - | ||||||||||||||||||||||||
| 1382 | p.d_func()->dirtyControlBounds = true; | - | ||||||||||||||||||||||||
| 1383 | return s; | - | ||||||||||||||||||||||||
| 1384 | } | - | ||||||||||||||||||||||||
| 1385 | - | |||||||||||||||||||||||||
| 1386 | - | |||||||||||||||||||||||||
| 1387 | - | |||||||||||||||||||||||||
| 1388 | - | |||||||||||||||||||||||||
| 1389 | - | |||||||||||||||||||||||||
| 1390 | - | |||||||||||||||||||||||||
| 1391 | - | |||||||||||||||||||||||||
| 1392 | void qt_path_stroke_move_to(qfixed x, qfixed y, void *data) | - | ||||||||||||||||||||||||
| 1393 | { | - | ||||||||||||||||||||||||
| 1394 | ((QPainterPath *) data)->moveTo(x, y); | - | ||||||||||||||||||||||||
| 1395 | } | - | ||||||||||||||||||||||||
| 1396 | - | |||||||||||||||||||||||||
| 1397 | void qt_path_stroke_line_to(qfixed x, qfixed y, void *data) | - | ||||||||||||||||||||||||
| 1398 | { | - | ||||||||||||||||||||||||
| 1399 | ((QPainterPath *) data)->lineTo(x, y); | - | ||||||||||||||||||||||||
| 1400 | } | - | ||||||||||||||||||||||||
| 1401 | - | |||||||||||||||||||||||||
| 1402 | void qt_path_stroke_cubic_to(qfixed c1x, qfixed c1y, | - | ||||||||||||||||||||||||
| 1403 | qfixed c2x, qfixed c2y, | - | ||||||||||||||||||||||||
| 1404 | qfixed ex, qfixed ey, | - | ||||||||||||||||||||||||
| 1405 | void *data) | - | ||||||||||||||||||||||||
| 1406 | { | - | ||||||||||||||||||||||||
| 1407 | ((QPainterPath *) data)->cubicTo(c1x, c1y, | - | ||||||||||||||||||||||||
| 1408 | c2x, c2y, | - | ||||||||||||||||||||||||
| 1409 | ex, ey); | - | ||||||||||||||||||||||||
| 1410 | } | - | ||||||||||||||||||||||||
| 1411 | QPainterPathStrokerPrivate::QPainterPathStrokerPrivate() | - | ||||||||||||||||||||||||
| 1412 | : dashOffset(0) | - | ||||||||||||||||||||||||
| 1413 | { | - | ||||||||||||||||||||||||
| 1414 | stroker.setMoveToHook(qt_path_stroke_move_to); | - | ||||||||||||||||||||||||
| 1415 | stroker.setLineToHook(qt_path_stroke_line_to); | - | ||||||||||||||||||||||||
| 1416 | stroker.setCubicToHook(qt_path_stroke_cubic_to); | - | ||||||||||||||||||||||||
| 1417 | } | - | ||||||||||||||||||||||||
| 1418 | - | |||||||||||||||||||||||||
| 1419 | - | |||||||||||||||||||||||||
| 1420 | - | |||||||||||||||||||||||||
| 1421 | - | |||||||||||||||||||||||||
| 1422 | QPainterPathStroker::QPainterPathStroker() | - | ||||||||||||||||||||||||
| 1423 | : d_ptr(new QPainterPathStrokerPrivate) | - | ||||||||||||||||||||||||
| 1424 | { | - | ||||||||||||||||||||||||
| 1425 | } | - | ||||||||||||||||||||||||
| 1426 | - | |||||||||||||||||||||||||
| 1427 | - | |||||||||||||||||||||||||
| 1428 | - | |||||||||||||||||||||||||
| 1429 | - | |||||||||||||||||||||||||
| 1430 | - | |||||||||||||||||||||||||
| 1431 | - | |||||||||||||||||||||||||
| 1432 | QPainterPathStroker::QPainterPathStroker(const QPen &pen) | - | ||||||||||||||||||||||||
| 1433 | : d_ptr(new QPainterPathStrokerPrivate) | - | ||||||||||||||||||||||||
| 1434 | { | - | ||||||||||||||||||||||||
| 1435 | setWidth(pen.widthF()); | - | ||||||||||||||||||||||||
| 1436 | setCapStyle(pen.capStyle()); | - | ||||||||||||||||||||||||
| 1437 | setJoinStyle(pen.joinStyle()); | - | ||||||||||||||||||||||||
| 1438 | setMiterLimit(pen.miterLimit()); | - | ||||||||||||||||||||||||
| 1439 | setDashOffset(pen.dashOffset()); | - | ||||||||||||||||||||||||
| 1440 | - | |||||||||||||||||||||||||
| 1441 | if (pen.style() == Qt::CustomDashLine) | - | ||||||||||||||||||||||||
| 1442 | setDashPattern(pen.dashPattern()); | - | ||||||||||||||||||||||||
| 1443 | else | - | ||||||||||||||||||||||||
| 1444 | setDashPattern(pen.style()); | - | ||||||||||||||||||||||||
| 1445 | } | - | ||||||||||||||||||||||||
| 1446 | - | |||||||||||||||||||||||||
| 1447 | - | |||||||||||||||||||||||||
| 1448 | - | |||||||||||||||||||||||||
| 1449 | - | |||||||||||||||||||||||||
| 1450 | QPainterPathStroker::~QPainterPathStroker() | - | ||||||||||||||||||||||||
| 1451 | { | - | ||||||||||||||||||||||||
| 1452 | } | - | ||||||||||||||||||||||||
| 1453 | QPainterPath QPainterPathStroker::createStroke(const QPainterPath &path) const | - | ||||||||||||||||||||||||
| 1454 | { | - | ||||||||||||||||||||||||
| 1455 | QPainterPathStrokerPrivate *d = const_cast<QPainterPathStrokerPrivate *>(d_func()); | - | ||||||||||||||||||||||||
| 1456 | QPainterPath stroke; | - | ||||||||||||||||||||||||
| 1457 | if (path.isEmpty()) | - | ||||||||||||||||||||||||
| 1458 | return path; | - | ||||||||||||||||||||||||
| 1459 | if (d->dashPattern.isEmpty()) { | - | ||||||||||||||||||||||||
| 1460 | d->stroker.strokePath(path, &stroke, QTransform()); | - | ||||||||||||||||||||||||
| 1461 | } else { | - | ||||||||||||||||||||||||
| 1462 | QDashStroker dashStroker(&d->stroker); | - | ||||||||||||||||||||||||
| 1463 | dashStroker.setDashPattern(d->dashPattern); | - | ||||||||||||||||||||||||
| 1464 | dashStroker.setDashOffset(d->dashOffset); | - | ||||||||||||||||||||||||
| 1465 | dashStroker.setClipRect(d->stroker.clipRect()); | - | ||||||||||||||||||||||||
| 1466 | dashStroker.strokePath(path, &stroke, QTransform()); | - | ||||||||||||||||||||||||
| 1467 | } | - | ||||||||||||||||||||||||
| 1468 | stroke.setFillRule(Qt::WindingFill); | - | ||||||||||||||||||||||||
| 1469 | return stroke; | - | ||||||||||||||||||||||||
| 1470 | } | - | ||||||||||||||||||||||||
| 1471 | - | |||||||||||||||||||||||||
| 1472 | - | |||||||||||||||||||||||||
| 1473 | - | |||||||||||||||||||||||||
| 1474 | - | |||||||||||||||||||||||||
| 1475 | - | |||||||||||||||||||||||||
| 1476 | - | |||||||||||||||||||||||||
| 1477 | - | |||||||||||||||||||||||||
| 1478 | void QPainterPathStroker::setWidth(qreal width) | - | ||||||||||||||||||||||||
| 1479 | { | - | ||||||||||||||||||||||||
| 1480 | QPainterPathStrokerPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1481 | if (width <= 0) | - | ||||||||||||||||||||||||
| 1482 | width = 1; | - | ||||||||||||||||||||||||
| 1483 | d->stroker.setStrokeWidth(qfixed(width)); | - | ||||||||||||||||||||||||
| 1484 | } | - | ||||||||||||||||||||||||
| 1485 | - | |||||||||||||||||||||||||
| 1486 | - | |||||||||||||||||||||||||
| 1487 | - | |||||||||||||||||||||||||
| 1488 | - | |||||||||||||||||||||||||
| 1489 | qreal QPainterPathStroker::width() const | - | ||||||||||||||||||||||||
| 1490 | { | - | ||||||||||||||||||||||||
| 1491 | return d_func()->stroker.strokeWidth(); | - | ||||||||||||||||||||||||
| 1492 | } | - | ||||||||||||||||||||||||
| 1493 | - | |||||||||||||||||||||||||
| 1494 | - | |||||||||||||||||||||||||
| 1495 | - | |||||||||||||||||||||||||
| 1496 | - | |||||||||||||||||||||||||
| 1497 | - | |||||||||||||||||||||||||
| 1498 | - | |||||||||||||||||||||||||
| 1499 | - | |||||||||||||||||||||||||
| 1500 | void QPainterPathStroker::setCapStyle(Qt::PenCapStyle style) | - | ||||||||||||||||||||||||
| 1501 | { | - | ||||||||||||||||||||||||
| 1502 | d_func()->stroker.setCapStyle(style); | - | ||||||||||||||||||||||||
| 1503 | } | - | ||||||||||||||||||||||||
| 1504 | - | |||||||||||||||||||||||||
| 1505 | - | |||||||||||||||||||||||||
| 1506 | - | |||||||||||||||||||||||||
| 1507 | - | |||||||||||||||||||||||||
| 1508 | - | |||||||||||||||||||||||||
| 1509 | Qt::PenCapStyle QPainterPathStroker::capStyle() const | - | ||||||||||||||||||||||||
| 1510 | { | - | ||||||||||||||||||||||||
| 1511 | return d_func()->stroker.capStyle(); | - | ||||||||||||||||||||||||
| 1512 | } | - | ||||||||||||||||||||||||
| 1513 | - | |||||||||||||||||||||||||
| 1514 | - | |||||||||||||||||||||||||
| 1515 | - | |||||||||||||||||||||||||
| 1516 | - | |||||||||||||||||||||||||
| 1517 | void QPainterPathStroker::setJoinStyle(Qt::PenJoinStyle style) | - | ||||||||||||||||||||||||
| 1518 | { | - | ||||||||||||||||||||||||
| 1519 | d_func()->stroker.setJoinStyle(style); | - | ||||||||||||||||||||||||
| 1520 | } | - | ||||||||||||||||||||||||
| 1521 | - | |||||||||||||||||||||||||
| 1522 | - | |||||||||||||||||||||||||
| 1523 | - | |||||||||||||||||||||||||
| 1524 | - | |||||||||||||||||||||||||
| 1525 | Qt::PenJoinStyle QPainterPathStroker::joinStyle() const | - | ||||||||||||||||||||||||
| 1526 | { | - | ||||||||||||||||||||||||
| 1527 | return d_func()->stroker.joinStyle(); | - | ||||||||||||||||||||||||
| 1528 | } | - | ||||||||||||||||||||||||
| 1529 | void QPainterPathStroker::setMiterLimit(qreal limit) | - | ||||||||||||||||||||||||
| 1530 | { | - | ||||||||||||||||||||||||
| 1531 | d_func()->stroker.setMiterLimit(qfixed(limit)); | - | ||||||||||||||||||||||||
| 1532 | } | - | ||||||||||||||||||||||||
| 1533 | - | |||||||||||||||||||||||||
| 1534 | - | |||||||||||||||||||||||||
| 1535 | - | |||||||||||||||||||||||||
| 1536 | - | |||||||||||||||||||||||||
| 1537 | qreal QPainterPathStroker::miterLimit() const | - | ||||||||||||||||||||||||
| 1538 | { | - | ||||||||||||||||||||||||
| 1539 | return d_func()->stroker.miterLimit(); | - | ||||||||||||||||||||||||
| 1540 | } | - | ||||||||||||||||||||||||
| 1541 | void QPainterPathStroker::setCurveThreshold(qreal threshold) | - | ||||||||||||||||||||||||
| 1542 | { | - | ||||||||||||||||||||||||
| 1543 | d_func()->stroker.setCurveThreshold(qfixed(threshold)); | - | ||||||||||||||||||||||||
| 1544 | } | - | ||||||||||||||||||||||||
| 1545 | - | |||||||||||||||||||||||||
| 1546 | - | |||||||||||||||||||||||||
| 1547 | - | |||||||||||||||||||||||||
| 1548 | - | |||||||||||||||||||||||||
| 1549 | - | |||||||||||||||||||||||||
| 1550 | qreal QPainterPathStroker::curveThreshold() const | - | ||||||||||||||||||||||||
| 1551 | { | - | ||||||||||||||||||||||||
| 1552 | return d_func()->stroker.curveThreshold(); | - | ||||||||||||||||||||||||
| 1553 | } | - | ||||||||||||||||||||||||
| 1554 | - | |||||||||||||||||||||||||
| 1555 | - | |||||||||||||||||||||||||
| 1556 | - | |||||||||||||||||||||||||
| 1557 | - | |||||||||||||||||||||||||
| 1558 | void QPainterPathStroker::setDashPattern(Qt::PenStyle style) | - | ||||||||||||||||||||||||
| 1559 | { | - | ||||||||||||||||||||||||
| 1560 | d_func()->dashPattern = QDashStroker::patternForStyle(style); | - | ||||||||||||||||||||||||
| 1561 | } | - | ||||||||||||||||||||||||
| 1562 | void QPainterPathStroker::setDashPattern(const QVector<qreal> &dashPattern) | - | ||||||||||||||||||||||||
| 1563 | { | - | ||||||||||||||||||||||||
| 1564 | d_func()->dashPattern.clear(); | - | ||||||||||||||||||||||||
| 1565 | for (int i=0; i<dashPattern.size(); ++i) | - | ||||||||||||||||||||||||
| 1566 | d_func()->dashPattern << qfixed(dashPattern.at(i)); | - | ||||||||||||||||||||||||
| 1567 | } | - | ||||||||||||||||||||||||
| 1568 | - | |||||||||||||||||||||||||
| 1569 | - | |||||||||||||||||||||||||
| 1570 | - | |||||||||||||||||||||||||
| 1571 | - | |||||||||||||||||||||||||
| 1572 | QVector<qreal> QPainterPathStroker::dashPattern() const | - | ||||||||||||||||||||||||
| 1573 | { | - | ||||||||||||||||||||||||
| 1574 | return d_func()->dashPattern; | - | ||||||||||||||||||||||||
| 1575 | } | - | ||||||||||||||||||||||||
| 1576 | - | |||||||||||||||||||||||||
| 1577 | - | |||||||||||||||||||||||||
| 1578 | - | |||||||||||||||||||||||||
| 1579 | - | |||||||||||||||||||||||||
| 1580 | qreal QPainterPathStroker::dashOffset() const | - | ||||||||||||||||||||||||
| 1581 | { | - | ||||||||||||||||||||||||
| 1582 | return d_func()->dashOffset; | - | ||||||||||||||||||||||||
| 1583 | } | - | ||||||||||||||||||||||||
| 1584 | - | |||||||||||||||||||||||||
| 1585 | - | |||||||||||||||||||||||||
| 1586 | - | |||||||||||||||||||||||||
| 1587 | - | |||||||||||||||||||||||||
| 1588 | - | |||||||||||||||||||||||||
| 1589 | - | |||||||||||||||||||||||||
| 1590 | - | |||||||||||||||||||||||||
| 1591 | void QPainterPathStroker::setDashOffset(qreal offset) | - | ||||||||||||||||||||||||
| 1592 | { | - | ||||||||||||||||||||||||
| 1593 | d_func()->dashOffset = offset; | - | ||||||||||||||||||||||||
| 1594 | } | - | ||||||||||||||||||||||||
| 1595 | QPolygonF QPainterPath::toFillPolygon(const QTransform &matrix) const | - | ||||||||||||||||||||||||
| 1596 | { | - | ||||||||||||||||||||||||
| 1597 | - | |||||||||||||||||||||||||
| 1598 | const QList<QPolygonF> flats = toSubpathPolygons(matrix); | - | ||||||||||||||||||||||||
| 1599 | QPolygonF polygon; | - | ||||||||||||||||||||||||
| 1600 | if (flats.isEmpty()
| 0 | ||||||||||||||||||||||||
| 1601 | return never executed: polygon;return polygon;never executed: return polygon; | 0 | ||||||||||||||||||||||||
| 1602 | QPointF first = flats.first().first(); | - | ||||||||||||||||||||||||
| 1603 | for (int i=0; i<flats.size()
| 0 | ||||||||||||||||||||||||
| 1604 | polygon += flats.at(i); | - | ||||||||||||||||||||||||
| 1605 | if (!flats.at(i).isClosed()
| 0 | ||||||||||||||||||||||||
| 1606 | polygon += flats.at(i).first(); never executed: polygon += flats.at(i).first(); | 0 | ||||||||||||||||||||||||
| 1607 | if (i > 0
| 0 | ||||||||||||||||||||||||
| 1608 | polygon += first; never executed: polygon += first; | 0 | ||||||||||||||||||||||||
| 1609 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1610 | return never executed: polygon;return polygon;never executed: return polygon; | 0 | ||||||||||||||||||||||||
| 1611 | } | - | ||||||||||||||||||||||||
| 1612 | - | |||||||||||||||||||||||||
| 1613 | - | |||||||||||||||||||||||||
| 1614 | - | |||||||||||||||||||||||||
| 1615 | - | |||||||||||||||||||||||||
| 1616 | QPolygonF QPainterPath::toFillPolygon(const QMatrix &matrix) const | - | ||||||||||||||||||||||||
| 1617 | { | - | ||||||||||||||||||||||||
| 1618 | return toFillPolygon(QTransform(matrix)); | - | ||||||||||||||||||||||||
| 1619 | } | - | ||||||||||||||||||||||||
| 1620 | - | |||||||||||||||||||||||||
| 1621 | - | |||||||||||||||||||||||||
| 1622 | - | |||||||||||||||||||||||||
| 1623 | static inline qreal slopeAt(qreal t, qreal a, qreal b, qreal c, qreal d) | - | ||||||||||||||||||||||||
| 1624 | { | - | ||||||||||||||||||||||||
| 1625 | return 3*t*t*(d - 3*c + 3*b - a) + 6*t*(c - 2*b + a) + 3*(b - a); | - | ||||||||||||||||||||||||
| 1626 | } | - | ||||||||||||||||||||||||
| 1627 | - | |||||||||||||||||||||||||
| 1628 | - | |||||||||||||||||||||||||
| 1629 | - | |||||||||||||||||||||||||
| 1630 | - | |||||||||||||||||||||||||
| 1631 | qreal QPainterPath::length() const | - | ||||||||||||||||||||||||
| 1632 | { | - | ||||||||||||||||||||||||
| 1633 | QPainterPathPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1634 | if (isEmpty()) | - | ||||||||||||||||||||||||
| 1635 | return 0; | - | ||||||||||||||||||||||||
| 1636 | - | |||||||||||||||||||||||||
| 1637 | qreal len = 0; | - | ||||||||||||||||||||||||
| 1638 | for (int i=1; i<d->elements.size(); ++i) { | - | ||||||||||||||||||||||||
| 1639 | const Element &e = d->elements.at(i); | - | ||||||||||||||||||||||||
| 1640 | - | |||||||||||||||||||||||||
| 1641 | switch (e.type) { | - | ||||||||||||||||||||||||
| 1642 | case MoveToElement: | - | ||||||||||||||||||||||||
| 1643 | break; | - | ||||||||||||||||||||||||
| 1644 | case LineToElement: | - | ||||||||||||||||||||||||
| 1645 | { | - | ||||||||||||||||||||||||
| 1646 | len += QLineF(d->elements.at(i-1), e).length(); | - | ||||||||||||||||||||||||
| 1647 | break; | - | ||||||||||||||||||||||||
| 1648 | } | - | ||||||||||||||||||||||||
| 1649 | case CurveToElement: | - | ||||||||||||||||||||||||
| 1650 | { | - | ||||||||||||||||||||||||
| 1651 | QBezier b = QBezier::fromPoints(d->elements.at(i-1), | - | ||||||||||||||||||||||||
| 1652 | e, | - | ||||||||||||||||||||||||
| 1653 | d->elements.at(i+1), | - | ||||||||||||||||||||||||
| 1654 | d->elements.at(i+2)); | - | ||||||||||||||||||||||||
| 1655 | len += b.length(); | - | ||||||||||||||||||||||||
| 1656 | i += 2; | - | ||||||||||||||||||||||||
| 1657 | break; | - | ||||||||||||||||||||||||
| 1658 | } | - | ||||||||||||||||||||||||
| 1659 | default: | - | ||||||||||||||||||||||||
| 1660 | break; | - | ||||||||||||||||||||||||
| 1661 | } | - | ||||||||||||||||||||||||
| 1662 | } | - | ||||||||||||||||||||||||
| 1663 | return len; | - | ||||||||||||||||||||||||
| 1664 | } | - | ||||||||||||||||||||||||
| 1665 | qreal QPainterPath::percentAtLength(qreal len) const | - | ||||||||||||||||||||||||
| 1666 | { | - | ||||||||||||||||||||||||
| 1667 | QPainterPathPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 1668 | if (isEmpty() || len <= 0) | - | ||||||||||||||||||||||||
| 1669 | return 0; | - | ||||||||||||||||||||||||
| 1670 | - | |||||||||||||||||||||||||
| 1671 | qreal totalLength = length(); | - | ||||||||||||||||||||||||
| 1672 | if (len > totalLength) | - | ||||||||||||||||||||||||
| 1673 | return 1; | - | ||||||||||||||||||||||||
| 1674 | - | |||||||||||||||||||||||||
| 1675 | qreal curLen = 0; | - | ||||||||||||||||||||||||
| 1676 | for (int i=1; i<d->elements.size(); ++i) { | - | ||||||||||||||||||||||||
| 1677 | const Element &e = d->elements.at(i); | - | ||||||||||||||||||||||||
| 1678 | - | |||||||||||||||||||||||||
| 1679 | switch (e.type) { | - | ||||||||||||||||||||||||
| 1680 | case MoveToElement: | - | ||||||||||||||||||||||||
| 1681 | break; | - | ||||||||||||||||||||||||
| 1682 | case LineToElement: | - | ||||||||||||||||||||||||
| 1683 | { | - | ||||||||||||||||||||||||
| 1684 | QLineF line(d->elements.at(i-1), e); | - | ||||||||||||||||||||||||
| 1685 | qreal llen = line.length(); | - | ||||||||||||||||||||||||
| 1686 | curLen += llen; | - | ||||||||||||||||||||||||
| 1687 | if (curLen >= len) { | - | ||||||||||||||||||||||||
| 1688 | return len/totalLength ; | - | ||||||||||||||||||||||||
| 1689 | } | - | ||||||||||||||||||||||||
| 1690 | - | |||||||||||||||||||||||||
| 1691 | break; | - | ||||||||||||||||||||||||
| 1692 | } | - | ||||||||||||||||||||||||
| 1693 | case CurveToElement: | - | ||||||||||||||||||||||||
| 1694 | { | - | ||||||||||||||||||||||||
| 1695 | QBezier b = QBezier::fromPoints(d->elements.at(i-1), | - | ||||||||||||||||||||||||
| 1696 | e, | - | ||||||||||||||||||||||||
| 1697 | d->elements.at(i+1), | - | ||||||||||||||||||||||||
| 1698 | d->elements.at(i+2)); | - | ||||||||||||||||||||||||
| 1699 | qreal blen = b.length(); | - | ||||||||||||||||||||||||
| 1700 | qreal prevLen = curLen; | - | ||||||||||||||||||||||||
| 1701 | curLen += blen; | - | ||||||||||||||||||||||||
| 1702 | - | |||||||||||||||||||||||||
| 1703 | if (curLen >= len) { | - | ||||||||||||||||||||||||
| 1704 | qreal res = b.tAtLength(len - prevLen); | - | ||||||||||||||||||||||||
| 1705 | return (res * blen + prevLen)/totalLength; | - | ||||||||||||||||||||||||
| 1706 | } | - | ||||||||||||||||||||||||
| 1707 | - | |||||||||||||||||||||||||
| 1708 | i += 2; | - | ||||||||||||||||||||||||
| 1709 | break; | - | ||||||||||||||||||||||||
| 1710 | } | - | ||||||||||||||||||||||||
| 1711 | default: | - | ||||||||||||||||||||||||
| 1712 | break; | - | ||||||||||||||||||||||||
| 1713 | } | - | ||||||||||||||||||||||||
| 1714 | } | - | ||||||||||||||||||||||||
| 1715 | - | |||||||||||||||||||||||||
| 1716 | return 0; | - | ||||||||||||||||||||||||
| 1717 | } | - | ||||||||||||||||||||||||
| 1718 | - | |||||||||||||||||||||||||
| 1719 | static inline QBezier bezierAtT(const QPainterPath &path, qreal t, qreal *startingLength, qreal *bezierLength) | - | ||||||||||||||||||||||||
| 1720 | { | - | ||||||||||||||||||||||||
| 1721 | *startingLength = 0; | - | ||||||||||||||||||||||||
| 1722 | if (t > 1) | - | ||||||||||||||||||||||||
| 1723 | return QBezier(); | - | ||||||||||||||||||||||||
| 1724 | - | |||||||||||||||||||||||||
| 1725 | qreal curLen = 0; | - | ||||||||||||||||||||||||
| 1726 | qreal totalLength = path.length(); | - | ||||||||||||||||||||||||
| 1727 | - | |||||||||||||||||||||||||
| 1728 | const int lastElement = path.elementCount() - 1; | - | ||||||||||||||||||||||||
| 1729 | for (int i=0; i <= lastElement; ++i) { | - | ||||||||||||||||||||||||
| 1730 | const QPainterPath::Element &e = path.elementAt(i); | - | ||||||||||||||||||||||||
| 1731 | - | |||||||||||||||||||||||||
| 1732 | switch (e.type) { | - | ||||||||||||||||||||||||
| 1733 | case QPainterPath::MoveToElement: | - | ||||||||||||||||||||||||
| 1734 | break; | - | ||||||||||||||||||||||||
| 1735 | case QPainterPath::LineToElement: | - | ||||||||||||||||||||||||
| 1736 | { | - | ||||||||||||||||||||||||
| 1737 | QLineF line(path.elementAt(i-1), e); | - | ||||||||||||||||||||||||
| 1738 | qreal llen = line.length(); | - | ||||||||||||||||||||||||
| 1739 | curLen += llen; | - | ||||||||||||||||||||||||
| 1740 | if (i == lastElement || curLen/totalLength >= t) { | - | ||||||||||||||||||||||||
| 1741 | *bezierLength = llen; | - | ||||||||||||||||||||||||
| 1742 | QPointF a = path.elementAt(i-1); | - | ||||||||||||||||||||||||
| 1743 | QPointF delta = e - a; | - | ||||||||||||||||||||||||
| 1744 | return QBezier::fromPoints(a, a + delta / 3, a + 2 * delta / 3, e); | - | ||||||||||||||||||||||||
| 1745 | } | - | ||||||||||||||||||||||||
| 1746 | break; | - | ||||||||||||||||||||||||
| 1747 | } | - | ||||||||||||||||||||||||
| 1748 | case QPainterPath::CurveToElement: | - | ||||||||||||||||||||||||
| 1749 | { | - | ||||||||||||||||||||||||
| 1750 | QBezier b = QBezier::fromPoints(path.elementAt(i-1), | - | ||||||||||||||||||||||||
| 1751 | e, | - | ||||||||||||||||||||||||
| 1752 | path.elementAt(i+1), | - | ||||||||||||||||||||||||
| 1753 | path.elementAt(i+2)); | - | ||||||||||||||||||||||||
| 1754 | qreal blen = b.length(); | - | ||||||||||||||||||||||||
| 1755 | curLen += blen; | - | ||||||||||||||||||||||||
| 1756 | - | |||||||||||||||||||||||||
| 1757 | if (i + 2 == lastElement || curLen/totalLength >= t) { | - | ||||||||||||||||||||||||
| 1758 | *bezierLength = blen; | - | ||||||||||||||||||||||||
| 1759 | return b; | - | ||||||||||||||||||||||||
| 1760 | } | - | ||||||||||||||||||||||||
| 1761 | - | |||||||||||||||||||||||||
| 1762 | i += 2; | - | ||||||||||||||||||||||||
| 1763 | break; | - | ||||||||||||||||||||||||
| 1764 | } | - | ||||||||||||||||||||||||
| 1765 | default: | - | ||||||||||||||||||||||||
| 1766 | break; | - | ||||||||||||||||||||||||
| 1767 | } | - | ||||||||||||||||||||||||
| 1768 | *startingLength = curLen; | - | ||||||||||||||||||||||||
| 1769 | } | - | ||||||||||||||||||||||||
| 1770 | return QBezier(); | - | ||||||||||||||||||||||||
| 1771 | } | - | ||||||||||||||||||||||||
| 1772 | QPointF QPainterPath::pointAtPercent(qreal t) const | - | ||||||||||||||||||||||||
| 1773 | { | - | ||||||||||||||||||||||||
| 1774 | if (t < 0 || t > 1) { | - | ||||||||||||||||||||||||
| 1775 | QMessageLogger(__FILE__, 29822990, __PRETTY_FUNCTION__).warning("QPainterPath::pointAtPercent accepts only values between 0 and 1"); | - | ||||||||||||||||||||||||
| 1776 | return QPointF(); | - | ||||||||||||||||||||||||
| 1777 | } | - | ||||||||||||||||||||||||
| 1778 | - | |||||||||||||||||||||||||
| 1779 | if (!d_ptr || d_ptr->elements.size() == 0) | - | ||||||||||||||||||||||||
| 1780 | return QPointF(); | - | ||||||||||||||||||||||||
| 1781 | - | |||||||||||||||||||||||||
| 1782 | if (d_ptr->elements.size() == 1) | - | ||||||||||||||||||||||||
| 1783 | return d_ptr->elements.at(0); | - | ||||||||||||||||||||||||
| 1784 | - | |||||||||||||||||||||||||
| 1785 | qreal totalLength = length(); | - | ||||||||||||||||||||||||
| 1786 | qreal curLen = 0; | - | ||||||||||||||||||||||||
| 1787 | qreal bezierLen = 0; | - | ||||||||||||||||||||||||
| 1788 | QBezier b = bezierAtT(*this, t, &curLen, &bezierLen); | - | ||||||||||||||||||||||||
| 1789 | qreal realT = (totalLength * t - curLen) / bezierLen; | - | ||||||||||||||||||||||||
| 1790 | - | |||||||||||||||||||||||||
| 1791 | return b.pointAt(qBound(qreal(0), realT, qreal(1))); | - | ||||||||||||||||||||||||
| 1792 | } | - | ||||||||||||||||||||||||
| 1793 | qreal QPainterPath::angleAtPercent(qreal t) const | - | ||||||||||||||||||||||||
| 1794 | { | - | ||||||||||||||||||||||||
| 1795 | if (t < 0 || t > 1) { | - | ||||||||||||||||||||||||
| 1796 | QMessageLogger(__FILE__, 30163024, __PRETTY_FUNCTION__).warning("QPainterPath::angleAtPercent accepts only values between 0 and 1"); | - | ||||||||||||||||||||||||
| 1797 | return 0; | - | ||||||||||||||||||||||||
| 1798 | } | - | ||||||||||||||||||||||||
| 1799 | - | |||||||||||||||||||||||||
| 1800 | qreal totalLength = length(); | - | ||||||||||||||||||||||||
| 1801 | qreal curLen = 0; | - | ||||||||||||||||||||||||
| 1802 | qreal bezierLen = 0; | - | ||||||||||||||||||||||||
| 1803 | QBezier bez = bezierAtT(*this, t, &curLen, &bezierLen); | - | ||||||||||||||||||||||||
| 1804 | qreal realT = (totalLength * t - curLen) / bezierLen; | - | ||||||||||||||||||||||||
| 1805 | - | |||||||||||||||||||||||||
| 1806 | qreal m1 = slopeAt(realT, bez.x1, bez.x2, bez.x3, bez.x4); | - | ||||||||||||||||||||||||
| 1807 | qreal m2 = slopeAt(realT, bez.y1, bez.y2, bez.y3, bez.y4); | - | ||||||||||||||||||||||||
| 1808 | - | |||||||||||||||||||||||||
| 1809 | return QLineF(0, 0, m1, m2).angle(); | - | ||||||||||||||||||||||||
| 1810 | } | - | ||||||||||||||||||||||||
| 1811 | qreal QPainterPath::slopeAtPercent(qreal t) const | - | ||||||||||||||||||||||||
| 1812 | { | - | ||||||||||||||||||||||||
| 1813 | if (t < 0 || t > 1) { | - | ||||||||||||||||||||||||
| 1814 | QMessageLogger(__FILE__, 30453053, __PRETTY_FUNCTION__).warning("QPainterPath::slopeAtPercent accepts only values between 0 and 1"); | - | ||||||||||||||||||||||||
| 1815 | return 0; | - | ||||||||||||||||||||||||
| 1816 | } | - | ||||||||||||||||||||||||
| 1817 | - | |||||||||||||||||||||||||
| 1818 | qreal totalLength = length(); | - | ||||||||||||||||||||||||
| 1819 | qreal curLen = 0; | - | ||||||||||||||||||||||||
| 1820 | qreal bezierLen = 0; | - | ||||||||||||||||||||||||
| 1821 | QBezier bez = bezierAtT(*this, t, &curLen, &bezierLen); | - | ||||||||||||||||||||||||
| 1822 | qreal realT = (totalLength * t - curLen) / bezierLen; | - | ||||||||||||||||||||||||
| 1823 | - | |||||||||||||||||||||||||
| 1824 | qreal m1 = slopeAt(realT, bez.x1, bez.x2, bez.x3, bez.x4); | - | ||||||||||||||||||||||||
| 1825 | qreal m2 = slopeAt(realT, bez.y1, bez.y2, bez.y3, bez.y4); | - | ||||||||||||||||||||||||
| 1826 | - | |||||||||||||||||||||||||
| 1827 | qreal slope = 0; | - | ||||||||||||||||||||||||
| 1828 | - | |||||||||||||||||||||||||
| 1829 | if (m1) | - | ||||||||||||||||||||||||
| 1830 | slope = m2/m1; | - | ||||||||||||||||||||||||
| 1831 | else { | - | ||||||||||||||||||||||||
| 1832 | if (std::numeric_limits<qreal>::has_infinity) { | - | ||||||||||||||||||||||||
| 1833 | slope = (m2 < 0) ? -std::numeric_limits<qreal>::infinity() | - | ||||||||||||||||||||||||
| 1834 | : std::numeric_limits<qreal>::infinity(); | - | ||||||||||||||||||||||||
| 1835 | } else { | - | ||||||||||||||||||||||||
| 1836 | if (sizeof(qreal) == sizeof(double)) { | - | ||||||||||||||||||||||||
| 1837 | return 1.79769313486231570e+308; | - | ||||||||||||||||||||||||
| 1838 | } else { | - | ||||||||||||||||||||||||
| 1839 | return ((qreal)3.40282346638528860e+38); | - | ||||||||||||||||||||||||
| 1840 | } | - | ||||||||||||||||||||||||
| 1841 | } | - | ||||||||||||||||||||||||
| 1842 | } | - | ||||||||||||||||||||||||
| 1843 | - | |||||||||||||||||||||||||
| 1844 | return slope; | - | ||||||||||||||||||||||||
| 1845 | } | - | ||||||||||||||||||||||||
| 1846 | void QPainterPath::addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, | - | ||||||||||||||||||||||||
| 1847 | Qt::SizeMode mode) | - | ||||||||||||||||||||||||
| 1848 | { | - | ||||||||||||||||||||||||
| 1849 | QRectF r = rect.normalized(); | - | ||||||||||||||||||||||||
| 1850 | - | |||||||||||||||||||||||||
| 1851 | if (r.isNull()) | - | ||||||||||||||||||||||||
| 1852 | return; | - | ||||||||||||||||||||||||
| 1853 | - | |||||||||||||||||||||||||
| 1854 | if (mode == Qt::AbsoluteSize) { | - | ||||||||||||||||||||||||
| 1855 | qreal w = r.width() / 2; | - | ||||||||||||||||||||||||
| 1856 | qreal h = r.height() / 2; | - | ||||||||||||||||||||||||
| 1857 | - | |||||||||||||||||||||||||
| 1858 | if (w == 0) { | - | ||||||||||||||||||||||||
| 1859 | xRadius = 0; | - | ||||||||||||||||||||||||
| 1860 | } else { | - | ||||||||||||||||||||||||
| 1861 | xRadius = 100 * qMin(xRadius, w) / w; | - | ||||||||||||||||||||||||
| 1862 | } | - | ||||||||||||||||||||||||
| 1863 | if (h == 0) { | - | ||||||||||||||||||||||||
| 1864 | yRadius = 0; | - | ||||||||||||||||||||||||
| 1865 | } else { | - | ||||||||||||||||||||||||
| 1866 | yRadius = 100 * qMin(yRadius, h) / h; | - | ||||||||||||||||||||||||
| 1867 | } | - | ||||||||||||||||||||||||
| 1868 | } else { | - | ||||||||||||||||||||||||
| 1869 | if (xRadius > 100) | - | ||||||||||||||||||||||||
| 1870 | xRadius = 100; | - | ||||||||||||||||||||||||
| 1871 | - | |||||||||||||||||||||||||
| 1872 | if (yRadius > 100) | - | ||||||||||||||||||||||||
| 1873 | yRadius = 100; | - | ||||||||||||||||||||||||
| 1874 | } | - | ||||||||||||||||||||||||
| 1875 | - | |||||||||||||||||||||||||
| 1876 | if (xRadius <= 0 || yRadius <= 0) { | - | ||||||||||||||||||||||||
| 1877 | addRect(r); | - | ||||||||||||||||||||||||
| 1878 | return; | - | ||||||||||||||||||||||||
| 1879 | } | - | ||||||||||||||||||||||||
| 1880 | - | |||||||||||||||||||||||||
| 1881 | qreal x = r.x(); | - | ||||||||||||||||||||||||
| 1882 | qreal y = r.y(); | - | ||||||||||||||||||||||||
| 1883 | qreal w = r.width(); | - | ||||||||||||||||||||||||
| 1884 | qreal h = r.height(); | - | ||||||||||||||||||||||||
| 1885 | qreal rxx2 = w*xRadius/100; | - | ||||||||||||||||||||||||
| 1886 | qreal ryy2 = h*yRadius/100; | - | ||||||||||||||||||||||||
| 1887 | - | |||||||||||||||||||||||||
| 1888 | ensureData(); | - | ||||||||||||||||||||||||
| 1889 | detach(); | - | ||||||||||||||||||||||||
| 1890 | - | |||||||||||||||||||||||||
| 1891 | bool first = d_func()->elements.size() < 2; | - | ||||||||||||||||||||||||
| 1892 | - | |||||||||||||||||||||||||
| 1893 | arcMoveTo(x, y, rxx2, ryy2, 180); | - | ||||||||||||||||||||||||
| 1894 | arcTo(x, y, rxx2, ryy2, 180, -90); | - | ||||||||||||||||||||||||
| 1895 | arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90); | - | ||||||||||||||||||||||||
| 1896 | arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90); | - | ||||||||||||||||||||||||
| 1897 | arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90); | - | ||||||||||||||||||||||||
| 1898 | closeSubpath(); | - | ||||||||||||||||||||||||
| 1899 | - | |||||||||||||||||||||||||
| 1900 | d_func()->require_moveTo = true; | - | ||||||||||||||||||||||||
| 1901 | d_func()->convex = first; | - | ||||||||||||||||||||||||
| 1902 | } | - | ||||||||||||||||||||||||
| 1903 | void QPainterPath::addRoundRect(const QRectF &r, int xRnd, int yRnd) | - | ||||||||||||||||||||||||
| 1904 | { | - | ||||||||||||||||||||||||
| 1905 | if(xRnd >= 100) | - | ||||||||||||||||||||||||
| 1906 | xRnd = 99; | - | ||||||||||||||||||||||||
| 1907 | if(yRnd >= 100) | - | ||||||||||||||||||||||||
| 1908 | yRnd = 99; | - | ||||||||||||||||||||||||
| 1909 | if(xRnd <= 0 || yRnd <= 0) { | - | ||||||||||||||||||||||||
| 1910 | addRect(r); | - | ||||||||||||||||||||||||
| 1911 | return; | - | ||||||||||||||||||||||||
| 1912 | } | - | ||||||||||||||||||||||||
| 1913 | - | |||||||||||||||||||||||||
| 1914 | QRectF rect = r.normalized(); | - | ||||||||||||||||||||||||
| 1915 | - | |||||||||||||||||||||||||
| 1916 | if (rect.isNull()) | - | ||||||||||||||||||||||||
| 1917 | return; | - | ||||||||||||||||||||||||
| 1918 | - | |||||||||||||||||||||||||
| 1919 | qreal x = rect.x(); | - | ||||||||||||||||||||||||
| 1920 | qreal y = rect.y(); | - | ||||||||||||||||||||||||
| 1921 | qreal w = rect.width(); | - | ||||||||||||||||||||||||
| 1922 | qreal h = rect.height(); | - | ||||||||||||||||||||||||
| 1923 | qreal rxx2 = w*xRnd/100; | - | ||||||||||||||||||||||||
| 1924 | qreal ryy2 = h*yRnd/100; | - | ||||||||||||||||||||||||
| 1925 | - | |||||||||||||||||||||||||
| 1926 | ensureData(); | - | ||||||||||||||||||||||||
| 1927 | detach(); | - | ||||||||||||||||||||||||
| 1928 | - | |||||||||||||||||||||||||
| 1929 | bool first = d_func()->elements.size() < 2; | - | ||||||||||||||||||||||||
| 1930 | - | |||||||||||||||||||||||||
| 1931 | arcMoveTo(x, y, rxx2, ryy2, 180); | - | ||||||||||||||||||||||||
| 1932 | arcTo(x, y, rxx2, ryy2, 180, -90); | - | ||||||||||||||||||||||||
| 1933 | arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90); | - | ||||||||||||||||||||||||
| 1934 | arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90); | - | ||||||||||||||||||||||||
| 1935 | arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90); | - | ||||||||||||||||||||||||
| 1936 | closeSubpath(); | - | ||||||||||||||||||||||||
| 1937 | - | |||||||||||||||||||||||||
| 1938 | d_func()->require_moveTo = true; | - | ||||||||||||||||||||||||
| 1939 | d_func()->convex = first; | - | ||||||||||||||||||||||||
| 1940 | } | - | ||||||||||||||||||||||||
| 1941 | QPainterPath QPainterPath::united(const QPainterPath &p) const | - | ||||||||||||||||||||||||
| 1942 | { | - | ||||||||||||||||||||||||
| 1943 | if (isEmpty() || p.isEmpty()) | - | ||||||||||||||||||||||||
| 1944 | return isEmpty() ? p : *this; | - | ||||||||||||||||||||||||
| 1945 | QPathClipper clipper(*this, p); | - | ||||||||||||||||||||||||
| 1946 | return clipper.clip(QPathClipper::BoolOr); | - | ||||||||||||||||||||||||
| 1947 | } | - | ||||||||||||||||||||||||
| 1948 | QPainterPath QPainterPath::intersected(const QPainterPath &p) const | - | ||||||||||||||||||||||||
| 1949 | { | - | ||||||||||||||||||||||||
| 1950 | if (isEmpty() || p.isEmpty()) | - | ||||||||||||||||||||||||
| 1951 | return QPainterPath(); | - | ||||||||||||||||||||||||
| 1952 | QPathClipper clipper(*this, p); | - | ||||||||||||||||||||||||
| 1953 | return clipper.clip(QPathClipper::BoolAnd); | - | ||||||||||||||||||||||||
| 1954 | } | - | ||||||||||||||||||||||||
| 1955 | QPainterPath QPainterPath::subtracted(const QPainterPath &p) const | - | ||||||||||||||||||||||||
| 1956 | { | - | ||||||||||||||||||||||||
| 1957 | if (isEmpty() || p.isEmpty()) | - | ||||||||||||||||||||||||
| 1958 | return *this; | - | ||||||||||||||||||||||||
| 1959 | QPathClipper clipper(*this, p); | - | ||||||||||||||||||||||||
| 1960 | return clipper.clip(QPathClipper::BoolSub); | - | ||||||||||||||||||||||||
| 1961 | } | - | ||||||||||||||||||||||||
| 1962 | QPainterPath QPainterPath::subtractedInverted(const QPainterPath &p) const | - | ||||||||||||||||||||||||
| 1963 | { | - | ||||||||||||||||||||||||
| 1964 | return p.subtracted(*this); | - | ||||||||||||||||||||||||
| 1965 | } | - | ||||||||||||||||||||||||
| 1966 | QPainterPath QPainterPath::simplified() const | - | ||||||||||||||||||||||||
| 1967 | { | - | ||||||||||||||||||||||||
| 1968 | if(isEmpty()) | - | ||||||||||||||||||||||||
| 1969 | return *this; | - | ||||||||||||||||||||||||
| 1970 | QPathClipper clipper(*this, QPainterPath()); | - | ||||||||||||||||||||||||
| 1971 | return clipper.clip(QPathClipper::Simplify); | - | ||||||||||||||||||||||||
| 1972 | } | - | ||||||||||||||||||||||||
| 1973 | bool QPainterPath::intersects(const QPainterPath &p) const | - | ||||||||||||||||||||||||
| 1974 | { | - | ||||||||||||||||||||||||
| 1975 | if (p.elementCount() == 1) | - | ||||||||||||||||||||||||
| 1976 | return contains(p.elementAt(0)); | - | ||||||||||||||||||||||||
| 1977 | if (isEmpty() || p.isEmpty()) | - | ||||||||||||||||||||||||
| 1978 | return false; | - | ||||||||||||||||||||||||
| 1979 | QPathClipper clipper(*this, p); | - | ||||||||||||||||||||||||
| 1980 | return clipper.intersect(); | - | ||||||||||||||||||||||||
| 1981 | } | - | ||||||||||||||||||||||||
| 1982 | bool QPainterPath::contains(const QPainterPath &p) const | - | ||||||||||||||||||||||||
| 1983 | { | - | ||||||||||||||||||||||||
| 1984 | if (p.elementCount() == 1) | - | ||||||||||||||||||||||||
| 1985 | return contains(p.elementAt(0)); | - | ||||||||||||||||||||||||
| 1986 | if (isEmpty() || p.isEmpty()) | - | ||||||||||||||||||||||||
| 1987 | return false; | - | ||||||||||||||||||||||||
| 1988 | QPathClipper clipper(*this, p); | - | ||||||||||||||||||||||||
| 1989 | return clipper.contains(); | - | ||||||||||||||||||||||||
| 1990 | } | - | ||||||||||||||||||||||||
| 1991 | - | |||||||||||||||||||||||||
| 1992 | void QPainterPath::setDirty(bool dirty) | - | ||||||||||||||||||||||||
| 1993 | { | - | ||||||||||||||||||||||||
| 1994 | d_func()->dirtyBounds = dirty; | - | ||||||||||||||||||||||||
| 1995 | d_func()->dirtyControlBounds = dirty; | - | ||||||||||||||||||||||||
| 1996 | delete d_func()->pathConverter; | - | ||||||||||||||||||||||||
| 1997 | d_func()->pathConverter = 0; | - | ||||||||||||||||||||||||
| 1998 | d_func()->convex = false; | - | ||||||||||||||||||||||||
| 1999 | } | - | ||||||||||||||||||||||||
| 2000 | - | |||||||||||||||||||||||||
| 2001 | void QPainterPath::computeBoundingRect() const | - | ||||||||||||||||||||||||
| 2002 | { | - | ||||||||||||||||||||||||
| 2003 | QPainterPathData *d = d_func(); | - | ||||||||||||||||||||||||
| 2004 | d->dirtyBounds = false; | - | ||||||||||||||||||||||||
| 2005 | if (!d_ptr) { | - | ||||||||||||||||||||||||
| 2006 | d->bounds = QRect(); | - | ||||||||||||||||||||||||
| 2007 | return; | - | ||||||||||||||||||||||||
| 2008 | } | - | ||||||||||||||||||||||||
| 2009 | - | |||||||||||||||||||||||||
| 2010 | qreal minx, maxx, miny, maxy; | - | ||||||||||||||||||||||||
| 2011 | minx = maxx = d->elements.at(0).x; | - | ||||||||||||||||||||||||
| 2012 | miny = maxy = d->elements.at(0).y; | - | ||||||||||||||||||||||||
| 2013 | for (int i=1; i<d->elements.size(); ++i) { | - | ||||||||||||||||||||||||
| 2014 | const Element &e = d->elements.at(i); | - | ||||||||||||||||||||||||
| 2015 | - | |||||||||||||||||||||||||
| 2016 | switch (e.type) { | - | ||||||||||||||||||||||||
| 2017 | case MoveToElement: | - | ||||||||||||||||||||||||
| 2018 | case LineToElement: | - | ||||||||||||||||||||||||
| 2019 | if (e.x > maxx) maxx = e.x; | - | ||||||||||||||||||||||||
| 2020 | else if (e.x < minx) minx = e.x; | - | ||||||||||||||||||||||||
| 2021 | if (e.y > maxy) maxy = e.y; | - | ||||||||||||||||||||||||
| 2022 | else if (e.y < miny) miny = e.y; | - | ||||||||||||||||||||||||
| 2023 | break; | - | ||||||||||||||||||||||||
| 2024 | case CurveToElement: | - | ||||||||||||||||||||||||
| 2025 | { | - | ||||||||||||||||||||||||
| 2026 | QBezier b = QBezier::fromPoints(d->elements.at(i-1), | - | ||||||||||||||||||||||||
| 2027 | e, | - | ||||||||||||||||||||||||
| 2028 | d->elements.at(i+1), | - | ||||||||||||||||||||||||
| 2029 | d->elements.at(i+2)); | - | ||||||||||||||||||||||||
| 2030 | QRectF r = qt_painterpath_bezier_extrema(b); | - | ||||||||||||||||||||||||
| 2031 | qreal right = r.right(); | - | ||||||||||||||||||||||||
| 2032 | qreal bottom = r.bottom(); | - | ||||||||||||||||||||||||
| 2033 | if (r.x() < minx) minx = r.x(); | - | ||||||||||||||||||||||||
| 2034 | if (right > maxx) maxx = right; | - | ||||||||||||||||||||||||
| 2035 | if (r.y() < miny) miny = r.y(); | - | ||||||||||||||||||||||||
| 2036 | if (bottom > maxy) maxy = bottom; | - | ||||||||||||||||||||||||
| 2037 | i += 2; | - | ||||||||||||||||||||||||
| 2038 | } | - | ||||||||||||||||||||||||
| 2039 | break; | - | ||||||||||||||||||||||||
| 2040 | default: | - | ||||||||||||||||||||||||
| 2041 | break; | - | ||||||||||||||||||||||||
| 2042 | } | - | ||||||||||||||||||||||||
| 2043 | } | - | ||||||||||||||||||||||||
| 2044 | d->bounds = QRectF(minx, miny, maxx - minx, maxy - miny); | - | ||||||||||||||||||||||||
| 2045 | } | - | ||||||||||||||||||||||||
| 2046 | - | |||||||||||||||||||||||||
| 2047 | - | |||||||||||||||||||||||||
| 2048 | void QPainterPath::computeControlPointRect() const | - | ||||||||||||||||||||||||
| 2049 | { | - | ||||||||||||||||||||||||
| 2050 | QPainterPathData *d = d_func(); | - | ||||||||||||||||||||||||
| 2051 | d->dirtyControlBounds = false; | - | ||||||||||||||||||||||||
| 2052 | if (!d_ptr) { | - | ||||||||||||||||||||||||
| 2053 | d->controlBounds = QRect(); | - | ||||||||||||||||||||||||
| 2054 | return; | - | ||||||||||||||||||||||||
| 2055 | } | - | ||||||||||||||||||||||||
| 2056 | - | |||||||||||||||||||||||||
| 2057 | qreal minx, maxx, miny, maxy; | - | ||||||||||||||||||||||||
| 2058 | minx = maxx = d->elements.at(0).x; | - | ||||||||||||||||||||||||
| 2059 | miny = maxy = d->elements.at(0).y; | - | ||||||||||||||||||||||||
| 2060 | for (int i=1; i<d->elements.size(); ++i) { | - | ||||||||||||||||||||||||
| 2061 | const Element &e = d->elements.at(i); | - | ||||||||||||||||||||||||
| 2062 | if (e.x > maxx) maxx = e.x; | - | ||||||||||||||||||||||||
| 2063 | else if (e.x < minx) minx = e.x; | - | ||||||||||||||||||||||||
| 2064 | if (e.y > maxy) maxy = e.y; | - | ||||||||||||||||||||||||
| 2065 | else if (e.y < miny) miny = e.y; | - | ||||||||||||||||||||||||
| 2066 | } | - | ||||||||||||||||||||||||
| 2067 | d->controlBounds = QRectF(minx, miny, maxx - minx, maxy - miny); | - | ||||||||||||||||||||||||
| 2068 | } | - | ||||||||||||||||||||||||
| 2069 | - | |||||||||||||||||||||||||
| 2070 | - | |||||||||||||||||||||||||
| 2071 | QDebug operator<<(QDebug s, const QPainterPath &p) | - | ||||||||||||||||||||||||
| 2072 | { | - | ||||||||||||||||||||||||
| 2073 | s.nospace() << "QPainterPath: Element count=" << p.elementCount() << endl; | - | ||||||||||||||||||||||||
| 2074 | const char *types[] = {"MoveTo", "LineTo", "CurveTo", "CurveToData"}; | - | ||||||||||||||||||||||||
| 2075 | for (int i=0; i<p.elementCount(); ++i) { | - | ||||||||||||||||||||||||
| 2076 | s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ')' << endl; | - | ||||||||||||||||||||||||
| 2077 | - | |||||||||||||||||||||||||
| 2078 | } | - | ||||||||||||||||||||||||
| 2079 | return s; | - | ||||||||||||||||||||||||
| 2080 | } | - | ||||||||||||||||||||||||
| 2081 | - | |||||||||||||||||||||||||
| 2082 | - | |||||||||||||||||||||||||
| 2083 | - | |||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |