Make QRegion not need to be friends with QVector
[profile/ivi/qtbase.git] / src / gui / painting / qpainterpath.cpp
index c238578..f249fe1 100644 (file)
@@ -1,8 +1,7 @@
 /****************************************************************************
 **
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
 **
 ** This file is part of the QtGui module of the Qt Toolkit.
 **
@@ -35,6 +34,7 @@
 **
 **
 **
+**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
@@ -227,9 +227,9 @@ static void qt_debug_path(const QPainterPath &path)
 
     \table 100%
     \row
-    \o \inlineimage qpainterpath-construction.png
-    \o
-    \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 0
+    \li \inlineimage qpainterpath-construction.png
+    \li
+    \snippet code/src_gui_painting_qpainterpath.cpp 0
     \endtable
 
     The painter path is initially empty when constructed. We first add
@@ -241,11 +241,11 @@ static void qt_debug_path(const QPainterPath &path)
 
     \table
     \header
-    \o Qt::OddEvenFill
-    \o Qt::WindingFill
+    \li Qt::OddEvenFill
+    \li Qt::WindingFill
     \row
-    \o \inlineimage qt-fillrule-oddeven.png
-    \o \inlineimage qt-fillrule-winding.png
+    \li \inlineimage qt-fillrule-oddeven.png
+    \li \inlineimage qt-fillrule-winding.png
     \endtable
 
     See the Qt::FillRule documentation for the definition of the
@@ -305,22 +305,22 @@ static void qt_debug_path(const QPainterPath &path)
     \section1 Examples
 
     Qt provides the \l {painting/painterpaths}{Painter Paths Example}
-    and the \l {demos/deform}{Vector Deformation Demo} which are
-    located in Qt's example and demo directories respectively.
+    and the \l {painting/deform}{Vector Deformation example} which are
+    located in Qt's example directory.
 
     The \l {painting/painterpaths}{Painter Paths Example} shows how
     painter paths can be used to build complex shapes for rendering
     and lets the user experiment with the filling and stroking.  The
-    \l {demos/deform}{Vector Deformation Demo} shows how to use
+    \l {painting/deform}{Vector Deformation Example} shows how to use
     QPainterPath to draw text.
 
     \table
     \header
-    \o \l {painting/painterpaths}{Painter Paths Example}
-    \o \l {demos/deform}{Vector Deformation Demo}
+    \li \l {painting/painterpaths}{Painter Paths Example}
+    \li \l {painting/deform}{Vector Deformation Example}
     \row
-    \o \inlineimage qpainterpath-example.png
-    \o \inlineimage qpainterpath-demo.png
+    \li \inlineimage qpainterpath-example.png
+    \li \inlineimage qpainterpath-demo.png
     \endtable
 
     \sa QPainterPathStroker, QPainter, QRegion, {Painter Paths Example}
@@ -344,7 +344,7 @@ static void qt_debug_path(const QPainterPath &path)
     \value CurveToDataElement  The extra data required to describe a curve in
                                                a CurveToElement element.
 
-    \sa elementAt(),  elementCount()
+    \sa elementAt(), elementCount()
 */
 
 /*!
@@ -478,14 +478,26 @@ static void qt_debug_path(const QPainterPath &path)
     \sa ElementType, elementAt(), isEmpty()
 */
 
+int QPainterPath::elementCount() const
+{
+    return d_ptr ? d_ptr->elements.size() : 0;
+}
+
 /*!
-    \fn const QPainterPath::Element &QPainterPath::elementAt(int index) const
+    \fn QPainterPath::Element QPainterPath::elementAt(int index) const
 
     Returns the element at the given \a index in the painter path.
 
     \sa ElementType, elementCount(), isEmpty()
 */
 
+QPainterPath::Element QPainterPath::elementAt(int i) const
+{
+    Q_ASSERT(d_ptr);
+    Q_ASSERT(i >= 0 && i < elementCount());
+    return d_ptr->elements.at(i);
+}
+
 /*!
     \fn void QPainterPath::setElementPositionAt(int index, qreal x, qreal y)
     \since 4.2
@@ -494,6 +506,17 @@ static void qt_debug_path(const QPainterPath &path)
     x and \a y.
 */
 
+void QPainterPath::setElementPositionAt(int i, qreal x, qreal y)
+{
+    Q_ASSERT(d_ptr);
+    Q_ASSERT(i >= 0 && i < elementCount());
+    detach();
+    QPainterPath::Element &e = d_ptr->elements[i];
+    e.x = x;
+    e.y = y;
+}
+
+
 /*###
     \fn QPainterPath &QPainterPath::operator +=(const QPainterPath &other)
 
@@ -535,6 +558,13 @@ QPainterPath::QPainterPath(const QPointF &startPoint)
     d_func()->elements << e;
 }
 
+void QPainterPath::detach()
+{
+    if (d_ptr->ref.load() != 1)
+        detach_helper();
+    setDirty(true);
+}
+
 /*!
     \internal
 */
@@ -731,9 +761,9 @@ void QPainterPath::lineTo(const QPointF &p)
 
     \table 100%
     \row
