1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
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/qbrush.h"
57 #include "QtGui/qfont.h"
58 #include "QtGui/qpen.h"
59 #include "QtGui/qregion.h"
60 #include "QtGui/qmatrix.h"
61 #include "QtGui/qpainter.h"
62 #include "QtGui/qpainterpath.h"
63 #include "QtGui/qpaintengine.h"
64 #include <QtCore/qhash.h>
66 #include <private/qpen_p.h>
71 class QEmulationPaintEngine;
77 struct DataPtrContainer {
81 inline void *data_ptr(const QTransform &t) { return (DataPtrContainer *) &t; }
82 inline bool qtransform_fast_equals(const QTransform &a, const QTransform &b) { return data_ptr(a) == data_ptr(b); }
84 // QPen inline functions...
85 inline QPen::DataPtr &data_ptr(const QPen &p) { return const_cast<QPen &>(p).data_ptr(); }
86 inline bool qpen_fast_equals(const QPen &a, const QPen &b) { return data_ptr(a) == data_ptr(b); }
87 inline QBrush qpen_brush(const QPen &p) { return data_ptr(p)->brush; }
88 inline qreal qpen_widthf(const QPen &p) { return data_ptr(p)->width; }
89 inline Qt::PenStyle qpen_style(const QPen &p) { return data_ptr(p)->style; }
90 inline Qt::PenCapStyle qpen_capStyle(const QPen &p) { return data_ptr(p)->capStyle; }
91 inline Qt::PenJoinStyle qpen_joinStyle(const QPen &p) { return data_ptr(p)->joinStyle; }
93 // QBrush inline functions...
94 inline QBrush::DataPtr &data_ptr(const QBrush &p) { return const_cast<QBrush &>(p).data_ptr(); }
95 inline bool qbrush_fast_equals(const QBrush &a, const QBrush &b) { return data_ptr(a) == data_ptr(b); }
96 inline Qt::BrushStyle qbrush_style(const QBrush &b) { return data_ptr(b)->style; }
97 inline const QColor &qbrush_color(const QBrush &b) { return data_ptr(b)->color; }
98 inline bool qbrush_has_transform(const QBrush &b) { return data_ptr(b)->transform.type() > QTransform::TxNone; }
100 class QPainterClipInfo
103 enum ClipType { RegionClip, PathClip, RectClip, RectFClip };
105 QPainterClipInfo(const QPainterPath &p, Qt::ClipOperation op, const QTransform &m) :
106 clipType(PathClip), matrix(m), operation(op), path(p) { }
108 QPainterClipInfo(const QRegion &r, Qt::ClipOperation op, const QTransform &m) :
109 clipType(RegionClip), matrix(m), operation(op), region(r) { }
111 QPainterClipInfo(const QRect &r, Qt::ClipOperation op, const QTransform &m) :
112 clipType(RectClip), matrix(m), operation(op), rect(r) { }
114 QPainterClipInfo(const QRectF &r, Qt::ClipOperation op, const QTransform &m) :
115 clipType(RectFClip), matrix(m), operation(op), rectf(r) { }
119 Qt::ClipOperation operation;
128 // QPainterPathPrivate *pathData;
141 class Q_GUI_EXPORT QPainterState : public QPaintEngineState
145 QPainterState(const QPainterState *s);
146 virtual ~QPainterState();
147 void init(QPainter *p);
154 QBrush bgBrush; // background brush
156 QPainterPath clipPath;
157 Qt::ClipOperation clipOperation;
158 QPainter::RenderHints renderHints;
159 QList<QPainterClipInfo> clipInfo; // ### Make me smaller and faster to copy around...
160 QTransform worldMatrix; // World transformation matrix, not window and viewport
161 QTransform matrix; // Complete transformation matrix,
162 QTransform redirectionMatrix;
163 int wx, wy, ww, wh; // window rectangle
164 int vx, vy, vw, vh; // viewport rectangle
167 uint WxF:1; // World transformation
168 uint VxF:1; // View transformation
173 Qt::LayoutDirection layoutDirection;
174 QPainter::CompositionMode composition_mode;
175 uint emulationSpecifier;
179 struct QPainterDummyState
184 QTransform transform;
188 class QPainterPrivate
190 Q_DECLARE_PUBLIC(QPainter)
192 QPainterPrivate(QPainter *painter)
193 : q_ptr(painter), d_ptrs(0), state(0), dummyState(0), txinv(0), inDestructor(false), d_ptrs_size(0),
194 refcount(1), device(0), original_device(0), helper_device(0), engine(0), emulationEngine(0),
202 QPainterPrivate **d_ptrs;
204 QPainterState *state;
205 QVector<QPainterState*> states;
207 mutable QPainterDummyState *dummyState;
209 QTransform invMatrix;
211 uint inDestructor : 1;
215 enum DrawOperation { StrokeDraw = 0x1,
217 StrokeAndFillDraw = 0x3
220 QPainterDummyState *fakeState() const {
222 dummyState = new QPainterDummyState();
226 void updateEmulationSpecifier(QPainterState *s);
227 void updateStateImpl(QPainterState *state);
228 void updateState(QPainterState *state);
230 void draw_helper(const QPainterPath &path, DrawOperation operation = StrokeAndFillDraw);
231 void drawStretchedGradient(const QPainterPath &path, DrawOperation operation);
232 void drawOpaqueBackground(const QPainterPath &path, DrawOperation operation);
234 #if !defined(QT_NO_RAWFONT)
235 void drawGlyphs(const quint32 *glyphArray, QFixedPoint *positionArray, int glyphCount,
236 const QRawFont &font, bool overline = false, bool underline = false,
237 bool strikeOut = false);
241 void updateInvMatrix();
243 int rectSubtraction() const {
244 return state->pen.style() != Qt::NoPen && state->pen.width() == 0 ? 1 : 0;
247 void checkEmulation();
249 static QPainterPrivate *get(QPainter *painter)
251 return painter->d_ptr.data();
254 QTransform viewTransform() const;
255 static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev);
256 void detachPainterPrivate(QPainter *q);
258 QPaintDevice *device;
259 QPaintDevice *original_device;
260 QPaintDevice *helper_device;
261 QPaintEngine *engine;
262 QEmulationPaintEngine *emulationEngine;
263 QPaintEngineEx *extended;
264 QBrush colorBrush; // for fill with solid color
267 Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation);
269 QString qt_generate_brush_key(const QBrush &brush);
273 #endif // QPAINTER_P_H