1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QVECTORPATH_P_H
43 #define QVECTORPATH_P_H
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.
56 #include <QtGui/qpaintengine.h>
58 #include <private/qpaintengine_p.h>
59 #include <private/qstroker_p.h>
60 #include <private/qpainter_p.h>
70 typedef void (*qvectorpath_cache_cleanup)(QPaintEngineEx *engine, void *data);
76 class Q_GUI_EXPORT QVectorPath
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,
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,
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...
102 // Shape rendering specifiers...
103 OddEvenFill = 0x1000,
104 WindingFill = 0x2000,
105 ImplicitClose = 0x4000
108 // ### Falcon: introduca a struct XY for points so lars is not so confused...
109 QVectorPath(const qreal *points,
111 const QPainterPath::ElementType *elements = 0,
112 uint hints = ArbitraryShapeHint)
113 : m_elements(elements),
122 QRectF controlPointRect() const;
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; }
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; }
132 inline void makeCacheable() const { m_hints |= ShouldUseCacheHint; m_cache = 0; }
133 inline uint hints() const { return m_hints; }
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; }
139 inline int elementCount() const { return m_count; }
140 inline const QPainterPath convertToPainterPath() const;
142 static inline uint polygonFlags(QPaintEngine::PolygonDrawMode 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;
154 QPaintEngineEx *engine;
156 qvectorpath_cache_cleanup cleanup;
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;
165 if (e->engine == engine)
174 Q_DISABLE_COPY(QVectorPath)
176 const QPainterPath::ElementType *m_elements;
177 const qreal *m_points;
180 mutable uint m_hints;
181 mutable QRealRect m_cp_rect;
183 mutable CacheEntry *m_cache;
186 Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &path);