-    \o \inlineimage qpainterpath-cubicto.png
-    \o
-    \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 1
+    \li \inlineimage qpainterpath-cubicto.png
+    \li
+    \snippet code/src_gui_painting_qpainterpath.cpp 1
     \endtable
 
     \sa quadTo(), {QPainterPath#Composing a QPainterPath}{Composing
@@ -858,9 +888,9 @@ void QPainterPath::quadTo(const QPointF &c, const QPointF &e)
 
     \table 100%
     \row
-    \o \inlineimage qpainterpath-arcto.png
-    \o
-    \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 2
+    \li \inlineimage qpainterpath-arcto.png
+    \li
+    \snippet code/src_gui_painting_qpainterpath.cpp 2
     \endtable
 
     \sa arcMoveTo(), addEllipse(), QPainter::drawArc(), QPainter::drawPie(),
@@ -970,9 +1000,9 @@ QPointF QPainterPath::currentPosition() const
 
     \table 100%
     \row
-    \o \inlineimage qpainterpath-addrectangle.png
-    \o
-    \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 3
+    \li \inlineimage qpainterpath-addrectangle.png
+    \li
+    \snippet code/src_gui_painting_qpainterpath.cpp 3
     \endtable
 
     \sa addRegion(), lineTo(), {QPainterPath#Composing a
@@ -1017,9 +1047,9 @@ void QPainterPath::addRect(const QRectF &r)
 
     \table 100%
     \row
-    \o \inlineimage qpainterpath-addpolygon.png
-    \o
-    \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 4
+    \li \inlineimage qpainterpath-addpolygon.png
+    \li
+    \snippet code/src_gui_painting_qpainterpath.cpp 4
     \endtable
 
     \sa lineTo(), {QPainterPath#Composing a QPainterPath}{Composing
@@ -1053,9 +1083,9 @@ void QPainterPath::addPolygon(const QPolygonF &polygon)
 
     \table 100%
     \row
-    \o \inlineimage qpainterpath-addellipse.png
-    \o
-    \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 5
+    \li \inlineimage qpainterpath-addellipse.png
+    \li
+    \snippet code/src_gui_painting_qpainterpath.cpp 5
     \endtable
 
     \sa arcTo(), QPainter::drawEllipse(), {QPainterPath#Composing a
@@ -1105,9 +1135,9 @@ void QPainterPath::addEllipse(const QRectF &boundingRect)
 
     \table 100%
     \row
-    \o \inlineimage qpainterpath-addtext.png
-    \o
-    \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 6
+    \li \inlineimage qpainterpath-addtext.png
+    \li
+    \snippet code/src_gui_painting_qpainterpath.cpp 6
     \endtable
 
     \sa QPainter::drawText(), {QPainterPath#Composing a
@@ -1281,11 +1311,11 @@ Qt::FillRule QPainterPath::fillRule() const
 
     \table
     \header
-    \o Qt::OddEvenFill (default)
-    \o Qt::WindingFill
+    \li Qt::OddEvenFill (default)
+    \li Qt::WindingFill
     \row
-    \o \inlineimage qt-fillrule-oddeven.png
-    \o \inlineimage qt-fillrule-winding.png
+    \li \inlineimage qt-fillrule-oddeven.png
+    \li \inlineimage qt-fillrule-winding.png
     \endtable
 
     \sa fillRule()
@@ -1451,6 +1481,11 @@ QRectF QPainterPath::controlPointRect() const
     \sa elementCount()
 */
 
+bool QPainterPath::isEmpty() const
+{
+    return !d_ptr || (d_ptr->elements.size() == 1 && d_ptr->elements.first().type == MoveToElement);
+}
+
 /*!
     Creates and returns a reversed copy of the path.
 
@@ -2399,7 +2434,7 @@ QDataStream &operator>>(QDataStream &s, QPainterPath &p)
 #endif
             continue;
         }
-        QPainterPath::Element elm = { x, y, QPainterPath::ElementType(type) };
+        QPainterPath::Element elm = { qreal(x), qreal(y), QPainterPath::ElementType(type) };
         p.d_func()->elements.append(elm);
     }
     s >> p.d_func()->cStart;
@@ -2457,10 +2492,10 @@ void qt_path_stroke_cubic_to(qfixed c1x, qfixed c1y,
     functions:
 
     \list
-    \o setWidth()
-    \o setCapStyle()
-    \o setJoinStyle()
-    \o setDashPattern()
+    \li setWidth()
+    \li setCapStyle()
+    \li setJoinStyle()
+    \li setDashPattern()
     \endlist
 
     The setDashPattern() function accepts both a Qt::PenStyle object
@@ -2970,9 +3005,6 @@ qreal QPainterPath::angleAtPercent(qreal t) const
     return QLineF(0, 0, m1, m2).angle();
 }
 
-#if defined(Q_WS_WINCE)
-#pragma warning( disable : 4056 4756 )
-#endif
 
 /*!
     Returns the slope of the path at the percentage \a t. The