src/qt3support/painting/q3pointarray.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt3Support module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "q3pointarray.h"
       
    43 #include "private/qbezier_p.h"
       
    44 #include "private/qpainterpath_p.h"
       
    45 
       
    46 QT_BEGIN_NAMESPACE
       
    47 
       
    48 /*!
       
    49     \class Q3PointArray
       
    50     The Q3PointArray class provides an array of points.
       
    51 
       
    52     \compat
       
    53 
       
    54     Q3PointArray is a QPolygon subclass that provides functions
       
    55     to make it more source compatible with the \c QPointArray class
       
    56     in Qt 3.
       
    57 
       
    58     In Qt 4, we recommend that you use QPainterPath for representing
       
    59     arcs, ellipses, and Bezier curves, rather than QPolygon.
       
    60 */
       
    61 
       
    62 /*!
       
    63     Sets the points of the array to those describing an arc of an
       
    64     ellipse with size, width \a w by height \a h, and position (\a x,
       
    65     \a y), starting from angle \a a1 and spanning by angle \a a2. The
       
    66     resulting array has sufficient resolution for pixel accuracy (see
       
    67     the overloaded function which takes an additional QMatrix
       
    68     parameter).
       
    69 
       
    70     Angles are specified in 16ths of a degree, i.e. a full circle
       
    71     equals 5760 (16*360). Positive values mean counter-clockwise,
       
    72     whereas negative values mean the clockwise direction. Zero degrees
       
    73     is at the 3 o'clock position.
       
    74 */
       
    75 #ifndef QT_NO_WMATRIX
       
    76 void Q3PointArray::makeArc(int x, int y, int w, int h, int a1, int a2)
       
    77 {
       
    78     QRectF r(x, y, w, h);
       
    79     QPointF startPoint;
       
    80     qt_find_ellipse_coords(r, a1 / 16.0, a2 / 16.0, &startPoint, 0);
       
    81 
       
    82     QPainterPath path(startPoint);
       
    83     path.arcTo(r, a1 / 16.0, a2 / 16.0);
       
    84 
       
    85     if (path.isEmpty())
       
    86         *this = Q3PointArray();
       
    87     else
       
    88         *this = path.toSubpathPolygons().at(0).toPolygon();
       
    89 }
       
    90 #endif
       
    91 
       
    92 #ifndef QT_NO_TRANSFORMATIONS
       
    93 /*!
       
    94     \overload
       
    95 
       
    96     Sets the points of the array to those describing an arc of an
       
    97     ellipse with width \a w and height \a h and position (\a x, \a y),
       
    98     starting from angle \a a1, and spanning angle by \a a2, and
       
    99     transformed by the matrix \a xf. The resulting array has
       
   100     sufficient resolution for pixel accuracy.
       
   101 
       
   102     Angles are specified in 16ths of a degree, i.e. a full circle
       
   103     equals 5760 (16 * 360). Positive values mean counter-clockwise,
       
   104     whereas negative values mean the clockwise direction. Zero
       
   105     degrees is at the 3 o'clock position.
       
   106 */
       
   107 void Q3PointArray::makeArc(int x, int y, int w, int h, int a1, int a2, const QMatrix &xf)
       
   108 {
       
   109     QRectF r(x, y, w, h);
       
   110     QPointF startPoint;
       
   111     qt_find_ellipse_coords(r, a1 / 16.0, a2 / 16.0, &startPoint, 0);
       
   112 
       
   113     QPainterPath path(startPoint);
       
   114     path.arcTo(r, a1 / 16.0, a2 / 16.0);
       
   115     path = path * xf;
       
   116     if (path.isEmpty())
       
   117         *this = Q3PointArray();
       
   118     else
       
   119         *this = path.toSubpathPolygons().at(0).toPolygon();
       
   120 }
       
   121 
       
   122 #endif // QT_NO_TRANSFORMATIONS
       
   123 
       
   124 /*!
       
   125     \fn Q3PointArray::Q3PointArray()
       
   126 
       
   127     Constructs an empty Q3PointArray.
       
   128 */
       
   129 
       
   130 /*!
       
   131     \fn Q3PointArray::Q3PointArray(const QRect &r, bool closed)
       
   132 
       
   133     Constructs a point array from the rectangle \a r.
       
   134 
       
   135     If \a closed is false, then the point array just contains the
       
   136     following four points of the rectangle ordered clockwise. The
       
   137     bottom-right point is located at (r.x() + r.width(), r.y() +
       
   138     r.height()).
       
   139 */
       
   140 
       
   141 /*!
       
   142     \fn Q3PointArray::Q3PointArray(const QPolygon& other)
       
   143 
       
   144     Constructs a copy of \a other.
       
   145 */
       
   146 
       
   147 /*!
       
   148     \fn Q3PointArray Q3PointArray::copy() const
       
   149 
       
   150     Returns a copy of this Q3PointArray.
       
   151 */
       
   152 
       
   153 /*!
       
   154     \fn bool Q3PointArray::isNull()
       
   155 
       
   156     Returns isEmpty(). Use isEmpty() instead.
       
   157 */
       
   158 
       
   159 /*!
       
   160     Sets the points of the array to those describing an ellipse with
       
   161     size, width \a w by height \a h, and position (\a x, \a y).
       
   162 
       
   163     The returned array has sufficient resolution for use as pixels.
       
   164 */
       
   165 void Q3PointArray::makeEllipse(int x, int y, int w, int h)
       
   166 {
       
   167     QPainterPath path;
       
   168     path.addEllipse(x, y, w, h);
       
   169     *this = path.toSubpathPolygons().at(0).toPolygon();
       
   170 }
       
   171 
       
   172 #ifndef QT_NO_BEZIER
       
   173 
       
   174 /*!
       
   175     Returns the Bezier points for the four control points in this
       
   176     array.
       
   177 */
       
   178 Q3PointArray Q3PointArray::cubicBezier() const
       
   179 {
       
   180     if (size() != 4) {
       
   181 	qWarning( "Q3PointArray::bezier: The array must have 4 control points" );
       
   182         return QPolygon();
       
   183     }
       
   184     QPolygonF polygon = QBezier::fromPoints(at(0), at(1), at(2), at(3)).toPolygon();
       
   185     return polygon.toPolygon();
       
   186 }
       
   187 #endif //QT_NO_BEZIER
       
   188 
       
   189 QT_END_NAMESPACE