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 ****************************************************************************/
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);
233 void drawTextItem(const QPointF &p, const QTextItem &_ti, QTextEngine *textEngine);
235 #if !defined(QT_NO_RAWFONT)
236 void drawGlyphs(const quint32 *glyphArray, QFixedPoint *positionArray, int glyphCount,
237 const QRawFont &font, bool overline = false, bool underline = false,
238 bool strikeOut = false);
242 void updateInvMatrix();
244 int rectSubtraction() const {
245 return state->pen.style() != Qt::NoPen && state->pen.width() == 0 ? 1 : 0;
248 void checkEmulation();
250 static QPainterPrivate *get(QPainter *painter)
252 return painter->d_ptr.data();
255 QTransform viewTransform() const;
256 static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev);
257 void detachPainterPrivate(QPainter *q);
259 QPaintDevice *device;
260 QPaintDevice *original_device;
261 QPaintDevice *helper_device;
262 QPaintEngine *engine;
263 QEmulationPaintEngine *emulationEngine;
264 QPaintEngineEx *extended;
265 QBrush colorBrush; // for fill with solid color
268 Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation);
270 QString qt_generate_brush_key(const QBrush &brush);
274 #endif // QPAINTER_P_H