24 class ClipPainterPrivate
49 inline int sector(
const QPointF & point )
const;
56 inline void initClipRect();
58 inline void clipPolyObject (
const QPolygonF & sourcePolygon,
62 inline void clipMultiple(
QPolygonF & clippedPolyObject,
65 inline void clipOnce(
QPolygonF & clippedPolyObject,
68 inline void clipOnceCorner(
QPolygonF & clippedPolyObject,
72 bool isClosed )
const;
73 inline void clipOnceEdge(
QPolygonF & clippedPolyObject,
76 bool isClosed )
const;
80 LabelPositionFlags labelPositionFlags);
82 bool pointAllowsLabel(
const QPointF& point );
85 LabelPositionFlags labelPositionFlags );
87 static inline qreal _m(
const QPointF & start,
const QPointF & end );
89 #ifdef DEBUG_DRAW_NODES
93 qreal m_labelAreaMargin;
98 using namespace Marble;
103 :
QPainter( pd ), d( new ClipPainterPrivate( this ) )
113 : d( new ClipPainterPrivate( this ) )
126 d->m_doClip = enable;
137 Qt::FillRule fillRule )
144 d->clipPolyObject( polygon, clippedPolyObjects,
true );
146 foreach(
const QPolygonF & clippedPolyObject, clippedPolyObjects ) {
147 if ( clippedPolyObject.
size() > 2 ) {
151 #ifdef DEBUG_DRAW_NODES
152 d->debugDrawNodes( clippedPolyObject );
160 #ifdef DEBUG_DRAW_NODES
161 d->debugDrawNodes( polygon );
173 d->clipPolyObject( polygon, clippedPolyObjects,
false );
175 foreach(
const QPolygonF & clippedPolyObject, clippedPolyObjects ) {
176 if ( clippedPolyObject.
size() > 1 ) {
181 #ifdef DEBUG_DRAW_NODES
182 d->debugDrawNodes( clippedPolyObject );
190 #ifdef DEBUG_DRAW_NODES
191 d->debugDrawNodes( polygon );
197 LabelPositionFlags positionFlags)
205 d->clipPolyObject( polygon, clippedPolyObjects,
false );
207 foreach(
const QPolygonF & clippedPolyObject, clippedPolyObjects ) {
208 if ( clippedPolyObject.
size() > 1 ) {
213 #ifdef DEBUG_DRAW_NODES
214 d->debugDrawNodes( clippedPolyObject );
217 d->labelPosition( clippedPolyObject, labelNodes, positionFlags );
224 #ifdef DEBUG_DRAW_NODES
225 d->debugDrawNodes( polygon );
228 d->labelPosition( polygon, labelNodes, positionFlags );
233 LabelPositionFlags labelPositionFlags)
235 bool currentAllowsLabel =
false;
237 if ( labelPositionFlags.testFlag(
LineCenter ) ) {
239 int labelPosition =
static_cast<int>( polygon.
size() / 2.0 );
240 if ( polygon.
size() > 0 ) {
241 if ( labelPosition >= polygon.
size() ) {
242 labelPosition = polygon.
size() - 1;
244 labelNodes << polygon.
at( labelPosition );
248 if ( polygon.
size() > 0 && labelPositionFlags.testFlag(
LineStart ) ) {
249 if ( pointAllowsLabel( polygon.
first() ) ) {
250 labelNodes << polygon.
first();
254 for (
int it = 1; it < polygon.
size(); ++it ) {
255 currentAllowsLabel = pointAllowsLabel( polygon.
at( it ) );
257 if ( currentAllowsLabel ) {
259 QPointF node = interpolateLabelPoint( polygon.
at( it -1 ), polygon.
at( it ),
260 labelPositionFlags );
261 if ( node !=
QPointF( -1.0, -1.0 ) ) {
269 if ( polygon.
size() > 1 && labelPositionFlags.testFlag(
LineEnd ) ) {
270 if ( pointAllowsLabel( polygon.
at( polygon.
size() - 1 ) ) ) {
271 labelNodes << polygon.
at( polygon.
size() - 1 );
275 for (
int it = polygon.
size() - 2; it > 0; --it ) {
276 currentAllowsLabel = pointAllowsLabel( polygon.
at( it ) );
278 if ( currentAllowsLabel ) {
279 QPointF node = interpolateLabelPoint( polygon.
at( it + 1 ), polygon.
at( it ),
280 labelPositionFlags );
281 if ( node !=
QPointF( -1.0, -1.0 ) ) {
290 bool ClipPainterPrivate::pointAllowsLabel(
const QPointF& point )
293 if ( point.
x() > m_labelAreaMargin && point.
x() < q->viewport().width() - m_labelAreaMargin
294 && point.
y() > m_labelAreaMargin && point.
y() < q->viewport().height() - m_labelAreaMargin ) {
300 QPointF ClipPainterPrivate::interpolateLabelPoint(
const QPointF& previousPoint,
302 LabelPositionFlags labelPositionFlags )
304 qreal m = _m( previousPoint, currentPoint );
305 if ( previousPoint.
x() <= m_labelAreaMargin ) {
309 return QPointF( m_labelAreaMargin,
310 previousPoint.
y() + ( m_labelAreaMargin - previousPoint.
x() ) * m );
312 else if ( previousPoint.
x() >= q->viewport().width() - m_labelAreaMargin ) {
316 return QPointF( q->viewport().width() - m_labelAreaMargin,
318 ( previousPoint.
x() - q->viewport().width() + m_labelAreaMargin ) * m );
321 if ( previousPoint.
y() <= m_labelAreaMargin ) {
325 return QPointF( previousPoint.
x() + ( m_labelAreaMargin - previousPoint.
y() ) / m,
328 else if ( previousPoint.
y() >= q->viewport().height() - m_labelAreaMargin ) {
333 ( previousPoint.
y() - q->viewport().height() + m_labelAreaMargin ) / m,
334 q->viewport().height() - m_labelAreaMargin );
342 ClipPainterPrivate::ClipPainterPrivate(
ClipPainter * parent )
352 m_labelAreaMargin(10.0)
357 void ClipPainterPrivate::initClipRect ()
359 qreal penHalfWidth = q->
pen().
widthF() / 2.0 + 1.0;
361 m_left = -penHalfWidth;
362 m_right = (qreal)(q->device()->width()) + penHalfWidth;
363 m_top = -penHalfWidth;
364 m_bottom = (qreal)(q->device()->height()) + penHalfWidth;
367 qreal ClipPainterPrivate::_m(
const QPointF & start,
const QPointF & end )
369 qreal divisor = end.
x() - start.
x();
370 if ( std::fabs( divisor ) < 0.000001 ) {
376 return ( end.
y() - start.
y() )
381 QPointF ClipPainterPrivate::clipTop( qreal m,
const QPointF & point )
const
383 return QPointF( ( m_top - point.
y() ) / m + point.
x(), m_top );
386 QPointF ClipPainterPrivate::clipLeft( qreal m,
const QPointF & point )
const
388 return QPointF( m_left, ( m_left - point.
x() ) * m + point.
y() );
391 QPointF ClipPainterPrivate::clipBottom( qreal m,
const QPointF & point )
const
393 return QPointF( ( m_bottom - point.
y() ) / m + point.
x(), m_bottom );
396 QPointF ClipPainterPrivate::clipRight( qreal m,
const QPointF & point )
const
398 return QPointF( m_right, ( m_right - point.
x() ) * m + point.
y() );
401 int ClipPainterPrivate::sector(
const QPointF & point )
const
416 if ( point.
x() < m_left )
418 else if ( point.
x() > m_right )
422 if ( point.
y() < m_top )
424 else if ( point.
y() > m_bottom )
429 return ySector + xSector;
433 void ClipPainterPrivate::clipPolyObject (
const QPolygonF & polygon,
451 bool processingLastNode =
false;
453 while ( itPoint != itEndPoint ) {
454 m_currentPoint = (*itPoint);
458 m_currentSector = sector( m_currentPoint );
461 if ( itPoint == itStartPoint && processingLastNode ==
false ) {
463 m_previousPoint = polygon.
last();
466 m_previousSector = sector( m_previousPoint );
469 m_previousSector = m_currentSector;
474 if ( m_currentSector != m_previousSector ) {
475 if ( m_currentSector == 4 || m_previousSector == 4 ) {
480 clipOnce( clippedPolyObject, clippedPolyObjects, isClosed );
487 clipMultiple( clippedPolyObject, clippedPolyObjects, isClosed );
490 m_previousSector = m_currentSector;
494 if ( m_currentSector == 4 ) {
496 clippedPolyObject << m_currentPoint;
498 ++(m_debugNodeCount);
502 m_previousPoint = m_currentPoint;
507 if ( processingLastNode ) {
512 if ( itPoint == itEndPoint && isClosed ) {
513 itPoint = itStartPoint;
514 processingLastNode =
true;
519 if ( !clippedPolyObject.
isEmpty() ) {
520 clippedPolyObjects << clippedPolyObject;
525 void ClipPainterPrivate::clipMultiple(
QPolygonF & clippedPolyObject,
529 Q_UNUSED( clippedPolyObjects )
535 qreal m = _m( m_previousPoint, m_currentPoint );
537 switch ( m_currentSector ) {
539 if ( m_previousSector == 5 ) {
540 QPointF pointRight = clipRight( m, m_previousPoint );
541 QPointF pointTop = clipTop( m, m_currentPoint );
542 QPointF pointLeft = clipLeft( m, m_currentPoint );
544 if ( pointRight.
y() > m_top ) {
545 clippedPolyObject << pointRight;
547 clippedPolyObject <<
QPointF( m_right, m_top );
549 if ( pointTop.
x() >= m_left && pointTop.
x() < m_right )
550 clippedPolyObject << pointTop;
551 if ( pointLeft.
y() > m_top )
552 clippedPolyObject << pointLeft;
554 else if ( m_previousSector == 7 ) {
555 QPointF pointBottom = clipBottom( m, m_previousPoint );
556 QPointF pointTop = clipTop( m, m_currentPoint );
557 QPointF pointLeft = clipLeft( m, m_currentPoint );
559 if ( pointBottom.
x() > m_left ) {
560 clippedPolyObject << pointBottom;
562 clippedPolyObject <<
QPointF( m_left, m_bottom );
564 if ( pointLeft.
y() >= m_top && pointLeft.
y() < m_bottom )
565 clippedPolyObject << pointLeft;
566 if ( pointTop.
x() > m_left )
567 clippedPolyObject << pointTop;
569 else if ( m_previousSector == 8 ) {
570 QPointF pointBottom = clipBottom( m, m_previousPoint );
571 QPointF pointRight = clipRight( m, m_previousPoint );
572 QPointF pointTop = clipTop( m, m_currentPoint );
573 QPointF pointLeft = clipLeft( m, m_currentPoint );
575 if ( pointBottom.
x() > m_left && pointBottom.
x() < m_right )
576 clippedPolyObject << pointBottom;
577 if ( pointRight.
y() > m_top && pointRight.
y() < m_bottom )
578 clippedPolyObject << pointRight;
579 if ( pointTop.
x() > m_left && pointTop.
x() < m_right )
580 clippedPolyObject << pointTop;
581 if ( pointLeft.
y() > m_top && pointLeft.
y() < m_bottom )
582 clippedPolyObject << pointLeft;
584 if ( pointBottom.
x() <= m_left && pointLeft.
y() >= m_bottom )
585 clippedPolyObject <<
QPointF( m_left, m_bottom );
586 if ( pointTop.
x() >= m_right && pointRight.
y() <= m_top )
587 clippedPolyObject <<
QPointF( m_right, m_top );
590 clippedPolyObject <<
QPointF( m_left, m_top );
594 if ( m_previousSector == 3 ) {
595 QPointF pointLeft = clipLeft( m, m_previousPoint );
596 QPointF pointTop = clipTop( m, m_currentPoint );
598 if ( pointLeft.
y() > m_top ) {
599 clippedPolyObject << pointLeft;
601 clippedPolyObject <<
QPointF( m_left, m_top );
603 if ( pointTop.
x() > m_left )
604 clippedPolyObject << pointTop;
606 else if ( m_previousSector == 5 ) {
607 QPointF pointRight = clipRight( m, m_previousPoint );
608 QPointF pointTop = clipTop( m, m_currentPoint );
610 if ( pointRight.
y() > m_top ) {
611 clippedPolyObject << pointRight;
613 clippedPolyObject <<
QPointF( m_right, m_top );
615 if ( pointTop.
x() < m_right )
616 clippedPolyObject << pointTop;
618 else if ( m_previousSector == 6 ) {
619 QPointF pointBottom = clipBottom( m, m_previousPoint );
620 QPointF pointLeft = clipLeft( m, m_previousPoint );
621 QPointF pointTop = clipTop( m, m_currentPoint );
623 if ( pointBottom.
x() > m_left )
624 clippedPolyObject << pointBottom;
625 if ( pointLeft.
y() > m_top && pointLeft.
y() <= m_bottom )
626 clippedPolyObject << pointLeft;
627 if ( pointTop.
x() > m_left ) {
628 clippedPolyObject << pointTop;
630 clippedPolyObject <<
QPointF( m_left, m_top );
633 else if ( m_previousSector == 7 ) {
634 clippedPolyObject << clipBottom( m, m_previousPoint );
635 clippedPolyObject << clipTop( m, m_currentPoint );
637 else if ( m_previousSector == 8 ) {
638 QPointF pointBottom = clipBottom( m, m_previousPoint );
639 QPointF pointRight = clipRight( m, m_previousPoint );
640 QPointF pointTop = clipTop( m, m_currentPoint );
642 if ( pointBottom.
x() < m_right )
643 clippedPolyObject << pointBottom;
644 if ( pointRight.
y() > m_top && pointRight.
y() <= m_bottom )
645 clippedPolyObject << pointRight;
646 if ( pointTop.
x() < m_right ) {
647 clippedPolyObject << pointTop;
649 clippedPolyObject <<
QPointF( m_right, m_top );
655 if ( m_previousSector == 3 ) {
656 QPointF pointLeft = clipLeft( m, m_previousPoint );
657 QPointF pointTop = clipTop( m, m_currentPoint );
658 QPointF pointRight = clipRight( m, m_currentPoint );
660 if ( pointLeft.
y() > m_top ) {
661 clippedPolyObject << pointLeft;
663 clippedPolyObject <<
QPointF( m_left, m_top );
665 if ( pointTop.
x() > m_left && pointTop.
x() <= m_right )
666 clippedPolyObject << pointTop;
667 if ( pointRight.
y() > m_top )
668 clippedPolyObject << pointRight;
670 else if ( m_previousSector == 7 ) {
671 QPointF pointBottom = clipBottom( m, m_previousPoint );
672 QPointF pointTop = clipTop( m, m_currentPoint );
673 QPointF pointRight = clipRight( m, m_currentPoint );
675 if ( pointBottom.
x() < m_right ) {
676 clippedPolyObject << pointBottom;
678 clippedPolyObject <<
QPointF( m_right, m_bottom );
680 if ( pointRight.
y() >= m_top && pointRight.
y() < m_bottom )
681 clippedPolyObject << pointRight;
682 if ( pointTop.
x() < m_right )
683 clippedPolyObject << pointTop;
685 else if ( m_previousSector == 6 ) {
686 QPointF pointBottom = clipBottom( m, m_previousPoint );
687 QPointF pointLeft = clipLeft( m, m_currentPoint );
688 QPointF pointTop = clipTop( m, m_currentPoint );
689 QPointF pointRight = clipRight( m, m_previousPoint );
691 if ( pointBottom.
x() > m_left && pointBottom.
x() < m_right )
692 clippedPolyObject << pointBottom;
693 if ( pointLeft.
y() > m_top && pointLeft.
y() < m_bottom )
694 clippedPolyObject << pointLeft;
695 if ( pointTop.
x() > m_left && pointTop.
x() < m_right )
696 clippedPolyObject << pointTop;
697 if ( pointRight.
y() > m_top && pointRight.
y() < m_bottom )
698 clippedPolyObject << pointRight;
700 if ( pointBottom.
x() >= m_right && pointRight.
y() >= m_bottom )
701 clippedPolyObject <<
QPointF( m_right, m_bottom );
702 if ( pointTop.
x() <= m_left && pointLeft.
y() <= m_top )
703 clippedPolyObject <<
QPointF( m_left, m_top );
706 clippedPolyObject <<
QPointF( m_right, m_top );
710 if ( m_previousSector == 7 ) {
711 QPointF pointBottom = clipBottom( m, m_previousPoint );
712 QPointF pointLeft = clipLeft( m, m_currentPoint );
714 if ( pointBottom.
x() > m_left )
715 clippedPolyObject << pointBottom;
716 if ( pointLeft.
y() < m_bottom ) {
717 clippedPolyObject << pointLeft;
719 clippedPolyObject <<
QPointF( m_left, m_bottom );
722 else if ( m_previousSector == 1 ) {
723 QPointF pointTop = clipTop( m, m_previousPoint );
724 QPointF pointLeft = clipLeft( m, m_currentPoint );
726 if ( pointTop.
x() > m_left )
727 clippedPolyObject << pointTop;
728 if ( pointLeft.
y() > m_top ) {
729 clippedPolyObject << pointLeft;
731 clippedPolyObject <<
QPointF( m_left, m_top );
734 else if ( m_previousSector == 8 ) {
735 QPointF pointRight = clipRight( m, m_previousPoint );
736 QPointF pointBottom = clipBottom( m, m_previousPoint );
737 QPointF pointLeft = clipLeft( m, m_currentPoint );
739 if ( pointRight.
y() < m_bottom )
740 clippedPolyObject << pointRight;
741 if ( pointBottom.
x() > m_left && pointBottom.
x() <= m_right )
742 clippedPolyObject << pointBottom;
743 if ( pointLeft.
y() < m_bottom ) {
744 clippedPolyObject << pointLeft;
746 clippedPolyObject <<
QPointF( m_left, m_bottom );
749 else if ( m_previousSector == 5 ) {
750 clippedPolyObject << clipRight( m, m_previousPoint );
751 clippedPolyObject << clipLeft( m, m_currentPoint );
753 else if ( m_previousSector == 2 ) {
754 QPointF pointRight = clipRight( m, m_previousPoint );
755 QPointF pointTop = clipTop( m, m_previousPoint );
756 QPointF pointLeft = clipLeft( m, m_currentPoint );
758 if ( pointRight.
y() > m_top )
759 clippedPolyObject << pointRight;
760 if ( pointTop.
x() > m_left && pointTop.
x() <= m_right )
761 clippedPolyObject << pointTop;
762 if ( pointLeft.
y() > m_top ) {
763 clippedPolyObject << pointLeft;
765 clippedPolyObject <<
QPointF( m_left, m_top );
771 if ( m_previousSector == 7 ) {
772 QPointF pointBottom = clipBottom( m, m_previousPoint );
773 QPointF pointRight = clipRight( m, m_currentPoint );
775 if ( pointBottom.
x() < m_right )
776 clippedPolyObject << pointBottom;
777 if ( pointRight.
y() < m_bottom ) {
778 clippedPolyObject << pointRight;
780 clippedPolyObject <<
QPointF( m_right, m_bottom );
783 else if ( m_previousSector == 1 ) {
784 QPointF pointTop = clipTop( m, m_previousPoint );
785 QPointF pointRight = clipRight( m, m_currentPoint );
787 if ( pointTop.
x() < m_right )
788 clippedPolyObject << pointTop;
789 if ( pointRight.
y() > m_top ) {
790 clippedPolyObject << pointRight;
792 clippedPolyObject <<
QPointF( m_right, m_top );
795 else if ( m_previousSector == 6 ) {
796 QPointF pointLeft = clipLeft( m, m_previousPoint );
797 QPointF pointBottom = clipBottom( m, m_previousPoint );
798 QPointF pointRight = clipRight( m, m_currentPoint );
800 if ( pointLeft.
y() < m_bottom )
801 clippedPolyObject << pointLeft;
802 if ( pointBottom.
x() >= m_left && pointBottom.
x() < m_right )
803 clippedPolyObject << pointBottom;
804 if ( pointRight.
y() < m_bottom ) {
805 clippedPolyObject << pointRight;
807 clippedPolyObject <<
QPointF( m_right, m_bottom );
810 else if ( m_previousSector == 3 ) {
811 clippedPolyObject << clipLeft( m, m_previousPoint );
812 clippedPolyObject << clipRight( m, m_currentPoint );
814 else if ( m_previousSector == 0 ) {
815 QPointF pointLeft = clipLeft( m, m_previousPoint );
816 QPointF pointTop = clipTop( m, m_previousPoint );
817 QPointF pointRight = clipRight( m, m_currentPoint );
819 if ( pointLeft.
y() > m_top )
820 clippedPolyObject << pointLeft;
821 if ( pointTop.
x() >= m_left && pointTop.
x() < m_right )
822 clippedPolyObject << pointTop;
823 if ( pointRight.
y() > m_top ) {
824 clippedPolyObject << pointRight;
826 clippedPolyObject <<
QPointF( m_right, m_top );
832 if ( m_previousSector == 5 ) {
833 QPointF pointRight = clipRight( m, m_previousPoint );
834 QPointF pointBottom = clipBottom( m, m_currentPoint );
835 QPointF pointLeft = clipLeft( m, m_currentPoint );
837 if ( pointRight.
y() < m_bottom ) {
838 clippedPolyObject << pointRight;
840 clippedPolyObject <<
QPointF( m_right, m_bottom );
842 if ( pointBottom.
x() >= m_left && pointBottom.
x() < m_right )
843 clippedPolyObject << pointBottom;
844 if ( pointLeft.
y() < m_bottom )
845 clippedPolyObject << pointLeft;
847 else if ( m_previousSector == 1 ) {
848 QPointF pointTop = clipTop( m, m_previousPoint );
849 QPointF pointLeft = clipLeft( m, m_currentPoint );
850 QPointF pointBottom = clipBottom( m, m_currentPoint );
852 if ( pointTop.
x() > m_left ) {
853 clippedPolyObject << pointTop;
855 clippedPolyObject <<
QPointF( m_left, m_top );
857 if ( pointLeft.
y() > m_top && pointLeft.
y() <= m_bottom )
858 clippedPolyObject << pointLeft;
859 if ( pointBottom.
x() > m_left )
860 clippedPolyObject << pointBottom;
862 else if ( m_previousSector == 2 ) {
863 QPointF pointTop = clipTop( m, m_currentPoint );
864 QPointF pointRight = clipRight( m, m_previousPoint );
865 QPointF pointBottom = clipBottom( m, m_previousPoint );
866 QPointF pointLeft = clipLeft( m, m_currentPoint );
868 if ( pointTop.
x() > m_left && pointTop.
x() < m_right )
869 clippedPolyObject << pointTop;
870 if ( pointRight.
y() > m_top && pointRight.
y() < m_bottom )
871 clippedPolyObject << pointRight;
872 if ( pointBottom.
x() > m_left && pointBottom.
x() < m_right )
873 clippedPolyObject << pointBottom;
874 if ( pointLeft.
y() > m_top && pointLeft.
y() < m_bottom )
875 clippedPolyObject << pointLeft;
877 if ( pointBottom.
x() >= m_right && pointRight.
y() >= m_bottom )
878 clippedPolyObject <<
QPointF( m_right, m_bottom );
879 if ( pointTop.
x() <= m_left && pointLeft.
y() <= m_top )
880 clippedPolyObject <<
QPointF( m_left, m_top );
883 clippedPolyObject <<
QPointF( m_left, m_bottom );
887 if ( m_previousSector == 3 ) {
888 QPointF pointLeft = clipLeft( m, m_previousPoint );
889 QPointF pointBottom = clipBottom( m, m_currentPoint );
891 if ( pointLeft.
y() < m_bottom ) {
892 clippedPolyObject << pointLeft;
894 clippedPolyObject <<
QPointF( m_left, m_bottom );
896 if ( pointBottom.
x() > m_left )
897 clippedPolyObject << pointBottom;
899 else if ( m_previousSector == 5 ) {
900 QPointF pointRight = clipRight( m, m_previousPoint );
901 QPointF pointBottom = clipBottom( m, m_currentPoint );
903 if ( pointRight.
y() < m_bottom ) {
904 clippedPolyObject << pointRight;
906 clippedPolyObject <<
QPointF( m_right, m_bottom );
908 if ( pointBottom.
x() < m_right )
909 clippedPolyObject << pointBottom;
911 else if ( m_previousSector == 0 ) {
912 QPointF pointTop = clipTop( m, m_previousPoint );
913 QPointF pointLeft = clipLeft( m, m_previousPoint );
914 QPointF pointBottom = clipBottom( m, m_currentPoint );
916 if ( pointTop.
x() > m_left )
917 clippedPolyObject << pointTop;
918 if ( pointLeft.
y() >= m_top && pointLeft.
y() < m_bottom )
919 clippedPolyObject << pointLeft;
920 if ( pointBottom.
x() > m_left ) {
921 clippedPolyObject << pointBottom;
923 clippedPolyObject <<
QPointF( m_left, m_bottom );
926 else if ( m_previousSector == 1 ) {
927 clippedPolyObject << clipTop( m, m_previousPoint );
928 clippedPolyObject << clipBottom( m, m_currentPoint );
930 else if ( m_previousSector == 2 ) {
931 QPointF pointTop = clipTop( m, m_previousPoint );
932 QPointF pointRight = clipRight( m, m_previousPoint );
933 QPointF pointBottom = clipBottom( m, m_currentPoint );
935 if ( pointTop.
x() < m_right )
936 clippedPolyObject << pointTop;
937 if ( pointRight.
y() >= m_top && pointRight.
y() < m_bottom )
938 clippedPolyObject << pointRight;
939 if ( pointBottom.
x() < m_right ) {
940 clippedPolyObject << pointBottom;
942 clippedPolyObject <<
QPointF( m_right, m_bottom );
948 if ( m_previousSector == 3 ) {
949 QPointF pointLeft = clipLeft( m, m_previousPoint );
950 QPointF pointBottom = clipBottom( m, m_currentPoint );
951 QPointF pointRight = clipRight( m, m_currentPoint );
953 if ( pointLeft.
y() < m_bottom ) {
954 clippedPolyObject << pointLeft;
956 clippedPolyObject <<
QPointF( m_left, m_bottom );
958 if ( pointBottom.
x() > m_left && pointBottom.
x() <= m_right )
959 clippedPolyObject << pointBottom;
960 if ( pointRight.
y() < m_bottom )
961 clippedPolyObject << pointRight;
963 else if ( m_previousSector == 1 ) {
964 QPointF pointTop = clipTop( m, m_previousPoint );
965 QPointF pointRight = clipRight( m, m_currentPoint );
966 QPointF pointBottom = clipBottom( m, m_currentPoint );
968 if ( pointTop.
x() < m_right ) {
969 clippedPolyObject << pointTop;
971 clippedPolyObject <<
QPointF( m_right, m_top );
973 if ( pointRight.
y() > m_top && pointRight.
y() <= m_bottom )
974 clippedPolyObject << pointRight;
975 if ( pointBottom.
x() < m_right )
976 clippedPolyObject << pointBottom;
978 else if ( m_previousSector == 0 ) {
979 QPointF pointTop = clipTop( m, m_currentPoint );
980 QPointF pointLeft = clipLeft( m, m_currentPoint );
981 QPointF pointBottom = clipBottom( m, m_previousPoint );
982 QPointF pointRight = clipRight( m, m_previousPoint );
984 if ( pointTop.
x() > m_left && pointTop.
x() < m_right )
985 clippedPolyObject << pointTop;
986 if ( pointLeft.
y() > m_top && pointLeft.
y() < m_bottom )
987 clippedPolyObject << pointLeft;
988 if ( pointBottom.
x() > m_left && pointBottom.
x() < m_right )
989 clippedPolyObject << pointBottom;
990 if ( pointRight.
y() > m_top && pointRight.
y() < m_bottom )
991 clippedPolyObject << pointRight;
993 if ( pointBottom.
x() <= m_left && pointLeft.
y() >= m_bottom )
994 clippedPolyObject <<
QPointF( m_left, m_bottom );
995 if ( pointTop.
x() >= m_right && pointRight.
y() <= m_top )
996 clippedPolyObject <<
QPointF( m_right, m_top );
999 clippedPolyObject <<
QPointF( m_right, m_bottom );
1007 void ClipPainterPrivate::clipOnceCorner(
QPolygonF & clippedPolyObject,
1011 bool isClosed )
const
1013 Q_UNUSED( clippedPolyObjects )
1014 Q_UNUSED( isClosed )
1016 if ( m_currentSector == 4) {
1018 clippedPolyObject << corner;
1019 clippedPolyObject << point;
1022 clippedPolyObject << point;
1023 clippedPolyObject << corner;
1027 void ClipPainterPrivate::clipOnceEdge(
QPolygonF & clippedPolyObject,
1030 bool isClosed )
const
1032 if ( m_currentSector == 4) {
1037 clippedPolyObject << point;
1041 clippedPolyObject << point;
1043 clippedPolyObjects << clippedPolyObject;
1048 void ClipPainterPrivate::clipOnce(
QPolygonF & clippedPolyObject,
1056 qreal m = _m( m_previousPoint, m_currentPoint );
1059 int offscreenpos = ( m_currentSector == 4 ) ? m_previousSector : m_currentSector;
1062 switch ( offscreenpos ) {
1064 point = clipTop( m, m_previousPoint );
1065 if ( point.
x() < m_left ) {
1066 point = clipLeft( m, point );
1068 clipOnceCorner( clippedPolyObject, clippedPolyObjects,
QPointF( m_left, m_top ), point, isClosed );
1071 point = clipTop( m, m_previousPoint );
1072 clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed );
1075 point = clipTop( m, m_previousPoint );
1076 if ( point.
x() > m_right ) {
1077 point = clipRight( m, point );
1079 clipOnceCorner( clippedPolyObject, clippedPolyObjects,
QPointF( m_right, m_top ), point, isClosed );
1082 point = clipLeft( m, m_previousPoint );
1083 clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed );
1086 point = clipRight( m, m_previousPoint );
1087 clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed );
1090 point = clipBottom( m, m_previousPoint );
1091 if ( point.
x() < m_left ) {
1092 point = clipLeft( m, point );
1094 clipOnceCorner( clippedPolyObject, clippedPolyObjects,
QPointF( m_left, m_bottom ), point, isClosed );
1097 point = clipBottom( m, m_previousPoint );
1098 clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed );
1101 point = clipBottom( m, m_previousPoint );
1102 if ( point.
x() > m_right ) {
1103 point = clipRight( m, point );
1105 clipOnceCorner( clippedPolyObject, clippedPolyObjects,
QPointF( m_right, m_bottom ), point, isClosed );
1113 #ifdef DEBUG_DRAW_NODES
1115 void ClipPainterPrivate::debugDrawNodes(
const QPolygonF & polygon )
1119 q->setRenderHint( QPainter::Antialiasing,
false );
1121 q->setPen( Qt::red );
1122 q->setBrush( Qt::transparent );
1128 for (; itPoint != itEndPoint; ++itPoint ) {
1130 if ( itPoint == itStartPoint || itPoint == itStartPoint + 1 || itPoint == itStartPoint + 2 ) {
1131 q->setPen( Qt::darkGreen );
1132 if ( itPoint == itStartPoint ) {
1133 q->drawRect( itPoint->x() - 3.0, itPoint->y() - 3.0 , 6.0, 6.0 );
1135 else if ( itPoint == itStartPoint + 1 ) {
1136 q->drawRect( itPoint->x() - 2.0, itPoint->y() - 2.0 , 4.0, 4.0 );
1139 q->drawRect( itPoint->x() - 1.0, itPoint->y() - 1.0 , 2.0, 2.0 );
1141 q->setPen( Qt::red );
1143 else if ( itPoint == itEndPoint - 1 || itPoint == itEndPoint - 2 || itPoint == itEndPoint - 3 ) {
1144 q->setPen( Qt::blue );
1145 if ( itPoint == itEndPoint - 3 ) {
1146 q->drawRect( itPoint->x() - 3.0, itPoint->y() - 3.0 , 6.0, 6.0 );
1148 else if ( itPoint == itEndPoint - 2 ) {
1149 q->drawRect( itPoint->x() - 2.0, itPoint->y() - 2.0 , 4.0, 4.0 );
1152 q->drawRect( itPoint->x() - 1.0, itPoint->y() - 1.0 , 2.0, 2.0 );
1154 q->setPen( Qt::red );
1157 q->drawRect( itPoint->x() - 1.5, itPoint->y() - 1.5 , 3.0, 3.0 );
void drawPolyline(const QPointF *points, int pointCount)
const_iterator constEnd() const
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule)
void drawPolygon(const QPolygonF &, Qt::FillRule fillRule=Qt::OddEvenFill)
const T & at(int i) const
const_iterator constBegin() const
void drawPolyline(const QPolygonF &)
void setClipping(bool enable)