Replace 'i < len-1 && func(i+1)' by 'i+1 < len && func(i+1)'
[profile/ivi/qtbase.git] / src / gui / painting / qvectorpath_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 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 QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QVECTORPATH_P_H
43 #define QVECTORPATH_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include <QtGui/qpaintengine.h>
57
58 #include <private/qpaintengine_p.h>
59 #include <private/qstroker_p.h>
60 #include <private/qpainter_p.h>
61
62
63 QT_BEGIN_HEADER
64
65 QT_BEGIN_NAMESPACE
66
67 QT_MODULE(Gui)
68
69 class QPaintEngineEx;
70
71 typedef void (*qvectorpath_cache_cleanup)(QPaintEngineEx *engine, void *data);
72
73 struct QRealRect {
74     qreal x1, y1, x2, y2;
75 };
76
77 class Q_GUI_EXPORT QVectorPath
78 {
79 public:
80     enum Hint {
81         // Shape hints, in 0x000000ff, access using shape()
82         AreaShapeMask           = 0x0001,       // shape covers an area
83         NonConvexShapeMask      = 0x0002,       // shape is not convex
84         CurvedShapeMask         = 0x0004,       // shape contains curves...
85         LinesShapeMask          = 0x0008,
86         RectangleShapeMask      = 0x0010,
87         ShapeMask               = 0x001f,
88
89         // Shape hints merged into basic shapes..
90         LinesHint               = LinesShapeMask,
91         RectangleHint           = AreaShapeMask | RectangleShapeMask,
92         EllipseHint             = AreaShapeMask | CurvedShapeMask,
93         ConvexPolygonHint       = AreaShapeMask,
94         PolygonHint             = AreaShapeMask | NonConvexShapeMask,
95         RoundedRectHint         = AreaShapeMask | CurvedShapeMask,
96         ArbitraryShapeHint      = AreaShapeMask | NonConvexShapeMask | CurvedShapeMask,
97
98         // Other hints
99         IsCachedHint            = 0x0100, // Set if the cache hint is set
100         ShouldUseCacheHint      = 0x0200, // Set if the path should be cached when possible..
101         ControlPointRect        = 0x0400, // Set if the control point rect has been calculated...
102
103         // Shape rendering specifiers...
104         OddEvenFill             = 0x1000,
105         WindingFill             = 0x2000,
106         ImplicitClose           = 0x4000
107     };
108
109     // ### Falcon: introduca a struct XY for points so lars is not so confused...
110     QVectorPath(const qreal *points,
111                 int count,
112                 const QPainterPath::ElementType *elements = 0,
113                 uint hints = ArbitraryShapeHint)
114         : m_elements(elements),
115           m_points(points),
116           m_count(count),
117           m_hints(hints)
118     {
119     }
120
121     ~QVectorPath();
122
123     QRectF controlPointRect() const;
124
125     inline Hint shape() const { return (Hint) (m_hints & ShapeMask); }
126     inline bool isConvex() const { return (m_hints & NonConvexShapeMask) == 0; }
127     inline bool isCurved() const { return m_hints & CurvedShapeMask; }
128
129     inline bool isCacheable() const { return m_hints & ShouldUseCacheHint; }
130     inline bool hasImplicitClose() const { return m_hints & ImplicitClose; }
131     inline bool hasWindingFill() const { return m_hints & WindingFill; }
132
133     inline void makeCacheable() const { m_hints |= ShouldUseCacheHint; m_cache = 0; }
134     inline uint hints() const { return m_hints; }
135
136     inline const QPainterPath::ElementType *elements() const { return m_elements; }
137     inline const qreal *points() const { return m_points; }
138     inline bool isEmpty() const { return m_points == 0; }
139
140     inline int elementCount() const { return m_count; }
141     inline const QPainterPath convertToPainterPath() const;
142
143     static inline uint polygonFlags(QPaintEngine::PolygonDrawMode mode);
144
145     struct CacheEntry {
146         QPaintEngineEx *engine;
147         void *data;
148         qvectorpath_cache_cleanup cleanup;
149         CacheEntry *next;
150     };
151
152     CacheEntry *addCacheData(QPaintEngineEx *engine, void *data, qvectorpath_cache_cleanup cleanup) const;
153     inline CacheEntry *lookupCacheData(QPaintEngineEx *engine) const {
154         Q_ASSERT(m_hints & ShouldUseCacheHint);
155         CacheEntry *e = m_cache;
156         while (e) {
157             if (e->engine == engine)
158                 return e;
159             e = e->next;
160         }
161         return 0;
162     }
163
164
165 private:
166     Q_DISABLE_COPY(QVectorPath)
167
168     const QPainterPath::ElementType *m_elements;
169     const qreal *m_points;
170     const int m_count;
171
172     mutable uint m_hints;
173     mutable QRealRect m_cp_rect;
174
175     mutable CacheEntry *m_cache;
176 };
177
178 Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &path);
179
180 QT_END_NAMESPACE
181
182 QT_END_HEADER
183
184 #endif