Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qpainterpath.h" | - |
41 | #include "qpainterpath_p.h" | - |
42 | | - |
43 | #include <qbitmap.h> | - |
44 | #include <qdebug.h> | - |
45 | #include <qiodevice.h> | - |
46 | #include <qlist.h> | - |
47 | #include <qmatrix.h> | - |
48 | #include <qpen.h> | - |
49 | #include <qpolygon.h> | - |
50 | #include <qtextlayout.h> | - |
51 | #include <qvarlengtharray.h> | - |
52 | #include <qmath.h> | - |
53 | | - |
54 | #include <private/qbezier_p.h> | - |
55 | #include <private/qfontengine_p.h> | - |
56 | #include <private/qnumeric_p.h> | - |
57 | #include <private/qobject_p.h> | - |
58 | #include <private/qpathclipper_p.h> | - |
59 | #include <private/qstroker_p.h> | - |
60 | #include <private/qtextengine_p.h> | - |
61 | | - |
62 | #include <limits.h> | - |
63 | | - |
64 | #if 0 | - |
65 | #include <performance.h> | - |
66 | #else | - |
67 | #define PM_INIT | - |
68 | #define PM_MEASURE(x) | - |
69 | #define PM_DISPLAY | - |
70 | #endif | - |
71 | | - |
72 | QT_BEGIN_NAMESPACE | - |
73 | | - |
74 | struct QPainterPathPrivateDeleter | - |
75 | { | - |
76 | static inline void cleanup(QPainterPathPrivate *d) | - |
77 | { | - |
78 | | - |
79 | | - |
80 | if (d && !d->ref.deref()) | - |
81 | delete static_cast<QPainterPathData *>(d); | - |
82 | } | - |
83 | }; | - |
84 | | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | | - |
92 | | - |
93 | QPainterPath qt_stroke_dash(const QPainterPath &path, qreal *dashes, int dashCount); | - |
94 | | - |
95 | void qt_find_ellipse_coords(const QRectF &r, qreal angle, qreal length, | - |
96 | QPointF* startPoint, QPointF *endPoint) | - |
97 | { | - |
98 | if (r.isNull()) { | - |
99 | if (startPoint) | - |
100 | *startPoint = QPointF(); | - |
101 | if (endPoint) | - |
102 | *endPoint = QPointF(); | - |
103 | return; | - |
104 | } | - |
105 | | - |
106 | qreal w2 = r.width() / 2; | - |
107 | qreal h2 = r.height() / 2; | - |
108 | | - |
109 | qreal angles[2] = { angle, angle + length }; | - |
110 | QPointF *points[2] = { startPoint, endPoint }; | - |
111 | | - |
112 | for (int i = 0; i < 2; ++i) { | - |
113 | if (!points[i]) | - |
114 | continue; | - |
115 | | - |
116 | qreal theta = angles[i] - 360 * qFloor(angles[i] / 360); | - |
117 | qreal t = theta / 90; | - |
118 | | - |
119 | int quadrant = int(t); | - |
120 | t -= quadrant; | - |
121 | | - |
122 | t = qt_t_for_arc_angle(90 * t); | - |
123 | | - |
124 | | - |
125 | if (quadrant & 1) | - |
126 | t = 1 - t; | - |
127 | | - |
128 | qreal a, b, c, d; | - |
129 | QBezier::coefficients(t, a, b, c, d); | - |
130 | QPointF p(a + b + c*QT_PATH_KAPPA, d + c + b*QT_PATH_KAPPA); | - |
131 | | - |
132 | | - |
133 | if (quadrant == 1 || quadrant == 2) | - |
134 | p.rx() = -p.x(); | - |
135 | | - |
136 | | - |
137 | if (quadrant == 0 || quadrant == 1) | - |
138 | p.ry() = -p.y(); | - |
139 | | - |
140 | *points[i] = r.center() + QPointF(w2 * p.x(), h2 * p.y()); | - |
141 | } | - |
142 | } | - |
143 | | - |
144 | #ifdef QPP_DEBUG | - |
145 | static void qt_debug_path(const QPainterPath &path) | - |
146 | { | - |
147 | const char *names[] = { | - |
148 | "MoveTo ", | - |
149 | "LineTo ", | - |
150 | "CurveTo ", | - |
151 | "CurveToData" | - |
152 | }; | - |
153 | | - |
154 | printf("\nQPainterPath: elementCount=%d\n", path.elementCount()); | - |
155 | for (int i=0; i<path.elementCount(); ++i) { | - |
156 | const QPainterPath::Element &e = path.elementAt(i); | - |
157 | Q_ASSERT(e.type >= 0 && e.type <= QPainterPath::CurveToDataElement); | - |
158 | printf(" - %3d:: %s, (%.2f, %.2f)\n", i, names[e.type], e.x, e.y); | - |
159 | } | - |
160 | } | - |
161 | #endif | - |
162 | | - |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | | - |
169 | | - |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | | - |
179 | | - |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
184 | | - |
185 | | - |
186 | | - |
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | | - |
193 | | - |
194 | | - |
195 | | - |
196 | | - |
197 | | - |
198 | | - |
199 | | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | | - |
206 | | - |
207 | | - |
208 | | - |
209 | | - |
210 | | - |
211 | | - |
212 | | - |
213 | | - |
214 | | - |
215 | | - |
216 | | - |
217 | | - |
218 | | - |
219 | | - |
220 | | - |
221 | | - |
222 | | - |
223 | | - |
224 | | - |
225 | | - |
226 | | - |
227 | | - |
228 | | - |
229 | | - |
230 | | - |
231 | | - |
232 | | - |
233 | | - |
234 | | - |
235 | | - |
236 | | - |
237 | | - |
238 | | - |
239 | | - |
240 | | - |
241 | | - |
242 | | - |
243 | | - |
244 | | - |
245 | | - |
246 | | - |
247 | | - |
248 | | - |
249 | | - |
250 | | - |
251 | | - |
252 | | - |
253 | | - |
254 | | - |
255 | | - |
256 | | - |
257 | | - |
258 | | - |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | | - |
266 | | - |
267 | | - |
268 | | - |
269 | | - |
270 | | - |
271 | | - |
272 | | - |
273 | | - |
274 | | - |
275 | | - |
276 | | - |
277 | | - |
278 | | - |
279 | | - |
280 | | - |
281 | | - |
282 | | - |
283 | | - |
284 | | - |
285 | | - |
286 | | - |
287 | | - |
288 | | - |
289 | | - |
290 | | - |
291 | | - |
292 | | - |
293 | | - |
294 | | - |
295 | | - |
296 | | - |
297 | | - |
298 | | - |
299 | | - |
300 | | - |
301 | | - |
302 | | - |
303 | | - |
304 | | - |
305 | | - |
306 | | - |
307 | | - |
308 | | - |
309 | | - |
310 | | - |
311 | | - |
312 | | - |
313 | | - |
314 | | - |
315 | | - |
316 | | - |
317 | | - |
318 | | - |
319 | | - |
320 | | - |
321 | | - |
322 | | - |
323 | | - |
324 | | - |
325 | | - |
326 | | - |
327 | | - |
328 | | - |
329 | | - |
330 | | - |
331 | | - |
332 | | - |
333 | | - |
334 | | - |
335 | | - |
336 | | - |
337 | | - |
338 | | - |
339 | | - |
340 | | - |
341 | | - |
342 | | - |
343 | | - |
344 | | - |
345 | | - |
346 | | - |
347 | | - |
348 | | - |
349 | | - |
350 | | - |
351 | | - |
352 | | - |
353 | | - |
354 | | - |
355 | | - |
356 | | - |
357 | | - |
358 | | - |
359 | | - |
360 | | - |
361 | | - |
362 | | - |
363 | | - |
364 | | - |
365 | | - |
366 | | - |
367 | | - |
368 | | - |
369 | | - |
370 | | - |
371 | | - |
372 | | - |
373 | | - |
374 | | - |
375 | | - |
376 | | - |
377 | | - |
378 | | - |
379 | | - |
380 | | - |
381 | | - |
382 | | - |
383 | | - |
384 | | - |
385 | | - |
386 | | - |
387 | | - |
388 | | - |
389 | | - |
390 | | - |
391 | | - |
392 | | - |
393 | | - |
394 | | - |
395 | | - |
396 | | - |
397 | | - |
398 | | - |
399 | | - |
400 | | - |
401 | | - |
402 | | - |
403 | | - |
404 | | - |
405 | | - |
406 | | - |
407 | | - |
408 | | - |
409 | | - |
410 | | - |
411 | | - |
412 | | - |
413 | | - |
414 | | - |
415 | | - |
416 | | - |
417 | | - |
418 | | - |
419 | | - |
420 | | - |
421 | | - |
422 | | - |
423 | | - |
424 | | - |
425 | | - |
426 | | - |
427 | | - |
428 | | - |
429 | | - |
430 | | - |
431 | | - |
432 | | - |
433 | | - |
434 | | - |
435 | | - |
436 | | - |
437 | | - |
438 | | - |
439 | | - |
440 | | - |
441 | | - |
442 | | - |
443 | | - |
444 | | - |
445 | | - |
446 | | - |
447 | | - |
448 | | - |
449 | | - |
450 | | - |
451 | | - |
452 | | - |
453 | | - |
454 | | - |
455 | | - |
456 | | - |
457 | | - |
458 | | - |
459 | | - |
460 | | - |
461 | | - |
462 | | - |
463 | | - |
464 | | - |
465 | | - |
466 | | - |
467 | | - |
468 | | - |
469 | | - |
470 | | - |
471 | | - |
472 | | - |
473 | | - |
474 | | - |
475 | | - |
476 | | - |
477 | | - |
478 | | - |
479 | | - |
480 | | - |
481 | int QPainterPath::elementCount() const | - |
482 | { | - |
483 | return d_ptr ? d_ptr->elements.size() : 0; | - |
484 | } | - |
485 | | - |
486 | | - |
487 | | - |
488 | | - |
489 | | - |
490 | | - |
491 | | - |
492 | | - |
493 | | - |
494 | QPainterPath::Element QPainterPath::elementAt(int i) const | - |
495 | { | - |
496 | Q_ASSERT(d_ptr); | - |
497 | Q_ASSERT(i >= 0 && i < elementCount()); | - |
498 | return d_ptr->elements.at(i); | - |
499 | } | - |
500 | | - |
501 | | - |
502 | | - |
503 | | - |
504 | | - |
505 | | - |
506 | | - |
507 | | - |
508 | | - |
509 | void QPainterPath::setElementPositionAt(int i, qreal x, qreal y) | - |
510 | { | - |
511 | Q_ASSERT(d_ptr); | - |
512 | Q_ASSERT(i >= 0 && i < elementCount()); | - |
513 | detach(); | - |
514 | QPainterPath::Element &e = d_ptr->elements[i]; | - |
515 | e.x = x; | - |
516 | e.y = y; | - |
517 | } | - |
518 | | - |
519 | | - |
520 | | - |
521 | | - |
522 | | - |
523 | | - |
524 | | - |
525 | | - |
526 | | - |
527 | | - |
528 | | - |
529 | | - |
530 | QPainterPath::QPainterPath() Q_DECL_NOEXCEPT | - |
531 | : d_ptr(0) | - |
532 | { | - |
533 | } never executed: end of block | 0 |
534 | | - |
535 | | - |
536 | | - |
537 | | - |
538 | | - |
539 | | - |
540 | | - |
541 | | - |
542 | QPainterPath::QPainterPath(const QPainterPath &other) | - |
543 | : d_ptr(other.d_ptr.data()) | - |
544 | { | - |
545 | if (d_ptr) | - |
546 | d_ptr->ref.ref(); | - |
547 | } | - |
548 | | - |
549 | | - |
550 | | - |
551 | | - |
552 | | - |
553 | | - |
554 | QPainterPath::QPainterPath(const QPointF &startPoint) | - |
555 | : d_ptr(new QPainterPathData) | - |
556 | { | - |
557 | Element e = { startPoint.x(), startPoint.y(), MoveToElement }; | - |
558 | d_func()->elements << e; | - |
559 | } | - |
560 | | - |
561 | void QPainterPath::detach() | - |
562 | { | - |
563 | if (d_ptr->ref.load() != 1) | - |
564 | detach_helper(); | - |
565 | setDirty(true); | - |
566 | } | - |
567 | | - |
568 | | - |
569 | | - |
570 | | - |
571 | void QPainterPath::detach_helper() | - |
572 | { | - |
573 | QPainterPathPrivate *data = new QPainterPathData(*d_func()); | - |
574 | d_ptr.reset(data); | - |
575 | } | - |
576 | | - |
577 | | - |
578 | | - |
579 | | - |
580 | void QPainterPath::ensureData_helper() | - |
581 | { | - |
582 | QPainterPathPrivate *data = new QPainterPathData; | - |
583 | data->elements.reserve(16); | - |
584 | QPainterPath::Element e = { 0, 0, QPainterPath::MoveToElement }; | - |
585 | data->elements << e; | - |
586 | d_ptr.reset(data); | - |
587 | Q_ASSERT(d_ptr != 0); | - |
588 | } | - |
589 | | - |
590 | | - |
591 | | - |
592 | | - |
593 | | - |
594 | | - |
595 | | - |
596 | | - |
597 | QPainterPath &QPainterPath::operator=(const QPainterPath &other) | - |
598 | { | - |
599 | if (other.d_func() != d_func()) { | - |
600 | QPainterPathPrivate *data = other.d_func(); | - |
601 | if (data) | - |
602 | data->ref.ref(); | - |
603 | d_ptr.reset(data); | - |
604 | } | - |
605 | return *this; | - |
606 | } | - |
607 | | - |
608 | | - |
609 | | - |
610 | | - |
611 | | - |
612 | | - |
613 | | - |
614 | | - |
615 | | - |
616 | | - |
617 | | - |
618 | | - |
619 | | - |
620 | | - |
621 | | - |
622 | | - |
623 | | - |
624 | | - |
625 | | - |
626 | | - |
627 | QPainterPath::~QPainterPath() | - |
628 | { | - |
629 | } | - |
630 | | - |
631 | | - |
632 | | - |
633 | | - |
634 | | - |
635 | | - |
636 | | - |
637 | | - |
638 | | - |
639 | | - |
640 | | - |
641 | | - |
642 | void QPainterPath::closeSubpath() | - |
643 | { | - |
644 | #ifdef QPP_DEBUG | - |
645 | printf("QPainterPath::closeSubpath()\n"); | - |
646 | #endif | - |
647 | if (isEmpty()) | - |
648 | return; | - |
649 | detach(); | - |
650 | | - |
651 | d_func()->close(); | - |
652 | } | - |
653 | | - |
654 | | - |
655 | | - |
656 | | - |
657 | | - |
658 | | - |
659 | | - |
660 | | - |
661 | | - |
662 | | - |
663 | | - |
664 | | - |
665 | | - |
666 | | - |
667 | | - |
668 | | - |
669 | | - |
670 | | - |
671 | | - |
672 | void QPainterPath::moveTo(const QPointF &p) | - |
673 | { | - |
674 | #ifdef QPP_DEBUG | - |
675 | printf("QPainterPath::moveTo() (%.2f,%.2f)\n", p.x(), p.y()); | - |
676 | #endif | - |
677 | | - |
678 | if (!qt_is_finite(p.x()) || !qt_is_finite(p.y())) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
679 | #ifndef QT_NO_DEBUG | - |
680 | qWarning("QPainterPath::moveTo: Adding point where x or y is NaN or Inf, ignoring call"); | - |
681 | #endif | - |
682 | return; never executed: return; | 0 |
683 | } | - |
684 | | - |
685 | ensureData(); | - |
686 | detach(); | - |
687 | | - |
688 | QPainterPathData *d = d_func(); | - |
689 | Q_ASSERT(!d->elements.isEmpty()); | - |
690 | | - |
691 | d->require_moveTo = false; | - |
692 | | - |
693 | if (d->elements.lastconstLast().type == MoveToElement) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
694 | d->elements.last().x = p.x(); | - |
695 | d->elements.last().y = p.y(); | - |
696 | } else { never executed: end of block | 0 |
697 | Element elm = { p.x(), p.y(), MoveToElement }; | - |
698 | d->elements.append(elm); | - |
699 | } never executed: end of block | 0 |
700 | d->cStart = d->elements.size() - 1; | - |
701 | } never executed: end of block | 0 |
702 | | - |
703 | | - |
704 | | - |
705 | | - |
706 | | - |
707 | | - |
708 | | - |
709 | | - |
710 | | - |
711 | | - |
712 | | - |
713 | | - |
714 | | - |
715 | | - |
716 | | - |
717 | | - |
718 | | - |
719 | | - |
720 | | - |
721 | | - |
722 | void QPainterPath::lineTo(const QPointF &p) | - |
723 | { | - |
724 | #ifdef QPP_DEBUG | - |
725 | printf("QPainterPath::lineTo() (%.2f,%.2f)\n", p.x(), p.y()); | - |
726 | #endif | - |
727 | | - |
728 | if (!qt_is_finite(p.x()) || !qt_is_finite(p.y())) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
729 | #ifndef QT_NO_DEBUG | - |
730 | qWarning("QPainterPath::lineTo: Adding point where x or y is NaN or Inf, ignoring call"); | - |
731 | #endif | - |
732 | return; never executed: return; | 0 |
733 | } | - |
734 | | - |
735 | ensureData(); | - |
736 | detach(); | - |
737 | | - |
738 | QPainterPathData *d = d_func(); | - |
739 | Q_ASSERT(!d->elements.isEmpty()); | - |
740 | d->maybeMoveTo(); | - |
741 | if (p == QPointF(d->elements.lastconstLast()))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
742 | return; never executed: return; | 0 |
743 | Element elm = { p.x(), p.y(), LineToElement }; | - |
744 | d->elements.append(elm); | - |
745 | | - |
746 | d->convex = d->elements.size() == 3 || (d->elements.size() == 4 && d->isClosed());TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
747 | } never executed: end of block | 0 |
748 | | - |
749 | | - |
750 | | - |
751 | | - |
752 | | - |
753 | | - |
754 | | - |
755 | | - |
756 | | - |
757 | | - |
758 | | - |
759 | | - |
760 | | - |
761 | | - |
762 | | - |
763 | | - |
764 | | - |
765 | | - |
766 | | - |
767 | | - |
768 | | - |
769 | | - |
770 | | - |
771 | | - |
772 | | - |
773 | | - |
774 | | - |
775 | | - |
776 | | - |
777 | | - |
778 | | - |
779 | | - |
780 | void QPainterPath::cubicTo(const QPointF &c1, const QPointF &c2, const QPointF &e) | - |
781 | { | - |
782 | #ifdef QPP_DEBUG | - |
783 | printf("QPainterPath::cubicTo() (%.2f,%.2f), (%.2f,%.2f), (%.2f,%.2f)\n", | - |
784 | c1.x(), c1.y(), c2.x(), c2.y(), e.x(), e.y()); | - |
785 | #endif | - |
786 | | - |
787 | if (!qt_is_finite(c1.x()) || !qt_is_finite(c1.y()) || !qt_is_finite(c2.x()) || !qt_is_finite(c2.y())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
788 | || !qt_is_finite(e.x()) || !qt_is_finite(e.y())) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
789 | #ifndef QT_NO_DEBUG | - |
790 | qWarning("QPainterPath::cubicTo: Adding point where x or y is NaN or Inf, ignoring call"); | - |
791 | #endif | - |
792 | return; never executed: return; | 0 |
793 | } | - |
794 | | - |
795 | ensureData(); | - |
796 | detach(); | - |
797 | | - |
798 | QPainterPathData *d = d_func(); | - |
799 | Q_ASSERT(!d->elements.isEmpty()); | - |
800 | | - |
801 | | - |
802 | | - |
803 | | - |
804 | if (d->elements.lastconstLast() == c1 && c1 == c2 && c2 == e)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
805 | return; never executed: return; | 0 |
806 | | - |
807 | d->maybeMoveTo(); | - |
808 | | - |
809 | Element ce1 = { c1.x(), c1.y(), CurveToElement }; | - |
810 | Element ce2 = { c2.x(), c2.y(), CurveToDataElement }; | - |
811 | Element ee = { e.x(), e.y(), CurveToDataElement }; | - |
812 | d->elements << ce1 << ce2 << ee; | - |
813 | } never executed: end of block | 0 |
814 | | - |
815 | | - |
816 | | - |
817 | | - |
818 | | - |
819 | | - |
820 | | - |
821 | | - |
822 | | - |
823 | | - |
824 | | - |
825 | | - |
826 | | - |
827 | | - |
828 | | - |
829 | | - |
830 | | - |
831 | | - |
832 | | - |
833 | | - |
834 | | - |
835 | | - |
836 | | - |
837 | void QPainterPath::quadTo(const QPointF &c, const QPointF &e) | - |
838 | { | - |
839 | #ifdef QPP_DEBUG | - |
840 | printf("QPainterPath::quadTo() (%.2f,%.2f), (%.2f,%.2f)\n", | - |
841 | c.x(), c.y(), e.x(), e.y()); | - |
842 | #endif | - |
843 | | - |
844 | if (!qt_is_finite(c.x()) || !qt_is_finite(c.y()) || !qt_is_finite(e.x()) || !qt_is_finite(e.y())) { | - |
845 | #ifndef QT_NO_DEBUG | - |
846 | qWarning("QPainterPath::quadTo: Adding point where x or y is NaN or Inf, ignoring call"); | - |
847 | #endif | - |
848 | return; | - |
849 | } | - |
850 | | - |
851 | ensureData(); | - |
852 | detach(); | - |
853 | | - |
854 | Q_D(QPainterPath); | - |
855 | Q_ASSERT(!d->elements.isEmpty()); | - |
856 | const QPainterPath::Element &elm = d->elements.at(elementCount()-1); | - |
857 | QPointF prev(elm.x, elm.y); | - |
858 | | - |
859 | | - |
860 | | - |
861 | if (prev == c && c == e) | - |
862 | return; | - |
863 | | - |
864 | QPointF c1((prev.x() + 2*c.x()) / 3, (prev.y() + 2*c.y()) / 3); | - |
865 | QPointF c2((e.x() + 2*c.x()) / 3, (e.y() + 2*c.y()) / 3); | - |
866 | cubicTo(c1, c2, e); | - |
867 | } | - |
868 | | - |
869 | | - |
870 | | - |
871 | | - |
872 | | - |
873 | | - |
874 | | - |
875 | | - |
876 | | - |
877 | | - |
878 | | - |
879 | | - |
880 | | - |
881 | | - |
882 | | - |
883 | | - |
884 | | - |
885 | | - |
886 | | - |
887 | | - |
888 | | - |
889 | | - |
890 | | - |
891 | | - |
892 | | - |
893 | | - |
894 | | - |
895 | | - |
896 | | - |
897 | | - |
898 | | - |
899 | | - |
900 | | - |
901 | | - |
902 | | - |
903 | | - |
904 | | - |
905 | | - |
906 | | - |
907 | | - |
908 | void QPainterPath::arcTo(const QRectF &rect, qreal startAngle, qreal sweepLength) | - |
909 | { | - |
910 | #ifdef QPP_DEBUG | - |
911 | printf("QPainterPath::arcTo() (%.2f, %.2f, %.2f, %.2f, angle=%.2f, sweep=%.2f\n", | - |
912 | rect.x(), rect.y(), rect.width(), rect.height(), startAngle, sweepLength); | - |
913 | #endif | - |
914 | | - |
915 | if ((!qt_is_finite(rect.x()) && !qt_is_finite(rect.y())) || !qt_is_finite(rect.width()) || !qt_is_finite(rect.height()) | - |
916 | || !qt_is_finite(startAngle) || !qt_is_finite(sweepLength)) { | - |
917 | #ifndef QT_NO_DEBUG | - |
918 | qWarning("QPainterPath::arcTo: Adding arc where a parameter is NaN or Inf, ignoring call"); | - |
919 | #endif | - |
920 | return; | - |
921 | } | - |
922 | | - |
923 | if (rect.isNull()) | - |
924 | return; | - |
925 | | - |
926 | ensureData(); | - |
927 | detach(); | - |
928 | | - |
929 | int point_count; | - |
930 | QPointF pts[15]; | - |
931 | QPointF curve_start = qt_curves_for_arc(rect, startAngle, sweepLength, pts, &point_count); | - |
932 | | - |
933 | lineTo(curve_start); | - |
934 | for (int i=0; i<point_count; i+=3) { | - |
935 | cubicTo(pts[i].x(), pts[i].y(), | - |
936 | pts[i+1].x(), pts[i+1].y(), | - |
937 | pts[i+2].x(), pts[i+2].y()); | - |
938 | } | - |
939 | | - |
940 | } | - |
941 | | - |
942 | | - |
943 | | - |
944 | | - |
945 | | - |
946 | | - |
947 | | - |
948 | | - |
949 | | - |
950 | | - |
951 | | - |
952 | | - |
953 | | - |
954 | | - |
955 | | - |
956 | | - |
957 | | - |
958 | | - |
959 | | - |
960 | | - |
961 | | - |
962 | | - |
963 | | - |
964 | | - |
965 | | - |
966 | void QPainterPath::arcMoveTo(const QRectF &rect, qreal angle) | - |
967 | { | - |
968 | if (rect.isNull()) | - |
969 | return; | - |
970 | | - |
971 | QPointF pt; | - |
972 | qt_find_ellipse_coords(rect, angle, 0, &pt, 0); | - |
973 | moveTo(pt); | - |
974 | } | - |
975 | | - |
976 | | - |
977 | | - |
978 | | - |
979 | | - |
980 | | - |
981 | | - |
982 | | - |
983 | QPointF QPainterPath::currentPosition() const | - |
984 | { | - |
985 | return !d_ptr || d_func()->elements.isEmpty() never executed: return !d_ptr || d_func()->elements.isEmpty() ? QPointF() : QPointF(d_func()->elements.constLast().x, d_func()->elements.constLast().y); | 0 |
986 | ? QPointF() never executed: return !d_ptr || d_func()->elements.isEmpty() ? QPointF() : QPointF(d_func()->elements.constLast().x, d_func()->elements.constLast().y); | 0 |
987 | : 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 |
988 | } | - |
989 | | - |
990 | | - |
991 | | - |
992 | | - |
993 | | - |
994 | | - |
995 | | - |
996 | | - |
997 | | - |
998 | | - |
999 | | - |
1000 | | - |
1001 | | - |
1002 | | - |
1003 | | - |
1004 | | - |
1005 | | - |
1006 | | - |
1007 | | - |
1008 | | - |
1009 | | - |
1010 | | - |
1011 | | - |
1012 | | - |
1013 | | - |
1014 | | - |
1015 | | - |
1016 | | - |
1017 | | - |
1018 | | - |
1019 | void QPainterPath::addRect(const QRectF &r) | - |
1020 | { | - |
1021 | if (!qt_is_finite(r.x()) || !qt_is_finite(r.y()) || !qt_is_finite(r.width()) || !qt_is_finite(r.height())) { | - |
1022 | #ifndef QT_NO_DEBUG | - |
1023 | qWarning("QPainterPath::addRect: Adding rect where a parameter is NaN or Inf, ignoring call"); | - |
1024 | #endif | - |
1025 | return; | - |
1026 | } | - |
1027 | | - |
1028 | if (r.isNull()) | - |
1029 | return; | - |
1030 | | - |
1031 | ensureData(); | - |
1032 | detach(); | - |
1033 | | - |
1034 | bool first = d_func()->elements.size() < 2; | - |
1035 | | - |
1036 | d_func()->elements.reserve(d_func()->elements.size() + 5); | - |
1037 | moveTo(r.x(), r.y()); | - |
1038 | | - |
1039 | Element l1 = { r.x() + r.width(), r.y(), LineToElement }; | - |
1040 | Element l2 = { r.x() + r.width(), r.y() + r.height(), LineToElement }; | - |
1041 | Element l3 = { r.x(), r.y() + r.height(), LineToElement }; | - |
1042 | Element l4 = { r.x(), r.y(), LineToElement }; | - |
1043 | | - |
1044 | d_func()->elements << l1 << l2 << l3 << l4; | - |
1045 | d_func()->require_moveTo = true; | - |
1046 | d_func()->convex = first; | - |
1047 | } | - |
1048 | | - |
1049 | | - |
1050 | | - |
1051 | | - |
1052 | | - |
1053 | | - |
1054 | | - |
1055 | | - |
1056 | | - |
1057 | | - |
1058 | | - |
1059 | | - |
1060 | | - |
1061 | | - |
1062 | | - |
1063 | | - |
1064 | | - |
1065 | | - |
1066 | void QPainterPath::addPolygon(const QPolygonF &polygon) | - |
1067 | { | - |
1068 | if (polygon.isEmpty())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1069 | return; never executed: return; | 0 |
1070 | | - |
1071 | ensureData(); | - |
1072 | detach(); | - |
1073 | | - |
1074 | d_func()->elements.reserve(d_func()->elements.size() + polygon.size()); | - |
1075 | | - |
1076 | moveTo(polygon.firstconstFirst()); | - |
1077 | for (int i=1; i<polygon.size(); ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1078 | Element elm = { polygon.at(i).x(), polygon.at(i).y(), LineToElement }; | - |
1079 | d_func()->elements << elm; | - |
1080 | } never executed: end of block | 0 |
1081 | } never executed: end of block | 0 |
1082 | | - |
1083 | | - |
1084 | | - |
1085 | | - |
1086 | | - |
1087 | | - |
1088 | | - |
1089 | | - |
1090 | | - |
1091 | | - |
1092 | | - |
1093 | | - |
1094 | | - |
1095 | | - |
1096 | | - |
1097 | | - |
1098 | | - |
1099 | | - |
1100 | | - |
1101 | | - |
1102 | void QPainterPath::addEllipse(const QRectF &boundingRect) | - |
1103 | { | - |
1104 | if (!qt_is_finite(boundingRect.x()) || !qt_is_finite(boundingRect.y()) | - |
1105 | || !qt_is_finite(boundingRect.width()) || !qt_is_finite(boundingRect.height())) { | - |
1106 | #ifndef QT_NO_DEBUG | - |
1107 | qWarning("QPainterPath::addEllipse: Adding ellipse where a parameter is NaN or Inf, ignoring call"); | - |
1108 | #endif | - |
1109 | return; | - |
1110 | } | - |
1111 | | - |
1112 | if (boundingRect.isNull()) | - |
1113 | return; | - |
1114 | | - |
1115 | ensureData(); | - |
1116 | detach(); | - |
1117 | | - |
1118 | Q_D(QPainterPath); | - |
1119 | bool first = d_func()->elements.size() < 2; | - |
1120 | d->elements.reserve(d->elements.size() + 13); | - |
1121 | | - |
1122 | QPointF pts[12]; | - |
1123 | int point_count; | - |
1124 | QPointF start = qt_curves_for_arc(boundingRect, 0, -360, pts, &point_count); | - |
1125 | | - |
1126 | moveTo(start); | - |
1127 | cubicTo(pts[0], pts[1], pts[2]); | - |
1128 | cubicTo(pts[3], pts[4], pts[5]); | - |
1129 | cubicTo(pts[6], pts[7], pts[8]); | - |
1130 | cubicTo(pts[9], pts[10], pts[11]); | - |
1131 | d_func()->require_moveTo = true; | - |
1132 | | - |
1133 | d_func()->convex = first; | - |
1134 | } | - |
1135 | | - |
1136 | | - |
1137 | | - |
1138 | | - |
1139 | | - |
1140 | | - |
1141 | | - |
1142 | | - |
1143 | | - |
1144 | | - |
1145 | | - |
1146 | | - |
1147 | | - |
1148 | | - |
1149 | | - |
1150 | | - |
1151 | | - |
1152 | | - |
1153 | | - |
1154 | void QPainterPath::addText(const QPointF &point, const QFont &f, const QString &text) | - |
1155 | { | - |
1156 | if (text.isEmpty())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1157 | return; never executed: return; | 0 |
1158 | | - |
1159 | ensureData(); | - |
1160 | detach(); | - |
1161 | | - |
1162 | QTextLayout layout(text, f); | - |
1163 | layout.setCacheEnabled(true); | - |
1164 | QTextEngine *eng = layout.engine(); | - |
1165 | layout.beginLayout(); | - |
1166 | QTextLine line = layout.createLine(); | - |
1167 | Q_UNUSED(line); | - |
1168 | layout.endLayout(); | - |
1169 | const QScriptLine &sl = eng->lines[0]; | - |
1170 | if (!sl.length || !eng->layoutData)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1171 | return; never executed: return; | 0 |
1172 | | - |
1173 | int nItems = eng->layoutData->items.size(); | - |
1174 | | - |
1175 | qreal x(point.x()); | - |
1176 | qreal y(point.y()); | - |
1177 | | - |
1178 | QVarLengthArray<int> visualOrder(nItems); | - |
1179 | QVarLengthArray<uchar> levels(nItems); | - |
1180 | for (int i = 0; i < nItems; ++i)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1181 | levels[i] = eng->layoutData->items[.at(i].).analysis.bidiLevel; never executed: levels[i] = eng->layoutData->items.at(i).analysis.bidiLevel; | 0 |
1182 | QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data()); | - |
1183 | | - |
1184 | for (int i = 0; i < nItems; ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1185 | int item = visualOrder[i]; | - |
1186 | const QScriptItem &si = eng->layoutData->items[.at(item];); | - |
1187 | | - |
1188 | if (si.analysis.flags < QScriptAnalysis::TabOrObject) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1189 | QGlyphLayout glyphs = eng->shapedGlyphs(&si); | - |
1190 | QFontEngine *fe = f.d->engineForScript(si.analysis.script); | - |
1191 | Q_ASSERT(fe); | - |
1192 | fe->addOutlineToPath(x, y, glyphs, this, | - |
1193 | si.analysis.bidiLevel % 2 | - |
1194 | ? QTextItem::RenderFlags(QTextItem::RightToLeft) | - |
1195 | : QTextItem::RenderFlags(0)); | - |
1196 | | - |
1197 | const qreal lw = fe->lineThickness().toReal(); | - |
1198 | if (f.d->underline) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1199 | qreal pos = fe->underlinePosition().toReal(); | - |
1200 | addRect(x, y + pos, si.width.toReal(), lw); | - |
1201 | } never executed: end of block | 0 |
1202 | if (f.d->overline) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1203 | qreal pos = fe->ascent().toReal() + 1; | - |
1204 | addRect(x, y - pos, si.width.toReal(), lw); | - |
1205 | } never executed: end of block | 0 |
1206 | if (f.d->strikeOut) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1207 | qreal pos = fe->ascent().toReal() / 3; | - |
1208 | addRect(x, y - pos, si.width.toReal(), lw); | - |
1209 | } never executed: end of block | 0 |
1210 | } never executed: end of block | 0 |
1211 | x += si.width.toReal(); | - |
1212 | } never executed: end of block | 0 |
1213 | } never executed: end of block | 0 |
1214 | | - |
1215 | | - |
1216 | | - |
1217 | | - |
1218 | | - |
1219 | | - |
1220 | | - |
1221 | | - |
1222 | | - |
1223 | void QPainterPath::addPath(const QPainterPath &other) | - |
1224 | { | - |
1225 | if (other.isEmpty())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1226 | return; never executed: return; | 0 |
1227 | | - |
1228 | ensureData(); | - |
1229 | detach(); | - |
1230 | | - |
1231 | QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func()); | - |
1232 | | - |
1233 | if (d->elements.lastconstLast().type == MoveToElement)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1234 | d->elements.remove(d->elements.size()-1); never executed: d->elements.remove(d->elements.size()-1); | 0 |
1235 | | - |
1236 | | - |
1237 | int cStart = d->elements.size() + other.d_func()->cStart; | - |
1238 | d->elements += other.d_func()->elements; | - |
1239 | d->cStart = cStart; | - |
1240 | | - |
1241 | d->require_moveTo = other.d_func()->isClosed(); | - |
1242 | } never executed: end of block | 0 |
1243 | | - |
1244 | | - |
1245 | | - |
1246 | | - |
1247 | | - |
1248 | | - |
1249 | | - |
1250 | | - |
1251 | | - |
1252 | | - |
1253 | | - |
1254 | void QPainterPath::connectPath(const QPainterPath &other) | - |
1255 | { | - |
1256 | if (other.isEmpty())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1257 | return; never executed: return; | 0 |
1258 | | - |
1259 | ensureData(); | - |
1260 | detach(); | - |
1261 | | - |
1262 | QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func()); | - |
1263 | | - |
1264 | if (d->elements.lastconstLast().type == MoveToElement)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1265 | d->elements.remove(d->elements.size()-1); never executed: d->elements.remove(d->elements.size()-1); | 0 |
1266 | | - |
1267 | | - |
1268 | int cStart = d->elements.size() + other.d_func()->cStart; | - |
1269 | int first = d->elements.size(); | - |
1270 | d->elements += other.d_func()->elements; | - |
1271 | | - |
1272 | if (first != 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1273 | d->elements[first].type = LineToElement; never executed: d->elements[first].type = LineToElement; | 0 |
1274 | | - |
1275 | | - |
1276 | if (first > 0 && QPointF(d->elements[.at(first]))) == QPointF(d->elements[.at(first - 1]))))) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1277 | d->elements.remove(first--); | - |
1278 | --cStart; | - |
1279 | } never executed: end of block | 0 |
1280 | | - |
1281 | if (cStart != first)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1282 | d->cStart = cStart; never executed: d->cStart = cStart; | 0 |
1283 | } never executed: end of block | 0 |
1284 | | - |
1285 | | - |
1286 | | - |
1287 | | - |
1288 | | - |
1289 | | - |
1290 | | - |
1291 | | - |
1292 | void QPainterPath::addRegion(const QRegion ®ion) | - |
1293 | { | - |
1294 | ensureData(); | - |
1295 | detach(); | - |
1296 | | - |
1297 | QVector<QRect> rects = region.rects(); | - |
1298 | d_func()->elements.reserve(rects.size() * 5); | - |
1299 | for (int i=0; i<rects.size(); ++i) | - |
1300 | addRect(rects.at(i)); | - |
1301 | } | - |
1302 | | - |
1303 | | - |
1304 | | - |
1305 | | - |
1306 | | - |
1307 | | - |
1308 | | - |
1309 | Qt::FillRule QPainterPath::fillRule() const | - |
1310 | { | - |
1311 | return isEmpty() ? Qt::OddEvenFill : d_func()->fillRule; | - |
1312 | } | - |
1313 | | - |
1314 | | - |
1315 | | - |
1316 | | - |
1317 | | - |
1318 | | - |
1319 | | - |
1320 | | - |
1321 | | - |
1322 | | - |
1323 | | - |
1324 | | - |
1325 | | - |
1326 | | - |
1327 | | - |
1328 | | - |
1329 | | - |
1330 | | - |
1331 | void QPainterPath::setFillRule(Qt::FillRule fillRule) | - |
1332 | { | - |
1333 | ensureData(); | - |
1334 | if (d_func()->fillRule == fillRule) | - |
1335 | return; | - |
1336 | detach(); | - |
1337 | | - |
1338 | d_func()->fillRule = fillRule; | - |
1339 | } | - |
1340 | | - |
1341 | #define QT_BEZIER_A(bezier, coord) 3 * (-bezier.coord##1 \ | - |
1342 | + 3*bezier.coord##2 \ | - |
1343 | - 3*bezier.coord##3 \ | - |
1344 | +bezier.coord##4) | - |
1345 | | - |
1346 | #define QT_BEZIER_B(bezier, coord) 6 * (bezier.coord##1 \ | - |
1347 | - 2*bezier.coord##2 \ | - |
1348 | + bezier.coord##3) | - |
1349 | | - |
1350 | #define QT_BEZIER_C(bezier, coord) 3 * (- bezier.coord##1 \ | - |
1351 | + bezier.coord##2) | - |
1352 | | - |
1353 | #define QT_BEZIER_CHECK_T(bezier, t) \ | - |
1354 | if (t >= 0 && t <= 1) { \ | - |
1355 | QPointF p(b.pointAt(t)); \ | - |
1356 | if (p.x() < minx) minx = p.x(); \ | - |
1357 | else if (p.x() > maxx) maxx = p.x(); \ | - |
1358 | if (p.y() < miny) miny = p.y(); \ | - |
1359 | else if (p.y() > maxy) maxy = p.y(); \ | - |
1360 | } | - |
1361 | | - |
1362 | | - |
1363 | static QRectF qt_painterpath_bezier_extrema(const QBezier &b) | - |
1364 | { | - |
1365 | qreal minx, miny, maxx, maxy; | - |
1366 | | - |
1367 | | - |
1368 | if (b.x1 < b.x4) { | - |
1369 | minx = b.x1; | - |
1370 | maxx = b.x4; | - |
1371 | } else { | - |
1372 | minx = b.x4; | - |
1373 | maxx = b.x1; | - |
1374 | } | - |
1375 | if (b.y1 < b.y4) { | - |
1376 | miny = b.y1; | - |
1377 | maxy = b.y4; | - |
1378 | } else { | - |
1379 | miny = b.y4; | - |
1380 | maxy = b.y1; | - |
1381 | } | - |
1382 | | - |
1383 | | - |
1384 | { | - |
1385 | qreal ax = QT_BEZIER_A(b, x); | - |
1386 | qreal bx = QT_BEZIER_B(b, x); | - |
1387 | qreal cx = QT_BEZIER_C(b, x); | - |
1388 | | - |
1389 | if (qFuzzyIsNull(ax)) { | - |
1390 | | - |
1391 | | - |
1392 | if (!qFuzzyIsNull(bx)) { | - |
1393 | qreal t = -cx / bx; | - |
1394 | QT_BEZIER_CHECK_T(b, t); | - |
1395 | } | - |
1396 | | - |
1397 | } else { | - |
1398 | const qreal tx = bx * bx - 4 * ax * cx; | - |
1399 | | - |
1400 | if (tx >= 0) { | - |
1401 | qreal temp = qSqrt(tx); | - |
1402 | qreal rcp = 1 / (2 * ax); | - |
1403 | qreal t1 = (-bx + temp) * rcp; | - |
1404 | QT_BEZIER_CHECK_T(b, t1); | - |
1405 | | - |
1406 | qreal t2 = (-bx - temp) * rcp; | - |
1407 | QT_BEZIER_CHECK_T(b, t2); | - |
1408 | } | - |
1409 | } | - |
1410 | } | - |
1411 | | - |
1412 | | - |
1413 | { | - |
1414 | qreal ay = QT_BEZIER_A(b, y); | - |
1415 | qreal by = QT_BEZIER_B(b, y); | - |
1416 | qreal cy = QT_BEZIER_C(b, y); | - |
1417 | | - |
1418 | | - |
1419 | if (qFuzzyIsNull(ay)) { | - |
1420 | | - |
1421 | | - |
1422 | if (!qFuzzyIsNull(by)) { | - |
1423 | qreal t = -cy / by; | - |
1424 | QT_BEZIER_CHECK_T(b, t); | - |
1425 | } | - |
1426 | | - |
1427 | } else { | - |
1428 | const qreal ty = by * by - 4 * ay * cy; | - |
1429 | | - |
1430 | if (ty > 0) { | - |
1431 | qreal temp = qSqrt(ty); | - |
1432 | qreal rcp = 1 / (2 * ay); | - |
1433 | qreal t1 = (-by + temp) * rcp; | - |
1434 | QT_BEZIER_CHECK_T(b, t1); | - |
1435 | | - |
1436 | qreal t2 = (-by - temp) * rcp; | - |
1437 | QT_BEZIER_CHECK_T(b, t2); | - |
1438 | } | - |
1439 | } | - |
1440 | } | - |
1441 | return QRectF(minx, miny, maxx - minx, maxy - miny); | - |
1442 | } | - |
1443 | | - |
1444 | | - |
1445 | | - |
1446 | | - |
1447 | | - |
1448 | | - |
1449 | | - |
1450 | QRectF QPainterPath::boundingRect() const | - |
1451 | { | - |
1452 | if (!d_ptr) | - |
1453 | return QRectF(); | - |
1454 | QPainterPathData *d = d_func(); | - |
1455 | | - |
1456 | if (d->dirtyBounds) | - |
1457 | computeBoundingRect(); | - |
1458 | return d->bounds; | - |
1459 | } | - |
1460 | | - |
1461 | | - |
1462 | | - |
1463 | | - |
1464 | | - |
1465 | | - |
1466 | | - |
1467 | | - |
1468 | | - |
1469 | | - |
1470 | | - |
1471 | QRectF QPainterPath::controlPointRect() const | - |
1472 | { | - |
1473 | if (!d_ptr) | - |
1474 | return QRectF(); | - |
1475 | QPainterPathData *d = d_func(); | - |
1476 | | - |
1477 | if (d->dirtyControlBounds) | - |
1478 | computeControlPointRect(); | - |
1479 | return d->controlBounds; | - |
1480 | } | - |
1481 | | - |
1482 | | - |
1483 | | - |
1484 | | - |
1485 | | - |
1486 | | - |
1487 | | - |
1488 | | - |
1489 | | - |
1490 | | - |
1491 | | - |
1492 | bool QPainterPath::isEmpty() const | - |
1493 | { | - |
1494 | return !d_ptr || (d_ptr->elements.size() == 1 && d_ptr->elements.first().type == MoveToElement); | - |
1495 | } | - |
1496 | | - |
1497 | | - |
1498 | | - |
1499 | | - |
1500 | | - |
1501 | | - |
1502 | | - |
1503 | | - |
1504 | | - |
1505 | QPainterPath QPainterPath::toReversed() const | - |
1506 | { | - |
1507 | Q_D(const QPainterPath); | - |
1508 | QPainterPath rev; | - |
1509 | | - |
1510 | if (isEmpty()) { | - |
1511 | rev = *this; | - |
1512 | return rev; | - |
1513 | } | - |
1514 | | - |
1515 | rev.moveTo(d->elements.at(d->elements.size()-1).x, d->elements.at(d->elements.size()-1).y); | - |
1516 | | - |
1517 | for (int i=d->elements.size()-1; i>=1; --i) { | - |
1518 | const QPainterPath::Element &elm = d->elements.at(i); | - |
1519 | const QPainterPath::Element &prev = d->elements.at(i-1); | - |
1520 | switch (elm.type) { | - |
1521 | case LineToElement: | - |
1522 | rev.lineTo(prev.x, prev.y); | - |
1523 | break; | - |
1524 | case MoveToElement: | - |
1525 | rev.moveTo(prev.x, prev.y); | - |
1526 | break; | - |
1527 | case CurveToDataElement: | - |
1528 | { | - |
1529 | Q_ASSERT(i>=3); | - |
1530 | const QPainterPath::Element &cp1 = d->elements.at(i-2); | - |
1531 | const QPainterPath::Element &sp = d->elements.at(i-3); | - |
1532 | Q_ASSERT(prev.type == CurveToDataElement); | - |
1533 | Q_ASSERT(cp1.type == CurveToElement); | - |
1534 | rev.cubicTo(prev.x, prev.y, cp1.x, cp1.y, sp.x, sp.y); | - |
1535 | i -= 2; | - |
1536 | break; | - |
1537 | } | - |
1538 | default: | - |
1539 | Q_ASSERT(!"qt_reversed_path"); | - |
1540 | break; | - |
1541 | } | - |
1542 | } | - |
1543 | | - |
1544 | return rev; | - |
1545 | } | - |
1546 | | - |
1547 | | - |
1548 | | - |
1549 | | - |
1550 | | - |
1551 | | - |
1552 | | - |
1553 | | - |
1554 | | - |
1555 | | - |
1556 | | - |
1557 | | - |
1558 | | - |
1559 | QList<QPolygonF> QPainterPath::toSubpathPolygons(const QTransform &matrix) const | - |
1560 | { | - |
1561 | | - |
1562 | Q_D(const QPainterPath); | - |
1563 | QList<QPolygonF> flatCurves; | - |
1564 | if (isEmpty()) | - |
1565 | return flatCurves; | - |
1566 | | - |
1567 | QPolygonF current; | - |
1568 | for (int i=0; i<elementCount(); ++i) { | - |
1569 | const QPainterPath::Element &e = d->elements.at(i); | - |
1570 | switch (e.type) { | - |
1571 | case QPainterPath::MoveToElement: | - |
1572 | if (current.size() > 1) | - |
1573 | flatCurves += current; | - |
1574 | current.clear(); | - |
1575 | current.reserve(16); | - |
1576 | current += QPointF(e.x, e.y) * matrix; | - |
1577 | break; | - |
1578 | case QPainterPath::LineToElement: | - |
1579 | current += QPointF(e.x, e.y) * matrix; | - |
1580 | break; | - |
1581 | case QPainterPath::CurveToElement: { | - |
1582 | Q_ASSERT(d->elements.at(i+1).type == QPainterPath::CurveToDataElement); | - |
1583 | Q_ASSERT(d->elements.at(i+2).type == QPainterPath::CurveToDataElement); | - |
1584 | QBezier bezier = QBezier::fromPoints(QPointF(d->elements.at(i-1).x, d->elements.at(i-1).y) * matrix, | - |
1585 | QPointF(e.x, e.y) * matrix, | - |
1586 | QPointF(d->elements.at(i+1).x, d->elements.at(i+1).y) * matrix, | - |
1587 | QPointF(d->elements.at(i+2).x, d->elements.at(i+2).y) * matrix); | - |
1588 | bezier.addToPolygon(¤t); | - |
1589 | i+=2; | - |
1590 | break; | - |
1591 | } | - |
1592 | case QPainterPath::CurveToDataElement: | - |
1593 | Q_ASSERT(!"QPainterPath::toSubpathPolygons(), bad element type"); | - |
1594 | break; | - |
1595 | } | - |
1596 | } | - |
1597 | | - |
1598 | if (current.size()>1) | - |
1599 | flatCurves += current; | - |
1600 | | - |
1601 | return flatCurves; | - |
1602 | } | - |
1603 | | - |
1604 | | - |
1605 | | - |
1606 | | - |
1607 | QList<QPolygonF> QPainterPath::toSubpathPolygons(const QMatrix &matrix) const | - |
1608 | { | - |
1609 | return toSubpathPolygons(QTransform(matrix)); | - |
1610 | } | - |
1611 | | - |
1612 | | - |
1613 | | - |
1614 | | - |
1615 | | - |
1616 | | - |
1617 | | - |
1618 | | - |
1619 | | - |
1620 | | - |
1621 | | - |
1622 | | - |
1623 | | - |
1624 | | - |
1625 | | - |
1626 | | - |
1627 | | - |
1628 | | - |
1629 | | - |
1630 | | - |
1631 | | - |
1632 | | - |
1633 | | - |
1634 | QList<QPolygonF> QPainterPath::toFillPolygons(const QTransform &matrix) const | - |
1635 | { | - |
1636 | | - |
1637 | QList<QPolygonF> polys; | - |
1638 | | - |
1639 | QList<QPolygonF> subpaths = toSubpathPolygons(matrix); | - |
1640 | int count = subpaths.size(); | - |
1641 | | - |
1642 | if (count == 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1643 | return polys; never executed: return polys; | 0 |
1644 | | - |
1645 | QVector<QRectF> bounds; | - |
1646 | bounds.reserve(count); | - |
1647 | for (int i=0; i<count; ++i)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1648 | bounds += subpaths.at(i).boundingRect(); never executed: bounds += subpaths.at(i).boundingRect(); | 0 |
1649 | | - |
1650 | #ifdef QPP_FILLPOLYGONS_DEBUG | - |
1651 | printf("QPainterPath::toFillPolygons, subpathCount=%d\n", count); | - |
1652 | for (int i=0; i<bounds.size(); ++i) | - |
1653 | qDebug() << " bounds" << i << bounds.at(i); | - |
1654 | #endif | - |
1655 | | - |
1656 | QVector< QListQVector<int> > isects; | - |
1657 | isects.resize(count); | - |
1658 | | - |
1659 | | - |
1660 | for (int j=0; j<count; ++j) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1661 | if (subpaths.at(j).size() <= 2)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1662 | continue; never executed: continue; | 0 |
1663 | QRectF cbounds = bounds.at(j); | - |
1664 | for (int i=0; i<count; ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1665 | if (cbounds.intersects(bounds.at(i))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1666 | isects[j] << i; | - |
1667 | } never executed: end of block | 0 |
1668 | } never executed: end of block | 0 |
1669 | } never executed: end of block | 0 |
1670 | | - |
1671 | #ifdef QPP_FILLPOLYGONS_DEBUG | - |
1672 | printf("Intersections before flattening:\n"); | - |
1673 | for (int i = 0; i < count; ++i) { | - |
1674 | printf("%d: ", i); | - |
1675 | for (int j = 0; j < isects[i].size(); ++j) { | - |
1676 | printf("%d ", isects[i][j]); | - |
1677 | } | - |
1678 | printf("\n"); | - |
1679 | } | - |
1680 | #endif | - |
1681 | | - |
1682 | | - |
1683 | for (int i=0; i<count; ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1684 | const QListQVector<int> ¤t_isects = isects.at(i); | - |
1685 | for (int j=0; j<current_isects.size(); ++j) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1686 | int isect_j = current_isects.at(j); | - |
1687 | if (isect_j == i)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1688 | continue; never executed: continue; | 0 |
1689 | const QVector<int> &isects_j = isects.at(isect_j); | - |
1690 | for (int k = 0;, size = isects_j.size(); k < isects[isect_j].size();; ++k) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1691 | int isect_k = isects[isect_j][isects_j.at(k];); | - |
1692 | if (isect_k != i && !isects.at(i).contains(isect_k)) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1693 | isects[i] += isect_k; | - |
1694 | } never executed: end of block | 0 |
1695 | } never executed: end of block | 0 |
1696 | isects[isect_j].clear(); | - |
1697 | } never executed: end of block | 0 |
1698 | } never executed: end of block | 0 |
1699 | | - |
1700 | #ifdef QPP_FILLPOLYGONS_DEBUG | - |
1701 | printf("Intersections after flattening:\n"); | - |
1702 | for (int i = 0; i < count; ++i) { | - |
1703 | printf("%d: ", i); | - |
1704 | for (int j = 0; j < isects[i].size(); ++j) { | - |
1705 | printf("%d ", isects[i][j]); | - |
1706 | } | - |
1707 | printf("\n"); | - |
1708 | } | - |
1709 | #endif | - |
1710 | | - |
1711 | | - |
1712 | for (int i=0; i<count; ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1713 | const QListQVector<int> &subpath_list = isects[.at(i];); | - |
1714 | if (!subpath_list.isEmpty()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1715 | QPolygonF buildUp; | - |
1716 | for (int j=0; j<subpath_list.size(); ++j) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1717 | const QPolygonF &subpath = subpaths.at(subpath_list.at(j)); | - |
1718 | buildUp += subpath; | - |
1719 | if (!subpath.isClosed())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1720 | buildUp += subpath.first(); never executed: buildUp += subpath.first(); | 0 |
1721 | if (!buildUp.isClosed())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1722 | buildUp += buildUp.firstconstFirst(); never executed: buildUp += buildUp.constFirst(); | 0 |
1723 | } never executed: end of block | 0 |
1724 | polys += buildUp; | - |
1725 | } never executed: end of block | 0 |
1726 | } never executed: end of block | 0 |
1727 | | - |
1728 | return polys; never executed: return polys; | 0 |
1729 | } | - |
1730 | | - |
1731 | | - |
1732 | | - |
1733 | | - |
1734 | QList<QPolygonF> QPainterPath::toFillPolygons(const QMatrix &matrix) const | - |
1735 | { | - |
1736 | return toFillPolygons(QTransform(matrix)); | - |
1737 | } | - |
1738 | | - |
1739 | | - |
1740 | static void qt_painterpath_isect_line(const QPointF &p1, | - |
1741 | const QPointF &p2, | - |
1742 | const QPointF &pos, | - |
1743 | int *winding) | - |
1744 | { | - |
1745 | qreal x1 = p1.x(); | - |
1746 | qreal y1 = p1.y(); | - |
1747 | qreal x2 = p2.x(); | - |
1748 | qreal y2 = p2.y(); | - |
1749 | qreal y = pos.y(); | - |
1750 | | - |
1751 | int dir = 1; | - |
1752 | | - |
1753 | if (qFuzzyCompare(y1, y2)) { | - |
1754 | | - |
1755 | return; | - |
1756 | } else if (y2 < y1) { | - |
1757 | qreal x_tmp = x2; x2 = x1; x1 = x_tmp; | - |
1758 | qreal y_tmp = y2; y2 = y1; y1 = y_tmp; | - |
1759 | dir = -1; | - |
1760 | } | - |
1761 | | - |
1762 | if (y >= y1 && y < y2) { | - |
1763 | qreal x = x1 + ((x2 - x1) / (y2 - y1)) * (y - y1); | - |
1764 | | - |
1765 | | - |
1766 | if (x<=pos.x()) { | - |
1767 | (*winding) += dir; | - |
1768 | } | - |
1769 | } | - |
1770 | } | - |
1771 | | - |
1772 | static void qt_painterpath_isect_curve(const QBezier &bezier, const QPointF &pt, | - |
1773 | int *winding, int depth = 0) | - |
1774 | { | - |
1775 | qreal y = pt.y(); | - |
1776 | qreal x = pt.x(); | - |
1777 | QRectF bounds = bezier.bounds(); | - |
1778 | | - |
1779 | | - |
1780 | | - |
1781 | | - |
1782 | | - |
1783 | if (y >= bounds.y() && y < bounds.y() + bounds.height()) { | - |
1784 | | - |
1785 | | - |
1786 | | - |
1787 | const qreal lower_bound = qreal(.001); | - |
1788 | if (depth == 32 || (bounds.width() < lower_bound && bounds.height() < lower_bound)) { | - |
1789 | | - |
1790 | | - |
1791 | | - |
1792 | if (bezier.pt1().x() <= x) { | - |
1793 | (*winding) += (bezier.pt4().y() > bezier.pt1().y() ? 1 : -1); | - |
1794 | } | - |
1795 | return; | - |
1796 | } | - |
1797 | | - |
1798 | | - |
1799 | QBezier first_half, second_half; | - |
1800 | bezier.split(&first_half, &second_half); | - |
1801 | qt_painterpath_isect_curve(first_half, pt, winding, depth + 1); | - |
1802 | qt_painterpath_isect_curve(second_half, pt, winding, depth + 1); | - |
1803 | } | - |
1804 | } | - |
1805 | | - |
1806 | | - |
1807 | | - |
1808 | | - |
1809 | | - |
1810 | | - |
1811 | | - |
1812 | | - |
1813 | | - |
1814 | bool QPainterPath::contains(const QPointF &pt) const | - |
1815 | { | - |
1816 | if (isEmpty() || !controlPointRect().contains(pt)) | - |
1817 | return false; | - |
1818 | | - |
1819 | QPainterPathData *d = d_func(); | - |
1820 | | - |
1821 | int winding_number = 0; | - |
1822 | | - |
1823 | QPointF last_pt; | - |
1824 | QPointF last_start; | - |
1825 | for (int i=0; i<d->elements.size(); ++i) { | - |
1826 | const Element &e = d->elements.at(i); | - |
1827 | | - |
1828 | switch (e.type) { | - |
1829 | | - |
1830 | case MoveToElement: | - |
1831 | if (i > 0) | - |
1832 | qt_painterpath_isect_line(last_pt, last_start, pt, &winding_number); | - |
1833 | last_start = last_pt = e; | - |
1834 | break; | - |
1835 | | - |
1836 | case LineToElement: | - |
1837 | qt_painterpath_isect_line(last_pt, e, pt, &winding_number); | - |
1838 | last_pt = e; | - |
1839 | break; | - |
1840 | | - |
1841 | case CurveToElement: | - |
1842 | { | - |
1843 | const QPainterPath::Element &cp2 = d->elements.at(++i); | - |
1844 | const QPainterPath::Element &ep = d->elements.at(++i); | - |
1845 | qt_painterpath_isect_curve(QBezier::fromPoints(last_pt, e, cp2, ep), | - |
1846 | pt, &winding_number); | - |
1847 | last_pt = ep; | - |
1848 | | - |
1849 | } | - |
1850 | break; | - |
1851 | | - |
1852 | default: | - |
1853 | break; | - |
1854 | } | - |
1855 | } | - |
1856 | | - |
1857 | | - |
1858 | if (last_pt != last_start) | - |
1859 | qt_painterpath_isect_line(last_pt, last_start, pt, &winding_number); | - |
1860 | | - |
1861 | return (d->fillRule == Qt::WindingFill | - |
1862 | ? (winding_number != 0) | - |
1863 | : ((winding_number % 2) != 0)); | - |
1864 | } | - |
1865 | | - |
1866 | enum PainterDirections { Left, Right, Top, Bottom }; | - |
1867 | | - |
1868 | static bool qt_painterpath_isect_line_rect(qreal x1, qreal y1, qreal x2, qreal y2, | - |
1869 | const QRectF &rect) | - |
1870 | { | - |
1871 | qreal left = rect.left(); | - |
1872 | qreal right = rect.right(); | - |
1873 | qreal top = rect.top(); | - |
1874 | qreal bottom = rect.bottom(); | - |
1875 | | - |
1876 | enum { Left, Right, Top, Bottom }; | - |
1877 | int p1 = ((x1 < left) << Left) | - |
1878 | | ((x1 > right) << Right) | - |
1879 | | ((y1 < top) << Top) | - |
1880 | | ((y1 > bottom) << Bottom); | - |
1881 | int p2 = ((x2 < left) << Left) | - |
1882 | | ((x2 > right) << Right) | - |
1883 | | ((y2 < top) << Top) | - |
1884 | | ((y2 > bottom) << Bottom); | - |
1885 | | - |
1886 | if (p1 & p2)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1887 | | - |
1888 | return false; never executed: return false; | 0 |
1889 | | - |
1890 | if (p1 | p2) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1891 | qreal dx = x2 - x1; | - |
1892 | qreal dy = y2 - y1; | - |
1893 | | - |
1894 | | - |
1895 | if (x1 < left) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1896 | y1 += dy/dx * (left - x1); | - |
1897 | x1 = left; | - |
1898 | } else if (x1 > right) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1899 | y1 -= dy/dx * (x1 - right); | - |
1900 | x1 = right; | - |
1901 | } never executed: end of block | 0 |
1902 | if (x2 < left) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1903 | y2 += dy/dx * (left - x2); | - |
1904 | x2 = left; | - |
1905 | } else if (x2 > right) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1906 | y2 -= dy/dx * (x2 - right); | - |
1907 | x2 = right; | - |
1908 | } never executed: end of block | 0 |
1909 | | - |
1910 | p1 = ((y1 < top) << Top) | - |
1911 | | ((y1 > bottom) << Bottom); | - |
1912 | p2 = ((y2 < top) << Top) | - |
1913 | | ((y2 > bottom) << Bottom); | - |
1914 | | - |
1915 | if (p1 & p2)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1916 | return false; never executed: return false; | 0 |
1917 | | - |
1918 | | - |
1919 | if (y1 < top) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1920 | x1 += dx/dy * (top - y1); | - |
1921 | y1 = top; | - |
1922 | } else if (y1 > bottom) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1923 | x1 -= dx/dy * (y1 - bottom); | - |
1924 | y1 = bottom; | - |
1925 | } never executed: end of block | 0 |
1926 | if (y2 < top) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1927 | x2 += dx/dy * (top - y2); | - |
1928 | y2 = top; | - |
1929 | } else if (y2 > bottom) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1930 | x2 -= dx/dy * (y2 - bottom); | - |
1931 | y2 = bottom; | - |
1932 | } never executed: end of block | 0 |
1933 | | - |
1934 | p1 = ((x1 < left) << Left) | - |
1935 | | ((x1 > right) << Right); | - |
1936 | p2 = ((x2 < left) << Left) | - |
1937 | | ((x2 > right) << Right); | - |
1938 | | - |
1939 | if (p1 & p2)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
1940 | return false; never executed: return false; | 0 |
1941 | | - |
1942 | return true; never executed: return true; | 0 |
1943 | } | - |
1944 | return false; never executed: return false; | 0 |
1945 | } | - |
1946 | | - |
1947 | static bool qt_isect_curve_horizontal(const QBezier &bezier, qreal y, qreal x1, qreal x2, int depth = 0) | - |
1948 | { | - |
1949 | QRectF bounds = bezier.bounds(); | - |
1950 | | - |
1951 | if (y >= bounds.top() && y < bounds.bottom() | - |
1952 | && bounds.right() >= x1 && bounds.left() < x2) { | - |
1953 | const qreal lower_bound = qreal(.01); | - |
1954 | if (depth == 32 || (bounds.width() < lower_bound && bounds.height() < lower_bound)) | - |
1955 | return true; | - |
1956 | | - |
1957 | QBezier first_half, second_half; | - |
1958 | bezier.split(&first_half, &second_half); | - |
1959 | if (qt_isect_curve_horizontal(first_half, y, x1, x2, depth + 1) | - |
1960 | || qt_isect_curve_horizontal(second_half, y, x1, x2, depth + 1)) | - |
1961 | return true; | - |
1962 | } | - |
1963 | return false; | - |
1964 | } | - |
1965 | | - |
1966 | static bool qt_isect_curve_vertical(const QBezier &bezier, qreal x, qreal y1, qreal y2, int depth = 0) | - |
1967 | { | - |
1968 | QRectF bounds = bezier.bounds(); | - |
1969 | | - |
1970 | if (x >= bounds.left() && x < bounds.right() | - |
1971 | && bounds.bottom() >= y1 && bounds.top() < y2) { | - |
1972 | const qreal lower_bound = qreal(.01); | - |
1973 | if (depth == 32 || (bounds.width() < lower_bound && bounds.height() < lower_bound)) | - |
1974 | return true; | - |
1975 | | - |
1976 | QBezier first_half, second_half; | - |
1977 | bezier.split(&first_half, &second_half); | - |
1978 | if (qt_isect_curve_vertical(first_half, x, y1, y2, depth + 1) | - |
1979 | || qt_isect_curve_vertical(second_half, x, y1, y2, depth + 1)) | - |
1980 | return true; | - |
1981 | } | - |
1982 | return false; | - |
1983 | } | - |
1984 | | - |
1985 | | - |
1986 | | - |
1987 | | - |
1988 | static bool qt_painterpath_check_crossing(const QPainterPath *path, const QRectF &rect) | - |
1989 | { | - |
1990 | QPointF last_pt; | - |
1991 | QPointF last_start; | - |
1992 | for (int i=0; i<path->elementCount(); ++i) { | - |
1993 | const QPainterPath::Element &e = path->elementAt(i); | - |
1994 | | - |
1995 | switch (e.type) { | - |
1996 | | - |
1997 | case QPainterPath::MoveToElement: | - |
1998 | if (i > 0 | - |
1999 | && qFuzzyCompare(last_pt.x(), last_start.x()) | - |
2000 | && qFuzzyCompare(last_pt.y(), last_start.y()) | - |
2001 | && qt_painterpath_isect_line_rect(last_pt.x(), last_pt.y(), | - |
2002 | last_start.x(), last_start.y(), rect)) | - |
2003 | return true; | - |
2004 | last_start = last_pt = e; | - |
2005 | break; | - |
2006 | | - |
2007 | case QPainterPath::LineToElement: | - |
2008 | if (qt_painterpath_isect_line_rect(last_pt.x(), last_pt.y(), e.x, e.y, rect)) | - |
2009 | return true; | - |
2010 | last_pt = e; | - |
2011 | break; | - |
2012 | | - |
2013 | case QPainterPath::CurveToElement: | - |
2014 | { | - |
2015 | QPointF cp2 = path->elementAt(++i); | - |
2016 | QPointF ep = path->elementAt(++i); | - |
2017 | QBezier bezier = QBezier::fromPoints(last_pt, e, cp2, ep); | - |
2018 | if (qt_isect_curve_horizontal(bezier, rect.top(), rect.left(), rect.right()) | - |
2019 | || qt_isect_curve_horizontal(bezier, rect.bottom(), rect.left(), rect.right()) | - |
2020 | || qt_isect_curve_vertical(bezier, rect.left(), rect.top(), rect.bottom()) | - |
2021 | || qt_isect_curve_vertical(bezier, rect.right(), rect.top(), rect.bottom())) | - |
2022 | return true; | - |
2023 | last_pt = ep; | - |
2024 | } | - |
2025 | break; | - |
2026 | | - |
2027 | default: | - |
2028 | break; | - |
2029 | } | - |
2030 | } | - |
2031 | | - |
2032 | | - |
2033 | if (last_pt != last_start | - |
2034 | && qt_painterpath_isect_line_rect(last_pt.x(), last_pt.y(), | - |
2035 | last_start.x(), last_start.y(), rect)) | - |
2036 | return true; | - |
2037 | | - |
2038 | return false; | - |
2039 | } | - |
2040 | | - |
2041 | | - |
2042 | | - |
2043 | | - |
2044 | | - |
2045 | | - |
2046 | | - |
2047 | | - |
2048 | | - |
2049 | | - |
2050 | | - |
2051 | | - |
2052 | | - |
2053 | | - |
2054 | | - |
2055 | bool QPainterPath::intersects(const QRectF &rect) const | - |
2056 | { | - |
2057 | if (elementCount() == 1 && rect.contains(elementAt(0))) | - |
2058 | return true; | - |
2059 | | - |
2060 | if (isEmpty()) | - |
2061 | return false; | - |
2062 | | - |
2063 | QRectF cp = controlPointRect(); | - |
2064 | QRectF rn = rect.normalized(); | - |
2065 | | - |
2066 | | - |
2067 | | - |
2068 | | - |
2069 | if (qMax(rn.left(), cp.left()) > qMin(rn.right(), cp.right()) | - |
2070 | || qMax(rn.top(), cp.top()) > qMin(rn.bottom(), cp.bottom())) | - |
2071 | return false; | - |
2072 | | - |
2073 | | - |
2074 | if (qt_painterpath_check_crossing(this, rect)) | - |
2075 | return true; | - |
2076 | | - |
2077 | if (contains(rect.center())) | - |
2078 | return true; | - |
2079 | | - |
2080 | Q_D(QPainterPath); | - |
2081 | | - |
2082 | | - |
2083 | for (int i=0; i<d->elements.size(); ++i) { | - |
2084 | const Element &e = d->elements.at(i); | - |
2085 | if (e.type == QPainterPath::MoveToElement && rect.contains(e)) | - |
2086 | return true; | - |
2087 | } | - |
2088 | | - |
2089 | return false; | - |
2090 | } | - |
2091 | | - |
2092 | | - |
2093 | | - |
2094 | | - |
2095 | | - |
2096 | | - |
2097 | | - |
2098 | void QPainterPath::translate(qreal dx, qreal dy) | - |
2099 | { | - |
2100 | if (!d_ptr || (dx == 0 && dy == 0)) | - |
2101 | return; | - |
2102 | | - |
2103 | int elementsLeft = d_ptr->elements.size(); | - |
2104 | if (elementsLeft <= 0) | - |
2105 | return; | - |
2106 | | - |
2107 | detach(); | - |
2108 | QPainterPath::Element *element = d_func()->elements.data(); | - |
2109 | Q_ASSERT(element); | - |
2110 | while (elementsLeft--) { | - |
2111 | element->x += dx; | - |
2112 | element->y += dy; | - |
2113 | ++element; | - |
2114 | } | - |
2115 | } | - |
2116 | | - |
2117 | | - |
2118 | | - |
2119 | | - |
2120 | | - |
2121 | | - |
2122 | | - |
2123 | | - |
2124 | | - |
2125 | | - |
2126 | | - |
2127 | | - |
2128 | | - |
2129 | | - |
2130 | | - |
2131 | | - |
2132 | | - |
2133 | QPainterPath QPainterPath::translated(qreal dx, qreal dy) const | - |
2134 | { | - |
2135 | QPainterPath copy(*this); | - |
2136 | copy.translate(dx, dy); | - |
2137 | return copy; | - |
2138 | } | - |
2139 | | - |
2140 | | - |
2141 | | - |
2142 | | - |
2143 | | - |
2144 | | - |
2145 | | - |
2146 | | - |
2147 | | - |
2148 | | - |
2149 | | - |
2150 | | - |
2151 | | - |
2152 | | - |
2153 | | - |
2154 | | - |
2155 | | - |
2156 | bool QPainterPath::contains(const QRectF &rect) const | - |
2157 | { | - |
2158 | Q_D(QPainterPath); | - |
2159 | | - |
2160 | | - |
2161 | | - |
2162 | if (isEmpty() || !controlPointRect().contains(rect)) | - |
2163 | return false; | - |
2164 | | - |
2165 | | - |
2166 | | - |
2167 | | - |
2168 | if (qt_painterpath_check_crossing(this, rect)) { | - |
2169 | if (fillRule() == Qt::OddEvenFill) { | - |
2170 | return false; | - |
2171 | } else { | - |
2172 | | - |
2173 | | - |
2174 | if (!contains(rect.topLeft()) || | - |
2175 | !contains(rect.topRight()) || | - |
2176 | !contains(rect.bottomRight()) || | - |
2177 | !contains(rect.bottomLeft())) | - |
2178 | return false; | - |
2179 | } | - |
2180 | } | - |
2181 | | - |
2182 | | - |
2183 | | - |
2184 | | - |
2185 | | - |
2186 | if (!contains(rect.center())) | - |
2187 | return false; | - |
2188 | | - |
2189 | | - |
2190 | | - |
2191 | | - |
2192 | | - |
2193 | | - |
2194 | | - |
2195 | for (int i=0; i<d->elements.size(); ++i) { | - |
2196 | const Element &e = d->elements.at(i); | - |
2197 | if (e.type == QPainterPath::MoveToElement && rect.contains(e)) { | - |
2198 | if (fillRule() == Qt::OddEvenFill) | - |
2199 | return false; | - |
2200 | | - |
2201 | bool stop = false; | - |
2202 | for (; !stop && i<d->elements.size(); ++i) { | - |
2203 | const Element &el = d->elements.at(i); | - |
2204 | switch (el.type) { | - |
2205 | case MoveToElement: | - |
2206 | stop = true; | - |
2207 | break; | - |
2208 | case LineToElement: | - |
2209 | if (!contains(el)) | - |
2210 | return false; | - |
2211 | break; | - |
2212 | case CurveToElement: | - |
2213 | if (!contains(d->elements.at(i+2))) | - |
2214 | return false; | - |
2215 | i += 2; | - |
2216 | break; | - |
2217 | default: | - |
2218 | break; | - |
2219 | } | - |
2220 | } | - |
2221 | | - |
2222 | | - |
2223 | --i; | - |
2224 | } | - |
2225 | } | - |
2226 | | - |
2227 | return true; | - |
2228 | } | - |
2229 | | - |
2230 | static inline bool epsilonCompare(const QPointF &a, const QPointF &b, const QSizeF &epsilon) | - |
2231 | { | - |
2232 | return qAbs(a.x() - b.x()) <= epsilon.width() | - |
2233 | && qAbs(a.y() - b.y()) <= epsilon.height(); | - |
2234 | } | - |
2235 | | - |
2236 | | - |
2237 | | - |
2238 | | - |
2239 | | - |
2240 | | - |
2241 | | - |
2242 | | - |
2243 | | - |
2244 | | - |
2245 | bool QPainterPath::operator==(const QPainterPath &path) const | - |
2246 | { | - |
2247 | QPainterPathData *d = reinterpret_cast<QPainterPathData *>(d_func()); | - |
2248 | if (path.d_func() == d) | - |
2249 | return true; | - |
2250 | else if (!d || !path.d_func()) | - |
2251 | return false; | - |
2252 | else if (d->fillRule != path.d_func()->fillRule) | - |
2253 | return false; | - |
2254 | else if (d->elements.size() != path.d_func()->elements.size()) | - |
2255 | return false; | - |
2256 | | - |
2257 | const qreal qt_epsilon = sizeof(qreal) == sizeof(double) ? 1e-12 : qreal(1e-5); | - |
2258 | | - |
2259 | QSizeF epsilon = boundingRect().size(); | - |
2260 | epsilon.rwidth() *= qt_epsilon; | - |
2261 | epsilon.rheight() *= qt_epsilon; | - |
2262 | | - |
2263 | for (int i = 0; i < d->elements.size(); ++i) | - |
2264 | if (d->elements.at(i).type != path.d_func()->elements.at(i).type | - |
2265 | || !epsilonCompare(d->elements.at(i), path.d_func()->elements.at(i), epsilon)) | - |
2266 | return false; | - |
2267 | | - |
2268 | return true; | - |
2269 | } | - |
2270 | | - |
2271 | | - |
2272 | | - |
2273 | | - |
2274 | | - |
2275 | | - |
2276 | | - |
2277 | | - |
2278 | | - |
2279 | | - |
2280 | bool QPainterPath::operator!=(const QPainterPath &path) const | - |
2281 | { | - |
2282 | return !(*this==path); | - |
2283 | } | - |
2284 | | - |
2285 | | - |
2286 | | - |
2287 | | - |
2288 | | - |
2289 | | - |
2290 | | - |
2291 | | - |
2292 | QPainterPath QPainterPath::operator&(const QPainterPath &other) const | - |
2293 | { | - |
2294 | return intersected(other); | - |
2295 | } | - |
2296 | | - |
2297 | | - |
2298 | | - |
2299 | | - |
2300 | | - |
2301 | | - |
2302 | | - |
2303 | | - |
2304 | QPainterPath QPainterPath::operator|(const QPainterPath &other) const | - |
2305 | { | - |
2306 | return united(other); | - |
2307 | } | - |
2308 | | - |
2309 | | - |
2310 | | - |
2311 | | - |
2312 | | - |
2313 | | - |
2314 | | - |
2315 | | - |
2316 | | - |
2317 | QPainterPath QPainterPath::operator+(const QPainterPath &other) const | - |
2318 | { | - |
2319 | return united(other); | - |
2320 | } | - |
2321 | | - |
2322 | | - |
2323 | | - |
2324 | | - |
2325 | | - |
2326 | | - |
2327 | | - |
2328 | | - |
2329 | QPainterPath QPainterPath::operator-(const QPainterPath &other) const | - |
2330 | { | - |
2331 | return subtracted(other); | - |
2332 | } | - |
2333 | | - |
2334 | | - |
2335 | | - |
2336 | | - |
2337 | | - |
2338 | | - |
2339 | | - |
2340 | | - |
2341 | QPainterPath &QPainterPath::operator&=(const QPainterPath &other) | - |
2342 | { | - |
2343 | return *this = (*this & other); | - |
2344 | } | - |
2345 | | - |
2346 | | - |
2347 | | - |
2348 | | - |
2349 | | - |
2350 | | - |
2351 | | - |
2352 | | - |
2353 | QPainterPath &QPainterPath::operator|=(const QPainterPath &other) | - |
2354 | { | - |
2355 | return *this = (*this | other); | - |
2356 | } | - |
2357 | | - |
2358 | | - |
2359 | | - |
2360 | | - |
2361 | | - |
2362 | | - |
2363 | | - |
2364 | | - |
2365 | | - |
2366 | QPainterPath &QPainterPath::operator+=(const QPainterPath &other) | - |
2367 | { | - |
2368 | return *this = (*this + other); | - |
2369 | } | - |
2370 | | - |
2371 | | - |
2372 | | - |
2373 | | - |
2374 | | - |
2375 | | - |
2376 | | - |
2377 | | - |
2378 | | - |
2379 | QPainterPath &QPainterPath::operator-=(const QPainterPath &other) | - |
2380 | { | - |
2381 | return *this = (*this - other); | - |
2382 | } | - |
2383 | | - |
2384 | #ifndef QT_NO_DATASTREAM | - |
2385 | | - |
2386 | | - |
2387 | | - |
2388 | | - |
2389 | | - |
2390 | | - |
2391 | | - |
2392 | | - |
2393 | | - |
2394 | QDataStream &operator<<(QDataStream &s, const QPainterPath &p) | - |
2395 | { | - |
2396 | if (p.isEmpty()) { | - |
2397 | s << 0; | - |
2398 | return s; | - |
2399 | } | - |
2400 | | - |
2401 | s << p.elementCount(); | - |
2402 | for (int i=0; i < p.d_func()->elements.size(); ++i) { | - |
2403 | const QPainterPath::Element &e = p.d_func()->elements.at(i); | - |
2404 | s << int(e.type); | - |
2405 | s << double(e.x) << double(e.y); | - |
2406 | } | - |
2407 | s << p.d_func()->cStart; | - |
2408 | s << int(p.d_func()->fillRule); | - |
2409 | return s; | - |
2410 | } | - |
2411 | | - |
2412 | | - |
2413 | | - |
2414 | | - |
2415 | | - |
2416 | | - |
2417 | | - |
2418 | | - |
2419 | | - |
2420 | | - |
2421 | QDataStream &operator>>(QDataStream &s, QPainterPath &p) | - |
2422 | { | - |
2423 | int size; | - |
2424 | s >> size; | - |
2425 | | - |
2426 | if (size == 0) | - |
2427 | return s; | - |
2428 | | - |
2429 | p.ensureData(); | - |
2430 | if (p.d_func()->elements.size() == 1) { | - |
2431 | Q_ASSERT(p.d_func()->elements.at(0).type == QPainterPath::MoveToElement); | - |
2432 | p.d_func()->elements.clear(); | - |
2433 | } | - |
2434 | p.d_func()->elements.reserve(p.d_func()->elements.size() + size); | - |
2435 | for (int i=0; i<size; ++i) { | - |
2436 | int type; | - |
2437 | double x, y; | - |
2438 | s >> type; | - |
2439 | s >> x; | - |
2440 | s >> y; | - |
2441 | Q_ASSERT(type >= 0 && type <= 3); | - |
2442 | if (!qt_is_finite(x) || !qt_is_finite(y)) { | - |
2443 | #ifndef QT_NO_DEBUG | - |
2444 | qWarning("QDataStream::operator>>: NaN or Inf element found in path, skipping it"); | - |
2445 | #endif | - |
2446 | continue; | - |
2447 | } | - |
2448 | QPainterPath::Element elm = { qreal(x), qreal(y), QPainterPath::ElementType(type) }; | - |
2449 | p.d_func()->elements.append(elm); | - |
2450 | } | - |
2451 | s >> p.d_func()->cStart; | - |
2452 | int fillRule; | - |
2453 | s >> fillRule; | - |
2454 | Q_ASSERT(fillRule == Qt::OddEvenFill || Qt::WindingFill); | - |
2455 | p.d_func()->fillRule = Qt::FillRule(fillRule); | - |
2456 | p.d_func()->dirtyBounds = true; | - |
2457 | p.d_func()->dirtyControlBounds = true; | - |
2458 | return s; | - |
2459 | } | - |
2460 | #endif // QT_NO_DATASTREAM | - |
2461 | | - |
2462 | | - |
2463 | | - |
2464 | | - |
2465 | | - |
2466 | | - |
2467 | void qt_path_stroke_move_to(qfixed x, qfixed y, void *data) | - |
2468 | { | - |
2469 | ((QPainterPath *) data)->moveTo(qt_fixed_to_real(x), qt_fixed_to_real(y)); | - |
2470 | } | - |
2471 | | - |
2472 | void qt_path_stroke_line_to(qfixed x, qfixed y, void *data) | - |
2473 | { | - |
2474 | ((QPainterPath *) data)->lineTo(qt_fixed_to_real(x), qt_fixed_to_real(y)); | - |
2475 | } | - |
2476 | | - |
2477 | void qt_path_stroke_cubic_to(qfixed c1x, qfixed c1y, | - |
2478 | qfixed c2x, qfixed c2y, | - |
2479 | qfixed ex, qfixed ey, | - |
2480 | void *data) | - |
2481 | { | - |
2482 | ((QPainterPath *) data)->cubicTo(qt_fixed_to_real(c1x), qt_fixed_to_real(c1y), | - |
2483 | qt_fixed_to_real(c2x), qt_fixed_to_real(c2y), | - |
2484 | qt_fixed_to_real(ex), qt_fixed_to_real(ey)); | - |
2485 | } | - |
2486 | | - |
2487 | | - |
2488 | | - |
2489 | | - |
2490 | | - |
2491 | | - |
2492 | | - |
2493 | | - |
2494 | | - |
2495 | | - |
2496 | | - |
2497 | | - |
2498 | | - |
2499 | | - |
2500 | | - |
2501 | | - |
2502 | | - |
2503 | | - |
2504 | | - |
2505 | | - |
2506 | | - |
2507 | | - |
2508 | | - |
2509 | | - |
2510 | | - |
2511 | | - |
2512 | | - |
2513 | | - |
2514 | | - |
2515 | | - |
2516 | | - |
2517 | | - |
2518 | | - |
2519 | | - |
2520 | | - |
2521 | | - |
2522 | | - |
2523 | | - |
2524 | | - |
2525 | | - |
2526 | | - |
2527 | | - |
2528 | | - |
2529 | | - |
2530 | | - |
2531 | | - |
2532 | | - |
2533 | | - |
2534 | | - |
2535 | | - |
2536 | | - |
2537 | | - |
2538 | QPainterPathStrokerPrivate::QPainterPathStrokerPrivate() | - |
2539 | : dashOffset(0) | - |
2540 | { | - |
2541 | stroker.setMoveToHook(qt_path_stroke_move_to); | - |
2542 | stroker.setLineToHook(qt_path_stroke_line_to); | - |
2543 | stroker.setCubicToHook(qt_path_stroke_cubic_to); | - |
2544 | } | - |
2545 | | - |
2546 | | - |
2547 | | - |
2548 | | - |
2549 | QPainterPathStroker::QPainterPathStroker() | - |
2550 | : d_ptr(new QPainterPathStrokerPrivate) | - |
2551 | { | - |
2552 | } | - |
2553 | | - |
2554 | | - |
2555 | | - |
2556 | | - |
2557 | | - |
2558 | | - |
2559 | QPainterPathStroker::QPainterPathStroker(const QPen &pen) | - |
2560 | : d_ptr(new QPainterPathStrokerPrivate) | - |
2561 | { | - |
2562 | setWidth(pen.widthF()); | - |
2563 | setCapStyle(pen.capStyle()); | - |
2564 | setJoinStyle(pen.joinStyle()); | - |
2565 | setMiterLimit(pen.miterLimit()); | - |
2566 | setDashOffset(pen.dashOffset()); | - |
2567 | | - |
2568 | if (pen.style() == Qt::CustomDashLine) | - |
2569 | setDashPattern(pen.dashPattern()); | - |
2570 | else | - |
2571 | setDashPattern(pen.style()); | - |
2572 | } | - |
2573 | | - |
2574 | | - |
2575 | | - |
2576 | | - |
2577 | QPainterPathStroker::~QPainterPathStroker() | - |
2578 | { | - |
2579 | } | - |
2580 | | - |
2581 | | - |
2582 | | - |
2583 | | - |
2584 | | - |
2585 | | - |
2586 | | - |
2587 | | - |
2588 | | - |
2589 | | - |
2590 | | - |
2591 | | - |
2592 | | - |
2593 | | - |
2594 | | - |
2595 | QPainterPath QPainterPathStroker::createStroke(const QPainterPath &path) const | - |
2596 | { | - |
2597 | QPainterPathStrokerPrivate *d = const_cast<QPainterPathStrokerPrivate *>(d_func()); | - |
2598 | QPainterPath stroke; | - |
2599 | if (path.isEmpty()) | - |
2600 | return path; | - |
2601 | if (d->dashPattern.isEmpty()) { | - |
2602 | d->stroker.strokePath(path, &stroke, QTransform()); | - |
2603 | } else { | - |
2604 | QDashStroker dashStroker(&d->stroker); | - |
2605 | dashStroker.setDashPattern(d->dashPattern); | - |
2606 | dashStroker.setDashOffset(d->dashOffset); | - |
2607 | dashStroker.setClipRect(d->stroker.clipRect()); | - |
2608 | dashStroker.strokePath(path, &stroke, QTransform()); | - |
2609 | } | - |
2610 | stroke.setFillRule(Qt::WindingFill); | - |
2611 | return stroke; | - |
2612 | } | - |
2613 | | - |
2614 | | - |
2615 | | - |
2616 | | - |
2617 | | - |
2618 | | - |
2619 | | - |
2620 | void QPainterPathStroker::setWidth(qreal width) | - |
2621 | { | - |
2622 | Q_D(QPainterPathStroker); | - |
2623 | if (width <= 0) | - |
2624 | width = 1; | - |
2625 | d->stroker.setStrokeWidth(qt_real_to_fixed(width)); | - |
2626 | } | - |
2627 | | - |
2628 | | - |
2629 | | - |
2630 | | - |
2631 | qreal QPainterPathStroker::width() const | - |
2632 | { | - |
2633 | return qt_fixed_to_real(d_func()->stroker.strokeWidth()); | - |
2634 | } | - |
2635 | | - |
2636 | | - |
2637 | | - |
2638 | | - |
2639 | | - |
2640 | | - |
2641 | | - |
2642 | void QPainterPathStroker::setCapStyle(Qt::PenCapStyle style) | - |
2643 | { | - |
2644 | d_func()->stroker.setCapStyle(style); | - |
2645 | } | - |
2646 | | - |
2647 | | - |
2648 | | - |
2649 | | - |
2650 | | - |
2651 | Qt::PenCapStyle QPainterPathStroker::capStyle() const | - |
2652 | { | - |
2653 | return d_func()->stroker.capStyle(); | - |
2654 | } | - |
2655 | | - |
2656 | | - |
2657 | | - |
2658 | | - |
2659 | void QPainterPathStroker::setJoinStyle(Qt::PenJoinStyle style) | - |
2660 | { | - |
2661 | d_func()->stroker.setJoinStyle(style); | - |
2662 | } | - |
2663 | | - |
2664 | | - |
2665 | | - |
2666 | | - |
2667 | Qt::PenJoinStyle QPainterPathStroker::joinStyle() const | - |
2668 | { | - |
2669 | return d_func()->stroker.joinStyle(); | - |
2670 | } | - |
2671 | | - |
2672 | | - |
2673 | | - |
2674 | | - |
2675 | | - |
2676 | | - |
2677 | | - |
2678 | | - |
2679 | | - |
2680 | | - |
2681 | | - |
2682 | void QPainterPathStroker::setMiterLimit(qreal limit) | - |
2683 | { | - |
2684 | d_func()->stroker.setMiterLimit(qt_real_to_fixed(limit)); | - |
2685 | } | - |
2686 | | - |
2687 | | - |
2688 | | - |
2689 | | - |
2690 | qreal QPainterPathStroker::miterLimit() const | - |
2691 | { | - |
2692 | return qt_fixed_to_real(d_func()->stroker.miterLimit()); | - |
2693 | } | - |
2694 | | - |
2695 | | - |
2696 | | - |
2697 | | - |
2698 | | - |
2699 | | - |
2700 | | - |
2701 | | - |
2702 | | - |
2703 | | - |
2704 | void QPainterPathStroker::setCurveThreshold(qreal threshold) | - |
2705 | { | - |
2706 | d_func()->stroker.setCurveThreshold(qt_real_to_fixed(threshold)); | - |
2707 | } | - |
2708 | | - |
2709 | | - |
2710 | | - |
2711 | | - |
2712 | | - |
2713 | qreal QPainterPathStroker::curveThreshold() const | - |
2714 | { | - |
2715 | return qt_fixed_to_real(d_func()->stroker.curveThreshold()); | - |
2716 | } | - |
2717 | | - |
2718 | | - |
2719 | | - |
2720 | | - |
2721 | void QPainterPathStroker::setDashPattern(Qt::PenStyle style) | - |
2722 | { | - |
2723 | d_func()->dashPattern = QDashStroker::patternForStyle(style); | - |
2724 | } | - |
2725 | | - |
2726 | | - |
2727 | | - |
2728 | | - |
2729 | | - |
2730 | | - |
2731 | | - |
2732 | | - |
2733 | | - |
2734 | | - |
2735 | | - |
2736 | | - |
2737 | | - |
2738 | | - |
2739 | | - |
2740 | | - |
2741 | | - |
2742 | void QPainterPathStroker::setDashPattern(const QVector<qreal> &dashPattern) | - |
2743 | { | - |
2744 | d_func()->dashPattern.clear(); | - |
2745 | for (int i=0; i<dashPattern.size(); ++i) | - |
2746 | d_func()->dashPattern << qt_real_to_fixed(dashPattern.at(i)); | - |
2747 | } | - |
2748 | | - |
2749 | | - |
2750 | | - |
2751 | | - |
2752 | QVector<qreal> QPainterPathStroker::dashPattern() const | - |
2753 | { | - |
2754 | return d_func()->dashPattern; | - |
2755 | } | - |
2756 | | - |
2757 | | - |
2758 | | - |
2759 | | - |
2760 | qreal QPainterPathStroker::dashOffset() const | - |
2761 | { | - |
2762 | return d_func()->dashOffset; | - |
2763 | } | - |
2764 | | - |
2765 | | - |
2766 | | - |
2767 | | - |
2768 | | - |
2769 | | - |
2770 | | - |
2771 | void QPainterPathStroker::setDashOffset(qreal offset) | - |
2772 | { | - |
2773 | d_func()->dashOffset = offset; | - |
2774 | } | - |
2775 | | - |
2776 | | - |
2777 | | - |
2778 | | - |
2779 | | - |
2780 | | - |
2781 | | - |
2782 | | - |
2783 | | - |
2784 | | - |
2785 | | - |
2786 | | - |
2787 | | - |
2788 | | - |
2789 | | - |
2790 | | - |
2791 | QPolygonF QPainterPath::toFillPolygon(const QTransform &matrix) const | - |
2792 | { | - |
2793 | | - |
2794 | const QList<QPolygonF> flats = toSubpathPolygons(matrix); | - |
2795 | QPolygonF polygon; | - |
2796 | if (flats.isEmpty())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2797 | return polygon; never executed: return polygon; | 0 |
2798 | QPointF first = flats.first().first(); | - |
2799 | for (int i=0; i<flats.size(); ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2800 | polygon += flats.at(i); | - |
2801 | if (!flats.at(i).isClosed())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2802 | polygon += flats.at(i).first(); never executed: polygon += flats.at(i).first(); | 0 |
2803 | if (i > 0)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
2804 | polygon += first; never executed: polygon += first; | 0 |
2805 | } never executed: end of block | 0 |
2806 | return polygon; never executed: return polygon; | 0 |
2807 | } | - |
2808 | | - |
2809 | | - |
2810 | | - |
2811 | | - |
2812 | QPolygonF QPainterPath::toFillPolygon(const QMatrix &matrix) const | - |
2813 | { | - |
2814 | return toFillPolygon(QTransform(matrix)); | - |
2815 | } | - |
2816 | | - |
2817 | | - |
2818 | | - |
2819 | static inline qreal slopeAt(qreal t, qreal a, qreal b, qreal c, qreal d) | - |
2820 | { | - |
2821 | return 3*t*t*(d - 3*c + 3*b - a) + 6*t*(c - 2*b + a) + 3*(b - a); | - |
2822 | } | - |
2823 | | - |
2824 | | - |
2825 | | - |
2826 | | - |
2827 | qreal QPainterPath::length() const | - |
2828 | { | - |
2829 | Q_D(QPainterPath); | - |
2830 | if (isEmpty()) | - |
2831 | return 0; | - |
2832 | | - |
2833 | qreal len = 0; | - |
2834 | for (int i=1; i<d->elements.size(); ++i) { | - |
2835 | const Element &e = d->elements.at(i); | - |
2836 | | - |
2837 | switch (e.type) { | - |
2838 | case MoveToElement: | - |
2839 | break; | - |
2840 | case LineToElement: | - |
2841 | { | - |
2842 | len += QLineF(d->elements.at(i-1), e).length(); | - |
2843 | break; | - |
2844 | } | - |
2845 | case CurveToElement: | - |
2846 | { | - |
2847 | QBezier b = QBezier::fromPoints(d->elements.at(i-1), | - |
2848 | e, | - |
2849 | d->elements.at(i+1), | - |
2850 | d->elements.at(i+2)); | - |
2851 | len += b.length(); | - |
2852 | i += 2; | - |
2853 | break; | - |
2854 | } | - |
2855 | default: | - |
2856 | break; | - |
2857 | } | - |
2858 | } | - |
2859 | return len; | - |
2860 | } | - |
2861 | | - |
2862 | | - |
2863 | | - |
2864 | | - |
2865 | | - |
2866 | | - |
2867 | | - |
2868 | | - |
2869 | | - |
2870 | qreal QPainterPath::percentAtLength(qreal len) const | - |
2871 | { | - |
2872 | Q_D(QPainterPath); | - |
2873 | if (isEmpty() || len <= 0) | - |
2874 | return 0; | - |
2875 | | - |
2876 | qreal totalLength = length(); | - |
2877 | if (len > totalLength) | - |
2878 | return 1; | - |
2879 | | - |
2880 | qreal curLen = 0; | - |
2881 | for (int i=1; i<d->elements.size(); ++i) { | - |
2882 | const Element &e = d->elements.at(i); | - |
2883 | | - |
2884 | switch (e.type) { | - |
2885 | case MoveToElement: | - |
2886 | break; | - |
2887 | case LineToElement: | - |
2888 | { | - |
2889 | QLineF line(d->elements.at(i-1), e); | - |
2890 | qreal llen = line.length(); | - |
2891 | curLen += llen; | - |
2892 | if (curLen >= len) { | - |
2893 | return len/totalLength ; | - |
2894 | } | - |
2895 | | - |
2896 | break; | - |
2897 | } | - |
2898 | case CurveToElement: | - |
2899 | { | - |
2900 | QBezier b = QBezier::fromPoints(d->elements.at(i-1), | - |
2901 | e, | - |
2902 | d->elements.at(i+1), | - |
2903 | d->elements.at(i+2)); | - |
2904 | qreal blen = b.length(); | - |
2905 | qreal prevLen = curLen; | - |
2906 | curLen += blen; | - |
2907 | | - |
2908 | if (curLen >= len) { | - |
2909 | qreal res = b.tAtLength(len - prevLen); | - |
2910 | return (res * blen + prevLen)/totalLength; | - |
2911 | } | - |
2912 | | - |
2913 | i += 2; | - |
2914 | break; | - |
2915 | } | - |
2916 | default: | - |
2917 | break; | - |
2918 | } | - |
2919 | } | - |
2920 | | - |
2921 | return 0; | - |
2922 | } | - |
2923 | | - |
2924 | static inline QBezier bezierAtT(const QPainterPath &path, qreal t, qreal *startingLength, qreal *bezierLength) | - |
2925 | { | - |
2926 | *startingLength = 0; | - |
2927 | if (t > 1) | - |
2928 | return QBezier(); | - |
2929 | | - |
2930 | qreal curLen = 0; | - |
2931 | qreal totalLength = path.length(); | - |
2932 | | - |
2933 | const int lastElement = path.elementCount() - 1; | - |
2934 | for (int i=0; i <= lastElement; ++i) { | - |
2935 | const QPainterPath::Element &e = path.elementAt(i); | - |
2936 | | - |
2937 | switch (e.type) { | - |
2938 | case QPainterPath::MoveToElement: | - |
2939 | break; | - |
2940 | case QPainterPath::LineToElement: | - |
2941 | { | - |
2942 | QLineF line(path.elementAt(i-1), e); | - |
2943 | qreal llen = line.length(); | - |
2944 | curLen += llen; | - |
2945 | if (i == lastElement || curLen/totalLength >= t) { | - |
2946 | *bezierLength = llen; | - |
2947 | QPointF a = path.elementAt(i-1); | - |
2948 | QPointF delta = e - a; | - |
2949 | return QBezier::fromPoints(a, a + delta / 3, a + 2 * delta / 3, e); | - |
2950 | } | - |
2951 | break; | - |
2952 | } | - |
2953 | case QPainterPath::CurveToElement: | - |
2954 | { | - |
2955 | QBezier b = QBezier::fromPoints(path.elementAt(i-1), | - |
2956 | e, | - |
2957 | path.elementAt(i+1), | - |
2958 | path.elementAt(i+2)); | - |
2959 | qreal blen = b.length(); | - |
2960 | curLen += blen; | - |
2961 | | - |
2962 | if (i + 2 == lastElement || curLen/totalLength >= t) { | - |
2963 | *bezierLength = blen; | - |
2964 | return b; | - |
2965 | } | - |
2966 | | - |
2967 | i += 2; | - |
2968 | break; | - |
2969 | } | - |
2970 | default: | - |
2971 | break; | - |
2972 | } | - |
2973 | *startingLength = curLen; | - |
2974 | } | - |
2975 | return QBezier(); | - |
2976 | } | - |
2977 | | - |
2978 | | - |
2979 | | - |
2980 | | - |
2981 | | - |
2982 | | - |
2983 | | - |
2984 | | - |
2985 | | - |
2986 | | - |
2987 | QPointF QPainterPath::pointAtPercent(qreal t) const | - |
2988 | { | - |
2989 | if (t < 0 || t > 1) { | - |
2990 | qWarning("QPainterPath::pointAtPercent accepts only values between 0 and 1"); | - |
2991 | return QPointF(); | - |
2992 | } | - |
2993 | | - |
2994 | if (!d_ptr || d_ptr->elements.size() == 0) | - |
2995 | return QPointF(); | - |
2996 | | - |
2997 | if (d_ptr->elements.size() == 1) | - |
2998 | return d_ptr->elements.at(0); | - |
2999 | | - |
3000 | qreal totalLength = length(); | - |
3001 | qreal curLen = 0; | - |
3002 | qreal bezierLen = 0; | - |
3003 | QBezier b = bezierAtT(*this, t, &curLen, &bezierLen); | - |
3004 | qreal realT = (totalLength * t - curLen) / bezierLen; | - |
3005 | | - |
3006 | return b.pointAt(qBound(qreal(0), realT, qreal(1))); | - |
3007 | } | - |
3008 | | - |
3009 | | - |
3010 | | - |
3011 | | - |
3012 | | - |
3013 | | - |
3014 | | - |
3015 | | - |
3016 | | - |
3017 | | - |
3018 | | - |
3019 | | - |
3020 | | - |
3021 | qreal QPainterPath::angleAtPercent(qreal t) const | - |
3022 | { | - |
3023 | if (t < 0 || t > 1) { | - |
3024 | qWarning("QPainterPath::angleAtPercent accepts only values between 0 and 1"); | - |
3025 | return 0; | - |
3026 | } | - |
3027 | | - |
3028 | qreal totalLength = length(); | - |
3029 | qreal curLen = 0; | - |
3030 | qreal bezierLen = 0; | - |
3031 | QBezier bez = bezierAtT(*this, t, &curLen, &bezierLen); | - |
3032 | qreal realT = (totalLength * t - curLen) / bezierLen; | - |
3033 | | - |
3034 | qreal m1 = slopeAt(realT, bez.x1, bez.x2, bez.x3, bez.x4); | - |
3035 | qreal m2 = slopeAt(realT, bez.y1, bez.y2, bez.y3, bez.y4); | - |
3036 | | - |
3037 | return QLineF(0, 0, m1, m2).angle(); | - |
3038 | } | - |
3039 | | - |
3040 | | - |
3041 | | - |
3042 | | - |
3043 | | - |
3044 | | - |
3045 | | - |
3046 | | - |
3047 | | - |
3048 | | - |
3049 | | - |
3050 | qreal QPainterPath::slopeAtPercent(qreal t) const | - |
3051 | { | - |
3052 | if (t < 0 || t > 1) { | - |
3053 | qWarning("QPainterPath::slopeAtPercent accepts only values between 0 and 1"); | - |
3054 | return 0; | - |
3055 | } | - |
3056 | | - |
3057 | qreal totalLength = length(); | - |
3058 | qreal curLen = 0; | - |
3059 | qreal bezierLen = 0; | - |
3060 | QBezier bez = bezierAtT(*this, t, &curLen, &bezierLen); | - |
3061 | qreal realT = (totalLength * t - curLen) / bezierLen; | - |
3062 | | - |
3063 | qreal m1 = slopeAt(realT, bez.x1, bez.x2, bez.x3, bez.x4); | - |
3064 | qreal m2 = slopeAt(realT, bez.y1, bez.y2, bez.y3, bez.y4); | - |
3065 | | - |
3066 | qreal slope = 0; | - |
3067 | | - |
3068 | if (m1) | - |
3069 | slope = m2/m1; | - |
3070 | else { | - |
3071 | if (std::numeric_limits<qreal>::has_infinity) { | - |
3072 | slope = (m2 < 0) ? -std::numeric_limits<qreal>::infinity() | - |
3073 | : std::numeric_limits<qreal>::infinity(); | - |
3074 | } else { | - |
3075 | if (sizeof(qreal) == sizeof(double)) { | - |
3076 | return 1.79769313486231570e+308; | - |
3077 | } else { | - |
3078 | return ((qreal)3.40282346638528860e+38); | - |
3079 | } | - |
3080 | } | - |
3081 | } | - |
3082 | | - |
3083 | return slope; | - |
3084 | } | - |
3085 | | - |
3086 | | - |
3087 | | - |
3088 | | - |
3089 | | - |
3090 | | - |
3091 | | - |
3092 | | - |
3093 | | - |
3094 | | - |
3095 | | - |
3096 | | - |
3097 | | - |
3098 | | - |
3099 | void QPainterPath::addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, | - |
3100 | Qt::SizeMode mode) | - |
3101 | { | - |
3102 | QRectF r = rect.normalized(); | - |
3103 | | - |
3104 | if (r.isNull()) | - |
3105 | return; | - |
3106 | | - |
3107 | if (mode == Qt::AbsoluteSize) { | - |
3108 | qreal w = r.width() / 2; | - |
3109 | qreal h = r.height() / 2; | - |
3110 | | - |
3111 | if (w == 0) { | - |
3112 | xRadius = 0; | - |
3113 | } else { | - |
3114 | xRadius = 100 * qMin(xRadius, w) / w; | - |
3115 | } | - |
3116 | if (h == 0) { | - |
3117 | yRadius = 0; | - |
3118 | } else { | - |
3119 | yRadius = 100 * qMin(yRadius, h) / h; | - |
3120 | } | - |
3121 | } else { | - |
3122 | if (xRadius > 100) | - |
3123 | xRadius = 100; | - |
3124 | | - |
3125 | if (yRadius > 100) | - |
3126 | yRadius = 100; | - |
3127 | } | - |
3128 | | - |
3129 | if (xRadius <= 0 || yRadius <= 0) { | - |
3130 | addRect(r); | - |
3131 | return; | - |
3132 | } | - |
3133 | | - |
3134 | qreal x = r.x(); | - |
3135 | qreal y = r.y(); | - |
3136 | qreal w = r.width(); | - |
3137 | qreal h = r.height(); | - |
3138 | qreal rxx2 = w*xRadius/100; | - |
3139 | qreal ryy2 = h*yRadius/100; | - |
3140 | | - |
3141 | ensureData(); | - |
3142 | detach(); | - |
3143 | | - |
3144 | bool first = d_func()->elements.size() < 2; | - |
3145 | | - |
3146 | arcMoveTo(x, y, rxx2, ryy2, 180); | - |
3147 | arcTo(x, y, rxx2, ryy2, 180, -90); | - |
3148 | arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90); | - |
3149 | arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90); | - |
3150 | arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90); | - |
3151 | closeSubpath(); | - |
3152 | | - |
3153 | d_func()->require_moveTo = true; | - |
3154 | d_func()->convex = first; | - |
3155 | } | - |
3156 | | - |
3157 | | - |
3158 | | - |
3159 | | - |
3160 | | - |
3161 | | - |
3162 | | - |
3163 | | - |
3164 | | - |
3165 | | - |
3166 | | - |
3167 | | - |
3168 | | - |
3169 | | - |
3170 | | - |
3171 | | - |
3172 | | - |
3173 | | - |
3174 | | - |
3175 | void QPainterPath::addRoundRect(const QRectF &r, int xRnd, int yRnd) | - |
3176 | { | - |
3177 | if(xRnd >= 100) | - |
3178 | xRnd = 99; | - |
3179 | if(yRnd >= 100) | - |
3180 | yRnd = 99; | - |
3181 | if(xRnd <= 0 || yRnd <= 0) { | - |
3182 | addRect(r); | - |
3183 | return; | - |
3184 | } | - |
3185 | | - |
3186 | QRectF rect = r.normalized(); | - |
3187 | | - |
3188 | if (rect.isNull()) | - |
3189 | return; | - |
3190 | | - |
3191 | qreal x = rect.x(); | - |
3192 | qreal y = rect.y(); | - |
3193 | qreal w = rect.width(); | - |
3194 | qreal h = rect.height(); | - |
3195 | qreal rxx2 = w*xRnd/100; | - |
3196 | qreal ryy2 = h*yRnd/100; | - |
3197 | | - |
3198 | ensureData(); | - |
3199 | detach(); | - |
3200 | | - |
3201 | bool first = d_func()->elements.size() < 2; | - |
3202 | | - |
3203 | arcMoveTo(x, y, rxx2, ryy2, 180); | - |
3204 | arcTo(x, y, rxx2, ryy2, 180, -90); | - |
3205 | arcTo(x+w-rxx2, y, rxx2, ryy2, 90, -90); | - |
3206 | arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 0, -90); | - |
3207 | arcTo(x, y+h-ryy2, rxx2, ryy2, 270, -90); | - |
3208 | closeSubpath(); | - |
3209 | | - |
3210 | d_func()->require_moveTo = true; | - |
3211 | d_func()->convex = first; | - |
3212 | } | - |
3213 | | - |
3214 | | - |
3215 | | - |
3216 | | - |
3217 | | - |
3218 | | - |
3219 | | - |
3220 | | - |
3221 | | - |
3222 | | - |
3223 | | - |
3224 | | - |
3225 | | - |
3226 | | - |
3227 | | - |
3228 | | - |
3229 | | - |
3230 | | - |
3231 | | - |
3232 | | - |
3233 | | - |
3234 | | - |
3235 | | - |
3236 | | - |
3237 | | - |
3238 | | - |
3239 | | - |
3240 | | - |
3241 | | - |
3242 | | - |
3243 | | - |
3244 | | - |
3245 | | - |
3246 | | - |
3247 | | - |
3248 | | - |
3249 | | - |
3250 | | - |
3251 | | - |
3252 | | - |
3253 | | - |
3254 | | - |
3255 | | - |
3256 | | - |
3257 | | - |
3258 | | - |
3259 | | - |
3260 | | - |
3261 | | - |
3262 | | - |
3263 | | - |
3264 | | - |
3265 | | - |
3266 | | - |
3267 | | - |
3268 | | - |
3269 | | - |
3270 | | - |
3271 | | - |
3272 | | - |
3273 | | - |
3274 | | - |
3275 | | - |
3276 | | - |
3277 | | - |
3278 | | - |
3279 | QPainterPath QPainterPath::united(const QPainterPath &p) const | - |
3280 | { | - |
3281 | if (isEmpty() || p.isEmpty()) | - |
3282 | return isEmpty() ? p : *this; | - |
3283 | QPathClipper clipper(*this, p); | - |
3284 | return clipper.clip(QPathClipper::BoolOr); | - |
3285 | } | - |
3286 | | - |
3287 | | - |
3288 | | - |
3289 | | - |
3290 | | - |
3291 | | - |
3292 | | - |
3293 | | - |
3294 | QPainterPath QPainterPath::intersected(const QPainterPath &p) const | - |
3295 | { | - |
3296 | if (isEmpty() || p.isEmpty()) | - |
3297 | return QPainterPath(); | - |
3298 | QPathClipper clipper(*this, p); | - |
3299 | return clipper.clip(QPathClipper::BoolAnd); | - |
3300 | } | - |
3301 | | - |
3302 | | - |
3303 | | - |
3304 | | - |
3305 | | - |
3306 | | - |
3307 | | - |
3308 | | - |
3309 | | - |
3310 | | - |
3311 | | - |
3312 | QPainterPath QPainterPath::subtracted(const QPainterPath &p) const | - |
3313 | { | - |
3314 | if (isEmpty() || p.isEmpty()) | - |
3315 | return *this; | - |
3316 | QPathClipper clipper(*this, p); | - |
3317 | return clipper.clip(QPathClipper::BoolSub); | - |
3318 | } | - |
3319 | | - |
3320 | | - |
3321 | | - |
3322 | | - |
3323 | | - |
3324 | | - |
3325 | | - |
3326 | | - |
3327 | | - |
3328 | QPainterPath QPainterPath::subtractedInverted(const QPainterPath &p) const | - |
3329 | { | - |
3330 | return p.subtracted(*this); | - |
3331 | } | - |
3332 | | - |
3333 | | - |
3334 | | - |
3335 | | - |
3336 | | - |
3337 | | - |
3338 | | - |
3339 | | - |
3340 | | - |
3341 | | - |
3342 | QPainterPath QPainterPath::simplified() const | - |
3343 | { | - |
3344 | if(isEmpty()) | - |
3345 | return *this; | - |
3346 | QPathClipper clipper(*this, QPainterPath()); | - |
3347 | return clipper.clip(QPathClipper::Simplify); | - |
3348 | } | - |
3349 | | - |
3350 | | - |
3351 | | - |
3352 | | - |
3353 | | - |
3354 | | - |
3355 | | - |
3356 | | - |
3357 | | - |
3358 | | - |
3359 | | - |
3360 | | - |
3361 | bool QPainterPath::intersects(const QPainterPath &p) const | - |
3362 | { | - |
3363 | if (p.elementCount() == 1) | - |
3364 | return contains(p.elementAt(0)); | - |
3365 | if (isEmpty() || p.isEmpty()) | - |
3366 | return false; | - |
3367 | QPathClipper clipper(*this, p); | - |
3368 | return clipper.intersect(); | - |
3369 | } | - |
3370 | | - |
3371 | | - |
3372 | | - |
3373 | | - |
3374 | | - |
3375 | | - |
3376 | | - |
3377 | | - |
3378 | | - |
3379 | | - |
3380 | | - |
3381 | | - |
3382 | | - |
3383 | bool QPainterPath::contains(const QPainterPath &p) const | - |
3384 | { | - |
3385 | if (p.elementCount() == 1) | - |
3386 | return contains(p.elementAt(0)); | - |
3387 | if (isEmpty() || p.isEmpty()) | - |
3388 | return false; | - |
3389 | QPathClipper clipper(*this, p); | - |
3390 | return clipper.contains(); | - |
3391 | } | - |
3392 | | - |
3393 | void QPainterPath::setDirty(bool dirty) | - |
3394 | { | - |
3395 | d_func()->dirtyBounds = dirty; | - |
3396 | d_func()->dirtyControlBounds = dirty; | - |
3397 | delete d_func()->pathConverter; | - |
3398 | d_func()->pathConverter = 0; | - |
3399 | d_func()->convex = false; | - |
3400 | } | - |
3401 | | - |
3402 | void QPainterPath::computeBoundingRect() const | - |
3403 | { | - |
3404 | QPainterPathData *d = d_func(); | - |
3405 | d->dirtyBounds = false; | - |
3406 | if (!d_ptr) { | - |
3407 | d->bounds = QRect(); | - |
3408 | return; | - |
3409 | } | - |
3410 | | - |
3411 | qreal minx, maxx, miny, maxy; | - |
3412 | minx = maxx = d->elements.at(0).x; | - |
3413 | miny = maxy = d->elements.at(0).y; | - |
3414 | for (int i=1; i<d->elements.size(); ++i) { | - |
3415 | const Element &e = d->elements.at(i); | - |
3416 | | - |
3417 | switch (e.type) { | - |
3418 | case MoveToElement: | - |
3419 | case LineToElement: | - |
3420 | if (e.x > maxx) maxx = e.x; | - |
3421 | else if (e.x < minx) minx = e.x; | - |
3422 | if (e.y > maxy) maxy = e.y; | - |
3423 | else if (e.y < miny) miny = e.y; | - |
3424 | break; | - |
3425 | case CurveToElement: | - |
3426 | { | - |
3427 | QBezier b = QBezier::fromPoints(d->elements.at(i-1), | - |
3428 | e, | - |
3429 | d->elements.at(i+1), | - |
3430 | d->elements.at(i+2)); | - |
3431 | QRectF r = qt_painterpath_bezier_extrema(b); | - |
3432 | qreal right = r.right(); | - |
3433 | qreal bottom = r.bottom(); | - |
3434 | if (r.x() < minx) minx = r.x(); | - |
3435 | if (right > maxx) maxx = right; | - |
3436 | if (r.y() < miny) miny = r.y(); | - |
3437 | if (bottom > maxy) maxy = bottom; | - |
3438 | i += 2; | - |
3439 | } | - |
3440 | break; | - |
3441 | default: | - |
3442 | break; | - |
3443 | } | - |
3444 | } | - |
3445 | d->bounds = QRectF(minx, miny, maxx - minx, maxy - miny); | - |
3446 | } | - |
3447 | | - |
3448 | | - |
3449 | void QPainterPath::computeControlPointRect() const | - |
3450 | { | - |
3451 | QPainterPathData *d = d_func(); | - |
3452 | d->dirtyControlBounds = false; | - |
3453 | if (!d_ptr) { | - |
3454 | d->controlBounds = QRect(); | - |
3455 | return; | - |
3456 | } | - |
3457 | | - |
3458 | qreal minx, maxx, miny, maxy; | - |
3459 | minx = maxx = d->elements.at(0).x; | - |
3460 | miny = maxy = d->elements.at(0).y; | - |
3461 | for (int i=1; i<d->elements.size(); ++i) { | - |
3462 | const Element &e = d->elements.at(i); | - |
3463 | if (e.x > maxx) maxx = e.x; | - |
3464 | else if (e.x < minx) minx = e.x; | - |
3465 | if (e.y > maxy) maxy = e.y; | - |
3466 | else if (e.y < miny) miny = e.y; | - |
3467 | } | - |
3468 | d->controlBounds = QRectF(minx, miny, maxx - minx, maxy - miny); | - |
3469 | } | - |
3470 | | - |
3471 | #ifndef QT_NO_DEBUG_STREAM | - |
3472 | QDebug operator<<(QDebug s, const QPainterPath &p) | - |
3473 | { | - |
3474 | s.nospace() << "QPainterPath: Element count=" << p.elementCount() << endl; | - |
3475 | const char *types[] = {"MoveTo", "LineTo", "CurveTo", "CurveToData"}; | - |
3476 | for (int i=0; i<p.elementCount(); ++i) { | - |
3477 | s.nospace() << " -> " << types[p.elementAt(i).type] << "(x=" << p.elementAt(i).x << ", y=" << p.elementAt(i).y << ')' << endl; | - |
3478 | | - |
3479 | } | - |
3480 | return s; | - |
3481 | } | - |
3482 | #endif | - |
3483 | | - |
3484 | QT_END_NAMESPACE | - |
| | |