Make QRegion not need to be friends with QVector
[profile/ivi/qtbase.git] / src / gui / painting / qvectorpath_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
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
68 class QPaintEngineEx;
69
70 typedef void (*qvectorpath_cache_cleanup)(QPaintEngineEx *engine, void *data);
71
72 struct QRealRect {
73     qreal x1, y1, x2, y2;
74 };
75
76 class Q_GUI_EXPORT QVectorPath
77 {
78 public:
79     enum Hint {
80         // Shape hints, in 0x000000ff, access using shape()
81         AreaShapeMask           = 0x0001,       // shape covers an area
82         NonConvexShapeMask      = 0x0002,       // shape is not convex
83         CurvedShapeMask         = 0x0004,       // shape contains curves...
84         LinesShapeMask          = 0x0008,
85         RectangleShapeMask      = 0x0010,
86         ShapeMask               = 0x001f,
87
88         // Shape hints merged into basic shapes..
89         LinesHint               = LinesShapeMask,
90         RectangleHint           = AreaShapeMask | RectangleShapeMask,
91         EllipseHint             = AreaShapeMask | CurvedShapeMask,
92         ConvexPolygonHint       = AreaShapeMask,
93         PolygonHint             = AreaShapeMask | NonConvexShapeMask,
94         RoundedRectHint         = AreaShapeMask | CurvedShapeMask,
95         ArbitraryShapeHint      = AreaShapeMask | NonConvexShapeMask | CurvedShapeMask,
96
97         // Other hints
98         IsCachedHint            = 0x0100, // Set if the cache hint is set
99         ShouldUseCacheHint      = 0x0200, // Set if the path should be cached when possible..
100         ControlPointRect        = 0x0400, // Set if the control point rect has been calculated...
101
102         // Shape rendering specifiers...
103         OddEvenFill             = 0x1000,
104         WindingFill             = 0x2000,
105         ImplicitClose           = 0x4000
106     };
107
108     // ### Falcon: introduca a struct XY for points so lars is not so confused...
109     QVectorPath(const qreal *points,
110                 int count,
111                 const QPainterPath::ElementType *elements = 0,
112                 uint hints = ArbitraryShapeHint)
113         : m_elements(elements),
114           m_points(points),
115           m_count(count),
116           m_hints(hints)
117     {
118     }
119
120     ~QVectorPath();
121
122     QRectF controlPointRect() const;
123
124     inline Hint shape() const { return (Hint) (m_hints & ShapeMask); }
125     inline bool isConvex() const { return (m_hints & NonConvexShapeMask) == 0; }
126     inline bool isCurved() const { return m_hints & CurvedShapeMask; }
127
128     inline bool isCacheable() const { return m_hints & ShouldUseCacheHint; }
129     inline bool hasImplicitClose() const { return m_hints & ImplicitClose; }
130     inline bool hasWindingFill() const { return m_hints & WindingFill; }
131
132     inline void makeCacheable() const { m_hints |= ShouldUseCacheHint; m_cache = 0; }
133     inline uint hints() const { return m_hints; }
134
135     inline const QPainterPath::ElementType *elements() const { return m_elements; }
136     inline const qreal *points() const { return m_points; }
137     inline bool isEmpty() const { return m_points == 0; }
138
139     inline int elementCount() const { return m_count; }
140     inline const QPainterPath convertToPainterPath() const;
141
142     static inline uint polygonFlags(QPaintEngine::PolygonDrawMode mode)
143     {
144         switch (mode) {
145         case QPaintEngine::ConvexMode: return ConvexPolygonHint | ImplicitClose;
146         case QPaintEngine::OddEvenMode: return PolygonHint | OddEvenFill | ImplicitClose;
147         case QPaintEngine::WindingMode: return PolygonHint | WindingFill | ImplicitClose;
148         case QPaintEngine::PolylineMode: return PolygonHint;
149         default: return 0;
150         }
151     }
152
153     struct CacheEntry {
154         QPaintEngineEx *engine;
155         void *data;
156         qvectorpath_cache_cleanup cleanup;
157         CacheEntry *next;
158     };
159
160     CacheEntry *addCacheData(QPaintEngineEx *engine, void *data, qvectorpath_cache_cleanup cleanup) const;
161     inline CacheEntry *lookupCacheData(QPaintEngineEx *engine) const {
162         Q_ASSERT(m_hints & ShouldUseCacheHint);
163         CacheEntry *e = m_cache;
164         while (e) {
165             if (e->engine == engine)
166                 return e;
167             e = e->next;
168         }
169         return 0;
170     }
171
172
173 private:
174     Q_DISABLE_COPY(QVectorPath)
175
176     const QPainterPath::ElementType *m_elements;
177     const qreal *m_points;
178     const int m_count;
179
180     mutable uint m_hints;
181     mutable QRealRect m_cp_rect;
182
183     mutable CacheEntry *m_cache;
184 };
185
186 Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &path);
187
188 QT_END_NAMESPACE
189
190 QT_END_HEADER
191
192 #endif