Replace 'i < len-1 && func(i+1)' by 'i+1 < len && func(i+1)'
[profile/ivi/qtbase.git] / src / gui / painting / qpaintengineex_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 QPAINTENGINEEX_P_H
43 #define QPAINTENGINEEX_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 #include <QtGui/qdrawutil.h>
58
59 #include <private/qpaintengine_p.h>
60 #include <private/qstroker_p.h>
61 #include <private/qpainter_p.h>
62 #include <private/qvectorpath_p.h>
63
64
65 QT_BEGIN_HEADER
66
67 QT_BEGIN_NAMESPACE
68
69 QT_MODULE(Gui)
70
71 class QPainterState;
72 class QPaintEngineExPrivate;
73 class QStaticTextItem;
74 struct StrokeHandler;
75
76 struct QIntRect {
77     int x1, y1, x2, y2;
78     inline void set(const QRect &r) {
79         x1 = r.x();
80         y1 = r.y();
81         x2 = r.right() + 1;
82         y2 = r.bottom() + 1;
83         // We will assume normalized for later...
84         Q_ASSERT(x2 >= x1);
85         Q_ASSERT(y2 >= y1);
86     }
87 };
88
89 class QRectVectorPath : public QVectorPath {
90 public:
91     inline void set(const QRect &r) {
92         qreal left = r.x();
93         qreal right = r.x() + r.width();
94         qreal top = r.y();
95         qreal bottom = r.y() + r.height();
96         pts[0] = left;
97         pts[1] = top;
98         pts[2] = right;
99         pts[3] = top;
100         pts[4] = right;
101         pts[5] = bottom;
102         pts[6] = left;
103         pts[7] = bottom;
104     }
105
106     inline void set(const QRectF &r) {
107         qreal left = r.x();
108         qreal right = r.x() + r.width();
109         qreal top = r.y();
110         qreal bottom = r.y() + r.height();
111         pts[0] = left;
112         pts[1] = top;
113         pts[2] = right;
114         pts[3] = top;
115         pts[4] = right;
116         pts[5] = bottom;
117         pts[6] = left;
118         pts[7] = bottom;
119     }
120     inline QRectVectorPath(const QRect &r)
121         : QVectorPath(pts, 4, 0, QVectorPath::RectangleHint | QVectorPath::ImplicitClose)
122     {
123         set(r);
124     }
125     inline QRectVectorPath(const QRectF &r)
126         : QVectorPath(pts, 4, 0, QVectorPath::RectangleHint | QVectorPath::ImplicitClose)
127     {
128         set(r);
129     }
130     inline QRectVectorPath()
131         : QVectorPath(pts, 4, 0, QVectorPath::RectangleHint | QVectorPath::ImplicitClose)
132     { }
133
134     qreal pts[8];
135 };
136
137 #ifndef QT_NO_DEBUG_STREAM
138 QDebug Q_GUI_EXPORT &operator<<(QDebug &, const QVectorPath &path);
139 #endif
140
141 class QPixmapFilter;
142
143 class Q_GUI_EXPORT QPaintEngineEx : public QPaintEngine
144 {
145     Q_DECLARE_PRIVATE(QPaintEngineEx)
146 public:
147     QPaintEngineEx();
148
149     virtual QPainterState *createState(QPainterState *orig) const;
150
151     virtual void draw(const QVectorPath &path);
152     virtual void fill(const QVectorPath &path, const QBrush &brush) = 0;
153     virtual void stroke(const QVectorPath &path, const QPen &pen);
154
155     virtual void clip(const QVectorPath &path, Qt::ClipOperation op) = 0;
156     virtual void clip(const QRect &rect, Qt::ClipOperation op);
157     virtual void clip(const QRegion &region, Qt::ClipOperation op);
158     virtual void clip(const QPainterPath &path, Qt::ClipOperation op);
159
160     virtual void clipEnabledChanged() = 0;
161     virtual void penChanged() = 0;
162     virtual void brushChanged() = 0;
163     virtual void brushOriginChanged() = 0;
164     virtual void opacityChanged() = 0;
165     virtual void compositionModeChanged() = 0;
166     virtual void renderHintsChanged() = 0;
167     virtual void transformChanged() = 0;
168
169     virtual void fillRect(const QRectF &rect, const QBrush &brush);
170     virtual void fillRect(const QRectF &rect, const QColor &color);
171
172     virtual void drawRoundedRect(const QRectF &rect, qreal xrad, qreal yrad, Qt::SizeMode mode);
173
174     virtual void drawRects(const QRect *rects, int rectCount);
175     virtual void drawRects(const QRectF *rects, int rectCount);
176
177     virtual void drawLines(const QLine *lines, int lineCount);
178     virtual void drawLines(const QLineF *lines, int lineCount);
179
180     virtual void drawEllipse(const QRectF &r);
181     virtual void drawEllipse(const QRect &r);
182
183     virtual void drawPath(const QPainterPath &path);
184
185     virtual void drawPoints(const QPointF *points, int pointCount);
186     virtual void drawPoints(const QPoint *points, int pointCount);
187
188     virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
189     virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode);
190
191     virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) = 0;
192     virtual void drawPixmap(const QPointF &pos, const QPixmap &pm);
193
194     virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
195                            Qt::ImageConversionFlags flags = Qt::AutoColor) = 0;
196     virtual void drawImage(const QPointF &pos, const QImage &image);
197
198     virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
199
200     virtual void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap,
201                                      QFlags<QPainter::PixmapFragmentHint> hints);
202
203     virtual void updateState(const QPaintEngineState &state);
204
205     virtual void drawStaticTextItem(QStaticTextItem *);
206
207     virtual void setState(QPainterState *s);
208     inline QPainterState *state() { return static_cast<QPainterState *>(QPaintEngine::state); }
209     inline const QPainterState *state() const { return static_cast<const QPainterState *>(QPaintEngine::state); }
210
211     virtual void sync() {}
212
213     virtual void beginNativePainting() {}
214     virtual void endNativePainting() {}
215
216     // Return a pixmap filter of "type" that can render the parameters
217     // in "prototype".  The returned filter is owned by the engine and
218     // will be destroyed when the engine is destroyed.  The "prototype"
219     // allows the engine to pick different filters based on the parameters
220     // that will be requested, and not just the "type".
221     virtual QPixmapFilter *pixmapFilter(int /*type*/, const QPixmapFilter * /*prototype*/) { return 0; }
222
223     // These flags are needed in the implementation of paint buffers.
224     enum Flags
225     {
226         DoNotEmulate = 0x01,        // If set, QPainter will not wrap this engine in an emulation engine.
227         IsEmulationEngine = 0x02    // If set, this object is a QEmulationEngine.
228     };
229     virtual uint flags() const {return 0;}
230     virtual bool supportsTransformations(qreal pixelSize, const QTransform &m) const;
231     virtual bool shouldDrawCachedGlyphs(qreal pixelSize, const QTransform &m) const;
232
233 protected:
234     QPaintEngineEx(QPaintEngineExPrivate &data);
235 };
236
237 class Q_GUI_EXPORT QPaintEngineExPrivate : public QPaintEnginePrivate
238 {
239     Q_DECLARE_PUBLIC(QPaintEngineEx)
240 public:
241     QPaintEngineExPrivate();
242     ~QPaintEngineExPrivate();
243
244     void replayClipOperations();
245     bool hasClipOperations() const;
246
247     QStroker stroker;
248     QDashStroker dasher;
249     StrokeHandler *strokeHandler;
250     QStrokerOps *activeStroker;
251     QPen strokerPen;
252
253     QRect exDeviceRect;
254 };
255
256 inline uint QVectorPath::polygonFlags(QPaintEngine::PolygonDrawMode mode) {
257     switch (mode) {
258     case QPaintEngine::ConvexMode: return ConvexPolygonHint | ImplicitClose;
259     case QPaintEngine::OddEvenMode: return PolygonHint | OddEvenFill | ImplicitClose;
260     case QPaintEngine::WindingMode: return PolygonHint | WindingFill | ImplicitClose;
261     case QPaintEngine::PolylineMode: return PolygonHint;
262     default: return 0;
263     }
264 }
265
266 QT_END_NAMESPACE
267
268 QT_END_HEADER
269
270 #endif