author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
child 7 | f7bc934e204c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 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 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
// QtCore |
|
42 |
#include <qdebug.h> |
|
43 |
#include <qmath.h> |
|
44 |
#include <qmutex.h> |
|
45 |
||
46 |
// QtGui |
|
47 |
#include "qbitmap.h" |
|
48 |
#include "qimage.h" |
|
49 |
#include "qpaintdevice.h" |
|
50 |
#include "qpaintengine.h" |
|
51 |
#include "qpainter.h" |
|
52 |
#include "qpainter_p.h" |
|
53 |
#include "qpainterpath.h" |
|
54 |
#include "qpicture.h" |
|
55 |
#include "qpixmapcache.h" |
|
56 |
#include "qpolygon.h" |
|
57 |
#include "qtextlayout.h" |
|
58 |
#include "qwidget.h" |
|
59 |
#include "qapplication.h" |
|
60 |
#include "qstyle.h" |
|
61 |
#include "qthread.h" |
|
62 |
#include "qvarlengtharray.h" |
|
63 |
||
64 |
#include <private/qfontengine_p.h> |
|
65 |
#include <private/qpaintengine_p.h> |
|
66 |
#include <private/qemulationpaintengine_p.h> |
|
67 |
#include <private/qpainterpath_p.h> |
|
68 |
#include <private/qtextengine_p.h> |
|
69 |
#include <private/qwidget_p.h> |
|
70 |
#include <private/qpaintengine_raster_p.h> |
|
71 |
#include <private/qmath_p.h> |
|
72 |
||
73 |
QT_BEGIN_NAMESPACE |
|
74 |
||
75 |
#define QGradient_StretchToDevice 0x10000000 |
|
76 |
#define QPaintEngine_OpaqueBackground 0x40000000 |
|
77 |
||
78 |
// #define QT_DEBUG_DRAW |
|
79 |
#ifdef QT_DEBUG_DRAW |
|
80 |
bool qt_show_painter_debug_output = true; |
|
81 |
#endif |
|
82 |
||
83 |
extern QPixmap qt_pixmapForBrush(int style, bool invert); |
|
84 |
||
85 |
void qt_format_text(const QFont &font, |
|
86 |
const QRectF &_r, int tf, const QTextOption *option, const QString& str, QRectF *brect, |
|
87 |
int tabstops, int* tabarray, int tabarraylen, |
|
88 |
QPainter *painter); |
|
89 |
||
90 |
static inline QGradient::CoordinateMode coordinateMode(const QBrush &brush) |
|
91 |
{ |
|
92 |
switch (brush.style()) { |
|
93 |
case Qt::LinearGradientPattern: |
|
94 |
case Qt::RadialGradientPattern: |
|
95 |
case Qt::ConicalGradientPattern: |
|
96 |
return brush.gradient()->coordinateMode(); |
|
97 |
default: |
|
98 |
; |
|
99 |
} |
|
100 |
return QGradient::LogicalMode; |
|
101 |
} |
|
102 |
||
103 |
/* Returns true if the gradient requires stretch to device...*/ |
|
104 |
static inline bool check_gradient(const QBrush &brush) |
|
105 |
{ |
|
106 |
return coordinateMode(brush) == QGradient::StretchToDeviceMode; |
|
107 |
} |
|
108 |
||
109 |
extern bool qHasPixmapTexture(const QBrush &); |
|
110 |
||
111 |
static inline bool is_brush_transparent(const QBrush &brush) { |
|
112 |
Qt::BrushStyle s = brush.style(); |
|
113 |
bool brushBitmap = qHasPixmapTexture(brush) |
|
114 |
? brush.texture().isQBitmap() |
|
115 |
: (brush.textureImage().depth() == 1); |
|
116 |
return ((s >= Qt::Dense1Pattern && s <= Qt::DiagCrossPattern) |
|
117 |
|| (s == Qt::TexturePattern && brushBitmap)); |
|
118 |
} |
|
119 |
||
120 |
static inline bool is_pen_transparent(const QPen &pen) { |
|
121 |
return pen.style() > Qt::SolidLine || is_brush_transparent(pen.brush()); |
|
122 |
} |
|
123 |
||
124 |
/* Discards the emulation flags that are not relevant for line drawing |
|
125 |
and returns the result |
|
126 |
*/ |
|
127 |
static inline uint line_emulation(uint emulation) |
|
128 |
{ |
|
129 |
return emulation & (QPaintEngine::PrimitiveTransform |
|
130 |
| QPaintEngine::AlphaBlend |
|
131 |
| QPaintEngine::Antialiasing |
|
132 |
| QPaintEngine::BrushStroke |
|
133 |
| QPaintEngine::ConstantOpacity |
|
134 |
| QGradient_StretchToDevice |
|
135 |
| QPaintEngine::ObjectBoundingModeGradients |
|
136 |
| QPaintEngine_OpaqueBackground); |
|
137 |
} |
|
138 |
||
139 |
#ifndef QT_NO_DEBUG |
|
140 |
static bool qt_painter_thread_test(int devType, const char *what, bool extraCondition = false) |
|
141 |
{ |
|
142 |
switch (devType) { |
|
143 |
case QInternal::Image: |
|
144 |
case QInternal::Printer: |
|
145 |
case QInternal::Picture: |
|
146 |
// can be drawn onto these devices safely from any thread |
|
147 |
#ifndef Q_WS_WIN |
|
148 |
if (extraCondition) |
|
149 |
#endif |
|
150 |
break; |
|
151 |
default: |
|
152 |
if (!extraCondition && QThread::currentThread() != qApp->thread()) { |
|
153 |
qWarning("QPainter: It is not safe to use %s outside the GUI thread", what); |
|
154 |
return false; |
|
155 |
} |
|
156 |
break; |
|
157 |
} |
|
158 |
return true; |
|
159 |
} |
|
160 |
#endif |
|
161 |
||
162 |
void QPainterPrivate::checkEmulation() |
|
163 |
{ |
|
164 |
Q_ASSERT(extended); |
|
165 |
if (extended->flags() & QPaintEngineEx::DoNotEmulate) |
|
166 |
return; |
|
167 |
||
168 |
bool doEmulation = false; |
|
169 |
if (state->bgMode == Qt::OpaqueMode) |
|
170 |
doEmulation = true; |
|
171 |
||
172 |
const QGradient *bg = state->brush.gradient(); |
|
173 |
if (bg && bg->coordinateMode() > QGradient::LogicalMode) |
|
174 |
doEmulation = true; |
|
175 |
||
176 |
const QGradient *pg = qpen_brush(state->pen).gradient(); |
|
177 |
if (pg && pg->coordinateMode() > QGradient::LogicalMode) |
|
178 |
doEmulation = true; |
|
179 |
||
180 |
if (doEmulation) { |
|
181 |
if (extended != emulationEngine) { |
|
182 |
if (!emulationEngine) |
|
183 |
emulationEngine = new QEmulationPaintEngine(extended); |
|
184 |
extended = emulationEngine; |
|
185 |
extended->setState(state); |
|
186 |
} |
|
187 |
} else if (emulationEngine == extended) { |
|
188 |
extended = emulationEngine->real_engine; |
|
189 |
} |
|
190 |
} |
|
191 |
||
192 |
||
193 |
QPainterPrivate::~QPainterPrivate() |
|
194 |
{ |
|
195 |
delete emulationEngine; |
|
196 |
for (int i=0; i<states.size(); ++i) |
|
197 |
delete states.at(i); |
|
198 |
||
199 |
if (dummyState) |
|
200 |
delete dummyState; |
|
201 |
} |
|
202 |
||
203 |
||
204 |
QTransform QPainterPrivate::viewTransform() const |
|
205 |
{ |
|
206 |
if (state->VxF) { |
|
207 |
qreal scaleW = qreal(state->vw)/qreal(state->ww); |
|
208 |
qreal scaleH = qreal(state->vh)/qreal(state->wh); |
|
209 |
return QTransform(scaleW, 0, 0, scaleH, |
|
210 |
state->vx - state->wx*scaleW, state->vy - state->wy*scaleH); |
|
211 |
} |
|
212 |
return QTransform(); |
|
213 |
} |
|
214 |
||
215 |
||
216 |
/* |
|
217 |
\internal |
|
218 |
Returns true if using a shared painter; otherwise false. |
|
219 |
*/ |
|
220 |
bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev) |
|
221 |
{ |
|
222 |
Q_ASSERT(q); |
|
223 |
Q_ASSERT(pdev); |
|
224 |
||
225 |
if (pdev->devType() != QInternal::Widget) |
|
226 |
return false; |
|
227 |
||
228 |
QWidget *widget = static_cast<QWidget *>(pdev); |
|
229 |
Q_ASSERT(widget); |
|
230 |
||
231 |
// Someone either called QPainter::setRedirected in the widget's paint event |
|
232 |
// right before this painter was created (or begin was called) or |
|
233 |
// sent a paint event directly to the widget. |
|
234 |
if (!widget->d_func()->redirectDev) |
|
235 |
return false; |
|
236 |
||
237 |
QPainter *sp = widget->d_func()->sharedPainter(); |
|
238 |
if (!sp || !sp->isActive()) |
|
239 |
return false; |
|
240 |
||
241 |
if (sp->paintEngine()->paintDevice() != widget->d_func()->redirectDev) |
|
242 |
return false; |
|
243 |
||
244 |
// Check if we're attempting to paint outside a paint event. |
|
245 |
if (!sp->d_ptr->engine->hasFeature(QPaintEngine::PaintOutsidePaintEvent) |
|
246 |
&& !widget->testAttribute(Qt::WA_PaintOutsidePaintEvent) |
|
247 |
&& !widget->testAttribute(Qt::WA_WState_InPaintEvent)) { |
|
248 |
||
249 |
qWarning("QPainter::begin: Widget painting can only begin as a result of a paintEvent"); |
|
250 |
return false; |
|
251 |
} |
|
252 |
||
253 |
// Save the current state of the shared painter and assign |
|
254 |
// the current d_ptr to the shared painter's d_ptr. |
|
255 |
sp->save(); |
|
256 |
if (!sp->d_ptr->d_ptrs) { |
|
257 |
// Allocate space for 4 d-pointers (enough for up to 4 sub-sequent |
|
258 |
// redirections within the same paintEvent(), which should be enough |
|
259 |
// in 99% of all cases). E.g: A renders B which renders C which renders D. |
|
260 |
sp->d_ptr->d_ptrs_size = 4; |
|
261 |
sp->d_ptr->d_ptrs = (QPainterPrivate **)malloc(4 * sizeof(QPainterPrivate *)); |
|
262 |
Q_CHECK_PTR(sp->d_ptr->d_ptrs); |
|
263 |
} else if (sp->d_ptr->refcount - 1 == sp->d_ptr->d_ptrs_size) { |
|
264 |
// However, to support corner cases we grow the array dynamically if needed. |
|
265 |
sp->d_ptr->d_ptrs_size <<= 1; |
|
266 |
const int newSize = sp->d_ptr->d_ptrs_size * sizeof(QPainterPrivate *); |
|
267 |
sp->d_ptr->d_ptrs = q_check_ptr((QPainterPrivate **)realloc(sp->d_ptr->d_ptrs, newSize)); |
|
268 |
} |
|
269 |
sp->d_ptr->d_ptrs[++sp->d_ptr->refcount - 2] = q->d_ptr.data(); |
|
270 |
q->d_ptr.take(); |
|
271 |
q->d_ptr.reset(sp->d_ptr.data()); |
|
272 |
||
273 |
Q_ASSERT(q->d_ptr->state); |
|
274 |
||
275 |
// Now initialize the painter with correct widget properties. |
|
276 |
q->initFrom(widget); |
|
277 |
QPoint offset; |
|
278 |
widget->d_func()->redirected(&offset); |
|
279 |
offset += q->d_ptr->engine->coordinateOffset(); |
|
280 |
||
281 |
// Update system rect. |
|
282 |
q->d_ptr->state->ww = q->d_ptr->state->vw = widget->width(); |
|
283 |
q->d_ptr->state->wh = q->d_ptr->state->vh = widget->height(); |
|
284 |
||
285 |
// Update matrix. |
|
286 |
if (q->d_ptr->state->WxF) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
q->d_ptr->state->redirectionMatrix = q->d_ptr->state->matrix; |
0 | 288 |
q->d_ptr->state->redirectionMatrix.translate(-offset.x(), -offset.y()); |
289 |
q->d_ptr->state->worldMatrix = QTransform(); |
|
290 |
q->d_ptr->state->WxF = false; |
|
291 |
} else { |
|
292 |
q->d_ptr->state->redirectionMatrix = QTransform::fromTranslate(-offset.x(), -offset.y()); |
|
293 |
} |
|
294 |
q->d_ptr->updateMatrix(); |
|
295 |
||
296 |
QPaintEnginePrivate *enginePrivate = q->d_ptr->engine->d_func(); |
|
297 |
if (enginePrivate->currentClipWidget == widget) { |
|
298 |
enginePrivate->systemStateChanged(); |
|
299 |
return true; |
|
300 |
} |
|
301 |
||
302 |
// Update system transform and clip. |
|
303 |
enginePrivate->currentClipWidget = widget; |
|
304 |
enginePrivate->setSystemTransform(q->d_ptr->state->matrix); |
|
305 |
return true; |
|
306 |
} |
|
307 |
||
308 |
void QPainterPrivate::detachPainterPrivate(QPainter *q) |
|
309 |
{ |
|
310 |
Q_ASSERT(refcount > 1); |
|
311 |
Q_ASSERT(q); |
|
312 |
||
313 |
QPainterPrivate *original = d_ptrs[--refcount - 1]; |
|
314 |
if (inDestructor) { |
|
315 |
inDestructor = false; |
|
316 |
if (original) |
|
317 |
original->inDestructor = true; |
|
318 |
} else if (!original) { |
|
319 |
original = new QPainterPrivate(q); |
|
320 |
} |
|
321 |
||
322 |
d_ptrs[refcount - 1] = 0; |
|
323 |
q->restore(); |
|
324 |
q->d_ptr.take(); |
|
325 |
q->d_ptr.reset(original); |
|
326 |
||
327 |
if (emulationEngine) { |
|
328 |
extended = emulationEngine->real_engine; |
|
329 |
delete emulationEngine; |
|
330 |
emulationEngine = 0; |
|
331 |
} |
|
332 |
} |
|
333 |
||
334 |
||
335 |
void QPainterPrivate::draw_helper(const QPainterPath &originalPath, DrawOperation op) |
|
336 |
{ |
|
337 |
#ifdef QT_DEBUG_DRAW |
|
338 |
if (qt_show_painter_debug_output) { |
|
339 |
printf("QPainter::drawHelper\n"); |
|
340 |
} |
|
341 |
#endif |
|
342 |
||
343 |
if (originalPath.isEmpty()) |
|
344 |
return; |
|
345 |
||
346 |
QPaintEngine::PaintEngineFeatures gradientStretch = |
|
347 |
QPaintEngine::PaintEngineFeatures(QGradient_StretchToDevice |
|
348 |
| QPaintEngine::ObjectBoundingModeGradients); |
|
349 |
||
350 |
const bool mustEmulateObjectBoundingModeGradients = extended |
|
351 |
|| ((state->emulationSpecifier & QPaintEngine::ObjectBoundingModeGradients) |
|
352 |
&& !engine->hasFeature(QPaintEngine::PatternTransform)); |
|
353 |
||
354 |
if (!(state->emulationSpecifier & ~gradientStretch) |
|
355 |
&& !mustEmulateObjectBoundingModeGradients) { |
|
356 |
drawStretchedGradient(originalPath, op); |
|
357 |
return; |
|
358 |
} else if (state->emulationSpecifier & QPaintEngine_OpaqueBackground) { |
|
359 |
drawOpaqueBackground(originalPath, op); |
|
360 |
return; |
|
361 |
} |
|
362 |
||
363 |
Q_Q(QPainter); |
|
364 |
||
365 |
qreal strokeOffsetX = 0, strokeOffsetY = 0; |
|
366 |
||
367 |
QPainterPath path = originalPath * state->matrix; |
|
368 |
QRectF pathBounds = path.boundingRect(); |
|
369 |
QRectF strokeBounds; |
|
370 |
bool doStroke = (op & StrokeDraw) && (state->pen.style() != Qt::NoPen); |
|
371 |
if (doStroke) { |
|
372 |
qreal penWidth = state->pen.widthF(); |
|
373 |
if (penWidth == 0) { |
|
374 |
strokeOffsetX = 1; |
|
375 |
strokeOffsetY = 1; |
|
376 |
} else { |
|
377 |
// In case of complex xform |
|
378 |
if (state->matrix.type() > QTransform::TxScale) { |
|
379 |
QPainterPathStroker stroker; |
|
380 |
stroker.setWidth(penWidth); |
|
381 |
stroker.setJoinStyle(state->pen.joinStyle()); |
|
382 |
stroker.setCapStyle(state->pen.capStyle()); |
|
383 |
QPainterPath stroke = stroker.createStroke(originalPath); |
|
384 |
strokeBounds = (stroke * state->matrix).boundingRect(); |
|
385 |
} else { |
|
386 |
strokeOffsetX = qAbs(penWidth * state->matrix.m11() / 2.0); |
|
387 |
strokeOffsetY = qAbs(penWidth * state->matrix.m22() / 2.0); |
|
388 |
} |
|
389 |
} |
|
390 |
} |
|
391 |
||
392 |
QRect absPathRect; |
|
393 |
if (!strokeBounds.isEmpty()) { |
|
394 |
absPathRect = strokeBounds.intersected(QRectF(0, 0, device->width(), device->height())).toAlignedRect(); |
|
395 |
} else { |
|
396 |
absPathRect = pathBounds.adjusted(-strokeOffsetX, -strokeOffsetY, strokeOffsetX, strokeOffsetY) |
|
397 |
.intersected(QRectF(0, 0, device->width(), device->height())).toAlignedRect(); |
|
398 |
} |
|
399 |
||
400 |
if (q->hasClipping()) { |
|
401 |
bool hasPerspectiveTransform = false; |
|
402 |
for (int i = 0; i < state->clipInfo.size(); ++i) { |
|
403 |
const QPainterClipInfo &info = state->clipInfo.at(i); |
|
404 |
if (info.matrix.type() == QTransform::TxProject) { |
|
405 |
hasPerspectiveTransform = true; |
|
406 |
break; |
|
407 |
} |
|
408 |
} |
|
409 |
// avoid mapping QRegions with perspective transforms |
|
410 |
if (!hasPerspectiveTransform) { |
|
411 |
// The trick with txinv and invMatrix is done in order to |
|
412 |
// avoid transforming the clip to logical coordinates, and |
|
413 |
// then back to device coordinates. This is a problem with |
|
414 |
// QRegion/QRect based clips, since they use integer |
|
415 |
// coordinates and converting to/from logical coordinates will |
|
416 |
// lose precision. |
|
417 |
bool old_txinv = txinv; |
|
418 |
QTransform old_invMatrix = invMatrix; |
|
419 |
txinv = true; |
|
420 |
invMatrix = QTransform(); |
|
421 |
QPainterPath clipPath = q->clipPath(); |
|
422 |
QRectF r = clipPath.boundingRect().intersected(absPathRect); |
|
423 |
absPathRect = r.toAlignedRect(); |
|
424 |
txinv = old_txinv; |
|
425 |
invMatrix = old_invMatrix; |
|
426 |
} |
|
427 |
} |
|
428 |
||
429 |
// qDebug("\nQPainterPrivate::draw_helper(), x=%d, y=%d, w=%d, h=%d", |
|
430 |
// devMinX, devMinY, device->width(), device->height()); |
|
431 |
// qDebug() << " - matrix" << state->matrix; |
|
432 |
// qDebug() << " - originalPath.bounds" << originalPath.boundingRect(); |
|
433 |
// qDebug() << " - path.bounds" << path.boundingRect(); |
|
434 |
||
435 |
if (absPathRect.width() <= 0 || absPathRect.height() <= 0) |
|
436 |
return; |
|
437 |
||
438 |
QImage image(absPathRect.width(), absPathRect.height(), QImage::Format_ARGB32_Premultiplied); |
|
439 |
image.fill(0); |
|
440 |
||
441 |
QPainter p(&image); |
|
442 |
||
443 |
p.d_ptr->helper_device = helper_device; |
|
444 |
||
445 |
p.setOpacity(state->opacity); |
|
446 |
p.translate(-absPathRect.x(), -absPathRect.y()); |
|
447 |
p.setTransform(state->matrix, true); |
|
448 |
p.setPen(doStroke ? state->pen : QPen(Qt::NoPen)); |
|
449 |
p.setBrush((op & FillDraw) ? state->brush : QBrush(Qt::NoBrush)); |
|
450 |
p.setBackground(state->bgBrush); |
|
451 |
p.setBackgroundMode(state->bgMode); |
|
452 |
p.setBrushOrigin(state->brushOrigin); |
|
453 |
||
454 |
p.setRenderHint(QPainter::Antialiasing, state->renderHints & QPainter::Antialiasing); |
|
455 |
p.setRenderHint(QPainter::SmoothPixmapTransform, |
|
456 |
state->renderHints & QPainter::SmoothPixmapTransform); |
|
457 |
||
458 |
p.drawPath(originalPath); |
|
459 |
||
460 |
#ifndef QT_NO_DEBUG |
|
461 |
static bool do_fallback_overlay = qgetenv("QT_PAINT_FALLBACK_OVERLAY").size() > 0; |
|
462 |
if (do_fallback_overlay) { |
|
463 |
QImage block(8, 8, QImage::Format_ARGB32_Premultiplied); |
|
464 |
QPainter pt(&block); |
|
465 |
pt.fillRect(0, 0, 8, 8, QColor(196, 0, 196)); |
|
466 |
pt.drawLine(0, 0, 8, 8); |
|
467 |
pt.end(); |
|
468 |
p.resetTransform(); |
|
469 |
p.setCompositionMode(QPainter::CompositionMode_SourceAtop); |
|
470 |
p.setOpacity(0.5); |
|
471 |
p.fillRect(0, 0, image.width(), image.height(), QBrush(block)); |
|
472 |
} |
|
473 |
#endif |
|
474 |
||
475 |
p.end(); |
|
476 |
||
477 |
q->save(); |
|
478 |
state->matrix = QTransform(); |
|
479 |
state->dirtyFlags |= QPaintEngine::DirtyTransform; |
|
480 |
updateState(state); |
|
481 |
engine->drawImage(absPathRect, |
|
482 |
image, |
|
483 |
QRectF(0, 0, absPathRect.width(), absPathRect.height()), |
|
484 |
Qt::OrderedDither | Qt::OrderedAlphaDither); |
|
485 |
q->restore(); |
|
486 |
} |
|
487 |
||
488 |
void QPainterPrivate::drawOpaqueBackground(const QPainterPath &path, DrawOperation op) |
|
489 |
{ |
|
490 |
Q_Q(QPainter); |
|
491 |
||
492 |
q->setBackgroundMode(Qt::TransparentMode); |
|
493 |
||
494 |
if (op & FillDraw && state->brush.style() != Qt::NoBrush) { |
|
495 |
q->fillPath(path, state->bgBrush.color()); |
|
496 |
q->fillPath(path, state->brush); |
|
497 |
} |
|
498 |
||
499 |
if (op & StrokeDraw && state->pen.style() != Qt::NoPen) { |
|
500 |
q->strokePath(path, QPen(state->bgBrush.color(), state->pen.width())); |
|
501 |
q->strokePath(path, state->pen); |
|
502 |
} |
|
503 |
||
504 |
q->setBackgroundMode(Qt::OpaqueMode); |
|
505 |
} |
|
506 |
||
507 |
static inline QBrush stretchGradientToUserSpace(const QBrush &brush, const QRectF &boundingRect) |
|
508 |
{ |
|
509 |
Q_ASSERT(brush.style() >= Qt::LinearGradientPattern |
|
510 |
&& brush.style() <= Qt::ConicalGradientPattern); |
|
511 |
||
512 |
QTransform gradientToUser(boundingRect.width(), 0, 0, boundingRect.height(), |
|
513 |
boundingRect.x(), boundingRect.y()); |
|
514 |
||
515 |
QGradient g = *brush.gradient(); |
|
516 |
g.setCoordinateMode(QGradient::LogicalMode); |
|
517 |
||
518 |
QBrush b(g); |
|
519 |
b.setTransform(gradientToUser * b.transform()); |
|
520 |
return b; |
|
521 |
} |
|
522 |
||
523 |
void QPainterPrivate::drawStretchedGradient(const QPainterPath &path, DrawOperation op) |
|
524 |
{ |
|
525 |
Q_Q(QPainter); |
|
526 |
||
527 |
const qreal sw = helper_device->width(); |
|
528 |
const qreal sh = helper_device->height(); |
|
529 |
||
530 |
bool changedPen = false; |
|
531 |
bool changedBrush = false; |
|
532 |
bool needsFill = false; |
|
533 |
||
534 |
const QPen pen = state->pen; |
|
535 |
const QBrush brush = state->brush; |
|
536 |
||
537 |
const QGradient::CoordinateMode penMode = coordinateMode(pen.brush()); |
|
538 |
const QGradient::CoordinateMode brushMode = coordinateMode(brush); |
|
539 |
||
540 |
QRectF boundingRect; |
|
541 |
||
542 |
// Draw the xformed fill if the brush is a stretch gradient. |
|
543 |
if ((op & FillDraw) && brush.style() != Qt::NoBrush) { |
|
544 |
if (brushMode == QGradient::StretchToDeviceMode) { |
|
545 |
q->setPen(Qt::NoPen); |
|
546 |
changedPen = pen.style() != Qt::NoPen; |
|
547 |
q->scale(sw, sh); |
|
548 |
updateState(state); |
|
549 |
||
550 |
const qreal isw = 1.0 / sw; |
|
551 |
const qreal ish = 1.0 / sh; |
|
552 |
QTransform inv(isw, 0, 0, ish, 0, 0); |
|
553 |
engine->drawPath(path * inv); |
|
554 |
q->scale(isw, ish); |
|
555 |
} else { |
|
556 |
needsFill = true; |
|
557 |
||
558 |
if (brushMode == QGradient::ObjectBoundingMode) { |
|
559 |
Q_ASSERT(engine->hasFeature(QPaintEngine::PatternTransform)); |
|
560 |
boundingRect = path.boundingRect(); |
|
561 |
q->setBrush(stretchGradientToUserSpace(brush, boundingRect)); |
|
562 |
changedBrush = true; |
|
563 |
} |
|
564 |
} |
|
565 |
} |
|
566 |
||
567 |
if ((op & StrokeDraw) && pen.style() != Qt::NoPen) { |
|
568 |
// Draw the xformed outline if the pen is a stretch gradient. |
|
569 |
if (penMode == QGradient::StretchToDeviceMode) { |
|
570 |
q->setPen(Qt::NoPen); |
|
571 |
changedPen = true; |
|
572 |
||
573 |
if (needsFill) { |
|
574 |
updateState(state); |
|
575 |
engine->drawPath(path); |
|
576 |
} |
|
577 |
||
578 |
q->scale(sw, sh); |
|
579 |
q->setBrush(pen.brush()); |
|
580 |
changedBrush = true; |
|
581 |
updateState(state); |
|
582 |
||
583 |
QPainterPathStroker stroker; |
|
584 |
stroker.setDashPattern(pen.style()); |
|
585 |
stroker.setWidth(pen.widthF()); |
|
586 |
stroker.setJoinStyle(pen.joinStyle()); |
|
587 |
stroker.setCapStyle(pen.capStyle()); |
|
588 |
stroker.setMiterLimit(pen.miterLimit()); |
|
589 |
QPainterPath stroke = stroker.createStroke(path); |
|
590 |
||
591 |
const qreal isw = 1.0 / sw; |
|
592 |
const qreal ish = 1.0 / sh; |
|
593 |
QTransform inv(isw, 0, 0, ish, 0, 0); |
|
594 |
engine->drawPath(stroke * inv); |
|
595 |
q->scale(isw, ish); |
|
596 |
} else { |
|
597 |
if (!needsFill && brush.style() != Qt::NoBrush) { |
|
598 |
q->setBrush(Qt::NoBrush); |
|
599 |
changedBrush = true; |
|
600 |
} |
|
601 |
||
602 |
if (penMode == QGradient::ObjectBoundingMode) { |
|
603 |
Q_ASSERT(engine->hasFeature(QPaintEngine::PatternTransform)); |
|
604 |
||
605 |
// avoid computing the bounding rect twice |
|
606 |
if (!needsFill || brushMode != QGradient::ObjectBoundingMode) |
|
607 |
boundingRect = path.boundingRect(); |
|
608 |
||
609 |
QPen p = pen; |
|
610 |
p.setBrush(stretchGradientToUserSpace(pen.brush(), boundingRect)); |
|
611 |
q->setPen(p); |
|
612 |
changedPen = true; |
|
613 |
} else if (changedPen) { |
|
614 |
q->setPen(pen); |
|
615 |
changedPen = false; |
|
616 |
} |
|
617 |
||
618 |
updateState(state); |
|
619 |
engine->drawPath(path); |
|
620 |
} |
|
621 |
} else if (needsFill) { |
|
622 |
if (pen.style() != Qt::NoPen) { |
|
623 |
q->setPen(Qt::NoPen); |
|
624 |
changedPen = true; |
|
625 |
} |
|
626 |
||
627 |
updateState(state); |
|
628 |
engine->drawPath(path); |
|
629 |
} |
|
630 |
||
631 |
if (changedPen) |
|
632 |
q->setPen(pen); |
|
633 |
if (changedBrush) |
|
634 |
q->setBrush(brush); |
|
635 |
} |
|
636 |
||
637 |
||
638 |
void QPainterPrivate::updateMatrix() |
|
639 |
{ |
|
640 |
state->matrix = state->WxF ? state->worldMatrix : QTransform(); |
|
641 |
if (state->VxF) |
|
642 |
state->matrix *= viewTransform(); |
|
643 |
||
644 |
txinv = false; // no inverted matrix |
|
645 |
state->matrix *= state->redirectionMatrix; |
|
646 |
if (extended) |
|
647 |
extended->transformChanged(); |
|
648 |
else |
|
649 |
state->dirtyFlags |= QPaintEngine::DirtyTransform; |
|
650 |
||
651 |
// printf("VxF=%d, WxF=%d\n", state->VxF, state->WxF); |
|
652 |
// qDebug() << " --- using matrix" << state->matrix << redirection_offset; |
|
653 |
} |
|
654 |
||
655 |
/*! \internal */ |
|
656 |
void QPainterPrivate::updateInvMatrix() |
|
657 |
{ |
|
658 |
Q_ASSERT(txinv == false); |
|
659 |
txinv = true; // creating inverted matrix |
|
660 |
invMatrix = state->matrix.inverted(); |
|
661 |
} |
|
662 |
||
663 |
void QPainterPrivate::updateEmulationSpecifier(QPainterState *s) |
|
664 |
{ |
|
665 |
bool alpha = false; |
|
666 |
bool linearGradient = false; |
|
667 |
bool radialGradient = false; |
|
668 |
bool conicalGradient = false; |
|
669 |
bool patternBrush = false; |
|
670 |
bool xform = false; |
|
671 |
bool complexXform = false; |
|
672 |
||
673 |
bool skip = true; |
|
674 |
||
675 |
// Pen and brush properties (we have to check both if one changes because the |
|
676 |
// one that's unchanged can still be in a state which requires emulation) |
|
677 |
if (s->state() & (QPaintEngine::DirtyPen | QPaintEngine::DirtyBrush | QPaintEngine::DirtyHints)) { |
|
678 |
// Check Brush stroke emulation |
|
679 |
if (!s->pen.isSolid() && !engine->hasFeature(QPaintEngine::BrushStroke)) |
|
680 |
s->emulationSpecifier |= QPaintEngine::BrushStroke; |
|
681 |
else |
|
682 |
s->emulationSpecifier &= ~QPaintEngine::BrushStroke; |
|
683 |
||
684 |
skip = false; |
|
685 |
||
686 |
QBrush penBrush = s->pen.brush(); |
|
687 |
Qt::BrushStyle brushStyle = s->brush.style(); |
|
688 |
Qt::BrushStyle penBrushStyle = penBrush.style(); |
|
689 |
alpha = (penBrushStyle != Qt::NoBrush |
|
690 |
&& (penBrushStyle < Qt::LinearGradientPattern && penBrush.color().alpha() != 255) |
|
691 |
&& !penBrush.isOpaque()) |
|
692 |
|| (brushStyle != Qt::NoBrush |
|
693 |
&& (brushStyle < Qt::LinearGradientPattern && s->brush.color().alpha() != 255) |
|
694 |
&& !s->brush.isOpaque()); |
|
695 |
linearGradient = ((penBrushStyle == Qt::LinearGradientPattern) || |
|
696 |
(brushStyle == Qt::LinearGradientPattern)); |
|
697 |
radialGradient = ((penBrushStyle == Qt::RadialGradientPattern) || |
|
698 |
(brushStyle == Qt::RadialGradientPattern)); |
|
699 |
conicalGradient = ((penBrushStyle == Qt::ConicalGradientPattern) || |
|
700 |
(brushStyle == Qt::ConicalGradientPattern)); |
|
701 |
patternBrush = (((penBrushStyle > Qt::SolidPattern |
|
702 |
&& penBrushStyle < Qt::LinearGradientPattern) |
|
703 |
|| penBrushStyle == Qt::TexturePattern) || |
|
704 |
((brushStyle > Qt::SolidPattern |
|
705 |
&& brushStyle < Qt::LinearGradientPattern) |
|
706 |
|| brushStyle == Qt::TexturePattern)); |
|
707 |
||
708 |
bool penTextureAlpha = false; |
|
709 |
if (penBrush.style() == Qt::TexturePattern) |
|
710 |
penTextureAlpha = qHasPixmapTexture(penBrush) |
|
711 |
? penBrush.texture().hasAlpha() |
|
712 |
: penBrush.textureImage().hasAlphaChannel(); |
|
713 |
bool brushTextureAlpha = false; |
|
714 |
if (s->brush.style() == Qt::TexturePattern) |
|
715 |
brushTextureAlpha = qHasPixmapTexture(s->brush) |
|
716 |
? s->brush.texture().hasAlpha() |
|
717 |
: s->brush.textureImage().hasAlphaChannel(); |
|
718 |
if (((penBrush.style() == Qt::TexturePattern && penTextureAlpha) |
|
719 |
|| (s->brush.style() == Qt::TexturePattern && brushTextureAlpha)) |
|
720 |
&& !engine->hasFeature(QPaintEngine::MaskedBrush)) |
|
721 |
s->emulationSpecifier |= QPaintEngine::MaskedBrush; |
|
722 |
else |
|
723 |
s->emulationSpecifier &= ~QPaintEngine::MaskedBrush; |
|
724 |
} |
|
725 |
||
726 |
if (s->state() & (QPaintEngine::DirtyHints |
|
727 |
| QPaintEngine::DirtyOpacity |
|
728 |
| QPaintEngine::DirtyBackgroundMode)) { |
|
729 |
skip = false; |
|
730 |
} |
|
731 |
||
732 |
if (skip) |
|
733 |
return; |
|
734 |
||
735 |
#if 0 |
|
736 |
qDebug("QPainterPrivate::updateEmulationSpecifier, state=%p\n" |
|
737 |
" - alpha: %d\n" |
|
738 |
" - linearGradient: %d\n" |
|
739 |
" - radialGradient: %d\n" |
|
740 |
" - conicalGradient: %d\n" |
|
741 |
" - patternBrush: %d\n" |
|
742 |
" - hints: %x\n" |
|
743 |
" - xform: %d\n", |
|
744 |
s, |
|
745 |
alpha, |
|
746 |
linearGradient, |
|
747 |
radialGradient, |
|
748 |
conicalGradient, |
|
749 |
patternBrush, |
|
750 |
uint(s->renderHints), |
|
751 |
xform); |
|
752 |
#endif |
|
753 |
||
754 |
// XForm properties |
|
755 |
if (s->state() & QPaintEngine::DirtyTransform) { |
|
756 |
xform = !s->matrix.isIdentity(); |
|
757 |
complexXform = !s->matrix.isAffine(); |
|
758 |
} else if (s->matrix.type() >= QTransform::TxTranslate) { |
|
759 |
xform = true; |
|
760 |
complexXform = !s->matrix.isAffine(); |
|
761 |
} |
|
762 |
||
763 |
const bool brushXform = (!s->brush.transform().type() == QTransform::TxNone); |
|
764 |
const bool penXform = (!s->pen.brush().transform().type() == QTransform::TxNone); |
|
765 |
||
766 |
const bool patternXform = patternBrush && (xform || brushXform || penXform); |
|
767 |
||
768 |
// Check alphablending |
|
769 |
if (alpha && !engine->hasFeature(QPaintEngine::AlphaBlend)) |
|
770 |
s->emulationSpecifier |= QPaintEngine::AlphaBlend; |
|
771 |
else |
|
772 |
s->emulationSpecifier &= ~QPaintEngine::AlphaBlend; |
|
773 |
||
774 |
// Linear gradient emulation |
|
775 |
if (linearGradient && !engine->hasFeature(QPaintEngine::LinearGradientFill)) |
|
776 |
s->emulationSpecifier |= QPaintEngine::LinearGradientFill; |
|
777 |
else |
|
778 |
s->emulationSpecifier &= ~QPaintEngine::LinearGradientFill; |
|
779 |
||
780 |
// Radial gradient emulation |
|
781 |
if (radialGradient && !engine->hasFeature(QPaintEngine::RadialGradientFill)) |
|
782 |
s->emulationSpecifier |= QPaintEngine::RadialGradientFill; |
|
783 |
else |
|
784 |
s->emulationSpecifier &= ~QPaintEngine::RadialGradientFill; |
|
785 |
||
786 |
// Conical gradient emulation |
|
787 |
if (conicalGradient && !engine->hasFeature(QPaintEngine::ConicalGradientFill)) |
|
788 |
s->emulationSpecifier |= QPaintEngine::ConicalGradientFill; |
|
789 |
else |
|
790 |
s->emulationSpecifier &= ~QPaintEngine::ConicalGradientFill; |
|
791 |
||
792 |
// Pattern brushes |
|
793 |
if (patternBrush && !engine->hasFeature(QPaintEngine::PatternBrush)) |
|
794 |
s->emulationSpecifier |= QPaintEngine::PatternBrush; |
|
795 |
else |
|
796 |
s->emulationSpecifier &= ~QPaintEngine::PatternBrush; |
|
797 |
||
798 |
// Pattern XForms |
|
799 |
if (patternXform && !engine->hasFeature(QPaintEngine::PatternTransform)) |
|
800 |
s->emulationSpecifier |= QPaintEngine::PatternTransform; |
|
801 |
else |
|
802 |
s->emulationSpecifier &= ~QPaintEngine::PatternTransform; |
|
803 |
||
804 |
// Primitive XForms |
|
805 |
if (xform && !engine->hasFeature(QPaintEngine::PrimitiveTransform)) |
|
806 |
s->emulationSpecifier |= QPaintEngine::PrimitiveTransform; |
|
807 |
else |
|
808 |
s->emulationSpecifier &= ~QPaintEngine::PrimitiveTransform; |
|
809 |
||
810 |
// Perspective XForms |
|
811 |
if (complexXform && !engine->hasFeature(QPaintEngine::PerspectiveTransform)) |
|
812 |
s->emulationSpecifier |= QPaintEngine::PerspectiveTransform; |
|
813 |
else |
|
814 |
s->emulationSpecifier &= ~QPaintEngine::PerspectiveTransform; |
|
815 |
||
816 |
// Constant opacity |
|
817 |
if (state->opacity != 1 && !engine->hasFeature(QPaintEngine::ConstantOpacity)) |
|
818 |
s->emulationSpecifier |= QPaintEngine::ConstantOpacity; |
|
819 |
else |
|
820 |
s->emulationSpecifier &= ~QPaintEngine::ConstantOpacity; |
|
821 |
||
822 |
bool gradientStretch = false; |
|
823 |
bool objectBoundingMode = false; |
|
824 |
if (linearGradient || conicalGradient || radialGradient) { |
|
825 |
QGradient::CoordinateMode brushMode = coordinateMode(s->brush); |
|
826 |
QGradient::CoordinateMode penMode = coordinateMode(s->pen.brush()); |
|
827 |
||
828 |
gradientStretch |= (brushMode == QGradient::StretchToDeviceMode); |
|
829 |
gradientStretch |= (penMode == QGradient::StretchToDeviceMode); |
|
830 |
||
831 |
objectBoundingMode |= (brushMode == QGradient::ObjectBoundingMode); |
|
832 |
objectBoundingMode |= (penMode == QGradient::ObjectBoundingMode); |
|
833 |
} |
|
834 |
if (gradientStretch) |
|
835 |
s->emulationSpecifier |= QGradient_StretchToDevice; |
|
836 |
else |
|
837 |
s->emulationSpecifier &= ~QGradient_StretchToDevice; |
|
838 |
||
839 |
if (objectBoundingMode && !engine->hasFeature(QPaintEngine::ObjectBoundingModeGradients)) |
|
840 |
s->emulationSpecifier |= QPaintEngine::ObjectBoundingModeGradients; |
|
841 |
else |
|
842 |
s->emulationSpecifier &= ~QPaintEngine::ObjectBoundingModeGradients; |
|
843 |
||
844 |
// Opaque backgrounds... |
|
845 |
if (s->bgMode == Qt::OpaqueMode && |
|
846 |
(is_pen_transparent(s->pen) || is_brush_transparent(s->brush))) |
|
847 |
s->emulationSpecifier |= QPaintEngine_OpaqueBackground; |
|
848 |
else |
|
849 |
s->emulationSpecifier &= ~QPaintEngine_OpaqueBackground; |
|
850 |
||
851 |
#if 0 |
|
852 |
//won't be correct either way because the device can already have |
|
853 |
// something rendered to it in which case subsequent emulation |
|
854 |
// on a fully transparent qimage and then blitting the results |
|
855 |
// won't produce correct results |
|
856 |
// Blend modes |
|
857 |
if (state->composition_mode > QPainter::CompositionMode_Xor && |
|
858 |
!engine->hasFeature(QPaintEngine::BlendModes)) |
|
859 |
s->emulationSpecifier |= QPaintEngine::BlendModes; |
|
860 |
else |
|
861 |
s->emulationSpecifier &= ~QPaintEngine::BlendModes; |
|
862 |
#endif |
|
863 |
} |
|
864 |
||
865 |
void QPainterPrivate::updateStateImpl(QPainterState *newState) |
|
866 |
{ |
|
867 |
// ### we might have to call QPainter::begin() here... |
|
868 |
if (!engine->state) { |
|
869 |
engine->state = newState; |
|
870 |
engine->setDirty(QPaintEngine::AllDirty); |
|
871 |
} |
|
872 |
||
873 |
if (engine->state->painter() != newState->painter) |
|
874 |
// ### this could break with clip regions vs paths. |
|
875 |
engine->setDirty(QPaintEngine::AllDirty); |
|
876 |
||
877 |
// Upon restore, revert all changes since last save |
|
878 |
else if (engine->state != newState) |
|
879 |
newState->dirtyFlags |= QPaintEngine::DirtyFlags(static_cast<QPainterState *>(engine->state)->changeFlags); |
|
880 |
||
881 |
// We need to store all changes made so that restore can deal with them |
|
882 |
else |
|
883 |
newState->changeFlags |= newState->dirtyFlags; |
|
884 |
||
885 |
updateEmulationSpecifier(newState); |
|
886 |
||
887 |
// Unset potential dirty background mode |
|
888 |
newState->dirtyFlags &= ~(QPaintEngine::DirtyBackgroundMode |
|
889 |
| QPaintEngine::DirtyBackground); |
|
890 |
||
891 |
engine->state = newState; |
|
892 |
engine->updateState(*newState); |
|
893 |
engine->clearDirty(QPaintEngine::AllDirty); |
|
894 |
||
895 |
} |
|
896 |
||
897 |
void QPainterPrivate::updateState(QPainterState *newState) |
|
898 |
{ |
|
899 |
||
900 |
if (!newState) { |
|
901 |
engine->state = newState; |
|
902 |
||
903 |
} else if (newState->state() || engine->state!=newState) { |
|
904 |
bool setNonCosmeticPen = (newState->renderHints & QPainter::NonCosmeticDefaultPen) |
|
905 |
&& newState->pen.widthF() == 0; |
|
906 |
if (setNonCosmeticPen) { |
|
907 |
// Override the default pen's cosmetic state if the |
|
908 |
// NonCosmeticDefaultPen render hint is used. |
|
909 |
QPen oldPen = newState->pen; |
|
910 |
newState->pen.setWidth(1); |
|
911 |
newState->pen.setCosmetic(false); |
|
912 |
newState->dirtyFlags |= QPaintEngine::DirtyPen; |
|
913 |
||
914 |
updateStateImpl(newState); |
|
915 |
||
916 |
// Restore the state pen back to its default to preserve visible |
|
917 |
// state. |
|
918 |
newState->pen = oldPen; |
|
919 |
} else { |
|
920 |
updateStateImpl(newState); |
|
921 |
} |
|
922 |
} |
|
923 |
} |
|
924 |
||
925 |
||
926 |
/*! |
|
927 |
\class QPainter |
|
928 |
\brief The QPainter class performs low-level painting on widgets and |
|
929 |
other paint devices. |
|
930 |
||
931 |
\ingroup painting |
|
932 |
||
933 |
\reentrant |
|
934 |
||
935 |
QPainter provides highly optimized functions to do most of the |
|
936 |
drawing GUI programs require. It can draw everything from simple |
|
937 |
lines to complex shapes like pies and chords. It can also draw |
|
938 |
aligned text and pixmaps. Normally, it draws in a "natural" |
|
939 |
coordinate system, but it can also do view and world |
|
940 |
transformation. QPainter can operate on any object that inherits |
|
941 |
the QPaintDevice class. |
|
942 |
||
943 |
The common use of QPainter is inside a widget's paint event: |
|
944 |
Construct and customize (e.g. set the pen or the brush) the |
|
945 |
painter. Then draw. Remember to destroy the QPainter object after |
|
946 |
drawing. For example: |
|
947 |
||
948 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 0 |
|
949 |
||
950 |
The core functionality of QPainter is drawing, but the class also |
|
951 |
provide several functions that allows you to customize QPainter's |
|
952 |
settings and its rendering quality, and others that enable |
|
953 |
clipping. In addition you can control how different shapes are |
|
954 |
merged together by specifying the painter's composition mode. |
|
955 |
||
956 |
The isActive() function indicates whether the painter is active. A |
|
957 |
painter is activated by the begin() function and the constructor |
|
958 |
that takes a QPaintDevice argument. The end() function, and the |
|
959 |
destructor, deactivates it. |
|
960 |
||
961 |
Together with the QPaintDevice and QPaintEngine classes, QPainter |
|
962 |
form the basis for Qt's paint system. QPainter is the class used |
|
963 |
to perform drawing operations. QPaintDevice represents a device |
|
964 |
that can be painted on using a QPainter. QPaintEngine provides the |
|
965 |
interface that the painter uses to draw onto different types of |
|
966 |
devices. If the painter is active, device() returns the paint |
|
967 |
device on which the painter paints, and paintEngine() returns the |
|
968 |
paint engine that the painter is currently operating on. For more |
|
969 |
information, see \l {The Paint System} documentation. |
|
970 |
||
971 |
Sometimes it is desirable to make someone else paint on an unusual |
|
972 |
QPaintDevice. QPainter supports a static function to do this, |
|
973 |
setRedirected(). |
|
974 |
||
975 |
\warning When the paintdevice is a widget, QPainter can only be |
|
976 |
used inside a paintEvent() function or in a function called by |
|
977 |
paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent |
|
978 |
widget attribute is set. On Mac OS X and Windows, you can only |
|
979 |
paint in a paintEvent() function regardless of this attribute's |
|
980 |
setting. |
|
981 |
||
982 |
\tableofcontents |
|
983 |
||
984 |
\section1 Settings |
|
985 |
||
986 |
There are several settings that you can customize to make QPainter |
|
987 |
draw according to your preferences: |
|
988 |
||
989 |
\list |
|
990 |
||
991 |
\o font() is the font used for drawing text. If the painter |
|
992 |
isActive(), you can retrieve information about the currently set |
|
993 |
font, and its metrics, using the fontInfo() and fontMetrics() |
|
994 |
functions respectively. |
|
995 |
||
996 |
\o brush() defines the color or pattern that is used for filling |
|
997 |
shapes. |
|
998 |
||
999 |
\o pen() defines the color or stipple that is used for drawing |
|
1000 |
lines or boundaries. |
|
1001 |
||
1002 |
\o backgroundMode() defines whether there is a background() or |
|
1003 |
not, i.e it is either Qt::OpaqueMode or Qt::TransparentMode. |
|
1004 |
||
1005 |
\o background() only applies when backgroundMode() is \l |
|
1006 |
Qt::OpaqueMode and pen() is a stipple. In that case, it |
|
1007 |
describes the color of the background pixels in the stipple. |
|
1008 |
||
1009 |
\o brushOrigin() defines the origin of the tiled brushes, normally |
|
1010 |
the origin of widget's background. |
|
1011 |
||
1012 |
\o viewport(), window(), worldTransform() make up the painter's coordinate |
|
1013 |
transformation system. For more information, see the \l |
|
1014 |
{Coordinate Transformations} section and the \l {The Coordinate |
|
1015 |
System} documentation. |
|
1016 |
||
1017 |
\o hasClipping() tells whether the painter clips at all. (The paint |
|
1018 |
device clips, too.) If the painter clips, it clips to clipRegion(). |
|
1019 |
||
1020 |
\o layoutDirection() defines the layout direction used by the |
|
1021 |
painter when drawing text. |
|
1022 |
||
1023 |
\o worldMatrixEnabled() tells whether world transformation is enabled. |
|
1024 |
||
1025 |
\o viewTransformEnabled() tells whether view transformation is |
|
1026 |
enabled. |
|
1027 |
||
1028 |
\endlist |
|
1029 |
||
1030 |
Note that some of these settings mirror settings in some paint |
|
1031 |
devices, e.g. QWidget::font(). The QPainter::begin() function (or |
|
1032 |
equivalently the QPainter constructor) copies these attributes |
|
1033 |
from the paint device. |
|
1034 |
||
1035 |
You can at any time save the QPainter's state by calling the |
|
1036 |
save() function which saves all the available settings on an |
|
1037 |
internal stack. The restore() function pops them back. |
|
1038 |
||
1039 |
\section1 Drawing |
|
1040 |
||
1041 |
QPainter provides functions to draw most primitives: drawPoint(), |
|
1042 |
drawPoints(), drawLine(), drawRect(), drawRoundedRect(), |
|
1043 |
drawEllipse(), drawArc(), drawPie(), drawChord(), drawPolyline(), |
|
1044 |
drawPolygon(), drawConvexPolygon() and drawCubicBezier(). The two |
|
1045 |
convenience functions, drawRects() and drawLines(), draw the given |
|
1046 |
number of rectangles or lines in the given array of \l |
|
1047 |
{QRect}{QRects} or \l {QLine}{QLines} using the current pen and |
|
1048 |
brush. |
|
1049 |
||
1050 |
The QPainter class also provides the fillRect() function which |
|
1051 |
fills the given QRect, with the given QBrush, and the eraseRect() |
|
1052 |
function that erases the area inside the given rectangle. |
|
1053 |
||
1054 |
All of these functions have both integer and floating point |
|
1055 |
versions. |
|
1056 |
||
1057 |
\table 100% |
|
1058 |
\row |
|
1059 |
\o \inlineimage qpainter-basicdrawing.png |
|
1060 |
\o |
|
1061 |
\bold {Basic Drawing Example} |
|
1062 |
||
1063 |
The \l {painting/basicdrawing}{Basic Drawing} example shows how to |
|
1064 |
display basic graphics primitives in a variety of styles using the |
|
1065 |
QPainter class. |
|
1066 |
||
1067 |
\endtable |
|
1068 |
||
1069 |
If you need to draw a complex shape, especially if you need to do |
|
1070 |
so repeatedly, consider creating a QPainterPath and drawing it |
|
1071 |
using drawPath(). |
|
1072 |
||
1073 |
\table 100% |
|
1074 |
\row |
|
1075 |
\o |
|
1076 |
\bold {Painter Paths example} |
|
1077 |
||
1078 |
The QPainterPath class provides a container for painting |
|
1079 |
operations, enabling graphical shapes to be constructed and |
|
1080 |
reused. |
|
1081 |
||
1082 |
The \l {painting/painterpaths}{Painter Paths} example shows how |
|
1083 |
painter paths can be used to build complex shapes for rendering. |
|
1084 |
||
1085 |
\o \inlineimage qpainter-painterpaths.png |
|
1086 |
\endtable |
|
1087 |
||
1088 |
QPainter also provides the fillPath() function which fills the |
|
1089 |
given QPainterPath with the given QBrush, and the strokePath() |
|
1090 |
function that draws the outline of the given path (i.e. strokes |
|
1091 |
the path). |
|
1092 |
||
1093 |
See also the \l {demos/deform}{Vector Deformation} demo which |
|
1094 |
shows how to use advanced vector techniques to draw text using a |
|
1095 |
QPainterPath, the \l {demos/gradients}{Gradients} demo which shows |
|
1096 |
the different types of gradients that are available in Qt, and the \l |
|
1097 |
{demos/pathstroke}{Path Stroking} demo which shows Qt's built-in |
|
1098 |
dash patterns and shows how custom patterns can be used to extend |
|
1099 |
the range of available patterns. |
|
1100 |
||
1101 |
\table |
|
1102 |
\row |
|
1103 |
\o \inlineimage qpainter-vectordeformation.png |
|
1104 |
\o \inlineimage qpainter-gradients.png |
|
1105 |
\o \inlineimage qpainter-pathstroking.png |
|
1106 |
\header |
|
1107 |
\o \l {demos/deform}{Vector Deformation} |
|
1108 |
\o \l {demos/gradients}{Gradients} |
|
1109 |
\o \l {demos/pathstroke}{Path Stroking} |
|
1110 |
\endtable |
|
1111 |
||
1112 |
||
1113 |
There are functions to draw pixmaps/images, namely drawPixmap(), |
|
1114 |
drawImage() and drawTiledPixmap(). Both drawPixmap() and drawImage() |
|
1115 |
produce the same result, except that drawPixmap() is faster |
|
1116 |
on-screen while drawImage() may be faster on a QPrinter or other |
|
1117 |
devices. |
|
1118 |
||
1119 |
Text drawing is done using drawText(). When you need |
|
1120 |
fine-grained positioning, boundingRect() tells you where a given |
|
1121 |
drawText() command will draw. |
|
1122 |
||
1123 |
There is a drawPicture() function that draws the contents of an |
|
1124 |
entire QPicture. The drawPicture() function is the only function |
|
1125 |
that disregards all the painter's settings as QPicture has its own |
|
1126 |
settings. |
|
1127 |
||
1128 |
\section1 Rendering Quality |
|
1129 |
||
1130 |
To get the optimal rendering result using QPainter, you should use |
|
1131 |
the platform independent QImage as paint device; i.e. using QImage |
|
1132 |
will ensure that the result has an identical pixel representation |
|
1133 |
on any platform. |
|
1134 |
||
1135 |
The QPainter class also provides a means of controlling the |
|
1136 |
rendering quality through its RenderHint enum and the support for |
|
1137 |
floating point precision: All the functions for drawing primitives |
|
1138 |
has a floating point version. These are often used in combination |
|
1139 |
with the \l {RenderHint}{QPainter::Antialiasing} render hint. |
|
1140 |
||
1141 |
\table 100% |
|
1142 |
\row |
|
1143 |
\o \inlineimage qpainter-concentriccircles.png |
|
1144 |
\o |
|
1145 |
\bold {Concentric Circles Example} |
|
1146 |
||
1147 |
The \l {painting/concentriccircles}{Concentric Circles} example |
|
1148 |
shows the improved rendering quality that can be obtained using |
|
1149 |
floating point precision and anti-aliasing when drawing custom |
|
1150 |
widgets. |
|
1151 |
||
1152 |
The application's main window displays several widgets which are |
|
1153 |
drawn using the various combinations of precision and |
|
1154 |
anti-aliasing. |
|
1155 |
||
1156 |
\endtable |
|
1157 |
||
1158 |
The RenderHint enum specifies flags to QPainter that may or may |
|
1159 |
not be respected by any given engine. \l |
|
1160 |
{RenderHint}{QPainter::Antialiasing} indicates that the engine |
|
1161 |
should antialias edges of primitives if possible, \l |
|
1162 |
{RenderHint}{QPainter::TextAntialiasing} indicates that the engine |
|
1163 |
should antialias text if possible, and the \l |
|
1164 |
{RenderHint}{QPainter::SmoothPixmapTransform} indicates that the |
|
1165 |
engine should use a smooth pixmap transformation algorithm. |
|
1166 |
\l {RenderHint}{HighQualityAntialiasing} is an OpenGL-specific rendering hint |
|
1167 |
indicating that the engine should use fragment programs and offscreen |
|
1168 |
rendering for antialiasing. |
|
1169 |
||
1170 |
The renderHints() function returns a flag that specifies the |
|
1171 |
rendering hints that are set for this painter. Use the |
|
1172 |
setRenderHint() function to set or clear the currently set |
|
1173 |
RenderHints. |
|
1174 |
||
1175 |
\section1 Coordinate Transformations |
|
1176 |
||
1177 |
Normally, the QPainter operates on the device's own coordinate |
|
1178 |
system (usually pixels), but QPainter has good support for |
|
1179 |
coordinate transformations. |
|
1180 |
||
1181 |
\table |
|
1182 |
\row |
|
1183 |
\o \inlineimage qpainter-clock.png |
|
1184 |
\o \inlineimage qpainter-rotation.png |
|
1185 |
\o \inlineimage qpainter-scale.png |
|
1186 |
\o \inlineimage qpainter-translation.png |
|
1187 |
\header |
|
1188 |
\o nop \o rotate() \o scale() \o translate() |
|
1189 |
\endtable |
|
1190 |
||
1191 |
The most commonly used transformations are scaling, rotation, |
|
1192 |
translation and shearing. Use the scale() function to scale the |
|
1193 |
coordinate system by a given offset, the rotate() function to |
|
1194 |
rotate it clockwise and translate() to translate it (i.e. adding a |
|
1195 |
given offset to the points). You can also twist the coordinate |
|
1196 |
system around the origin using the shear() function. See the \l |
|
1197 |
{demos/affine}{Affine Transformations} demo for a visualization of |
|
1198 |
a sheared coordinate system. |
|
1199 |
||
1200 |
See also the \l {painting/transformations}{Transformations} |
|
1201 |
example which shows how transformations influence the way that |
|
1202 |
QPainter renders graphics primitives. In particular it shows how |
|
1203 |
the order of transformations affects the result. |
|
1204 |
||
1205 |
\table 100% |
|
1206 |
\row |
|
1207 |
\o |
|
1208 |
\bold {Affine Transformations Demo} |
|
1209 |
||
1210 |
The \l {demos/affine}{Affine Transformations} demo show Qt's |
|
1211 |
ability to perform affine transformations on painting |
|
1212 |
operations. The demo also allows the user to experiment with the |
|
1213 |
transformation operations and see the results immediately. |
|
1214 |
||
1215 |
\o \inlineimage qpainter-affinetransformations.png |
|
1216 |
\endtable |
|
1217 |
||
1218 |
All the tranformation operations operate on the transformation |
|
1219 |
worldTransform(). A matrix transforms a point in the plane to another |
|
1220 |
point. For more information about the transformation matrix, see |
|
1221 |
the \l {The Coordinate System} and QTransform documentation. |
|
1222 |
||
1223 |
The setWorldTransform() function can replace or add to the currently |
|
1224 |
set worldTransform(). The resetTransform() function resets any |
|
1225 |
transformations that were made using translate(), scale(), |
|
1226 |
shear(), rotate(), setWorldTransform(), setViewport() and setWindow() |
|
1227 |
functions. The deviceTransform() returns the matrix that transforms |
|
1228 |
from logical coordinates to device coordinates of the platform |
|
1229 |
dependent paint device. The latter function is only needed when |
|
1230 |
using platform painting commands on the platform dependent handle, |
|
1231 |
and the platform does not do transformations nativly. |
|
1232 |
||
1233 |
When drawing with QPainter, we specify points using logical |
|
1234 |
coordinates which then are converted into the physical coordinates |
|
1235 |
of the paint device. The mapping of the logical coordinates to the |
|
1236 |
physical coordinates are handled by QPainter's combinedTransform(), a |
|
1237 |
combination of viewport() and window() and worldTransform(). The |
|
1238 |
viewport() represents the physical coordinates specifying an |
|
1239 |
arbitrary rectangle, the window() describes the same rectangle in |
|
1240 |
logical coordinates, and the worldTransform() is identical with the |
|
1241 |
transformation matrix. |
|
1242 |
||
1243 |
See also \l {The Coordinate System} documentation. |
|
1244 |
||
1245 |
\section1 Clipping |
|
1246 |
||
1247 |
QPainter can clip any drawing operation to a rectangle, a region, |
|
1248 |
or a vector path. The current clip is available using the |
|
1249 |
functions clipRegion() and clipPath(). Whether paths or regions are |
|
1250 |
preferred (faster) depends on the underlying paintEngine(). For |
|
1251 |
example, the QImage paint engine prefers paths while the X11 paint |
|
1252 |
engine prefers regions. Setting a clip is done in the painters |
|
1253 |
logical coordinates. |
|
1254 |
||
1255 |
After QPainter's clipping, the paint device may also clip. For |
|
1256 |
example, most widgets clip away the pixels used by child widgets, |
|
1257 |
and most printers clip away an area near the edges of the paper. |
|
1258 |
This additional clipping is not reflected by the return value of |
|
1259 |
clipRegion() or hasClipping(). |
|
1260 |
||
1261 |
\section1 Composition Modes |
|
1262 |
\target Composition Modes |
|
1263 |
||
1264 |
QPainter provides the CompositionMode enum which defines the |
|
1265 |
Porter-Duff rules for digital image compositing; it describes a |
|
1266 |
model for combining the pixels in one image, the source, with the |
|
1267 |
pixels in another image, the destination. |
|
1268 |
||
1269 |
The two most common forms of composition are \l |
|
1270 |
{QPainter::CompositionMode}{Source} and \l |
|
1271 |
{QPainter::CompositionMode}{SourceOver}. \l |
|
1272 |
{QPainter::CompositionMode}{Source} is used to draw opaque objects |
|
1273 |
onto a paint device. In this mode, each pixel in the source |
|
1274 |
replaces the corresponding pixel in the destination. In \l |
|
1275 |
{QPainter::CompositionMode}{SourceOver} composition mode, the |
|
1276 |
source object is transparent and is drawn on top of the |
|
1277 |
destination. |
|
1278 |
||
1279 |
Note that composition transformation operates pixelwise. For that |
|
1280 |
reason, there is a difference between using the graphic primitive |
|
1281 |
itself and its bounding rectangle: The bounding rect contains |
|
1282 |
pixels with alpha == 0 (i.e the pixels surrounding the |
|
1283 |
primitive). These pixels will overwrite the other image's pixels, |
|
1284 |
affectively clearing those, while the primitive only overwrites |
|
1285 |
its own area. |
|
1286 |
||
1287 |
\table 100% |
|
1288 |
\row |
|
1289 |
\o \inlineimage qpainter-compositiondemo.png |
|
1290 |
||
1291 |
\o |
|
1292 |
\bold {Composition Modes Demo} |
|
1293 |
||
1294 |
The \l {demos/composition}{Composition Modes} demo, available in |
|
1295 |
Qt's demo directory, allows you to experiment with the various |
|
1296 |
composition modes and see the results immediately. |
|
1297 |
||
1298 |
\endtable |
|
1299 |
||
1300 |
\section1 Limitations |
|
1301 |
\target Limitations |
|
1302 |
||
1303 |
If you are using coordinates with Qt's raster-based paint engine, it is |
|
1304 |
important to note that, while coordinates greater than +/- 2\sup 15 can |
|
1305 |
be used, any painting performed with coordinates outside this range is not |
|
1306 |
guaranteed to be shown; the drawing may be clipped. This is due to the |
|
1307 |
use of \c{short int} in the implementation. |
|
1308 |
||
1309 |
The outlines generated by Qt's stroker are only an approximation when dealing |
|
1310 |
with curved shapes. It is in most cases impossible to represent the outline of |
|
1311 |
a bezier curve segment using another bezier curve segment, and so Qt approximates |
|
1312 |
the curve outlines by using several smaller curves. For performance reasons there |
|
1313 |
is a limit to how many curves Qt uses for these outlines, and thus when using |
|
1314 |
large pen widths or scales the outline error increases. To generate outlines with |
|
1315 |
smaller errors it is possible to use the QPainterPathStroker class, which has the |
|
1316 |
setCurveThreshold member function which let's the user specify the error tolerance. |
|
1317 |
Another workaround is to convert the paths to polygons first and then draw the |
|
1318 |
polygons instead. |
|
1319 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1320 |
\section1 Performance |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1321 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1322 |
QPainter is a rich framework that allows developers to do a great |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1323 |
variety of graphical operations, such as gradients, composition |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1324 |
modes and vector graphics. And QPainter can do this across a |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1325 |
variety of different hardware and software stacks. Naturally the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1326 |
underlying combination of hardware and software has some |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1327 |
implications for performance, and ensuring that every single |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1328 |
operation is fast in combination with all the various combinations |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1329 |
of composition modes, brushes, clipping, transformation, etc, is |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1330 |
close to an impossible task because of the number of |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1331 |
permutations. As a compromise we have selected a subset of the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1332 |
QPainter API and backends, were performance is guaranteed to be as |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1333 |
good as we can sensibly get it for the given combination of |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1334 |
hardware and software. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1335 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1336 |
The backends we focus on as high-performance engines are: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1337 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1338 |
\list |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1339 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1340 |
\o Raster - This backend implements all rendering in pure software |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1341 |
and is always used to render into QImages. For optimal performance |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1342 |
only use the format types QImage::Format_ARGB32_Premultiplied, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1343 |
QImage::Format_RGB32 or QImage::Format_RGB16. Any other format, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1344 |
including QImage::Format_ARGB32, has significantly worse |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1345 |
performance. This engine is also used by default on Windows and on |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1346 |
QWS. It can be used as default graphics system on any |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1347 |
OS/hardware/software combination by passing \c {-graphicssystem |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1348 |
raster} on the command line |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1349 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1350 |
\o OpenGL 2.0 (ES) - This backend is the primary backend for |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1351 |
hardware accelerated graphics. It can be run on desktop machines |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1352 |
and embedded devices supporting the OpenGL 2.0 or OpenGL/ES 2.0 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1353 |
specification. This includes most graphics chips produced in the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1354 |
last couple of years. The engine can be enabled by using QPainter |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1355 |
onto a QGLWidget or by passing \c {-graphicssystem opengl} on the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1356 |
command line when the underlying system supports it. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1357 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1358 |
\o OpenVG - This backend implements the Khronos standard for 2D |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1359 |
and Vector Graphics. It is primarily for embedded devices with |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1360 |
hardware support for OpenVG. The engine can be enabled by |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1361 |
passing \c {-graphicssystem openvg} on the command line when |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1362 |
the underlying system supports it. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1363 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1364 |
\endlist |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1365 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1366 |
These operations are: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1367 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1368 |
\list |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1369 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1370 |
\o Simple transformations, meaning translation and scaling, pluss |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1371 |
0, 90, 180, 270 degree rotations. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1372 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1373 |
\o \c drawPixmap() in combination with simple transformations and |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1374 |
opacity with non-smooth transformation mode |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1375 |
(\c QPainter::SmoothPixmapTransform not enabled as a render hint). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1376 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1377 |
\o Text drawing with regular font sizes with simple |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1378 |
transformations with solid colors using no or 8-bit antialiasing. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1379 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1380 |
\o Rectangle fills with solid color, two-color linear gradients |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1381 |
and simple transforms. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1382 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1383 |
\o Rectangular clipping with simple transformations and intersect |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1384 |
clip. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1385 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1386 |
\o Composition Modes \c QPainter::CompositionMode_Source and |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1387 |
QPainter::CompositionMode_SourceOver |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1388 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1389 |
\o Rounded rectangle filling using solid color and two-color |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1390 |
linear gradients fills. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1391 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1392 |
\o 3x3 patched pixmaps, via qDrawBorderPixmap. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1393 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1394 |
\endlist |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1395 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1396 |
This list gives an indication of which features to safely use in |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1397 |
an application where performance is critical. For certain setups, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1398 |
other operations may be fast too, but before making extensive use |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1399 |
of them, it is recommended to benchmark and verify them on the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1400 |
system where the software will run in the end. There are also |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1401 |
cases where expensive operations are ok to use, for instance when |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1402 |
the result is cached in a QPixmap. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1403 |
|
0 | 1404 |
\sa QPaintDevice, QPaintEngine, {QtSvg Module}, {Basic Drawing Example}, |
1405 |
{Drawing Utility Functions} |
|
1406 |
*/ |
|
1407 |
||
1408 |
/*! |
|
1409 |
\enum QPainter::RenderHint |
|
1410 |
||
1411 |
Renderhints are used to specify flags to QPainter that may or |
|
1412 |
may not be respected by any given engine. |
|
1413 |
||
1414 |
\value Antialiasing Indicates that the engine should antialias |
|
1415 |
edges of primitives if possible. |
|
1416 |
||
1417 |
\value TextAntialiasing Indicates that the engine should antialias |
|
1418 |
text if possible. To forcibly disable antialiasing for text, do not |
|
1419 |
use this hint. Instead, set QFont::NoAntialias on your font's style |
|
1420 |
strategy. |
|
1421 |
||
1422 |
\value SmoothPixmapTransform Indicates that the engine should use |
|
1423 |
a smooth pixmap transformation algorithm (such as bilinear) rather |
|
1424 |
than nearest neighbor. |
|
1425 |
||
1426 |
\value HighQualityAntialiasing An OpenGL-specific rendering hint |
|
1427 |
indicating that the engine should use fragment programs and offscreen |
|
1428 |
rendering for antialiasing. |
|
1429 |
||
1430 |
\value NonCosmeticDefaultPen The engine should interpret pens with a width |
|
1431 |
of 0 (which otherwise enables QPen::isCosmetic()) as being a non-cosmetic |
|
1432 |
pen with a width of 1. |
|
1433 |
||
1434 |
\sa renderHints(), setRenderHint(), {QPainter#Rendering |
|
1435 |
Quality}{Rendering Quality}, {Concentric Circles Example} |
|
1436 |
||
1437 |
*/ |
|
1438 |
||
1439 |
/*! |
|
1440 |
Constructs a painter. |
|
1441 |
||
1442 |
\sa begin(), end() |
|
1443 |
*/ |
|
1444 |
||
1445 |
QPainter::QPainter() |
|
1446 |
: d_ptr(new QPainterPrivate(this)) |
|
1447 |
{ |
|
1448 |
} |
|
1449 |
||
1450 |
/*! |
|
1451 |
\fn QPainter::QPainter(QPaintDevice *device) |
|
1452 |
||
1453 |
Constructs a painter that begins painting the paint \a device |
|
1454 |
immediately. |
|
1455 |
||
1456 |
This constructor is convenient for short-lived painters, e.g. in a |
|
1457 |
QWidget::paintEvent() and should be used only once. The |
|
1458 |
constructor calls begin() for you and the QPainter destructor |
|
1459 |
automatically calls end(). |
|
1460 |
||
1461 |
Here's an example using begin() and end(): |
|
1462 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 1 |
|
1463 |
||
1464 |
The same example using this constructor: |
|
1465 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 2 |
|
1466 |
||
1467 |
Since the constructor cannot provide feedback when the initialization |
|
1468 |
of the painter failed you should rather use begin() and end() to paint |
|
1469 |
on external devices, e.g. printers. |
|
1470 |
||
1471 |
\sa begin(), end() |
|
1472 |
*/ |
|
1473 |
||
1474 |
QPainter::QPainter(QPaintDevice *pd) |
|
1475 |
: d_ptr(0) |
|
1476 |
{ |
|
1477 |
Q_ASSERT(pd != 0); |
|
1478 |
if (!QPainterPrivate::attachPainterPrivate(this, pd)) { |
|
1479 |
d_ptr.reset(new QPainterPrivate(this)); |
|
1480 |
begin(pd); |
|
1481 |
} |
|
1482 |
Q_ASSERT(d_ptr); |
|
1483 |
} |
|
1484 |
||
1485 |
/*! |
|
1486 |
Destroys the painter. |
|
1487 |
*/ |
|
1488 |
QPainter::~QPainter() |
|
1489 |
{ |
|
1490 |
d_ptr->inDestructor = true; |
|
1491 |
QT_TRY { |
|
1492 |
if (isActive()) |
|
1493 |
end(); |
|
1494 |
else if (d_ptr->refcount > 1) |
|
1495 |
d_ptr->detachPainterPrivate(this); |
|
1496 |
} QT_CATCH(...) { |
|
1497 |
// don't throw anything in the destructor. |
|
1498 |
} |
|
1499 |
if (d_ptr) { |
|
1500 |
// Make sure we haven't messed things up. |
|
1501 |
Q_ASSERT(d_ptr->inDestructor); |
|
1502 |
d_ptr->inDestructor = false; |
|
1503 |
Q_ASSERT(d_ptr->refcount == 1); |
|
1504 |
if (d_ptr->d_ptrs) |
|
1505 |
free(d_ptr->d_ptrs); |
|
1506 |
} |
|
1507 |
} |
|
1508 |
||
1509 |
/*! |
|
1510 |
Returns the paint device on which this painter is currently |
|
1511 |
painting, or 0 if the painter is not active. |
|
1512 |
||
1513 |
\sa isActive() |
|
1514 |
*/ |
|
1515 |
||
1516 |
QPaintDevice *QPainter::device() const |
|
1517 |
{ |
|
1518 |
Q_D(const QPainter); |
|
1519 |
if (isActive() && d->engine->d_func()->currentClipWidget) |
|
1520 |
return d->engine->d_func()->currentClipWidget; |
|
1521 |
return d->original_device; |
|
1522 |
} |
|
1523 |
||
1524 |
/*! |
|
1525 |
Returns true if begin() has been called and end() has not yet been |
|
1526 |
called; otherwise returns false. |
|
1527 |
||
1528 |
\sa begin(), QPaintDevice::paintingActive() |
|
1529 |
*/ |
|
1530 |
||
1531 |
bool QPainter::isActive() const |
|
1532 |
{ |
|
1533 |
Q_D(const QPainter); |
|
1534 |
return d->engine; |
|
1535 |
} |
|
1536 |
||
1537 |
/*! |
|
1538 |
Initializes the painters pen, background and font to the same as |
|
1539 |
the given \a widget. This function is called automatically when the |
|
1540 |
painter is opened on a QWidget. |
|
1541 |
||
1542 |
\sa begin(), {QPainter#Settings}{Settings} |
|
1543 |
*/ |
|
1544 |
void QPainter::initFrom(const QWidget *widget) |
|
1545 |
{ |
|
1546 |
Q_ASSERT_X(widget, "QPainter::initFrom(const QWidget *widget)", "Widget cannot be 0"); |
|
1547 |
Q_D(QPainter); |
|
1548 |
if (!d->engine) { |
|
1549 |
qWarning("QPainter::initFrom: Painter not active, aborted"); |
|
1550 |
return; |
|
1551 |
} |
|
1552 |
||
1553 |
const QPalette &pal = widget->palette(); |
|
1554 |
d->state->pen = QPen(pal.brush(widget->foregroundRole()), 0); |
|
1555 |
d->state->bgBrush = pal.brush(widget->backgroundRole()); |
|
1556 |
d->state->deviceFont = QFont(widget->font(), const_cast<QWidget*> (widget)); |
|
1557 |
d->state->font = d->state->deviceFont; |
|
1558 |
if (d->extended) { |
|
1559 |
d->extended->penChanged(); |
|
1560 |
} else if (d->engine) { |
|
1561 |
d->engine->setDirty(QPaintEngine::DirtyPen); |
|
1562 |
d->engine->setDirty(QPaintEngine::DirtyBrush); |
|
1563 |
d->engine->setDirty(QPaintEngine::DirtyFont); |
|
1564 |
} |
|
1565 |
d->state->layoutDirection = widget->layoutDirection(); |
|
1566 |
} |
|
1567 |
||
1568 |
||
1569 |
/*! |
|
1570 |
Saves the current painter state (pushes the state onto a stack). A |
|
1571 |
save() must be followed by a corresponding restore(); the end() |
|
1572 |
function unwinds the stack. |
|
1573 |
||
1574 |
\sa restore() |
|
1575 |
*/ |
|
1576 |
||
1577 |
void QPainter::save() |
|
1578 |
{ |
|
1579 |
#ifdef QT_DEBUG_DRAW |
|
1580 |
if (qt_show_painter_debug_output) |
|
1581 |
printf("QPainter::save()\n"); |
|
1582 |
#endif |
|
1583 |
Q_D(QPainter); |
|
1584 |
if (!d->engine) { |
|
1585 |
qWarning("QPainter::save: Painter not active"); |
|
1586 |
return; |
|
1587 |
} |
|
1588 |
||
1589 |
if (d->extended) { |
|
1590 |
d->state = d->extended->createState(d->states.back()); |
|
1591 |
d->extended->setState(d->state); |
|
1592 |
} else { |
|
1593 |
d->updateState(d->state); |
|
1594 |
d->state = new QPainterState(d->states.back()); |
|
1595 |
d->engine->state = d->state; |
|
1596 |
} |
|
1597 |
d->states.push_back(d->state); |
|
1598 |
} |
|
1599 |
||
1600 |
/*! |
|
1601 |
Restores the current painter state (pops a saved state off the |
|
1602 |
stack). |
|
1603 |
||
1604 |
\sa save() |
|
1605 |
*/ |
|
1606 |
||
1607 |
void QPainter::restore() |
|
1608 |
{ |
|
1609 |
#ifdef QT_DEBUG_DRAW |
|
1610 |
if (qt_show_painter_debug_output) |
|
1611 |
printf("QPainter::restore()\n"); |
|
1612 |
#endif |
|
1613 |
Q_D(QPainter); |
|
1614 |
if (d->states.size()<=1) { |
|
1615 |
qWarning("QPainter::restore: Unbalanced save/restore"); |
|
1616 |
return; |
|
1617 |
} else if (!d->engine) { |
|
1618 |
qWarning("QPainter::restore: Painter not active"); |
|
1619 |
return; |
|
1620 |
} |
|
1621 |
||
1622 |
QPainterState *tmp = d->state; |
|
1623 |
d->states.pop_back(); |
|
1624 |
d->state = d->states.back(); |
|
1625 |
d->txinv = false; |
|
1626 |
||
1627 |
if (d->extended) { |
|
1628 |
d->checkEmulation(); |
|
1629 |
d->extended->setState(d->state); |
|
1630 |
delete tmp; |
|
1631 |
return; |
|
1632 |
} |
|
1633 |
||
1634 |
// trigger clip update if the clip path/region has changed since |
|
1635 |
// last save |
|
1636 |
if (!d->state->clipInfo.isEmpty() |
|
1637 |
&& (tmp->changeFlags & (QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyClipPath))) { |
|
1638 |
// reuse the tmp state to avoid any extra allocs... |
|
1639 |
tmp->dirtyFlags = QPaintEngine::DirtyClipPath; |
|
1640 |
tmp->clipOperation = Qt::NoClip; |
|
1641 |
tmp->clipPath = QPainterPath(); |
|
1642 |
d->engine->updateState(*tmp); |
|
1643 |
// replay the list of clip states, |
|
1644 |
for (int i=0; i<d->state->clipInfo.size(); ++i) { |
|
1645 |
const QPainterClipInfo &info = d->state->clipInfo.at(i); |
|
1646 |
tmp->matrix = info.matrix; |
|
1647 |
tmp->matrix *= d->state->redirectionMatrix; |
|
1648 |
tmp->clipOperation = info.operation; |
|
1649 |
if (info.clipType == QPainterClipInfo::RectClip) { |
|
1650 |
tmp->dirtyFlags = QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyTransform; |
|
1651 |
tmp->clipRegion = info.rect; |
|
1652 |
} else if (info.clipType == QPainterClipInfo::RegionClip) { |
|
1653 |
tmp->dirtyFlags = QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyTransform; |
|
1654 |
tmp->clipRegion = info.region; |
|
1655 |
} else { // clipType == QPainterClipInfo::PathClip |
|
1656 |
tmp->dirtyFlags = QPaintEngine::DirtyClipPath | QPaintEngine::DirtyTransform; |
|
1657 |
tmp->clipPath = info.path; |
|
1658 |
} |
|
1659 |
d->engine->updateState(*tmp); |
|
1660 |
} |
|
1661 |
||
1662 |
||
1663 |
//Since we've updated the clip region anyway, pretend that the clip path hasn't changed: |
|
1664 |
d->state->dirtyFlags &= ~(QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipRegion); |
|
1665 |
tmp->changeFlags &= ~(QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipRegion); |
|
1666 |
tmp->changeFlags |= QPaintEngine::DirtyTransform; |
|
1667 |
} |
|
1668 |
||
1669 |
d->updateState(d->state); |
|
1670 |
delete tmp; |
|
1671 |
} |
|
1672 |
||
1673 |
||
1674 |
/*! |
|
1675 |
||
1676 |
\fn bool QPainter::begin(QPaintDevice *device) |
|
1677 |
||
1678 |
Begins painting the paint \a device and returns true if |
|
1679 |
successful; otherwise returns false. |
|
1680 |
||
1681 |
Notice that all painter settings (setPen(), setBrush() etc.) are reset |
|
1682 |
to default values when begin() is called. |
|
1683 |
||
1684 |
The errors that can occur are serious problems, such as these: |
|
1685 |
||
1686 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 3 |
|
1687 |
||
1688 |
Note that most of the time, you can use one of the constructors |
|
1689 |
instead of begin(), and that end() is automatically done at |
|
1690 |
destruction. |
|
1691 |
||
1692 |
\warning A paint device can only be painted by one painter at a |
|
1693 |
time. |
|
1694 |
||
1695 |
\warning Painting on a QImage with the format |
|
1696 |
QImage::Format_Indexed8 is not supported. |
|
1697 |
||
1698 |
\sa end(), QPainter() |
|
1699 |
*/ |
|
1700 |
||
1701 |
static inline void qt_cleanup_painter_state(QPainterPrivate *d) |
|
1702 |
{ |
|
1703 |
d->states.clear(); |
|
1704 |
delete d->state; |
|
1705 |
d->state = 0; |
|
1706 |
d->engine = 0; |
|
1707 |
d->device = 0; |
|
1708 |
} |
|
1709 |
||
1710 |
bool QPainter::begin(QPaintDevice *pd) |
|
1711 |
{ |
|
1712 |
Q_ASSERT(pd); |
|
1713 |
||
1714 |
if (pd->painters > 0) { |
|
1715 |
qWarning("QPainter::begin: A paint device can only be painted by one painter at a time."); |
|
1716 |
return false; |
|
1717 |
} |
|
1718 |
||
1719 |
if (d_ptr->engine) { |
|
1720 |
qWarning("QPainter::begin: Painter already active"); |
|
1721 |
return false; |
|
1722 |
} |
|
1723 |
||
1724 |
if (QPainterPrivate::attachPainterPrivate(this, pd)) |
|
1725 |
return true; |
|
1726 |
||
1727 |
Q_D(QPainter); |
|
1728 |
||
1729 |
d->helper_device = pd; |
|
1730 |
d->original_device = pd; |
|
1731 |
QPaintDevice *rpd = 0; |
|
1732 |
||
1733 |
QPoint redirectionOffset; |
|
1734 |
// We know for sure that redirection is broken when the widget is inside |
|
1735 |
// its paint event, so it's safe to use our hard-coded redirection. However, |
|
1736 |
// there IS one particular case we still need to support, and that's |
|
1737 |
// when people call QPainter::setRedirected in the widget's paint event right |
|
1738 |
// before any painter is created (or QPainter::begin is called). In that |
|
1739 |
// particular case our hard-coded redirection is restored and the redirection |
|
1740 |
// is retrieved from QPainter::redirected (as before). |
|
1741 |
if (pd->devType() == QInternal::Widget) |
|
1742 |
rpd = static_cast<QWidget *>(pd)->d_func()->redirected(&redirectionOffset); |
|
1743 |
||
1744 |
if (!rpd) |
|
1745 |
rpd = redirected(pd, &redirectionOffset); |
|
1746 |
||
1747 |
if (rpd) |
|
1748 |
pd = rpd; |
|
1749 |
||
1750 |
#ifdef QT_DEBUG_DRAW |
|
1751 |
if (qt_show_painter_debug_output) |
|
1752 |
printf("QPainter::begin(), device=%p, type=%d\n", pd, pd->devType()); |
|
1753 |
#endif |
|
1754 |
||
1755 |
if (pd->devType() == QInternal::Pixmap) |
|
1756 |
static_cast<QPixmap *>(pd)->detach(); |
|
1757 |
else if (pd->devType() == QInternal::Image) |
|
1758 |
static_cast<QImage *>(pd)->detach(); |
|
1759 |
||
1760 |
d->engine = pd->paintEngine(); |
|
1761 |
||
1762 |
if (!d->engine) { |
|
1763 |
qWarning("QPainter::begin: Paint device returned engine == 0, type: %d", pd->devType()); |
|
1764 |
return false; |
|
1765 |
} |
|
1766 |
||
1767 |
d->device = pd; |
|
1768 |
||
1769 |
d->extended = d->engine->isExtended() ? static_cast<QPaintEngineEx *>(d->engine) : 0; |
|
1770 |
if (d->emulationEngine) |
|
1771 |
d->emulationEngine->real_engine = d->extended; |
|
1772 |
||
1773 |
// Setup new state... |
|
1774 |
Q_ASSERT(!d->state); |
|
1775 |
d->state = d->extended ? d->extended->createState(0) : new QPainterState; |
|
1776 |
d->state->painter = this; |
|
1777 |
d->states.push_back(d->state); |
|
1778 |
||
1779 |
d->state->redirectionMatrix.translate(-redirectionOffset.x(), -redirectionOffset.y()); |
|
1780 |
d->state->brushOrigin = QPointF(); |
|
1781 |
||
1782 |
// Slip a painter state into the engine before we do any other operations |
|
1783 |
if (d->extended) |
|
1784 |
d->extended->setState(d->state); |
|
1785 |
else |
|
1786 |
d->engine->state = d->state; |
|
1787 |
||
1788 |
switch (pd->devType()) { |
|
1789 |
case QInternal::Widget: |
|
1790 |
{ |
|
1791 |
const QWidget *widget = static_cast<const QWidget *>(pd); |
|
1792 |
Q_ASSERT(widget); |
|
1793 |
||
1794 |
const bool paintOutsidePaintEvent = widget->testAttribute(Qt::WA_PaintOutsidePaintEvent); |
|
1795 |
const bool inPaintEvent = widget->testAttribute(Qt::WA_WState_InPaintEvent); |
|
1796 |
if(!d->engine->hasFeature(QPaintEngine::PaintOutsidePaintEvent) |
|
1797 |
&& !paintOutsidePaintEvent && !inPaintEvent) { |
|
1798 |
qWarning("QPainter::begin: Widget painting can only begin as a " |
|
1799 |
"result of a paintEvent"); |
|
1800 |
qt_cleanup_painter_state(d); |
|
1801 |
return false; |
|
1802 |
} |
|
1803 |
||
1804 |
// Adjust offset for alien widgets painting outside the paint event. |
|
1805 |
if (!inPaintEvent && paintOutsidePaintEvent && !widget->internalWinId() |
|
1806 |
&& widget->testAttribute(Qt::WA_WState_Created)) { |
|
1807 |
const QPoint offset = widget->mapTo(widget->nativeParentWidget(), QPoint()); |
|
1808 |
d->state->redirectionMatrix.translate(offset.x(), offset.y()); |
|
1809 |
} |
|
1810 |
break; |
|
1811 |
} |
|
1812 |
case QInternal::Pixmap: |
|
1813 |
{ |
|
1814 |
QPixmap *pm = static_cast<QPixmap *>(pd); |
|
1815 |
Q_ASSERT(pm); |
|
1816 |
if (pm->isNull()) { |
|
1817 |
qWarning("QPainter::begin: Cannot paint on a null pixmap"); |
|
1818 |
qt_cleanup_painter_state(d); |
|
1819 |
return false; |
|
1820 |
} |
|
1821 |
||
1822 |
if (pm->depth() == 1) { |
|
1823 |
d->state->pen = QPen(Qt::color1); |
|
1824 |
d->state->brush = QBrush(Qt::color0); |
|
1825 |
} |
|
1826 |
break; |
|
1827 |
} |
|
1828 |
case QInternal::Image: |
|
1829 |
{ |
|
1830 |
QImage *img = static_cast<QImage *>(pd); |
|
1831 |
Q_ASSERT(img); |
|
1832 |
if (img->isNull()) { |
|
1833 |
qWarning("QPainter::begin: Cannot paint on a null image"); |
|
1834 |
qt_cleanup_painter_state(d); |
|
1835 |
return false; |
|
1836 |
} else if (img->format() == QImage::Format_Indexed8) { |
|
1837 |
// Painting on indexed8 images is not supported. |
|
1838 |
qWarning("QPainter::begin: Cannot paint on an image with the QImage::Format_Indexed8 format"); |
|
1839 |
qt_cleanup_painter_state(d); |
|
1840 |
return false; |
|
1841 |
} |
|
1842 |
if (img->depth() == 1) { |
|
1843 |
d->state->pen = QPen(Qt::color1); |
|
1844 |
d->state->brush = QBrush(Qt::color0); |
|
1845 |
} |
|
1846 |
break; |
|
1847 |
} |
|
1848 |
default: |
|
1849 |
break; |
|
1850 |
} |
|
1851 |
if (d->state->ww == 0) // For compat with 3.x painter defaults |
|
1852 |
d->state->ww = d->state->wh = d->state->vw = d->state->vh = 1024; |
|
1853 |
||
1854 |
d->engine->setPaintDevice(pd); |
|
1855 |
||
1856 |
bool begun = d->engine->begin(pd); |
|
1857 |
if (!begun) { |
|
1858 |
qWarning("QPainter::begin(): Returned false"); |
|
1859 |
if (d->engine->isActive()) { |
|
1860 |
end(); |
|
1861 |
} else { |
|
1862 |
qt_cleanup_painter_state(d); |
|
1863 |
} |
|
1864 |
return false; |
|
1865 |
} else { |
|
1866 |
d->engine->setActive(begun); |
|
1867 |
} |
|
1868 |
||
1869 |
// Copy painter properties from original paint device, |
|
1870 |
// required for QPixmap::grabWidget() |
|
1871 |
if (d->original_device->devType() == QInternal::Widget) { |
|
1872 |
QWidget *widget = static_cast<QWidget *>(d->original_device); |
|
1873 |
initFrom(widget); |
|
1874 |
} else { |
|
1875 |
d->state->layoutDirection = QApplication::layoutDirection(); |
|
1876 |
// make sure we have a font compatible with the paintdevice |
|
1877 |
d->state->deviceFont = d->state->font = QFont(d->state->deviceFont, device()); |
|
1878 |
} |
|
1879 |
||
1880 |
QRect systemRect = d->engine->systemRect(); |
|
1881 |
if (!systemRect.isEmpty()) { |
|
1882 |
d->state->ww = d->state->vw = systemRect.width(); |
|
1883 |
d->state->wh = d->state->vh = systemRect.height(); |
|
1884 |
} else { |
|
1885 |
d->state->ww = d->state->vw = pd->metric(QPaintDevice::PdmWidth); |
|
1886 |
d->state->wh = d->state->vh = pd->metric(QPaintDevice::PdmHeight); |
|
1887 |
} |
|
1888 |
||
1889 |
const QPoint coordinateOffset = d->engine->coordinateOffset(); |
|
1890 |
d->state->redirectionMatrix.translate(-coordinateOffset.x(), -coordinateOffset.y()); |
|
1891 |
||
1892 |
Q_ASSERT(d->engine->isActive()); |
|
1893 |
||
1894 |
if (!d->state->redirectionMatrix.isIdentity()) |
|
1895 |
d->updateMatrix(); |
|
1896 |
||
1897 |
Q_ASSERT(d->engine->isActive()); |
|
1898 |
d->state->renderHints = QPainter::TextAntialiasing; |
|
1899 |
++d->device->painters; |
|
1900 |
||
1901 |
d->state->emulationSpecifier = 0; |
|
1902 |
||
1903 |
return true; |
|
1904 |
} |
|
1905 |
||
1906 |
/*! |
|
1907 |
Ends painting. Any resources used while painting are released. You |
|
1908 |
don't normally need to call this since it is called by the |
|
1909 |
destructor. |
|
1910 |
||
1911 |
Returns true if the painter is no longer active; otherwise returns false. |
|
1912 |
||
1913 |
\sa begin(), isActive() |
|
1914 |
*/ |
|
1915 |
||
1916 |
bool QPainter::end() |
|
1917 |
{ |
|
1918 |
#ifdef QT_DEBUG_DRAW |
|
1919 |
if (qt_show_painter_debug_output) |
|
1920 |
printf("QPainter::end()\n"); |
|
1921 |
#endif |
|
1922 |
Q_D(QPainter); |
|
1923 |
||
1924 |
if (!d->engine) { |
|
1925 |
qWarning("QPainter::end: Painter not active, aborted"); |
|
1926 |
qt_cleanup_painter_state(d); |
|
1927 |
return false; |
|
1928 |
} |
|
1929 |
||
1930 |
if (d->refcount > 1) { |
|
1931 |
d->detachPainterPrivate(this); |
|
1932 |
return true; |
|
1933 |
} |
|
1934 |
||
1935 |
bool ended = true; |
|
1936 |
||
1937 |
if (d->engine->isActive()) { |
|
1938 |
ended = d->engine->end(); |
|
1939 |
d->updateState(0); |
|
1940 |
||
1941 |
--d->device->painters; |
|
1942 |
if (d->device->painters == 0) { |
|
1943 |
d->engine->setPaintDevice(0); |
|
1944 |
d->engine->setActive(false); |
|
1945 |
} |
|
1946 |
} |
|
1947 |
||
1948 |
if (d->states.size() > 1) { |
|
1949 |
qWarning("QPainter::end: Painter ended with %d saved states", |
|
1950 |
d->states.size()); |
|
1951 |
} |
|
1952 |
||
1953 |
if (d->engine->autoDestruct()) { |
|
1954 |
delete d->engine; |
|
1955 |
} |
|
1956 |
||
1957 |
if (d->emulationEngine) { |
|
1958 |
delete d->emulationEngine; |
|
1959 |
d->emulationEngine = 0; |
|
1960 |
} |
|
1961 |
||
1962 |
if (d->extended) { |
|
1963 |
d->extended = 0; |
|
1964 |
} |
|
1965 |
||
1966 |
qt_cleanup_painter_state(d); |
|
1967 |
||
1968 |
return ended; |
|
1969 |
} |
|
1970 |
||
1971 |
||
1972 |
/*! |
|
1973 |
Returns the paint engine that the painter is currently operating |
|
1974 |
on if the painter is active; otherwise 0. |
|
1975 |
||
1976 |
\sa isActive() |
|
1977 |
*/ |
|
1978 |
QPaintEngine *QPainter::paintEngine() const |
|
1979 |
{ |
|
1980 |
Q_D(const QPainter); |
|
1981 |
return d->engine; |
|
1982 |
} |
|
1983 |
||
1984 |
/*! |
|
1985 |
\since 4.6 |
|
1986 |
||
1987 |
Flushes the painting pipeline and prepares for the user issuing |
|
1988 |
commands directly to the underlying graphics context. Must be |
|
1989 |
followed by a call to endNativePainting(). |
|
1990 |
||
1991 |
Here is an example that shows intermixing of painter commands |
|
1992 |
and raw OpenGL commands: |
|
1993 |
||
1994 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 21 |
|
1995 |
||
1996 |
\sa endNativePainting() |
|
1997 |
*/ |
|
1998 |
void QPainter::beginNativePainting() |
|
1999 |
{ |
|
2000 |
Q_D(QPainter); |
|
2001 |
if (!d->engine) { |
|
2002 |
qWarning("QPainter::beginNativePainting: Painter not active"); |
|
2003 |
return; |
|
2004 |
} |
|
2005 |
||
2006 |
if (d->extended) |
|
2007 |
d->extended->beginNativePainting(); |
|
2008 |
} |
|
2009 |
||
2010 |
/*! |
|
2011 |
\since 4.6 |
|
2012 |
||
2013 |
Restores the painter after manually issuing native painting commands. |
|
2014 |
Lets the painter restore any native state that it relies on before |
|
2015 |
calling any other painter commands. |
|
2016 |
||
2017 |
\sa beginNativePainting() |
|
2018 |
*/ |
|
2019 |
void QPainter::endNativePainting() |
|
2020 |
{ |
|
2021 |
Q_D(const QPainter); |
|
2022 |
if (!d->engine) { |
|
2023 |
qWarning("QPainter::beginNativePainting: Painter not active"); |
|
2024 |
return; |
|
2025 |
} |
|
2026 |
||
2027 |
if (d->extended) |
|
2028 |
d->extended->endNativePainting(); |
|
2029 |
else |
|
2030 |
d->engine->syncState(); |
|
2031 |
} |
|
2032 |
||
2033 |
/*! |
|
2034 |
Returns the font metrics for the painter if the painter is |
|
2035 |
active. Otherwise, the return value is undefined. |
|
2036 |
||
2037 |
\sa font(), isActive(), {QPainter#Settings}{Settings} |
|
2038 |
*/ |
|
2039 |
||
2040 |
QFontMetrics QPainter::fontMetrics() const |
|
2041 |
{ |
|
2042 |
Q_D(const QPainter); |
|
2043 |
if (!d->engine) { |
|
2044 |
qWarning("QPainter::fontMetrics: Painter not active"); |
|
2045 |
return QFontMetrics(QFont()); |
|
2046 |
} |
|
2047 |
return QFontMetrics(d->state->font); |
|
2048 |
} |
|
2049 |
||
2050 |
||
2051 |
/*! |
|
2052 |
Returns the font info for the painter if the painter is |
|
2053 |
active. Otherwise, the return value is undefined. |
|
2054 |
||
2055 |
\sa font(), isActive(), {QPainter#Settings}{Settings} |
|
2056 |
*/ |
|
2057 |
||
2058 |
QFontInfo QPainter::fontInfo() const |
|
2059 |
{ |
|
2060 |
Q_D(const QPainter); |
|
2061 |
if (!d->engine) { |
|
2062 |
qWarning("QPainter::fontInfo: Painter not active"); |
|
2063 |
return QFontInfo(QFont()); |
|
2064 |
} |
|
2065 |
return QFontInfo(d->state->font); |
|
2066 |
} |
|
2067 |
||
2068 |
/*! |
|
2069 |
\since 4.2 |
|
2070 |
||
2071 |
Returns the opacity of the painter. The default value is |
|
2072 |
1. |
|
2073 |
*/ |
|
2074 |
||
2075 |
qreal QPainter::opacity() const |
|
2076 |
{ |
|
2077 |
Q_D(const QPainter); |
|
2078 |
if (!d->engine) { |
|
2079 |
qWarning("QPainter::opacity: Painter not active"); |
|
2080 |
return 1.0; |
|
2081 |
} |
|
2082 |
return d->state->opacity; |
|
2083 |
} |
|
2084 |
||
2085 |
/*! |
|
2086 |
\since 4.2 |
|
2087 |
||
2088 |
Sets the opacity of the painter to \a opacity. The value should |
|
2089 |
be in the range 0.0 to 1.0, where 0.0 is fully transparent and |
|
2090 |
1.0 is fully opaque. |
|
2091 |
||
2092 |
Opacity set on the painter will apply to all drawing operations |
|
2093 |
individually. |
|
2094 |
*/ |
|
2095 |
||
2096 |
void QPainter::setOpacity(qreal opacity) |
|
2097 |
{ |
|
2098 |
Q_D(QPainter); |
|
2099 |
||
2100 |
if (!d->engine) { |
|
2101 |
qWarning("QPainter::setOpacity: Painter not active"); |
|
2102 |
return; |
|
2103 |
} |
|
2104 |
||
2105 |
opacity = qMin(qreal(1), qMax(qreal(0), opacity)); |
|
2106 |
||
2107 |
if (opacity == d->state->opacity) |
|
2108 |
return; |
|
2109 |
||
2110 |
d->state->opacity = opacity; |
|
2111 |
||
2112 |
if (d->extended) |
|
2113 |
d->extended->opacityChanged(); |
|
2114 |
else |
|
2115 |
d->state->dirtyFlags |= QPaintEngine::DirtyOpacity; |
|
2116 |
} |
|
2117 |
||
2118 |
||
2119 |
/*! |
|
2120 |
Returns the currently set brush origin. |
|
2121 |
||
2122 |
\sa setBrushOrigin(), {QPainter#Settings}{Settings} |
|
2123 |
*/ |
|
2124 |
||
2125 |
QPoint QPainter::brushOrigin() const |
|
2126 |
{ |
|
2127 |
Q_D(const QPainter); |
|
2128 |
if (!d->engine) { |
|
2129 |
qWarning("QPainter::brushOrigin: Painter not active"); |
|
2130 |
return QPoint(); |
|
2131 |
} |
|
2132 |
return QPointF(d->state->brushOrigin).toPoint(); |
|
2133 |
} |
|
2134 |
||
2135 |
/*! |
|
2136 |
\fn void QPainter::setBrushOrigin(const QPointF &position) |
|
2137 |
||
2138 |
Sets the brush origin to \a position. |
|
2139 |
||
2140 |
The brush origin specifies the (0, 0) coordinate of the painter's |
|
2141 |
brush. |
|
2142 |
||
2143 |
Note that while the brushOrigin() was necessary to adopt the |
|
2144 |
parent's background for a widget in Qt 3, this is no longer the |
|
2145 |
case since the Qt 4 painter doesn't paint the background unless |
|
2146 |
you explicitly tell it to do so by setting the widget's \l |
|
2147 |
{QWidget::autoFillBackground}{autoFillBackground} property to |
|
2148 |
true. |
|
2149 |
||
2150 |
\sa brushOrigin(), {QPainter#Settings}{Settings} |
|
2151 |
*/ |
|
2152 |
||
2153 |
void QPainter::setBrushOrigin(const QPointF &p) |
|
2154 |
{ |
|
2155 |
Q_D(QPainter); |
|
2156 |
#ifdef QT_DEBUG_DRAW |
|
2157 |
if (qt_show_painter_debug_output) |
|
2158 |
printf("QPainter::setBrushOrigin(), (%.2f,%.2f)\n", p.x(), p.y()); |
|
2159 |
#endif |
|
2160 |
||
2161 |
if (!d->engine) { |
|
2162 |
qWarning("QPainter::setBrushOrigin: Painter not active"); |
|
2163 |
return; |
|
2164 |
} |
|
2165 |
||
2166 |
d->state->brushOrigin = p; |
|
2167 |
||
2168 |
if (d->extended) { |
|
2169 |
d->extended->brushOriginChanged(); |
|
2170 |
return; |
|
2171 |
} |
|
2172 |
||
2173 |
d->state->dirtyFlags |= QPaintEngine::DirtyBrushOrigin; |
|
2174 |
} |
|
2175 |
||
2176 |
/*! |
|
2177 |
\fn void QPainter::setBrushOrigin(const QPoint &position) |
|
2178 |
\overload |
|
2179 |
||
2180 |
Sets the brush's origin to the given \a position. |
|
2181 |
*/ |
|
2182 |
||
2183 |
/*! |
|
2184 |
\fn void QPainter::setBrushOrigin(int x, int y) |
|
2185 |
||
2186 |
\overload |
|
2187 |
||
2188 |
Sets the brush's origin to point (\a x, \a y). |
|
2189 |
*/ |
|
2190 |
||
2191 |
/*! |
|
2192 |
\enum QPainter::CompositionMode |
|
2193 |
||
2194 |
Defines the modes supported for digital image compositing. |
|
2195 |
Composition modes are used to specify how the pixels in one image, |
|
2196 |
the source, are merged with the pixel in another image, the |
|
2197 |
destination. |
|
2198 |
||
2199 |
Please note that the bitwise raster operation modes, denoted with |
|
2200 |
a RasterOp prefix, are only natively supported in the X11 and |
|
2201 |
raster paint engines. This means that the only way to utilize |
|
2202 |
these modes on the Mac is via a QImage. The RasterOp denoted blend |
|
2203 |
modes are \e not supported for pens and brushes with alpha |
|
2204 |
components. Also, turning on the QPainter::Antialiasing render |
|
2205 |
hint will effectively disable the RasterOp modes. |
|
2206 |
||
2207 |
||
2208 |
\image qpainter-compositionmode1.png |
|
2209 |
\image qpainter-compositionmode2.png |
|
2210 |
||
2211 |
The most common type is SourceOver (often referred to as just |
|
2212 |
alpha blending) where the source pixel is blended on top of the |
|
2213 |
destination pixel in such a way that the alpha component of the |
|
2214 |
source defines the translucency of the pixel. |
|
2215 |
||
2216 |
When the paint device is a QImage, the image format must be set to |
|
2217 |
\l {QImage::Format}{Format_ARGB32Premultiplied} or |
|
2218 |
\l {QImage::Format}{Format_ARGB32} for the composition modes to have |
|
2219 |
any effect. For performance the premultiplied version is the preferred |
|
2220 |
format. |
|
2221 |
||
2222 |
When a composition mode is set it applies to all painting |
|
2223 |
operator, pens, brushes, gradients and pixmap/image drawing. |
|
2224 |
||
2225 |
\value CompositionMode_SourceOver This is the default mode. The |
|
2226 |
alpha of the source is used to blend the pixel on top of the |
|
2227 |
destination. |
|
2228 |
||
2229 |
\value CompositionMode_DestinationOver The alpha of the |
|
2230 |
destination is used to blend it on top of the source pixels. This |
|
2231 |
mode is the inverse of CompositionMode_SourceOver. |
|
2232 |
||
2233 |
\value CompositionMode_Clear The pixels in the destination are |
|
2234 |
cleared (set to fully transparent) independent of the source. |
|
2235 |
||
2236 |
\value CompositionMode_Source The output is the source |
|
2237 |
pixel. (This means a basic copy operation and is identical to |
|
2238 |
SourceOver when the source pixel is opaque). |
|
2239 |
||
2240 |
\value CompositionMode_Destination The output is the destination |
|
2241 |
pixel. This means that the blending has no effect. This mode is |
|
2242 |
the inverse of CompositionMode_Source. |
|
2243 |
||
2244 |
\value CompositionMode_SourceIn The output is the source, where |
|
2245 |
the alpha is reduced by that of the destination. |
|
2246 |
||
2247 |
\value CompositionMode_DestinationIn The output is the |
|
2248 |
destination, where the alpha is reduced by that of the |
|
2249 |
source. This mode is the inverse of CompositionMode_SourceIn. |
|
2250 |
||
2251 |
\value CompositionMode_SourceOut The output is the source, where |
|
2252 |
the alpha is reduced by the inverse of destination. |
|
2253 |
||
2254 |
\value CompositionMode_DestinationOut The output is the |
|
2255 |
destination, where the alpha is reduced by the inverse of the |
|
2256 |
source. This mode is the inverse of CompositionMode_SourceOut. |
|
2257 |
||
2258 |
\value CompositionMode_SourceAtop The source pixel is blended on |
|
2259 |
top of the destination, with the alpha of the source pixel reduced |
|
2260 |
by the alpha of the destination pixel. |
|
2261 |
||
2262 |
\value CompositionMode_DestinationAtop The destination pixel is |
|
2263 |
blended on top of the source, with the alpha of the destination |
|
2264 |
pixel is reduced by the alpha of the destination pixel. This mode |
|
2265 |
is the inverse of CompositionMode_SourceAtop. |
|
2266 |
||
2267 |
\value CompositionMode_Xor The source, whose alpha is reduced with |
|
2268 |
the inverse of the destination alpha, is merged with the |
|
2269 |
destination, whose alpha is reduced by the inverse of the source |
|
2270 |
alpha. CompositionMode_Xor is not the same as the bitwise Xor. |
|
2271 |
||
2272 |
\value CompositionMode_Plus Both the alpha and color of the source |
|
2273 |
and destination pixels are added together. |
|
2274 |
||
2275 |
\value CompositionMode_Multiply The output is the source color |
|
2276 |
multiplied by the destination. Multiplying a color with white |
|
2277 |
leaves the color unchanged, while multiplying a color |
|
2278 |
with black produces black. |
|
2279 |
||
2280 |
\value CompositionMode_Screen The source and destination colors |
|
2281 |
are inverted and then multiplied. Screening a color with white |
|
2282 |
produces white, whereas screening a color with black leaves the |
|
2283 |
color unchanged. |
|
2284 |
||
2285 |
\value CompositionMode_Overlay Multiplies or screens the colors |
|
2286 |
depending on the destination color. The destination color is mixed |
|
2287 |
with the source color to reflect the lightness or darkness of the |
|
2288 |
destination. |
|
2289 |
||
2290 |
\value CompositionMode_Darken The darker of the source and |
|
2291 |
destination colors is selected. |
|
2292 |
||
2293 |
\value CompositionMode_Lighten The lighter of the source and |
|
2294 |
destination colors is selected. |
|
2295 |
||
2296 |
\value CompositionMode_ColorDodge The destination color is |
|
2297 |
brightened to reflect the source color. A black source color |
|
2298 |
leaves the destination color unchanged. |
|
2299 |
||
2300 |
\value CompositionMode_ColorBurn The destination color is darkened |
|
2301 |
to reflect the source color. A white source color leaves the |
|
2302 |
destination color unchanged. |
|
2303 |
||
2304 |
\value CompositionMode_HardLight Multiplies or screens the colors |
|
2305 |
depending on the source color. A light source color will lighten |
|
2306 |
the destination color, whereas a dark source color will darken the |
|
2307 |
destination color. |
|
2308 |
||
2309 |
\value CompositionMode_SoftLight Darkens or lightens the colors |
|
2310 |
depending on the source color. Similar to |
|
2311 |
CompositionMode_HardLight. |
|
2312 |
||
2313 |
\value CompositionMode_Difference Subtracts the darker of the |
|
2314 |
colors from the lighter. Painting with white inverts the |
|
2315 |
destination color, whereas painting with black leaves the |
|
2316 |
destination color unchanged. |
|
2317 |
||
2318 |
\value CompositionMode_Exclusion Similar to |
|
2319 |
CompositionMode_Difference, but with a lower contrast. Painting |
|
2320 |
with white inverts the destination color, whereas painting with |
|
2321 |
black leaves the destination color unchanged. |
|
2322 |
||
2323 |
\value RasterOp_SourceOrDestination Does a bitwise OR operation on |
|
2324 |
the source and destination pixels (src OR dst). |
|
2325 |
||
2326 |
\value RasterOp_SourceAndDestination Does a bitwise AND operation |
|
2327 |
on the source and destination pixels (src AND dst). |
|
2328 |
||
2329 |
\value RasterOp_SourceXorDestination Does a bitwise XOR operation |
|
2330 |
on the source and destination pixels (src XOR dst). |
|
2331 |
||
2332 |
\value RasterOp_NotSourceAndNotDestination Does a bitwise NOR |
|
2333 |
operation on the source and destination pixels ((NOT src) AND (NOT |
|
2334 |
dst)). |
|
2335 |
||
2336 |
\value RasterOp_NotSourceOrNotDestination Does a bitwise NAND |
|
2337 |
operation on the source and destination pixels ((NOT src) OR (NOT |
|
2338 |
dst)). |
|
2339 |
||
2340 |
\value RasterOp_NotSourceXorDestination Does a bitwise operation |
|
2341 |
where the source pixels are inverted and then XOR'ed with the |
|
2342 |
destination ((NOT src) XOR dst). |
|
2343 |
||
2344 |
\value RasterOp_NotSource Does a bitwise operation where the |
|
2345 |
source pixels are inverted (NOT src). |
|
2346 |
||
2347 |
\value RasterOp_NotSourceAndDestination Does a bitwise operation |
|
2348 |
where the source is inverted and then AND'ed with the destination |
|
2349 |
((NOT src) AND dst). |
|
2350 |
||
2351 |
\value RasterOp_SourceAndNotDestination Does a bitwise operation |
|
2352 |
where the source is AND'ed with the inverted destination pixels |
|
2353 |
(src AND (NOT dst)). |
|
2354 |
||
2355 |
\sa compositionMode(), setCompositionMode(), {QPainter#Composition |
|
2356 |
Modes}{Composition Modes}, {Image Composition Example} |
|
2357 |
*/ |
|
2358 |
||
2359 |
/*! |
|
2360 |
Sets the composition mode to the given \a mode. |
|
2361 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2362 |
\warning Only a QPainter operating on a QImage fully supports all |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2363 |
composition modes. The RasterOp modes are supported for X11 as |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2364 |
described in compositionMode(). |
0 | 2365 |
|
2366 |
\sa compositionMode() |
|
2367 |
*/ |
|
2368 |
void QPainter::setCompositionMode(CompositionMode mode) |
|
2369 |
{ |
|
2370 |
Q_D(QPainter); |
|
2371 |
if (!d->engine) { |
|
2372 |
qWarning("QPainter::setCompositionMode: Painter not active"); |
|
2373 |
return; |
|
2374 |
} |
|
2375 |
if (d->extended) { |
|
2376 |
d->state->composition_mode = mode; |
|
2377 |
d->extended->compositionModeChanged(); |
|
2378 |
return; |
|
2379 |
} |
|
2380 |
||
2381 |
if (mode >= QPainter::RasterOp_SourceOrDestination) { |
|
2382 |
if (!d->engine->hasFeature(QPaintEngine::RasterOpModes)) { |
|
2383 |
qWarning("QPainter::setCompositionMode: " |
|
2384 |
"Raster operation modes not supported on device"); |
|
2385 |
return; |
|
2386 |
} |
|
2387 |
} else if (mode >= QPainter::CompositionMode_Plus) { |
|
2388 |
if (!d->engine->hasFeature(QPaintEngine::BlendModes)) { |
|
2389 |
qWarning("QPainter::setCompositionMode: " |
|
2390 |
"Blend modes not supported on device"); |
|
2391 |
return; |
|
2392 |
} |
|
2393 |
} else if (!d->engine->hasFeature(QPaintEngine::PorterDuff)) { |
|
2394 |
if (mode != CompositionMode_Source && mode != CompositionMode_SourceOver) { |
|
2395 |
qWarning("QPainter::setCompositionMode: " |
|
2396 |
"PorterDuff modes not supported on device"); |
|
2397 |
return; |
|
2398 |
} |
|
2399 |
} |
|
2400 |
||
2401 |
d->state->composition_mode = mode; |
|
2402 |
d->state->dirtyFlags |= QPaintEngine::DirtyCompositionMode; |
|
2403 |
} |
|
2404 |
||
2405 |
/*! |
|
2406 |
Returns the current composition mode. |
|
2407 |
||
2408 |
\sa CompositionMode, setCompositionMode() |
|
2409 |
*/ |
|
2410 |
QPainter::CompositionMode QPainter::compositionMode() const |
|
2411 |
{ |
|
2412 |
Q_D(const QPainter); |
|
2413 |
if (!d->engine) { |
|
2414 |
qWarning("QPainter::compositionMode: Painter not active"); |
|
2415 |
return QPainter::CompositionMode_SourceOver; |
|
2416 |
} |
|
2417 |
return d->state->composition_mode; |
|
2418 |
} |
|
2419 |
||
2420 |
/*! |
|
2421 |
Returns the current background brush. |
|
2422 |
||
2423 |
\sa setBackground(), {QPainter#Settings}{Settings} |
|
2424 |
*/ |
|
2425 |
||
2426 |
const QBrush &QPainter::background() const |
|
2427 |
{ |
|
2428 |
Q_D(const QPainter); |
|
2429 |
if (!d->engine) { |
|
2430 |
qWarning("QPainter::background: Painter not active"); |
|
2431 |
return d->fakeState()->brush; |
|
2432 |
} |
|
2433 |
return d->state->bgBrush; |
|
2434 |
} |
|
2435 |
||
2436 |
||
2437 |
/*! |
|
2438 |
Returns true if clipping has been set; otherwise returns false. |
|
2439 |
||
2440 |
\sa setClipping(), {QPainter#Clipping}{Clipping} |
|
2441 |
*/ |
|
2442 |
||
2443 |
bool QPainter::hasClipping() const |
|
2444 |
{ |
|
2445 |
Q_D(const QPainter); |
|
2446 |
if (!d->engine) { |
|
2447 |
qWarning("QPainter::hasClipping: Painter not active"); |
|
2448 |
return false; |
|
2449 |
} |
|
2450 |
return d->state->clipEnabled && d->state->clipOperation != Qt::NoClip; |
|
2451 |
} |
|
2452 |
||
2453 |
||
2454 |
/*! |
|
2455 |
Enables clipping if \a enable is true, or disables clipping if \a |
|
2456 |
enable is false. |
|
2457 |
||
2458 |
\sa hasClipping(), {QPainter#Clipping}{Clipping} |
|
2459 |
*/ |
|
2460 |
||
2461 |
void QPainter::setClipping(bool enable) |
|
2462 |
{ |
|
2463 |
Q_D(QPainter); |
|
2464 |
#ifdef QT_DEBUG_DRAW |
|
2465 |
if (qt_show_painter_debug_output) |
|
2466 |
printf("QPainter::setClipping(), enable=%s, was=%s\n", |
|
2467 |
enable ? "on" : "off", |
|
2468 |
hasClipping() ? "on" : "off"); |
|
2469 |
#endif |
|
2470 |
if (!d->engine) { |
|
2471 |
qWarning("QPainter::setClipping: Painter not active, state will be reset by begin"); |
|
2472 |
return; |
|
2473 |
} |
|
2474 |
||
2475 |
if (hasClipping() == enable) |
|
2476 |
return; |
|
2477 |
||
2478 |
// we can't enable clipping if we don't have a clip |
|
2479 |
if (enable |
|
2480 |
&& (d->state->clipInfo.isEmpty() || d->state->clipInfo.last().operation == Qt::NoClip)) |
|
2481 |
return; |
|
2482 |
d->state->clipEnabled = enable; |
|
2483 |
||
2484 |
if (d->extended) { |
|
2485 |
d->extended->clipEnabledChanged(); |
|
2486 |
return; |
|
2487 |
} |
|
2488 |
||
2489 |
d->state->dirtyFlags |= QPaintEngine::DirtyClipEnabled; |
|
2490 |
d->updateState(d->state); |
|
2491 |
} |
|
2492 |
||
2493 |
||
2494 |
/*! |
|
2495 |
Returns the currently set clip region. Note that the clip region |
|
2496 |
is given in logical coordinates. |
|
2497 |
||
2498 |
\warning QPainter does not store the combined clip explicitly as |
|
2499 |
this is handled by the underlying QPaintEngine, so the path is |
|
2500 |
recreated on demand and transformed to the current logical |
|
2501 |
coordinate system. This is potentially an expensive operation. |
|
2502 |
||
2503 |
\sa setClipRegion(), clipPath(), setClipping() |
|
2504 |
*/ |
|
2505 |
||
2506 |
QRegion QPainter::clipRegion() const |
|
2507 |
{ |
|
2508 |
Q_D(const QPainter); |
|
2509 |
if (!d->engine) { |
|
2510 |
qWarning("QPainter::clipRegion: Painter not active"); |
|
2511 |
return QRegion(); |
|
2512 |
} |
|
2513 |
||
2514 |
QRegion region; |
|
2515 |
bool lastWasNothing = true; |
|
2516 |
||
2517 |
if (!d->txinv) |
|
2518 |
const_cast<QPainter *>(this)->d_ptr->updateInvMatrix(); |
|
2519 |
||
2520 |
// ### Falcon: Use QPainterPath |
|
2521 |
for (int i=0; i<d->state->clipInfo.size(); ++i) { |
|
2522 |
const QPainterClipInfo &info = d->state->clipInfo.at(i); |
|
2523 |
switch (info.clipType) { |
|
2524 |
||
2525 |
case QPainterClipInfo::RegionClip: { |
|
2526 |
QTransform matrix = (info.matrix * d->invMatrix); |
|
2527 |
if (lastWasNothing) { |
|
2528 |
region = info.region * matrix; |
|
2529 |
lastWasNothing = false; |
|
2530 |
continue; |
|
2531 |
} |
|
2532 |
if (info.operation == Qt::IntersectClip) |
|
2533 |
region &= info.region * matrix; |
|
2534 |
else if (info.operation == Qt::UniteClip) |
|
2535 |
region |= info.region * matrix; |
|
2536 |
else if (info.operation == Qt::NoClip) { |
|
2537 |
lastWasNothing = true; |
|
2538 |
region = QRegion(); |
|
2539 |
} else |
|
2540 |
region = info.region * matrix; |
|
2541 |
break; |
|
2542 |
} |
|
2543 |
||
2544 |
case QPainterClipInfo::PathClip: { |
|
2545 |
QTransform matrix = (info.matrix * d->invMatrix); |
|
2546 |
if (lastWasNothing) { |
|
2547 |
region = QRegion((info.path * matrix).toFillPolygon().toPolygon(), |
|
2548 |
info.path.fillRule()); |
|
2549 |
lastWasNothing = false; |
|
2550 |
continue; |
|
2551 |
} |
|
2552 |
if (info.operation == Qt::IntersectClip) { |
|
2553 |
region &= QRegion((info.path * matrix).toFillPolygon().toPolygon(), |
|
2554 |
info.path.fillRule()); |
|
2555 |
} else if (info.operation == Qt::UniteClip) { |
|
2556 |
region |= QRegion((info.path * matrix).toFillPolygon().toPolygon(), |
|
2557 |
info.path.fillRule()); |
|
2558 |
} else if (info.operation == Qt::NoClip) { |
|
2559 |
lastWasNothing = true; |
|
2560 |
region = QRegion(); |
|
2561 |
} else { |
|
2562 |
region = QRegion((info.path * matrix).toFillPolygon().toPolygon(), |
|
2563 |
info.path.fillRule()); |
|
2564 |
} |
|
2565 |
break; |
|
2566 |
} |
|
2567 |
||
2568 |
case QPainterClipInfo::RectClip: { |
|
2569 |
QTransform matrix = (info.matrix * d->invMatrix); |
|
2570 |
if (lastWasNothing) { |
|
2571 |
region = QRegion(info.rect) * matrix; |
|
2572 |
lastWasNothing = false; |
|
2573 |
continue; |
|
2574 |
} |
|
2575 |
if (info.operation == Qt::IntersectClip) { |
|
2576 |
// Use rect intersection if possible. |
|
2577 |
if (matrix.type() <= QTransform::TxScale) |
|
2578 |
region &= matrix.mapRect(info.rect); |
|
2579 |
else |
|
2580 |
region &= matrix.map(QRegion(info.rect)); |
|
2581 |
} else if (info.operation == Qt::UniteClip) { |
|
2582 |
region |= QRegion(info.rect) * matrix; |
|
2583 |
} else if (info.operation == Qt::NoClip) { |
|
2584 |
lastWasNothing = true; |
|
2585 |
region = QRegion(); |
|
2586 |
} else { |
|
2587 |
region = QRegion(info.rect) * matrix; |
|
2588 |
} |
|
2589 |
break; |
|
2590 |
} |
|
2591 |
||
2592 |
case QPainterClipInfo::RectFClip: { |
|
2593 |
QTransform matrix = (info.matrix * d->invMatrix); |
|
2594 |
if (lastWasNothing) { |
|
2595 |
region = QRegion(info.rectf.toRect()) * matrix; |
|
2596 |
lastWasNothing = false; |
|
2597 |
continue; |
|
2598 |
} |
|
2599 |
if (info.operation == Qt::IntersectClip) { |
|
2600 |
// Use rect intersection if possible. |
|
2601 |
if (matrix.type() <= QTransform::TxScale) |
|
2602 |
region &= matrix.mapRect(info.rectf.toRect()); |
|
2603 |
else |
|
2604 |
region &= matrix.map(QRegion(info.rectf.toRect())); |
|
2605 |
} else if (info.operation == Qt::UniteClip) { |
|
2606 |
region |= QRegion(info.rectf.toRect()) * matrix; |
|
2607 |
} else if (info.operation == Qt::NoClip) { |
|
2608 |
lastWasNothing = true; |
|
2609 |
region = QRegion(); |
|
2610 |
} else { |
|
2611 |
region = QRegion(info.rectf.toRect()) * matrix; |
|
2612 |
} |
|
2613 |
break; |
|
2614 |
} |
|
2615 |
} |
|
2616 |
} |
|
2617 |
||
2618 |
return region; |
|
2619 |
} |
|
2620 |
||
2621 |
extern QPainterPath qt_regionToPath(const QRegion ®ion); |
|
2622 |
||
2623 |
/*! |
|
2624 |
Returns the currently clip as a path. Note that the clip path is |
|
2625 |
given in logical coordinates. |
|
2626 |
||
2627 |
\warning QPainter does not store the combined clip explicitly as |
|
2628 |
this is handled by the underlying QPaintEngine, so the path is |
|
2629 |
recreated on demand and transformed to the current logical |
|
2630 |
coordinate system. This is potentially an expensive operation. |
|
2631 |
||
2632 |
\sa setClipPath(), clipRegion(), setClipping() |
|
2633 |
*/ |
|
2634 |
QPainterPath QPainter::clipPath() const |
|
2635 |
{ |
|
2636 |
Q_D(const QPainter); |
|
2637 |
||
2638 |
// ### Since we do not support path intersections and path unions yet, |
|
2639 |
// we just use clipRegion() here... |
|
2640 |
if (!d->engine) { |
|
2641 |
qWarning("QPainter::clipPath: Painter not active"); |
|
2642 |
return QPainterPath(); |
|
2643 |
} |
|
2644 |
||
2645 |
// No clip, return empty |
|
2646 |
if (d->state->clipInfo.size() == 0) { |
|
2647 |
return QPainterPath(); |
|
2648 |
} else { |
|
2649 |
||
2650 |
// Update inverse matrix, used below. |
|
2651 |
if (!d->txinv) |
|
2652 |
const_cast<QPainter *>(this)->d_ptr->updateInvMatrix(); |
|
2653 |
||
2654 |
// For the simple case avoid conversion. |
|
2655 |
if (d->state->clipInfo.size() == 1 |
|
2656 |
&& d->state->clipInfo.at(0).clipType == QPainterClipInfo::PathClip) { |
|
2657 |
QTransform matrix = (d->state->clipInfo.at(0).matrix * d->invMatrix); |
|
2658 |
return d->state->clipInfo.at(0).path * matrix; |
|
2659 |
||
2660 |
} else if (d->state->clipInfo.size() == 1 |
|
2661 |
&& d->state->clipInfo.at(0).clipType == QPainterClipInfo::RectClip) { |
|
2662 |
QTransform matrix = (d->state->clipInfo.at(0).matrix * d->invMatrix); |
|
2663 |
QPainterPath path; |
|
2664 |
path.addRect(d->state->clipInfo.at(0).rect); |
|
2665 |
return path * matrix; |
|
2666 |
} else { |
|
2667 |
// Fallback to clipRegion() for now, since we don't have isect/unite for paths |
|
2668 |
return qt_regionToPath(clipRegion()); |
|
2669 |
} |
|
2670 |
} |
|
2671 |
} |
|
2672 |
||
2673 |
/*! |
|
2674 |
\fn void QPainter::setClipRect(const QRectF &rectangle, Qt::ClipOperation operation) |
|
2675 |
||
2676 |
Enables clipping, and sets the clip region to the given \a |
|
2677 |
rectangle using the given clip \a operation. The default operation |
|
2678 |
is to replace the current clip rectangle. |
|
2679 |
||
2680 |
Note that the clip rectangle is specified in logical (painter) |
|
2681 |
coordinates. |
|
2682 |
||
2683 |
\sa clipRegion(), setClipping(), {QPainter#Clipping}{Clipping} |
|
2684 |
*/ |
|
2685 |
void QPainter::setClipRect(const QRectF &rect, Qt::ClipOperation op) |
|
2686 |
{ |
|
2687 |
Q_D(QPainter); |
|
2688 |
||
2689 |
if (d->extended) { |
|
2690 |
if (!hasClipping() && (op == Qt::IntersectClip || op == Qt::UniteClip)) |
|
2691 |
op = Qt::ReplaceClip; |
|
2692 |
||
2693 |
if (!d->engine) { |
|
2694 |
qWarning("QPainter::setClipRect: Painter not active"); |
|
2695 |
return; |
|
2696 |
} |
|
2697 |
qreal right = rect.x() + rect.width(); |
|
2698 |
qreal bottom = rect.y() + rect.height(); |
|
2699 |
qreal pts[] = { rect.x(), rect.y(), |
|
2700 |
right, rect.y(), |
|
2701 |
right, bottom, |
|
2702 |
rect.x(), bottom }; |
|
2703 |
QVectorPath vp(pts, 4, 0, QVectorPath::RectangleHint); |
|
2704 |
d->state->clipEnabled = true; |
|
2705 |
d->extended->clip(vp, op); |
|
2706 |
if (op == Qt::ReplaceClip || op == Qt::NoClip) |
|
2707 |
d->state->clipInfo.clear(); |
|
2708 |
d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix); |
|
2709 |
d->state->clipOperation = op; |
|
2710 |
return; |
|
2711 |
} |
|
2712 |
||
2713 |
if (qreal(int(rect.top())) == rect.top() |
|
2714 |
&& qreal(int(rect.bottom())) == rect.bottom() |
|
2715 |
&& qreal(int(rect.left())) == rect.left() |
|
2716 |
&& qreal(int(rect.right())) == rect.right()) |
|
2717 |
{ |
|
2718 |
setClipRect(rect.toRect(), op); |
|
2719 |
return; |
|
2720 |
} |
|
2721 |
||
2722 |
if (rect.isEmpty()) { |
|
2723 |
setClipRegion(QRegion(), op); |
|
2724 |
return; |
|
2725 |
} |
|
2726 |
||
2727 |
QPainterPath path; |
|
2728 |
path.addRect(rect); |
|
2729 |
setClipPath(path, op); |
|
2730 |
} |
|
2731 |
||
2732 |
/*! |
|
2733 |
\fn void QPainter::setClipRect(const QRect &rectangle, Qt::ClipOperation operation) |
|
2734 |
\overload |
|
2735 |
||
2736 |
Enables clipping, and sets the clip region to the given \a rectangle using the given |
|
2737 |
clip \a operation. |
|
2738 |
*/ |
|
2739 |
void QPainter::setClipRect(const QRect &rect, Qt::ClipOperation op) |
|
2740 |
{ |
|
2741 |
Q_D(QPainter); |
|
2742 |
||
2743 |
if (!d->engine) { |
|
2744 |
qWarning("QPainter::setClipRect: Painter not active"); |
|
2745 |
return; |
|
2746 |
} |
|
2747 |
||
2748 |
if (!hasClipping() && (op == Qt::IntersectClip || op == Qt::UniteClip)) |
|
2749 |
op = Qt::ReplaceClip; |
|
2750 |
||
2751 |
if (d->extended) { |
|
2752 |
d->state->clipEnabled = true; |
|
2753 |
d->extended->clip(rect, op); |
|
2754 |
if (op == Qt::ReplaceClip || op == Qt::NoClip) |
|
2755 |
d->state->clipInfo.clear(); |
|
2756 |
d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix); |
|
2757 |
d->state->clipOperation = op; |
|
2758 |
return; |
|
2759 |
} |
|
2760 |
||
2761 |
d->state->clipRegion = rect; |
|
2762 |
d->state->clipOperation = op; |
|
2763 |
if (op == Qt::NoClip || op == Qt::ReplaceClip) |
|
2764 |
d->state->clipInfo.clear(); |
|
2765 |
d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix); |
|
2766 |
d->state->clipEnabled = true; |
|
2767 |
d->state->dirtyFlags |= QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyClipEnabled; |
|
2768 |
d->updateState(d->state); |
|
2769 |
} |
|
2770 |
||
2771 |
/*! |
|
2772 |
\fn void QPainter::setClipRect(int x, int y, int width, int height, Qt::ClipOperation operation) |
|
2773 |
||
2774 |
Enables clipping, and sets the clip region to the rectangle beginning at (\a x, \a y) |
|
2775 |
with the given \a width and \a height. |
|
2776 |
*/ |
|
2777 |
||
2778 |
/*! |
|
2779 |
\fn void QPainter::setClipRegion(const QRegion ®ion, Qt::ClipOperation operation) |
|
2780 |
||
2781 |
Sets the clip region to the given \a region using the specified clip |
|
2782 |
\a operation. The default clip operation is to replace the current |
|
2783 |
clip region. |
|
2784 |
||
2785 |
Note that the clip region is given in logical coordinates. |
|
2786 |
||
2787 |
\sa clipRegion(), setClipRect(), {QPainter#Clipping}{Clipping} |
|
2788 |
*/ |
|
2789 |
void QPainter::setClipRegion(const QRegion &r, Qt::ClipOperation op) |
|
2790 |
{ |
|
2791 |
Q_D(QPainter); |
|
2792 |
#ifdef QT_DEBUG_DRAW |
|
2793 |
QRect rect = r.boundingRect(); |
|
2794 |
if (qt_show_painter_debug_output) |
|
2795 |
printf("QPainter::setClipRegion(), size=%d, [%d,%d,%d,%d]\n", |
|
2796 |
r.rects().size(), rect.x(), rect.y(), rect.width(), rect.height()); |
|
2797 |
#endif |
|
2798 |
if (!d->engine) { |
|
2799 |
qWarning("QPainter::setClipRegion: Painter not active"); |
|
2800 |
return; |
|
2801 |
} |
|
2802 |
||
2803 |
if (!hasClipping() && (op == Qt::IntersectClip || op == Qt::UniteClip)) |
|
2804 |
op = Qt::ReplaceClip; |
|
2805 |
||
2806 |
if (d->extended) { |
|
2807 |
d->state->clipEnabled = true; |
|
2808 |
d->extended->clip(r, op); |
|
2809 |
if (op == Qt::NoClip || op == Qt::ReplaceClip) |
|
2810 |
d->state->clipInfo.clear(); |
|
2811 |
d->state->clipInfo << QPainterClipInfo(r, op, d->state->matrix); |
|
2812 |
d->state->clipOperation = op; |
|
2813 |
return; |
|
2814 |
} |
|
2815 |
||
2816 |
d->state->clipRegion = r; |
|
2817 |
d->state->clipOperation = op; |
|
2818 |
if (op == Qt::NoClip || op == Qt::ReplaceClip) |
|
2819 |
d->state->clipInfo.clear(); |
|
2820 |
d->state->clipInfo << QPainterClipInfo(r, op, d->state->matrix); |
|
2821 |
d->state->clipEnabled = true; |
|
2822 |
d->state->dirtyFlags |= QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyClipEnabled; |
|
2823 |
d->updateState(d->state); |
|
2824 |
} |
|
2825 |
||
2826 |
/*! |
|
2827 |
\since 4.2 |
|
2828 |
\obsolete |
|
2829 |
||
2830 |
Sets the transformation matrix to \a matrix and enables transformations. |
|
2831 |
||
2832 |
\note It is advisable to use setWorldTransform() instead of this function to |
|
2833 |
preserve the properties of perspective transformations. |
|
2834 |
||
2835 |
If \a combine is true, then \a matrix is combined with the current |
|
2836 |
transformation matrix; otherwise \a matrix replaces the current |
|
2837 |
transformation matrix. |
|
2838 |
||
2839 |
If \a matrix is the identity matrix and \a combine is false, this |
|
2840 |
function calls setWorldMatrixEnabled(false). (The identity matrix is the |
|
2841 |
matrix where QMatrix::m11() and QMatrix::m22() are 1.0 and the |
|
2842 |
rest are 0.0.) |
|
2843 |
||
2844 |
The following functions can transform the coordinate system without using |
|
2845 |
a QMatrix: |
|
2846 |
\list |
|
2847 |
\i translate() |
|
2848 |
\i scale() |
|
2849 |
\i shear() |
|
2850 |
\i rotate() |
|
2851 |
\endlist |
|
2852 |
||
2853 |
They operate on the painter's worldMatrix() and are implemented like this: |
|
2854 |
||
2855 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 4 |
|
2856 |
||
2857 |
Note that when using setWorldMatrix() function you should always have |
|
2858 |
\a combine be true when you are drawing into a QPicture. Otherwise |
|
2859 |
it may not be possible to replay the picture with additional |
|
2860 |
transformations; using the translate(), scale(), etc. convenience |
|
2861 |
functions is safe. |
|
2862 |
||
2863 |
For more information about the coordinate system, transformations |
|
2864 |
and window-viewport conversion, see \l {The Coordinate System} |
|
2865 |
documentation. |
|
2866 |
||
2867 |
\sa setWorldTransform(), QTransform |
|
2868 |
*/ |
|
2869 |
||
2870 |
void QPainter::setWorldMatrix(const QMatrix &matrix, bool combine) |
|
2871 |
{ |
|
2872 |
setWorldTransform(QTransform(matrix), combine); |
|
2873 |
} |
|
2874 |
||
2875 |
/*! |
|
2876 |
\since 4.2 |
|
2877 |
\obsolete |
|
2878 |
||
2879 |
Returns the world transformation matrix. |
|
2880 |
||
2881 |
It is advisable to use worldTransform() because worldMatrix() does not |
|
2882 |
preserve the properties of perspective transformations. |
|
2883 |
||
2884 |
\sa {QPainter#Coordinate Transformations}{Coordinate Transformations}, |
|
2885 |
{The Coordinate System} |
|
2886 |
*/ |
|
2887 |
||
2888 |
const QMatrix &QPainter::worldMatrix() const |
|
2889 |
{ |
|
2890 |
Q_D(const QPainter); |
|
2891 |
if (!d->engine) { |
|
2892 |
qWarning("QPainter::worldMatrix: Painter not active"); |
|
2893 |
return d->fakeState()->transform.toAffine(); |
|
2894 |
} |
|
2895 |
return d->state->worldMatrix.toAffine(); |
|
2896 |
} |
|
2897 |
||
2898 |
/*! |
|
2899 |
\obsolete |
|
2900 |
||
2901 |
Use setWorldTransform() instead. |
|
2902 |
||
2903 |
\sa setWorldTransform() |
|
2904 |
*/ |
|
2905 |
||
2906 |
void QPainter::setMatrix(const QMatrix &matrix, bool combine) |
|
2907 |
{ |
|
2908 |
setWorldTransform(QTransform(matrix), combine); |
|
2909 |
} |
|
2910 |
||
2911 |
/*! |
|
2912 |
\obsolete |
|
2913 |
||
2914 |
Use worldTransform() instead. |
|
2915 |
||
2916 |
\sa worldTransform() |
|
2917 |
*/ |
|
2918 |
||
2919 |
const QMatrix &QPainter::matrix() const |
|
2920 |
{ |
|
2921 |
return worldMatrix(); |
|
2922 |
} |
|
2923 |
||
2924 |
||
2925 |
/*! |
|
2926 |
\since 4.2 |
|
2927 |
\obsolete |
|
2928 |
||
2929 |
Returns the transformation matrix combining the current |
|
2930 |
window/viewport and world transformation. |
|
2931 |
||
2932 |
It is advisable to use combinedTransform() instead of this |
|
2933 |
function to preserve the properties of perspective transformations. |
|
2934 |
||
2935 |
\sa setWorldTransform(), setWindow(), setViewport() |
|
2936 |
*/ |
|
2937 |
QMatrix QPainter::combinedMatrix() const |
|
2938 |
{ |
|
2939 |
return combinedTransform().toAffine(); |
|
2940 |
} |
|
2941 |
||
2942 |
||
2943 |
/*! |
|
2944 |
\obsolete |
|
2945 |
||
2946 |
Returns the matrix that transforms from logical coordinates to |
|
2947 |
device coordinates of the platform dependent paint device. |
|
2948 |
||
2949 |
\note It is advisable to use deviceTransform() instead of this |
|
2950 |
function to preserve the properties of perspective transformations. |
|
2951 |
||
2952 |
This function is \e only needed when using platform painting |
|
2953 |
commands on the platform dependent handle (Qt::HANDLE), and the |
|
2954 |
platform does not do transformations nativly. |
|
2955 |
||
2956 |
The QPaintEngine::PaintEngineFeature enum can be queried to |
|
2957 |
determine whether the platform performs the transformations or |
|
2958 |
not. |
|
2959 |
||
2960 |
\sa worldMatrix(), QPaintEngine::hasFeature(), |
|
2961 |
*/ |
|
2962 |
const QMatrix &QPainter::deviceMatrix() const |
|
2963 |
{ |
|
2964 |
Q_D(const QPainter); |
|
2965 |
if (!d->engine) { |
|
2966 |
qWarning("QPainter::deviceMatrix: Painter not active"); |
|
2967 |
return d->fakeState()->transform.toAffine(); |
|
2968 |
} |
|
2969 |
return d->state->matrix.toAffine(); |
|
2970 |
} |
|
2971 |
||
2972 |
/*! |
|
2973 |
\obsolete |
|
2974 |
||
2975 |
Resets any transformations that were made using translate(), scale(), |
|
2976 |
shear(), rotate(), setWorldMatrix(), setViewport() and |
|
2977 |
setWindow(). |
|
2978 |
||
2979 |
It is advisable to use resetTransform() instead of this function |
|
2980 |
to preserve the properties of perspective transformations. |
|
2981 |
||
2982 |
\sa {QPainter#Coordinate Transformations}{Coordinate |
|
2983 |
Transformations} |
|
2984 |
*/ |
|
2985 |
||
2986 |
void QPainter::resetMatrix() |
|
2987 |
{ |
|
2988 |
resetTransform(); |
|
2989 |
} |
|
2990 |
||
2991 |
||
2992 |
/*! |
|
2993 |
\since 4.2 |
|
2994 |
||
2995 |
Enables transformations if \a enable is true, or disables |
|
2996 |
transformations if \a enable is false. The world transformation |
|
2997 |
matrix is not changed. |
|
2998 |
||
2999 |
\sa worldMatrixEnabled(), worldTransform(), {QPainter#Coordinate |
|
3000 |
Transformations}{Coordinate Transformations} |
|
3001 |
*/ |
|
3002 |
||
3003 |
void QPainter::setWorldMatrixEnabled(bool enable) |
|
3004 |
{ |
|
3005 |
Q_D(QPainter); |
|
3006 |
#ifdef QT_DEBUG_DRAW |
|
3007 |
if (qt_show_painter_debug_output) |
|
3008 |
printf("QPainter::setMatrixEnabled(), enable=%d\n", enable); |
|
3009 |
#endif |
|
3010 |
||
3011 |
if (!d->engine) { |
|
3012 |
qWarning("QPainter::setMatrixEnabled: Painter not active"); |
|
3013 |
return; |
|
3014 |
} |
|
3015 |
if (enable == d->state->WxF) |
|
3016 |
return; |
|
3017 |
||
3018 |
d->state->WxF = enable; |
|
3019 |
d->updateMatrix(); |
|
3020 |
} |
|
3021 |
||
3022 |
/*! |
|
3023 |
\since 4.2 |
|
3024 |
||
3025 |
Returns true if world transformation is enabled; otherwise returns |
|
3026 |
false. |
|
3027 |
||
3028 |
\sa setWorldMatrixEnabled(), worldTransform(), {The Coordinate System} |
|
3029 |
*/ |
|
3030 |
||
3031 |
bool QPainter::worldMatrixEnabled() const |
|
3032 |
{ |
|
3033 |
Q_D(const QPainter); |
|
3034 |
if (!d->engine) { |
|
3035 |
qWarning("QPainter::worldMatrixEnabled: Painter not active"); |
|
3036 |
return false; |
|
3037 |
} |
|
3038 |
return d->state->WxF; |
|
3039 |
} |
|
3040 |
||
3041 |
/*! |
|
3042 |
\obsolete |
|
3043 |
||
3044 |
Use setWorldMatrixEnabled() instead. |
|
3045 |
||
3046 |
\sa setWorldMatrixEnabled() |
|
3047 |
*/ |
|
3048 |
||
3049 |
void QPainter::setMatrixEnabled(bool enable) |
|
3050 |
{ |
|
3051 |
setWorldMatrixEnabled(enable); |
|
3052 |
} |
|
3053 |
||
3054 |
/*! |
|
3055 |
\obsolete |
|
3056 |
||
3057 |
Use worldMatrixEnabled() instead |
|
3058 |
||
3059 |
\sa worldMatrixEnabled() |
|
3060 |
*/ |
|
3061 |
||
3062 |
bool QPainter::matrixEnabled() const |
|
3063 |
{ |
|
3064 |
return worldMatrixEnabled(); |
|
3065 |
} |
|
3066 |
||
3067 |
/*! |
|
3068 |
Scales the coordinate system by (\a{sx}, \a{sy}). |
|
3069 |
||
3070 |
\sa setWorldTransform() {QPainter#Coordinate Transformations}{Coordinate |
|
3071 |
Transformations} |
|
3072 |
*/ |
|
3073 |
||
3074 |
void QPainter::scale(qreal sx, qreal sy) |
|
3075 |
{ |
|
3076 |
#ifdef QT_DEBUG_DRAW |
|
3077 |
if (qt_show_painter_debug_output) |
|
3078 |
printf("QPainter::scale(), sx=%f, sy=%f\n", sx, sy); |
|
3079 |
#endif |
|
3080 |
Q_D(QPainter); |
|
3081 |
if (!d->engine) { |
|
3082 |
qWarning("QPainter::scale: Painter not active"); |
|
3083 |
return; |
|
3084 |
} |
|
3085 |
||
3086 |
d->state->worldMatrix.scale(sx,sy); |
|
3087 |
d->state->WxF = true; |
|
3088 |
d->updateMatrix(); |
|
3089 |
} |
|
3090 |
||
3091 |
/*! |
|
3092 |
Shears the coordinate system by (\a{sh}, \a{sv}). |
|
3093 |
||
3094 |
\sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate |
|
3095 |
Transformations} |
|
3096 |
*/ |
|
3097 |
||
3098 |
void QPainter::shear(qreal sh, qreal sv) |
|
3099 |
{ |
|
3100 |
#ifdef QT_DEBUG_DRAW |
|
3101 |
if (qt_show_painter_debug_output) |
|
3102 |
printf("QPainter::shear(), sh=%f, sv=%f\n", sh, sv); |
|
3103 |
#endif |
|
3104 |
Q_D(QPainter); |
|
3105 |
if (!d->engine) { |
|
3106 |
qWarning("QPainter::shear: Painter not active"); |
|
3107 |
return; |
|
3108 |
} |
|
3109 |
||
3110 |
d->state->worldMatrix.shear(sh, sv); |
|
3111 |
d->state->WxF = true; |
|
3112 |
d->updateMatrix(); |
|
3113 |
} |
|
3114 |
||
3115 |
/*! |
|
3116 |
\fn void QPainter::rotate(qreal angle) |
|
3117 |
||
3118 |
Rotates the coordinate system the given \a angle clockwise. |
|
3119 |
||
3120 |
\sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate |
|
3121 |
Transformations} |
|
3122 |
*/ |
|
3123 |
||
3124 |
void QPainter::rotate(qreal a) |
|
3125 |
{ |
|
3126 |
#ifdef QT_DEBUG_DRAW |
|
3127 |
if (qt_show_painter_debug_output) |
|
3128 |
printf("QPainter::rotate(), angle=%f\n", a); |
|
3129 |
#endif |
|
3130 |
Q_D(QPainter); |
|
3131 |
if (!d->engine) { |
|
3132 |
qWarning("QPainter::rotate: Painter not active"); |
|
3133 |
return; |
|
3134 |
} |
|
3135 |
||
3136 |
d->state->worldMatrix.rotate(a); |
|
3137 |
d->state->WxF = true; |
|
3138 |
d->updateMatrix(); |
|
3139 |
} |
|
3140 |
||
3141 |
/*! |
|
3142 |
Translates the coordinate system by the given \a offset; i.e. the |
|
3143 |
given \a offset is added to points. |
|
3144 |
||
3145 |
\sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate |
|
3146 |
Transformations} |
|
3147 |
*/ |
|
3148 |
void QPainter::translate(const QPointF &offset) |
|
3149 |
{ |
|
3150 |
qreal dx = offset.x(); |
|
3151 |
qreal dy = offset.y(); |
|
3152 |
#ifdef QT_DEBUG_DRAW |
|
3153 |
if (qt_show_painter_debug_output) |
|
3154 |
printf("QPainter::translate(), dx=%f, dy=%f\n", dx, dy); |
|
3155 |
#endif |
|
3156 |
Q_D(QPainter); |
|
3157 |
if (!d->engine) { |
|
3158 |
qWarning("QPainter::translate: Painter not active"); |
|
3159 |
return; |
|
3160 |
} |
|
3161 |
||
3162 |
d->state->worldMatrix.translate(dx, dy); |
|
3163 |
d->state->WxF = true; |
|
3164 |
d->updateMatrix(); |
|
3165 |
} |
|
3166 |
||
3167 |
/*! |
|
3168 |
\fn void QPainter::translate(const QPoint &offset) |
|
3169 |
\overload |
|
3170 |
||
3171 |
Translates the coordinate system by the given \a offset. |
|
3172 |
*/ |
|
3173 |
||
3174 |
/*! |
|
3175 |
\fn void QPainter::translate(qreal dx, qreal dy) |
|
3176 |
\overload |
|
3177 |
||
3178 |
Translates the coordinate system by the vector (\a dx, \a dy). |
|
3179 |
*/ |
|
3180 |
||
3181 |
/*! |
|
3182 |
\fn void QPainter::setClipPath(const QPainterPath &path, Qt::ClipOperation operation) |
|
3183 |
||
3184 |
Enables clipping, and sets the clip path for the painter to the |
|
3185 |
given \a path, with the clip \a operation. |
|
3186 |
||
3187 |
Note that the clip path is specified in logical (painter) |
|
3188 |
coordinates. |
|
3189 |
||
3190 |
\sa clipPath(), clipRegion(), {QPainter#Clipping}{Clipping} |
|
3191 |
||
3192 |
*/ |
|
3193 |
void QPainter::setClipPath(const QPainterPath &path, Qt::ClipOperation op) |
|
3194 |
{ |
|
3195 |
#ifdef QT_DEBUG_DRAW |
|
3196 |
if (qt_show_painter_debug_output) { |
|
3197 |
QRectF b = path.boundingRect(); |
|
3198 |
printf("QPainter::setClipPath(), size=%d, op=%d, bounds=[%.2f,%.2f,%.2f,%.2f]\n", |
|
3199 |
path.elementCount(), op, b.x(), b.y(), b.width(), b.height()); |
|
3200 |
} |
|
3201 |
#endif |
|
3202 |
Q_D(QPainter); |
|
3203 |
||
3204 |
if (!d->engine) { |
|
3205 |
qWarning("QPainter::setClipPath: Painter not active"); |
|
3206 |
return; |
|
3207 |
} |
|
3208 |
||
3209 |
if (!hasClipping() && (op == Qt::IntersectClip || op == Qt::UniteClip)) |
|
3210 |
op = Qt::ReplaceClip; |
|
3211 |
||
3212 |
if (d->extended) { |
|
3213 |
d->state->clipEnabled = true; |
|
3214 |
d->extended->clip(path, op); |
|
3215 |
if (op == Qt::NoClip || op == Qt::ReplaceClip) |
|
3216 |
d->state->clipInfo.clear(); |
|
3217 |
d->state->clipInfo << QPainterClipInfo(path, op, d->state->matrix); |
|
3218 |
d->state->clipOperation = op; |
|
3219 |
return; |
|
3220 |
} |
|
3221 |
||
3222 |
d->state->clipPath = path; |
|
3223 |
d->state->clipOperation = op; |
|
3224 |
if (op == Qt::NoClip || op == Qt::ReplaceClip) |
|
3225 |
d->state->clipInfo.clear(); |
|
3226 |
d->state->clipInfo << QPainterClipInfo(path, op, d->state->matrix); |
|
3227 |
d->state->clipEnabled = true; |
|
3228 |
d->state->dirtyFlags |= QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipEnabled; |
|
3229 |
d->updateState(d->state); |
|
3230 |
} |
|
3231 |
||
3232 |
/*! |
|
3233 |
Draws the outline (strokes) the path \a path with the pen specified |
|
3234 |
by \a pen |
|
3235 |
||
3236 |
\sa fillPath(), {QPainter#Drawing}{Drawing} |
|
3237 |
*/ |
|
3238 |
void QPainter::strokePath(const QPainterPath &path, const QPen &pen) |
|
3239 |
{ |
|
3240 |
Q_D(QPainter); |
|
3241 |
||
3242 |
if (!d->engine) { |
|
3243 |
qWarning("QPainter::strokePath: Painter not active"); |
|
3244 |
return; |
|
3245 |
} |
|
3246 |
||
3247 |
if (path.isEmpty()) |
|
3248 |
return; |
|
3249 |
||
3250 |
if (d->extended) { |
|
3251 |
const QGradient *g = qpen_brush(pen).gradient(); |
|
3252 |
if (!g || g->coordinateMode() == QGradient::LogicalMode) { |
|
3253 |
d->extended->stroke(qtVectorPathForPath(path), pen); |
|
3254 |
return; |
|
3255 |
} |
|
3256 |
} |
|
3257 |
||
3258 |
QBrush oldBrush = d->state->brush; |
|
3259 |
QPen oldPen = d->state->pen; |
|
3260 |
||
3261 |
setPen(pen); |
|
3262 |
setBrush(Qt::NoBrush); |
|
3263 |
||
3264 |
drawPath(path); |
|
3265 |
||
3266 |
// Reset old state |
|
3267 |
setPen(oldPen); |
|
3268 |
setBrush(oldBrush); |
|
3269 |
} |
|
3270 |
||
3271 |
/*! |
|
3272 |
Fills the given \a path using the given \a brush. The outline is |
|
3273 |
not drawn. |
|
3274 |
||
3275 |
Alternatively, you can specify a QColor instead of a QBrush; the |
|
3276 |
QBrush constructor (taking a QColor argument) will automatically |
|
3277 |
create a solid pattern brush. |
|
3278 |
||
3279 |
\sa drawPath() |
|
3280 |
*/ |
|
3281 |
void QPainter::fillPath(const QPainterPath &path, const QBrush &brush) |
|
3282 |
{ |
|
3283 |
Q_D(QPainter); |
|
3284 |
||
3285 |
if (!d->engine) { |
|
3286 |
qWarning("QPainter::fillPath: Painter not active"); |
|
3287 |
return; |
|
3288 |
} |
|
3289 |
||
3290 |
if (path.isEmpty()) |
|
3291 |
return; |
|
3292 |
||
3293 |
if (d->extended) { |
|
3294 |
const QGradient *g = brush.gradient(); |
|
3295 |
if (!g || g->coordinateMode() == QGradient::LogicalMode) { |
|
3296 |
d->extended->fill(qtVectorPathForPath(path), brush); |
|
3297 |
return; |
|
3298 |
} |
|
3299 |
} |
|
3300 |
||
3301 |
QBrush oldBrush = d->state->brush; |
|
3302 |
QPen oldPen = d->state->pen; |
|
3303 |
||
3304 |
setPen(Qt::NoPen); |
|
3305 |
setBrush(brush); |
|
3306 |
||
3307 |
drawPath(path); |
|
3308 |
||
3309 |
// Reset old state |
|
3310 |
setPen(oldPen); |
|
3311 |
setBrush(oldBrush); |
|
3312 |
} |
|
3313 |
||
3314 |
/*! |
|
3315 |
Draws the given painter \a path using the current pen for outline |
|
3316 |
and the current brush for filling. |
|
3317 |
||
3318 |
\table 100% |
|
3319 |
\row |
|
3320 |
\o \inlineimage qpainter-path.png |
|
3321 |
\o |
|
3322 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 5 |
|
3323 |
\endtable |
|
3324 |
||
3325 |
\sa {painting/painterpaths}{the Painter Paths |
|
3326 |
example},{demos/deform}{the Vector Deformation demo} |
|
3327 |
*/ |
|
3328 |
void QPainter::drawPath(const QPainterPath &path) |
|
3329 |
{ |
|
3330 |
#ifdef QT_DEBUG_DRAW |
|
3331 |
QRectF pathBounds = path.boundingRect(); |
|
3332 |
if (qt_show_painter_debug_output) |
|
3333 |
printf("QPainter::drawPath(), size=%d, [%.2f,%.2f,%.2f,%.2f]\n", |
|
3334 |
path.elementCount(), |
|
3335 |
pathBounds.x(), pathBounds.y(), pathBounds.width(), pathBounds.height()); |
|
3336 |
#endif |
|
3337 |
||
3338 |
Q_D(QPainter); |
|
3339 |
||
3340 |
if (!d->engine) { |
|
3341 |
qWarning("QPainter::drawPath: Painter not active"); |
|
3342 |
return; |
|
3343 |
} |
|
3344 |
||
3345 |
if (d->extended) { |
|
3346 |
d->extended->drawPath(path); |
|
3347 |
return; |
|
3348 |
} |
|
3349 |
d->updateState(d->state); |
|
3350 |
||
3351 |
if (d->engine->hasFeature(QPaintEngine::PainterPaths) && d->state->emulationSpecifier == 0) { |
|
3352 |
d->engine->drawPath(path); |
|
3353 |
} else { |
|
3354 |
d->draw_helper(path); |
|
3355 |
} |
|
3356 |
} |
|
3357 |
||
3358 |
/*! |
|
3359 |
\fn void QPainter::drawLine(const QLineF &line) |
|
3360 |
||
3361 |
Draws a line defined by \a line. |
|
3362 |
||
3363 |
\table 100% |
|
3364 |
\row |
|
3365 |
\o \inlineimage qpainter-line.png |
|
3366 |
\o |
|
3367 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 6 |
|
3368 |
\endtable |
|
3369 |
||
3370 |
\sa drawLines(), drawPolyline(), {The Coordinate System} |
|
3371 |
*/ |
|
3372 |
||
3373 |
/*! |
|
3374 |
\fn void QPainter::drawLine(const QLine &line) |
|
3375 |
\overload |
|
3376 |
||
3377 |
Draws a line defined by \a line. |
|
3378 |
*/ |
|
3379 |
||
3380 |
/*! |
|
3381 |
\fn void QPainter::drawLine(const QPoint &p1, const QPoint &p2) |
|
3382 |
\overload |
|
3383 |
||
3384 |
Draws a line from \a p1 to \a p2. |
|
3385 |
*/ |
|
3386 |
||
3387 |
/*! |
|
3388 |
\fn void QPainter::drawLine(const QPointF &p1, const QPointF &p2) |
|
3389 |
\overload |
|
3390 |
||
3391 |
Draws a line from \a p1 to \a p2. |
|
3392 |
*/ |
|
3393 |
||
3394 |
/*! |
|
3395 |
\fn void QPainter::drawLine(int x1, int y1, int x2, int y2) |
|
3396 |
\overload |
|
3397 |
||
3398 |
Draws a line from (\a x1, \a y1) to (\a x2, \a y2) and sets the |
|
3399 |
current pen position to (\a x2, \a y2). |
|
3400 |
*/ |
|
3401 |
||
3402 |
/*! |
|
3403 |
\fn void QPainter::drawRect(const QRectF &rectangle) |
|
3404 |
||
3405 |
Draws the current \a rectangle with the current pen and brush. |
|
3406 |
||
3407 |
A filled rectangle has a size of \a{rectangle}.size(). A stroked |
|
3408 |
rectangle has a size of \a{rectangle}.size() plus the pen width. |
|
3409 |
||
3410 |
\table 100% |
|
3411 |
\row |
|
3412 |
\o \inlineimage qpainter-rectangle.png |
|
3413 |
\o |
|
3414 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 7 |
|
3415 |
\endtable |
|
3416 |
||
3417 |
\sa drawRects(), drawPolygon(), {The Coordinate System} |
|
3418 |
*/ |
|
3419 |
||
3420 |
/*! |
|
3421 |
\fn void QPainter::drawRect(const QRect &rectangle) |
|
3422 |
||
3423 |
\overload |
|
3424 |
||
3425 |
Draws the current \a rectangle with the current pen and brush. |
|
3426 |
*/ |
|
3427 |
||
3428 |
/*! |
|
3429 |
\fn void QPainter::drawRect(int x, int y, int width, int height) |
|
3430 |
||
3431 |
\overload |
|
3432 |
||
3433 |
Draws a rectangle with upper left corner at (\a{x}, \a{y}) and |
|
3434 |
with the given \a width and \a height. |
|
3435 |
*/ |
|
3436 |
||
3437 |
/*! |
|
3438 |
\fn void QPainter::drawRects(const QRectF *rectangles, int rectCount) |
|
3439 |
||
3440 |
Draws the first \a rectCount of the given \a rectangles using the |
|
3441 |
current pen and brush. |
|
3442 |
||
3443 |
\sa drawRect() |
|
3444 |
*/ |
|
3445 |
void QPainter::drawRects(const QRectF *rects, int rectCount) |
|
3446 |
{ |
|
3447 |
#ifdef QT_DEBUG_DRAW |
|
3448 |
if (qt_show_painter_debug_output) |
|
3449 |
printf("QPainter::drawRects(), count=%d\n", rectCount); |
|
3450 |
#endif |
|
3451 |
Q_D(QPainter); |
|
3452 |
||
3453 |
if (!d->engine) { |
|
3454 |
qWarning("QPainter::drawRects: Painter not active"); |
|
3455 |
return; |
|
3456 |
} |
|
3457 |
||
3458 |
if (rectCount <= 0) |
|
3459 |
return; |
|
3460 |
||
3461 |
if (d->extended) { |
|
3462 |
d->extended->drawRects(rects, rectCount); |
|
3463 |
return; |
|
3464 |
} |
|
3465 |
||
3466 |
d->updateState(d->state); |
|
3467 |
||
3468 |
if (!d->state->emulationSpecifier) { |
|
3469 |
d->engine->drawRects(rects, rectCount); |
|
3470 |
return; |
|
3471 |
} |
|
3472 |
||
3473 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
3474 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
3475 |
for (int i=0; i<rectCount; ++i) { |
|
3476 |
QRectF r(rects[i].x() + d->state->matrix.dx(), |
|
3477 |
rects[i].y() + d->state->matrix.dy(), |
|
3478 |
rects[i].width(), |
|
3479 |
rects[i].height()); |
|
3480 |
d->engine->drawRects(&r, 1); |
|
3481 |
} |
|
3482 |
} else { |
|
3483 |
if (d->state->brushNeedsResolving() || d->state->penNeedsResolving()) { |
|
3484 |
for (int i=0; i<rectCount; ++i) { |
|
3485 |
QPainterPath rectPath; |
|
3486 |
rectPath.addRect(rects[i]); |
|
3487 |
d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw); |
|
3488 |
} |
|
3489 |
} else { |
|
3490 |
QPainterPath rectPath; |
|
3491 |
for (int i=0; i<rectCount; ++i) |
|
3492 |
rectPath.addRect(rects[i]); |
|
3493 |
d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw); |
|
3494 |
} |
|
3495 |
} |
|
3496 |
} |
|
3497 |
||
3498 |
/*! |
|
3499 |
\fn void QPainter::drawRects(const QRect *rectangles, int rectCount) |
|
3500 |
\overload |
|
3501 |
||
3502 |
Draws the first \a rectCount of the given \a rectangles using the |
|
3503 |
current pen and brush. |
|
3504 |
*/ |
|
3505 |
void QPainter::drawRects(const QRect *rects, int rectCount) |
|
3506 |
{ |
|
3507 |
#ifdef QT_DEBUG_DRAW |
|
3508 |
if (qt_show_painter_debug_output) |
|
3509 |
printf("QPainter::drawRects(), count=%d\n", rectCount); |
|
3510 |
#endif |
|
3511 |
Q_D(QPainter); |
|
3512 |
||
3513 |
if (!d->engine) { |
|
3514 |
qWarning("QPainter::drawRects: Painter not active"); |
|
3515 |
return; |
|
3516 |
} |
|
3517 |
||
3518 |
if (rectCount <= 0) |
|
3519 |
return; |
|
3520 |
||
3521 |
if (d->extended) { |
|
3522 |
d->extended->drawRects(rects, rectCount); |
|
3523 |
return; |
|
3524 |
} |
|
3525 |
||
3526 |
d->updateState(d->state); |
|
3527 |
||
3528 |
if (!d->state->emulationSpecifier) { |
|
3529 |
d->engine->drawRects(rects, rectCount); |
|
3530 |
return; |
|
3531 |
} |
|
3532 |
||
3533 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
3534 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
3535 |
for (int i=0; i<rectCount; ++i) { |
|
3536 |
QRectF r(rects[i].x() + d->state->matrix.dx(), |
|
3537 |
rects[i].y() + d->state->matrix.dy(), |
|
3538 |
rects[i].width(), |
|
3539 |
rects[i].height()); |
|
3540 |
||
3541 |
d->engine->drawRects(&r, 1); |
|
3542 |
} |
|
3543 |
} else { |
|
3544 |
if (d->state->brushNeedsResolving() || d->state->penNeedsResolving()) { |
|
3545 |
for (int i=0; i<rectCount; ++i) { |
|
3546 |
QPainterPath rectPath; |
|
3547 |
rectPath.addRect(rects[i]); |
|
3548 |
d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw); |
|
3549 |
} |
|
3550 |
} else { |
|
3551 |
QPainterPath rectPath; |
|
3552 |
for (int i=0; i<rectCount; ++i) |
|
3553 |
rectPath.addRect(rects[i]); |
|
3554 |
||
3555 |
d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw); |
|
3556 |
} |
|
3557 |
} |
|
3558 |
} |
|
3559 |
||
3560 |
/*! |
|
3561 |
\fn void QPainter::drawRects(const QVector<QRectF> &rectangles) |
|
3562 |
\overload |
|
3563 |
||
3564 |
Draws the given \a rectangles using the current pen and brush. |
|
3565 |
*/ |
|
3566 |
||
3567 |
/*! |
|
3568 |
\fn void QPainter::drawRects(const QVector<QRect> &rectangles) |
|
3569 |
||
3570 |
\overload |
|
3571 |
||
3572 |
Draws the given \a rectangles using the current pen and brush. |
|
3573 |
*/ |
|
3574 |
||
3575 |
/*! |
|
3576 |
\fn void QPainter::drawPoint(const QPointF &position) |
|
3577 |
||
3578 |
Draws a single point at the given \a position using the current |
|
3579 |
pen's color. |
|
3580 |
||
3581 |
\sa {The Coordinate System} |
|
3582 |
*/ |
|
3583 |
||
3584 |
/*! |
|
3585 |
\fn void QPainter::drawPoint(const QPoint &position) |
|
3586 |
\overload |
|
3587 |
||
3588 |
Draws a single point at the given \a position using the current |
|
3589 |
pen's color. |
|
3590 |
*/ |
|
3591 |
||
3592 |
/*! \fn void QPainter::drawPoint(int x, int y) |
|
3593 |
||
3594 |
\overload |
|
3595 |
||
3596 |
Draws a single point at position (\a x, \a y). |
|
3597 |
*/ |
|
3598 |
||
3599 |
/*! |
|
3600 |
Draws the first \a pointCount points in the array \a points using |
|
3601 |
the current pen's color. |
|
3602 |
||
3603 |
\sa {The Coordinate System} |
|
3604 |
*/ |
|
3605 |
void QPainter::drawPoints(const QPointF *points, int pointCount) |
|
3606 |
{ |
|
3607 |
#ifdef QT_DEBUG_DRAW |
|
3608 |
if (qt_show_painter_debug_output) |
|
3609 |
printf("QPainter::drawPoints(), count=%d\n", pointCount); |
|
3610 |
#endif |
|
3611 |
Q_D(QPainter); |
|
3612 |
||
3613 |
if (!d->engine) { |
|
3614 |
qWarning("QPainter::drawPoints: Painter not active"); |
|
3615 |
return; |
|
3616 |
} |
|
3617 |
||
3618 |
if (pointCount <= 0) |
|
3619 |
return; |
|
3620 |
||
3621 |
if (d->extended) { |
|
3622 |
d->extended->drawPoints(points, pointCount); |
|
3623 |
return; |
|
3624 |
} |
|
3625 |
||
3626 |
d->updateState(d->state); |
|
3627 |
||
3628 |
if (!d->state->emulationSpecifier) { |
|
3629 |
d->engine->drawPoints(points, pointCount); |
|
3630 |
return; |
|
3631 |
} |
|
3632 |
||
3633 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
3634 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
3635 |
// ### use drawPoints function |
|
3636 |
for (int i=0; i<pointCount; ++i) { |
|
3637 |
QPointF pt(points[i].x() + d->state->matrix.dx(), |
|
3638 |
points[i].y() + d->state->matrix.dy()); |
|
3639 |
d->engine->drawPoints(&pt, 1); |
|
3640 |
} |
|
3641 |
} else { |
|
3642 |
QPen pen = d->state->pen; |
|
3643 |
bool flat_pen = pen.capStyle() == Qt::FlatCap; |
|
3644 |
if (flat_pen) { |
|
3645 |
save(); |
|
3646 |
pen.setCapStyle(Qt::SquareCap); |
|
3647 |
setPen(pen); |
|
3648 |
} |
|
3649 |
QPainterPath path; |
|
3650 |
for (int i=0; i<pointCount; ++i) { |
|
3651 |
path.moveTo(points[i].x(), points[i].y()); |
|
3652 |
path.lineTo(points[i].x() + 0.0001, points[i].y()); |
|
3653 |
} |
|
3654 |
d->draw_helper(path, QPainterPrivate::StrokeDraw); |
|
3655 |
if (flat_pen) |
|
3656 |
restore(); |
|
3657 |
} |
|
3658 |
} |
|
3659 |
||
3660 |
/*! |
|
3661 |
\overload |
|
3662 |
||
3663 |
Draws the first \a pointCount points in the array \a points using |
|
3664 |
the current pen's color. |
|
3665 |
*/ |
|
3666 |
||
3667 |
void QPainter::drawPoints(const QPoint *points, int pointCount) |
|
3668 |
{ |
|
3669 |
#ifdef QT_DEBUG_DRAW |
|
3670 |
if (qt_show_painter_debug_output) |
|
3671 |
printf("QPainter::drawPoints(), count=%d\n", pointCount); |
|
3672 |
#endif |
|
3673 |
Q_D(QPainter); |
|
3674 |
||
3675 |
if (!d->engine) { |
|
3676 |
qWarning("QPainter::drawPoints: Painter not active"); |
|
3677 |
return; |
|
3678 |
} |
|
3679 |
||
3680 |
if (pointCount <= 0) |
|
3681 |
return; |
|
3682 |
||
3683 |
if (d->extended) { |
|
3684 |
d->extended->drawPoints(points, pointCount); |
|
3685 |
return; |
|
3686 |
} |
|
3687 |
||
3688 |
d->updateState(d->state); |
|
3689 |
||
3690 |
if (!d->state->emulationSpecifier) { |
|
3691 |
d->engine->drawPoints(points, pointCount); |
|
3692 |
return; |
|
3693 |
} |
|
3694 |
||
3695 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
3696 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
3697 |
// ### use drawPoints function |
|
3698 |
for (int i=0; i<pointCount; ++i) { |
|
3699 |
QPointF pt(points[i].x() + d->state->matrix.dx(), |
|
3700 |
points[i].y() + d->state->matrix.dy()); |
|
3701 |
d->engine->drawPoints(&pt, 1); |
|
3702 |
} |
|
3703 |
} else { |
|
3704 |
QPen pen = d->state->pen; |
|
3705 |
bool flat_pen = (pen.capStyle() == Qt::FlatCap); |
|
3706 |
if (flat_pen) { |
|
3707 |
save(); |
|
3708 |
pen.setCapStyle(Qt::SquareCap); |
|
3709 |
setPen(pen); |
|
3710 |
} |
|
3711 |
QPainterPath path; |
|
3712 |
for (int i=0; i<pointCount; ++i) { |
|
3713 |
path.moveTo(points[i].x(), points[i].y()); |
|
3714 |
path.lineTo(points[i].x() + 0.0001, points[i].y()); |
|
3715 |
} |
|
3716 |
d->draw_helper(path, QPainterPrivate::StrokeDraw); |
|
3717 |
if (flat_pen) |
|
3718 |
restore(); |
|
3719 |
} |
|
3720 |
} |
|
3721 |
||
3722 |
/*! |
|
3723 |
\fn void QPainter::drawPoints(const QPolygonF &points) |
|
3724 |
||
3725 |
\overload |
|
3726 |
||
3727 |
Draws the points in the vector \a points. |
|
3728 |
*/ |
|
3729 |
||
3730 |
/*! |
|
3731 |
\fn void QPainter::drawPoints(const QPolygon &points) |
|
3732 |
||
3733 |
\overload |
|
3734 |
||
3735 |
Draws the points in the vector \a points. |
|
3736 |
*/ |
|
3737 |
||
3738 |
/*! |
|
3739 |
\fn void QPainter::drawPoints(const QPolygon &polygon, int index, |
|
3740 |
int count) |
|
3741 |
||
3742 |
\overload |
|
3743 |
\compat |
|
3744 |
||
3745 |
Draws \a count points in the vector \a polygon starting on \a index |
|
3746 |
using the current pen. |
|
3747 |
||
3748 |
Use drawPoints() combined with QPolygon::constData() instead. |
|
3749 |
||
3750 |
\oldcode |
|
3751 |
QPainter painter(this); |
|
3752 |
painter.drawPoints(polygon, index, count); |
|
3753 |
\newcode |
|
3754 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
3755 |
||
3756 |
QPainter painter(this); |
|
3757 |
painter.drawPoints(polygon.constData() + index, pointCount); |
|
3758 |
\endcode |
|
3759 |
*/ |
|
3760 |
||
3761 |
/*! |
|
3762 |
Sets the background mode of the painter to the given \a mode |
|
3763 |
||
3764 |
Qt::TransparentMode (the default) draws stippled lines and text |
|
3765 |
without setting the background pixels. Qt::OpaqueMode fills these |
|
3766 |
space with the current background color. |
|
3767 |
||
3768 |
Note that in order to draw a bitmap or pixmap transparently, you |
|
3769 |
must use QPixmap::setMask(). |
|
3770 |
||
3771 |
\sa backgroundMode(), setBackground(), |
|
3772 |
{QPainter#Settings}{Settings} |
|
3773 |
*/ |
|
3774 |
||
3775 |
void QPainter::setBackgroundMode(Qt::BGMode mode) |
|
3776 |
{ |
|
3777 |
#ifdef QT_DEBUG_DRAW |
|
3778 |
if (qt_show_painter_debug_output) |
|
3779 |
printf("QPainter::setBackgroundMode(), mode=%d\n", mode); |
|
3780 |
#endif |
|
3781 |
||
3782 |
Q_D(QPainter); |
|
3783 |
if (!d->engine) { |
|
3784 |
qWarning("QPainter::setBackgroundMode: Painter not active"); |
|
3785 |
return; |
|
3786 |
} |
|
3787 |
if (d->state->bgMode == mode) |
|
3788 |
return; |
|
3789 |
||
3790 |
d->state->bgMode = mode; |
|
3791 |
if (d->extended) { |
|
3792 |
d->checkEmulation(); |
|
3793 |
} else { |
|
3794 |
d->state->dirtyFlags |= QPaintEngine::DirtyBackgroundMode; |
|
3795 |
} |
|
3796 |
} |
|
3797 |
||
3798 |
/*! |
|
3799 |
Returns the current background mode. |
|
3800 |
||
3801 |
\sa setBackgroundMode(), {QPainter#Settings}{Settings} |
|
3802 |
*/ |
|
3803 |
Qt::BGMode QPainter::backgroundMode() const |
|
3804 |
{ |
|
3805 |
Q_D(const QPainter); |
|
3806 |
if (!d->engine) { |
|
3807 |
qWarning("QPainter::backgroundMode: Painter not active"); |
|
3808 |
return Qt::TransparentMode; |
|
3809 |
} |
|
3810 |
return d->state->bgMode; |
|
3811 |
} |
|
3812 |
||
3813 |
||
3814 |
/*! |
|
3815 |
\overload |
|
3816 |
||
3817 |
Sets the painter's pen to have style Qt::SolidLine, width 0 and the |
|
3818 |
specified \a color. |
|
3819 |
*/ |
|
3820 |
||
3821 |
void QPainter::setPen(const QColor &color) |
|
3822 |
{ |
|
3823 |
#ifdef QT_DEBUG_DRAW |
|
3824 |
if (qt_show_painter_debug_output) |
|
3825 |
printf("QPainter::setPen(), color=%04x\n", color.rgb()); |
|
3826 |
#endif |
|
3827 |
Q_D(QPainter); |
|
3828 |
if (!d->engine) { |
|
3829 |
qWarning("QPainter::setPen: Painter not active"); |
|
3830 |
return; |
|
3831 |
} |
|
3832 |
||
3833 |
if (d->state->pen.style() == Qt::SolidLine |
|
3834 |
&& d->state->pen.widthF() == 0 |
|
3835 |
&& d->state->pen.isSolid() |
|
3836 |
&& d->state->pen.color() == color) |
|
3837 |
return; |
|
3838 |
||
3839 |
QPen pen(color.isValid() ? color : QColor(Qt::black), 0, Qt::SolidLine); |
|
3840 |
||
3841 |
d->state->pen = pen; |
|
3842 |
if (d->extended) |
|
3843 |
d->extended->penChanged(); |
|
3844 |
else |
|
3845 |
d->state->dirtyFlags |= QPaintEngine::DirtyPen; |
|
3846 |
} |
|
3847 |
||
3848 |
/*! |
|
3849 |
Sets the painter's pen to be the given \a pen. |
|
3850 |
||
3851 |
The \a pen defines how to draw lines and outlines, and it also |
|
3852 |
defines the text color. |
|
3853 |
||
3854 |
\sa pen(), {QPainter#Settings}{Settings} |
|
3855 |
*/ |
|
3856 |
||
3857 |
void QPainter::setPen(const QPen &pen) |
|
3858 |
{ |
|
3859 |
||
3860 |
#ifdef QT_DEBUG_DRAW |
|
3861 |
if (qt_show_painter_debug_output) |
|
3862 |
printf("QPainter::setPen(), color=%04x, (brushStyle=%d) style=%d, cap=%d, join=%d\n", |
|
3863 |
pen.color().rgb(), pen.brush().style(), pen.style(), pen.capStyle(), pen.joinStyle()); |
|
3864 |
#endif |
|
3865 |
Q_D(QPainter); |
|
3866 |
if (!d->engine) { |
|
3867 |
qWarning("QPainter::setPen: Painter not active"); |
|
3868 |
return; |
|
3869 |
} |
|
3870 |
||
3871 |
if (d->state->pen == pen) |
|
3872 |
return; |
|
3873 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3874 |
d->state->pen = pen; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3875 |
|
0 | 3876 |
if (d->extended) { |
3877 |
d->checkEmulation(); |
|
3878 |
d->extended->penChanged(); |
|
3879 |
return; |
|
3880 |
} |
|
3881 |
||
3882 |
d->state->dirtyFlags |= QPaintEngine::DirtyPen; |
|
3883 |
} |
|
3884 |
||
3885 |
/*! |
|
3886 |
\overload |
|
3887 |
||
3888 |
Sets the painter's pen to have the given \a style, width 0 and |
|
3889 |
black color. |
|
3890 |
*/ |
|
3891 |
||
3892 |
void QPainter::setPen(Qt::PenStyle style) |
|
3893 |
{ |
|
3894 |
Q_D(QPainter); |
|
3895 |
if (!d->engine) { |
|
3896 |
qWarning("QPainter::setPen: Painter not active"); |
|
3897 |
return; |
|
3898 |
} |
|
3899 |
||
3900 |
if (d->state->pen.style() == style |
|
3901 |
&& (style == Qt::NoPen || (d->state->pen.widthF() == 0 |
|
3902 |
&& d->state->pen.isSolid() |
|
3903 |
&& d->state->pen.color() == QColor(Qt::black)))) |
|
3904 |
return; |
|
3905 |
||
3906 |
// QPen(Qt::NoPen) is to avoid creating QPenData, including its brush (from the color) |
|
3907 |
// Note that this works well as long as QPen(Qt::NoPen) returns a black, zero-width pen |
|
3908 |
d->state->pen = (style == Qt::NoPen) ? QPen(Qt::NoPen) : QPen(Qt::black, 0, style); |
|
3909 |
||
3910 |
if (d->extended) |
|
3911 |
d->extended->penChanged(); |
|
3912 |
else |
|
3913 |
d->state->dirtyFlags |= QPaintEngine::DirtyPen; |
|
3914 |
||
3915 |
} |
|
3916 |
||
3917 |
/*! |
|
3918 |
Returns the painter's current pen. |
|
3919 |
||
3920 |
\sa setPen(), {QPainter#Settings}{Settings} |
|
3921 |
*/ |
|
3922 |
||
3923 |
const QPen &QPainter::pen() const |
|
3924 |
{ |
|
3925 |
Q_D(const QPainter); |
|
3926 |
if (!d->engine) { |
|
3927 |
qWarning("QPainter::pen: Painter not active"); |
|
3928 |
return d->fakeState()->pen; |
|
3929 |
} |
|
3930 |
return d->state->pen; |
|
3931 |
} |
|
3932 |
||
3933 |
||
3934 |
/*! |
|
3935 |
Sets the painter's brush to the given \a brush. |
|
3936 |
||
3937 |
The painter's brush defines how shapes are filled. |
|
3938 |
||
3939 |
\sa brush(), {QPainter#Settings}{Settings} |
|
3940 |
*/ |
|
3941 |
||
3942 |
void QPainter::setBrush(const QBrush &brush) |
|
3943 |
{ |
|
3944 |
#ifdef QT_DEBUG_DRAW |
|
3945 |
if (qt_show_painter_debug_output) |
|
3946 |
printf("QPainter::setBrush(), color=%04x, style=%d\n", brush.color().rgb(), brush.style()); |
|
3947 |
#endif |
|
3948 |
Q_D(QPainter); |
|
3949 |
if (!d->engine) { |
|
3950 |
qWarning("QPainter::setBrush: Painter not active"); |
|
3951 |
return; |
|
3952 |
} |
|
3953 |
||
3954 |
if (d->state->brush.d == brush.d) |
|
3955 |
return; |
|
3956 |
||
3957 |
if (d->extended) { |
|
3958 |
d->state->brush = brush; |
|
3959 |
d->checkEmulation(); |
|
3960 |
d->extended->brushChanged(); |
|
3961 |
return; |
|
3962 |
} |
|
3963 |
||
3964 |
d->state->brush = brush; |
|
3965 |
d->state->dirtyFlags |= QPaintEngine::DirtyBrush; |
|
3966 |
} |
|
3967 |
||
3968 |
||
3969 |
/*! |
|
3970 |
\overload |
|
3971 |
||
3972 |
Sets the painter's brush to black color and the specified \a |
|
3973 |
style. |
|
3974 |
*/ |
|
3975 |
||
3976 |
void QPainter::setBrush(Qt::BrushStyle style) |
|
3977 |
{ |
|
3978 |
Q_D(QPainter); |
|
3979 |
if (!d->engine) { |
|
3980 |
qWarning("QPainter::setBrush: Painter not active"); |
|
3981 |
return; |
|
3982 |
} |
|
3983 |
if (d->state->brush.style() == style && |
|
3984 |
(style == Qt::NoBrush |
|
3985 |
|| (style == Qt::SolidPattern && d->state->brush.color() == QColor(0, 0, 0)))) |
|
3986 |
return; |
|
3987 |
d->state->brush = QBrush(Qt::black, style); |
|
3988 |
if (d->extended) |
|
3989 |
d->extended->brushChanged(); |
|
3990 |
else |
|
3991 |
d->state->dirtyFlags |= QPaintEngine::DirtyBrush; |
|
3992 |
} |
|
3993 |
||
3994 |
/*! |
|
3995 |
Returns the painter's current brush. |
|
3996 |
||
3997 |
\sa QPainter::setBrush(), {QPainter#Settings}{Settings} |
|
3998 |
*/ |
|
3999 |
||
4000 |
const QBrush &QPainter::brush() const |
|
4001 |
{ |
|
4002 |
Q_D(const QPainter); |
|
4003 |
if (!d->engine) { |
|
4004 |
qWarning("QPainter::brush: Painter not active"); |
|
4005 |
return d->fakeState()->brush; |
|
4006 |
} |
|
4007 |
return d->state->brush; |
|
4008 |
} |
|
4009 |
||
4010 |
/*! |
|
4011 |
\fn void QPainter::setBackground(const QBrush &brush) |
|
4012 |
||
4013 |
Sets the background brush of the painter to the given \a brush. |
|
4014 |
||
4015 |
The background brush is the brush that is filled in when drawing |
|
4016 |
opaque text, stippled lines and bitmaps. The background brush has |
|
4017 |
no effect in transparent background mode (which is the default). |
|
4018 |
||
4019 |
\sa background(), setBackgroundMode(), |
|
4020 |
{QPainter#Settings}{Settings} |
|
4021 |
*/ |
|
4022 |
||
4023 |
void QPainter::setBackground(const QBrush &bg) |
|
4024 |
{ |
|
4025 |
#ifdef QT_DEBUG_DRAW |
|
4026 |
if (qt_show_painter_debug_output) |
|
4027 |
printf("QPainter::setBackground(), color=%04x, style=%d\n", bg.color().rgb(), bg.style()); |
|
4028 |
#endif |
|
4029 |
||
4030 |
Q_D(QPainter); |
|
4031 |
if (!d->engine) { |
|
4032 |
qWarning("QPainter::setBackground: Painter not active"); |
|
4033 |
return; |
|
4034 |
} |
|
4035 |
d->state->bgBrush = bg; |
|
4036 |
if (!d->extended) |
|
4037 |
d->state->dirtyFlags |= QPaintEngine::DirtyBackground; |
|
4038 |
} |
|
4039 |
||
4040 |
/*! |
|
4041 |
Sets the painter's font to the given \a font. |
|
4042 |
||
4043 |
This font is used by subsequent drawText() functions. The text |
|
4044 |
color is the same as the pen color. |
|
4045 |
||
4046 |
If you set a font that isn't available, Qt finds a close match. |
|
4047 |
font() will return what you set using setFont() and fontInfo() returns the |
|
4048 |
font actually being used (which may be the same). |
|
4049 |
||
4050 |
\sa font(), drawText(), {QPainter#Settings}{Settings} |
|
4051 |
*/ |
|
4052 |
||
4053 |
void QPainter::setFont(const QFont &font) |
|
4054 |
{ |
|
4055 |
Q_D(QPainter); |
|
4056 |
||
4057 |
#ifdef QT_DEBUG_DRAW |
|
4058 |
if (qt_show_painter_debug_output) |
|
4059 |
printf("QPainter::setFont(), family=%s, pointSize=%d\n", font.family().toLatin1().constData(), font.pointSize()); |
|
4060 |
#endif |
|
4061 |
||
4062 |
if (!d->engine) { |
|
4063 |
qWarning("QPainter::setFont: Painter not active"); |
|
4064 |
return; |
|
4065 |
} |
|
4066 |
||
4067 |
d->state->font = QFont(font.resolve(d->state->deviceFont), device()); |
|
4068 |
if (!d->extended) |
|
4069 |
d->state->dirtyFlags |= QPaintEngine::DirtyFont; |
|
4070 |
} |
|
4071 |
||
4072 |
/*! |
|
4073 |
Returns the currently set font used for drawing text. |
|
4074 |
||
4075 |
\sa setFont(), drawText(), {QPainter#Settings}{Settings} |
|
4076 |
*/ |
|
4077 |
const QFont &QPainter::font() const |
|
4078 |
{ |
|
4079 |
Q_D(const QPainter); |
|
4080 |
if (!d->engine) { |
|
4081 |
qWarning("QPainter::font: Painter not active"); |
|
4082 |
return d->fakeState()->font; |
|
4083 |
} |
|
4084 |
return d->state->font; |
|
4085 |
} |
|
4086 |
||
4087 |
/*! |
|
4088 |
\since 4.4 |
|
4089 |
||
4090 |
Draws the given rectangle \a rect with rounded corners. |
|
4091 |
||
4092 |
The \a xRadius and \a yRadius arguments specify the radii |
|
4093 |
of the ellipses defining the corners of the rounded rectangle. |
|
4094 |
When \a mode is Qt::RelativeSize, \a xRadius and |
|
4095 |
\a yRadius are specified in percentage of half the rectangle's |
|
4096 |
width and height respectively, and should be in the range |
|
4097 |
0.0 to 100.0. |
|
4098 |
||
4099 |
A filled rectangle has a size of rect.size(). A stroked rectangle |
|
4100 |
has a size of rect.size() plus the pen width. |
|
4101 |
||
4102 |
\table 100% |
|
4103 |
\row |
|
4104 |
\o \inlineimage qpainter-roundrect.png |
|
4105 |
\o |
|
4106 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 8 |
|
4107 |
\endtable |
|
4108 |
||
4109 |
\sa drawRect(), QPen |
|
4110 |
*/ |
|
4111 |
void QPainter::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode) |
|
4112 |
{ |
|
4113 |
#ifdef QT_DEBUG_DRAW |
|
4114 |
if (qt_show_painter_debug_output) |
|
4115 |
printf("QPainter::drawRoundedRect(), [%.2f,%.2f,%.2f,%.2f]\n", rect.x(), rect.y(), rect.width(), rect.height()); |
|
4116 |
#endif |
|
4117 |
Q_D(QPainter); |
|
4118 |
||
4119 |
if (!d->engine) |
|
4120 |
return; |
|
4121 |
||
4122 |
if (xRadius <= 0 || yRadius <= 0) { // draw normal rectangle |
|
4123 |
drawRect(rect); |
|
4124 |
return; |
|
4125 |
} |
|
4126 |
||
4127 |
if (d->extended) { |
|
4128 |
d->extended->drawRoundedRect(rect, xRadius, yRadius, mode); |
|
4129 |
return; |
|
4130 |
} |
|
4131 |
||
4132 |
QPainterPath path; |
|
4133 |
path.addRoundedRect(rect, xRadius, yRadius, mode); |
|
4134 |
drawPath(path); |
|
4135 |
} |
|
4136 |
||
4137 |
/*! |
|
4138 |
\fn void QPainter::drawRoundedRect(const QRect &rect, qreal xRadius, qreal yRadius, |
|
4139 |
Qt::SizeMode mode = Qt::AbsoluteSize); |
|
4140 |
\since 4.4 |
|
4141 |
\overload |
|
4142 |
||
4143 |
Draws the given rectangle \a rect with rounded corners. |
|
4144 |
*/ |
|
4145 |
||
4146 |
/*! |
|
4147 |
\fn void QPainter::drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius, |
|
4148 |
Qt::SizeMode mode = Qt::AbsoluteSize); |
|
4149 |
\since 4.4 |
|
4150 |
\overload |
|
4151 |
||
4152 |
Draws the given rectangle \a x, \a y, \a w, \a h with rounded corners. |
|
4153 |
*/ |
|
4154 |
||
4155 |
/*! |
|
4156 |
\obsolete |
|
4157 |
||
4158 |
Draws a rectangle \a r with rounded corners. |
|
4159 |
||
4160 |
The \a xRnd and \a yRnd arguments specify how rounded the corners |
|
4161 |
should be. 0 is angled corners, 99 is maximum roundedness. |
|
4162 |
||
4163 |
A filled rectangle has a size of r.size(). A stroked rectangle |
|
4164 |
has a size of r.size() plus the pen width. |
|
4165 |
||
4166 |
\sa drawRoundedRect() |
|
4167 |
*/ |
|
4168 |
void QPainter::drawRoundRect(const QRectF &r, int xRnd, int yRnd) |
|
4169 |
{ |
|
4170 |
drawRoundedRect(r, xRnd, yRnd, Qt::RelativeSize); |
|
4171 |
} |
|
4172 |
||
4173 |
||
4174 |
/*! |
|
4175 |
\fn void QPainter::drawRoundRect(const QRect &r, int xRnd = 25, int yRnd = 25) |
|
4176 |
||
4177 |
\overload |
|
4178 |
\obsolete |
|
4179 |
||
4180 |
Draws the rectangle \a r with rounded corners. |
|
4181 |
*/ |
|
4182 |
||
4183 |
/*! |
|
4184 |
\obsolete |
|
4185 |
||
4186 |
\fn QPainter::drawRoundRect(int x, int y, int w, int h, int xRnd, int yRnd) |
|
4187 |
||
4188 |
\overload |
|
4189 |
||
4190 |
Draws the rectangle \a x, \a y, \a w, \a h with rounded corners. |
|
4191 |
*/ |
|
4192 |
||
4193 |
/*! |
|
4194 |
\fn void QPainter::drawEllipse(const QRectF &rectangle) |
|
4195 |
||
4196 |
Draws the ellipse defined by the given \a rectangle. |
|
4197 |
||
4198 |
A filled ellipse has a size of \a{rectangle}.\l |
|
4199 |
{QRect::size()}{size()}. A stroked ellipse has a size of |
|
4200 |
\a{rectangle}.\l {QRect::size()}{size()} plus the pen width. |
|
4201 |
||
4202 |
\table 100% |
|
4203 |
\row |
|
4204 |
\o \inlineimage qpainter-ellipse.png |
|
4205 |
\o |
|
4206 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 9 |
|
4207 |
\endtable |
|
4208 |
||
4209 |
\sa drawPie(), {The Coordinate System} |
|
4210 |
*/ |
|
4211 |
void QPainter::drawEllipse(const QRectF &r) |
|
4212 |
{ |
|
4213 |
#ifdef QT_DEBUG_DRAW |
|
4214 |
if (qt_show_painter_debug_output) |
|
4215 |
printf("QPainter::drawEllipse(), [%.2f,%.2f,%.2f,%.2f]\n", r.x(), r.y(), r.width(), r.height()); |
|
4216 |
#endif |
|
4217 |
Q_D(QPainter); |
|
4218 |
||
4219 |
if (!d->engine) |
|
4220 |
return; |
|
4221 |
||
4222 |
QRectF rect(r.normalized()); |
|
4223 |
if (rect.isEmpty()) |
|
4224 |
return; |
|
4225 |
||
4226 |
if (d->extended) { |
|
4227 |
d->extended->drawEllipse(rect); |
|
4228 |
return; |
|
4229 |
} |
|
4230 |
||
4231 |
d->updateState(d->state); |
|
4232 |
if (d->state->emulationSpecifier) { |
|
4233 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
4234 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
4235 |
rect.translate(QPointF(d->state->matrix.dx(), d->state->matrix.dy())); |
|
4236 |
} else { |
|
4237 |
QPainterPath path; |
|
4238 |
path.addEllipse(rect); |
|
4239 |
d->draw_helper(path, QPainterPrivate::StrokeAndFillDraw); |
|
4240 |
return; |
|
4241 |
} |
|
4242 |
} |
|
4243 |
||
4244 |
d->engine->drawEllipse(rect); |
|
4245 |
} |
|
4246 |
||
4247 |
/*! |
|
4248 |
\fn QPainter::drawEllipse(const QRect &rectangle) |
|
4249 |
||
4250 |
\overload |
|
4251 |
||
4252 |
Draws the ellipse defined by the given \a rectangle. |
|
4253 |
*/ |
|
4254 |
void QPainter::drawEllipse(const QRect &r) |
|
4255 |
{ |
|
4256 |
#ifdef QT_DEBUG_DRAW |
|
4257 |
if (qt_show_painter_debug_output) |
|
4258 |
printf("QPainter::drawEllipse(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height()); |
|
4259 |
#endif |
|
4260 |
Q_D(QPainter); |
|
4261 |
||
4262 |
if (!d->engine) |
|
4263 |
return; |
|
4264 |
||
4265 |
QRect rect(r.normalized()); |
|
4266 |
if (rect.isEmpty()) |
|
4267 |
return; |
|
4268 |
||
4269 |
if (d->extended) { |
|
4270 |
d->extended->drawEllipse(rect); |
|
4271 |
return; |
|
4272 |
} |
|
4273 |
||
4274 |
d->updateState(d->state); |
|
4275 |
||
4276 |
if (d->state->emulationSpecifier) { |
|
4277 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
4278 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
4279 |
rect.translate(QPoint(qRound(d->state->matrix.dx()), qRound(d->state->matrix.dy()))); |
|
4280 |
} else { |
|
4281 |
QPainterPath path; |
|
4282 |
path.addEllipse(rect); |
|
4283 |
d->draw_helper(path, QPainterPrivate::StrokeAndFillDraw); |
|
4284 |
return; |
|
4285 |
} |
|
4286 |
} |
|
4287 |
||
4288 |
d->engine->drawEllipse(rect); |
|
4289 |
} |
|
4290 |
||
4291 |
/*! |
|
4292 |
\fn QPainter::drawEllipse(int x, int y, int width, int height) |
|
4293 |
||
4294 |
\overload |
|
4295 |
||
4296 |
Draws the ellipse defined by the rectangle beginning at (\a{x}, |
|
4297 |
\a{y}) with the given \a width and \a height. |
|
4298 |
*/ |
|
4299 |
||
4300 |
/*! |
|
4301 |
\since 4.4 |
|
4302 |
||
4303 |
\fn QPainter::drawEllipse(const QPointF ¢er, qreal rx, qreal ry) |
|
4304 |
||
4305 |
\overload |
|
4306 |
||
4307 |
Draws the ellipse positioned at \a{center} with radii \a{rx} and \a{ry}. |
|
4308 |
*/ |
|
4309 |
||
4310 |
/*! |
|
4311 |
\since 4.4 |
|
4312 |
||
4313 |
\fn QPainter::drawEllipse(const QPoint ¢er, int rx, int ry) |
|
4314 |
||
4315 |
\overload |
|
4316 |
||
4317 |
Draws the ellipse positioned at \a{center} with radii \a{rx} and \a{ry}. |
|
4318 |
*/ |
|
4319 |
||
4320 |
/*! |
|
4321 |
\fn void QPainter::drawArc(const QRectF &rectangle, int startAngle, int spanAngle) |
|
4322 |
||
4323 |
Draws the arc defined by the given \a rectangle, \a startAngle and |
|
4324 |
\a spanAngle. |
|
4325 |
||
4326 |
The \a startAngle and \a spanAngle must be specified in 1/16th of |
|
4327 |
a degree, i.e. a full circle equals 5760 (16 * 360). Positive |
|
4328 |
values for the angles mean counter-clockwise while negative values |
|
4329 |
mean the clockwise direction. Zero degrees is at the 3 o'clock |
|
4330 |
position. |
|
4331 |
||
4332 |
\table 100% |
|
4333 |
\row |
|
4334 |
\o \inlineimage qpainter-arc.png |
|
4335 |
\o |
|
4336 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 10 |
|
4337 |
\endtable |
|
4338 |
||
4339 |
\sa drawPie(), drawChord(), {The Coordinate System} |
|
4340 |
*/ |
|
4341 |
||
4342 |
void QPainter::drawArc(const QRectF &r, int a, int alen) |
|
4343 |
{ |
|
4344 |
#ifdef QT_DEBUG_DRAW |
|
4345 |
if (qt_show_painter_debug_output) |
|
4346 |
printf("QPainter::drawArc(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n", |
|
4347 |
r.x(), r.y(), r.width(), r.height(), a/16, alen/16); |
|
4348 |
#endif |
|
4349 |
Q_D(QPainter); |
|
4350 |
||
4351 |
if (!d->engine) |
|
4352 |
return; |
|
4353 |
||
4354 |
QRectF rect = r.normalized(); |
|
4355 |
||
4356 |
QPainterPath path; |
|
4357 |
path.arcMoveTo(rect, a/16.0); |
|
4358 |
path.arcTo(rect, a/16.0, alen/16.0); |
|
4359 |
strokePath(path, d->state->pen); |
|
4360 |
} |
|
4361 |
||
4362 |
/*! \fn void QPainter::drawArc(const QRect &rectangle, int startAngle, |
|
4363 |
int spanAngle) |
|
4364 |
||
4365 |
\overload |
|
4366 |
||
4367 |
Draws the arc defined by the given \a rectangle, \a startAngle and |
|
4368 |
\a spanAngle. |
|
4369 |
*/ |
|
4370 |
||
4371 |
/*! |
|
4372 |
\fn void QPainter::drawArc(int x, int y, int width, int height, |
|
4373 |
int startAngle, int spanAngle) |
|
4374 |
||
4375 |
\overload |
|
4376 |
||
4377 |
Draws the arc defined by the rectangle beginning at (\a x, \a y) |
|
4378 |
with the specified \a width and \a height, and the given \a |
|
4379 |
startAngle and \a spanAngle. |
|
4380 |
*/ |
|
4381 |
||
4382 |
/*! |
|
4383 |
\fn void QPainter::drawPie(const QRectF &rectangle, int startAngle, int spanAngle) |
|
4384 |
||
4385 |
Draws a pie defined by the given \a rectangle, \a startAngle and |
|
4386 |
and \a spanAngle. |
|
4387 |
||
4388 |
The pie is filled with the current brush(). |
|
4389 |
||
4390 |
The startAngle and spanAngle must be specified in 1/16th of a |
|
4391 |
degree, i.e. a full circle equals 5760 (16 * 360). Positive values |
|
4392 |
for the angles mean counter-clockwise while negative values mean |
|
4393 |
the clockwise direction. Zero degrees is at the 3 o'clock |
|
4394 |
position. |
|
4395 |
||
4396 |
\table 100% |
|
4397 |
\row |
|
4398 |
\o \inlineimage qpainter-pie.png |
|
4399 |
\o |
|
4400 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 11 |
|
4401 |
\endtable |
|
4402 |
||
4403 |
\sa drawEllipse(), drawChord(), {The Coordinate System} |
|
4404 |
*/ |
|
4405 |
void QPainter::drawPie(const QRectF &r, int a, int alen) |
|
4406 |
{ |
|
4407 |
#ifdef QT_DEBUG_DRAW |
|
4408 |
if (qt_show_painter_debug_output) |
|
4409 |
printf("QPainter::drawPie(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n", |
|
4410 |
r.x(), r.y(), r.width(), r.height(), a/16, alen/16); |
|
4411 |
#endif |
|
4412 |
Q_D(QPainter); |
|
4413 |
||
4414 |
if (!d->engine) |
|
4415 |
return; |
|
4416 |
||
4417 |
if (a > (360*16)) { |
|
4418 |
a = a % (360*16); |
|
4419 |
} else if (a < 0) { |
|
4420 |
a = a % (360*16); |
|
4421 |
if (a < 0) a += (360*16); |
|
4422 |
} |
|
4423 |
||
4424 |
QRectF rect = r.normalized(); |
|
4425 |
||
4426 |
QPainterPath path; |
|
4427 |
path.moveTo(rect.center()); |
|
4428 |
path.arcTo(rect.x(), rect.y(), rect.width(), rect.height(), a/16.0, alen/16.0); |
|
4429 |
path.closeSubpath(); |
|
4430 |
drawPath(path); |
|
4431 |
||
4432 |
} |
|
4433 |
||
4434 |
/*! |
|
4435 |
\fn void QPainter::drawPie(const QRect &rectangle, int startAngle, int spanAngle) |
|
4436 |
\overload |
|
4437 |
||
4438 |
Draws a pie defined by the given \a rectangle, \a startAngle and |
|
4439 |
and \a spanAngle. |
|
4440 |
*/ |
|
4441 |
||
4442 |
/*! |
|
4443 |
\fn void QPainter::drawPie(int x, int y, int width, int height, int |
|
4444 |
startAngle, int spanAngle) |
|
4445 |
||
4446 |
\overload |
|
4447 |
||
4448 |
Draws the pie defined by the rectangle beginning at (\a x, \a y) with |
|
4449 |
the specified \a width and \a height, and the given \a startAngle and |
|
4450 |
\a spanAngle. |
|
4451 |
*/ |
|
4452 |
||
4453 |
/*! |
|
4454 |
\fn void QPainter::drawChord(const QRectF &rectangle, int startAngle, int spanAngle) |
|
4455 |
||
4456 |
Draws the chord defined by the given \a rectangle, \a startAngle and |
|
4457 |
\a spanAngle. The chord is filled with the current brush(). |
|
4458 |
||
4459 |
The startAngle and spanAngle must be specified in 1/16th of a |
|
4460 |
degree, i.e. a full circle equals 5760 (16 * 360). Positive values |
|
4461 |
for the angles mean counter-clockwise while negative values mean |
|
4462 |
the clockwise direction. Zero degrees is at the 3 o'clock |
|
4463 |
position. |
|
4464 |
||
4465 |
\table 100% |
|
4466 |
\row |
|
4467 |
\o \inlineimage qpainter-chord.png |
|
4468 |
\o |
|
4469 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 12 |
|
4470 |
\endtable |
|
4471 |
||
4472 |
\sa drawArc(), drawPie(), {The Coordinate System} |
|
4473 |
*/ |
|
4474 |
void QPainter::drawChord(const QRectF &r, int a, int alen) |
|
4475 |
{ |
|
4476 |
#ifdef QT_DEBUG_DRAW |
|
4477 |
if (qt_show_painter_debug_output) |
|
4478 |
printf("QPainter::drawChord(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n", |
|
4479 |
r.x(), r.y(), r.width(), r.height(), a/16, alen/16); |
|
4480 |
#endif |
|
4481 |
Q_D(QPainter); |
|
4482 |
||
4483 |
if (!d->engine) |
|
4484 |
return; |
|
4485 |
||
4486 |
QRectF rect = r.normalized(); |
|
4487 |
||
4488 |
QPainterPath path; |
|
4489 |
path.arcMoveTo(rect, a/16.0); |
|
4490 |
path.arcTo(rect, a/16.0, alen/16.0); |
|
4491 |
path.closeSubpath(); |
|
4492 |
drawPath(path); |
|
4493 |
} |
|
4494 |
/*! |
|
4495 |
\fn void QPainter::drawChord(const QRect &rectangle, int startAngle, int spanAngle) |
|
4496 |
||
4497 |
\overload |
|
4498 |
||
4499 |
Draws the chord defined by the given \a rectangle, \a startAngle and |
|
4500 |
\a spanAngle. |
|
4501 |
*/ |
|
4502 |
||
4503 |
/*! |
|
4504 |
\fn void QPainter::drawChord(int x, int y, int width, int height, int |
|
4505 |
startAngle, int spanAngle) |
|
4506 |
||
4507 |
\overload |
|
4508 |
||
4509 |
Draws the chord defined by the rectangle beginning at (\a x, \a y) |
|
4510 |
with the specified \a width and \a height, and the given \a |
|
4511 |
startAngle and \a spanAngle. |
|
4512 |
*/ |
|
4513 |
||
4514 |
#ifdef QT3_SUPPORT |
|
4515 |
/*! |
|
4516 |
\fn void QPainter::drawLineSegments(const QPolygon &polygon, int |
|
4517 |
index, int count) |
|
4518 |
||
4519 |
Draws \a count separate lines from points defined by the \a |
|
4520 |
polygon, starting at \a{polygon}\e{[index]} (\a index defaults to |
|
4521 |
0). If \a count is -1 (the default) all points until the end of |
|
4522 |
the array are used. |
|
4523 |
||
4524 |
Use drawLines() combined with QPolygon::constData() instead. |
|
4525 |
||
4526 |
\oldcode |
|
4527 |
QPainter painter(this); |
|
4528 |
painter.drawLineSegments(polygon, index, count); |
|
4529 |
\newcode |
|
4530 |
int lineCount = (count == -1) ? (polygon.size() - index) / 2 : count; |
|
4531 |
||
4532 |
QPainter painter(this); |
|
4533 |
painter.drawLines(polygon.constData() + index * 2, lineCount); |
|
4534 |
\endcode |
|
4535 |
*/ |
|
4536 |
||
4537 |
void QPainter::drawLineSegments(const QPolygon &a, int index, int nlines) |
|
4538 |
{ |
|
4539 |
#ifdef QT_DEBUG_DRAW |
|
4540 |
if (qt_show_painter_debug_output) |
|
4541 |
printf("QPainter::drawLineSegments(), count=%d\n", a.size()/2); |
|
4542 |
#endif |
|
4543 |
Q_D(QPainter); |
|
4544 |
||
4545 |
if (!d->engine) |
|
4546 |
return; |
|
4547 |
||
4548 |
if (nlines < 0) |
|
4549 |
nlines = a.size()/2 - index/2; |
|
4550 |
if (index + nlines*2 > (int)a.size()) |
|
4551 |
nlines = (a.size() - index)/2; |
|
4552 |
if (nlines < 1 || index < 0) |
|
4553 |
return; |
|
4554 |
||
4555 |
if (d->extended) { |
|
4556 |
// FALCON: Use QVectorPath |
|
4557 |
QVector<QLineF> lines; |
|
4558 |
for (int i=index; i<index + nlines*2; i+=2) |
|
4559 |
lines << QLineF(a.at(i), a.at(i+1)); |
|
4560 |
d->extended->drawLines(lines.data(), lines.size()); |
|
4561 |
return; |
|
4562 |
} |
|
4563 |
||
4564 |
d->updateState(d->state); |
|
4565 |
||
4566 |
QVector<QLineF> lines; |
|
4567 |
if (d->state->emulationSpecifier) { |
|
4568 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
4569 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
4570 |
QPointF offset(d->state->matrix.dx(), d->state->matrix.dy()); |
|
4571 |
for (int i=index; i<index + nlines*2; i+=2) |
|
4572 |
lines << QLineF(a.at(i) + offset, a.at(i+1) + offset); |
|
4573 |
} else { |
|
4574 |
QPainterPath linesPath; |
|
4575 |
for (int i=index; i<index + nlines*2; i+=2) { |
|
4576 |
linesPath.moveTo(a.at(i)); |
|
4577 |
linesPath.lineTo(a.at(i+1)); |
|
4578 |
} |
|
4579 |
d->draw_helper(linesPath, QPainterPrivate::StrokeDraw); |
|
4580 |
return; |
|
4581 |
} |
|
4582 |
} else { |
|
4583 |
for (int i=index; i<index + nlines*2; i+=2) |
|
4584 |
lines << QLineF(a.at(i), a.at(i+1)); |
|
4585 |
} |
|
4586 |
||
4587 |
d->engine->drawLines(lines.data(), lines.size()); |
|
4588 |
} |
|
4589 |
#endif // QT3_SUPPORT |
|
4590 |
||
4591 |
/*! |
|
4592 |
Draws the first \a lineCount lines in the array \a lines |
|
4593 |
using the current pen. |
|
4594 |
||
4595 |
\sa drawLine(), drawPolyline() |
|
4596 |
*/ |
|
4597 |
void QPainter::drawLines(const QLineF *lines, int lineCount) |
|
4598 |
{ |
|
4599 |
#ifdef QT_DEBUG_DRAW |
|
4600 |
if (qt_show_painter_debug_output) |
|
4601 |
printf("QPainter::drawLines(), line count=%d\n", lineCount); |
|
4602 |
#endif |
|
4603 |
||
4604 |
Q_D(QPainter); |
|
4605 |
||
4606 |
if (!d->engine || lineCount < 1) |
|
4607 |
return; |
|
4608 |
||
4609 |
if (d->extended) { |
|
4610 |
d->extended->drawLines(lines, lineCount); |
|
4611 |
return; |
|
4612 |
} |
|
4613 |
||
4614 |
d->updateState(d->state); |
|
4615 |
||
4616 |
uint lineEmulation = line_emulation(d->state->emulationSpecifier); |
|
4617 |
||
4618 |
if (lineEmulation) { |
|
4619 |
if (lineEmulation == QPaintEngine::PrimitiveTransform |
|
4620 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
4621 |
for (int i = 0; i < lineCount; ++i) { |
|
4622 |
QLineF line = lines[i]; |
|
4623 |
line.translate(d->state->matrix.dx(), d->state->matrix.dy()); |
|
4624 |
d->engine->drawLines(&line, 1); |
|
4625 |
} |
|
4626 |
} else { |
|
4627 |
QPainterPath linePath; |
|
4628 |
for (int i = 0; i < lineCount; ++i) { |
|
4629 |
linePath.moveTo(lines[i].p1()); |
|
4630 |
linePath.lineTo(lines[i].p2()); |
|
4631 |
} |
|
4632 |
d->draw_helper(linePath, QPainterPrivate::StrokeDraw); |
|
4633 |
} |
|
4634 |
return; |
|
4635 |
} |
|
4636 |
d->engine->drawLines(lines, lineCount); |
|
4637 |
} |
|
4638 |
||
4639 |
/*! |
|
4640 |
\fn void QPainter::drawLines(const QLine *lines, int lineCount) |
|
4641 |
\overload |
|
4642 |
||
4643 |
Draws the first \a lineCount lines in the array \a lines |
|
4644 |
using the current pen. |
|
4645 |
*/ |
|
4646 |
void QPainter::drawLines(const QLine *lines, int lineCount) |
|
4647 |
{ |
|
4648 |
#ifdef QT_DEBUG_DRAW |
|
4649 |
if (qt_show_painter_debug_output) |
|
4650 |
printf("QPainter::drawLine(), line count=%d\n", lineCount); |
|
4651 |
#endif |
|
4652 |
||
4653 |
Q_D(QPainter); |
|
4654 |
||
4655 |
if (!d->engine || lineCount < 1) |
|
4656 |
return; |
|
4657 |
||
4658 |
if (d->extended) { |
|
4659 |
d->extended->drawLines(lines, lineCount); |
|
4660 |
return; |
|
4661 |
} |
|
4662 |
||
4663 |
d->updateState(d->state); |
|
4664 |
||
4665 |
uint lineEmulation = line_emulation(d->state->emulationSpecifier); |
|
4666 |
||
4667 |
if (lineEmulation) { |
|
4668 |
if (lineEmulation == QPaintEngine::PrimitiveTransform |
|
4669 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
4670 |
for (int i = 0; i < lineCount; ++i) { |
|
4671 |
QLineF line = lines[i]; |
|
4672 |
line.translate(d->state->matrix.dx(), d->state->matrix.dy()); |
|
4673 |
d->engine->drawLines(&line, 1); |
|
4674 |
} |
|
4675 |
} else { |
|
4676 |
QPainterPath linePath; |
|
4677 |
for (int i = 0; i < lineCount; ++i) { |
|
4678 |
linePath.moveTo(lines[i].p1()); |
|
4679 |
linePath.lineTo(lines[i].p2()); |
|
4680 |
} |
|
4681 |
d->draw_helper(linePath, QPainterPrivate::StrokeDraw); |
|
4682 |
} |
|
4683 |
return; |
|
4684 |
} |
|
4685 |
d->engine->drawLines(lines, lineCount); |
|
4686 |
} |
|
4687 |
||
4688 |
/*! |
|
4689 |
\overload |
|
4690 |
||
4691 |
Draws the first \a lineCount lines in the array \a pointPairs |
|
4692 |
using the current pen. The lines are specified as pairs of points |
|
4693 |
so the number of entries in \a pointPairs must be at least \a |
|
4694 |
lineCount * 2. |
|
4695 |
*/ |
|
4696 |
void QPainter::drawLines(const QPointF *pointPairs, int lineCount) |
|
4697 |
{ |
|
4698 |
Q_ASSERT(sizeof(QLineF) == 2*sizeof(QPointF)); |
|
4699 |
||
4700 |
drawLines((QLineF*)pointPairs, lineCount); |
|
4701 |
} |
|
4702 |
||
4703 |
/*! |
|
4704 |
\overload |
|
4705 |
||
4706 |
Draws the first \a lineCount lines in the array \a pointPairs |
|
4707 |
using the current pen. |
|
4708 |
*/ |
|
4709 |
void QPainter::drawLines(const QPoint *pointPairs, int lineCount) |
|
4710 |
{ |
|
4711 |
Q_ASSERT(sizeof(QLine) == 2*sizeof(QPoint)); |
|
4712 |
||
4713 |
drawLines((QLine*)pointPairs, lineCount); |
|
4714 |
} |
|
4715 |
||
4716 |
||
4717 |
/*! |
|
4718 |
\fn void QPainter::drawLines(const QVector<QPointF> &pointPairs) |
|
4719 |
\overload |
|
4720 |
||
4721 |
Draws a line for each pair of points in the vector \a pointPairs |
|
4722 |
using the current pen. If there is an odd number of points in the |
|
4723 |
array, the last point will be ignored. |
|
4724 |
*/ |
|
4725 |
||
4726 |
/*! |
|
4727 |
\fn void QPainter::drawLines(const QVector<QPoint> &pointPairs) |
|
4728 |
\overload |
|
4729 |
||
4730 |
Draws a line for each pair of points in the vector \a pointPairs |
|
4731 |
using the current pen. |
|
4732 |
*/ |
|
4733 |
||
4734 |
/*! |
|
4735 |
\fn void QPainter::drawLines(const QVector<QLineF> &lines) |
|
4736 |
\overload |
|
4737 |
||
4738 |
Draws the set of lines defined by the list \a lines using the |
|
4739 |
current pen and brush. |
|
4740 |
*/ |
|
4741 |
||
4742 |
/*! |
|
4743 |
\fn void QPainter::drawLines(const QVector<QLine> &lines) |
|
4744 |
\overload |
|
4745 |
||
4746 |
Draws the set of lines defined by the list \a lines using the |
|
4747 |
current pen and brush. |
|
4748 |
*/ |
|
4749 |
||
4750 |
/*! |
|
4751 |
Draws the polyline defined by the first \a pointCount points in \a |
|
4752 |
points using the current pen. |
|
4753 |
||
4754 |
Note that unlike the drawPolygon() function the last point is \e |
|
4755 |
not connected to the first, neither is the polyline filled. |
|
4756 |
||
4757 |
\table 100% |
|
4758 |
\row |
|
4759 |
\o |
|
4760 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 13 |
|
4761 |
\endtable |
|
4762 |
||
4763 |
\sa drawLines(), drawPolygon(), {The Coordinate System} |
|
4764 |
*/ |
|
4765 |
void QPainter::drawPolyline(const QPointF *points, int pointCount) |
|
4766 |
{ |
|
4767 |
#ifdef QT_DEBUG_DRAW |
|
4768 |
if (qt_show_painter_debug_output) |
|
4769 |
printf("QPainter::drawPolyline(), count=%d\n", pointCount); |
|
4770 |
#endif |
|
4771 |
Q_D(QPainter); |
|
4772 |
||
4773 |
if (!d->engine || pointCount < 2) |
|
4774 |
return; |
|
4775 |
||
4776 |
if (d->extended) { |
|
4777 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::PolylineMode); |
|
4778 |
return; |
|
4779 |
} |
|
4780 |
||
4781 |
d->updateState(d->state); |
|
4782 |
||
4783 |
uint lineEmulation = line_emulation(d->state->emulationSpecifier); |
|
4784 |
||
4785 |
if (lineEmulation) { |
|
4786 |
// ### |
|
4787 |
// if (lineEmulation == QPaintEngine::PrimitiveTransform |
|
4788 |
// && d->state->matrix.type() == QTransform::TxTranslate) { |
|
4789 |
// } else { |
|
4790 |
QPainterPath polylinePath(points[0]); |
|
4791 |
for (int i=1; i<pointCount; ++i) |
|
4792 |
polylinePath.lineTo(points[i]); |
|
4793 |
d->draw_helper(polylinePath, QPainterPrivate::StrokeDraw); |
|
4794 |
// } |
|
4795 |
} else { |
|
4796 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::PolylineMode); |
|
4797 |
} |
|
4798 |
} |
|
4799 |
||
4800 |
/*! |
|
4801 |
\overload |
|
4802 |
||
4803 |
Draws the polyline defined by the first \a pointCount points in \a |
|
4804 |
points using the current pen. |
|
4805 |
*/ |
|
4806 |
void QPainter::drawPolyline(const QPoint *points, int pointCount) |
|
4807 |
{ |
|
4808 |
#ifdef QT_DEBUG_DRAW |
|
4809 |
if (qt_show_painter_debug_output) |
|
4810 |
printf("QPainter::drawPolyline(), count=%d\n", pointCount); |
|
4811 |
#endif |
|
4812 |
Q_D(QPainter); |
|
4813 |
||
4814 |
if (!d->engine || pointCount < 2) |
|
4815 |
return; |
|
4816 |
||
4817 |
if (d->extended) { |
|
4818 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::PolylineMode); |
|
4819 |
return; |
|
4820 |
} |
|
4821 |
||
4822 |
d->updateState(d->state); |
|
4823 |
||
4824 |
uint lineEmulation = line_emulation(d->state->emulationSpecifier); |
|
4825 |
||
4826 |
if (lineEmulation) { |
|
4827 |
// ### |
|
4828 |
// if (lineEmulation == QPaintEngine::PrimitiveTransform |
|
4829 |
// && d->state->matrix.type() == QTransform::TxTranslate) { |
|
4830 |
// } else { |
|
4831 |
QPainterPath polylinePath(points[0]); |
|
4832 |
for (int i=1; i<pointCount; ++i) |
|
4833 |
polylinePath.lineTo(points[i]); |
|
4834 |
d->draw_helper(polylinePath, QPainterPrivate::StrokeDraw); |
|
4835 |
// } |
|
4836 |
} else { |
|
4837 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::PolylineMode); |
|
4838 |
} |
|
4839 |
} |
|
4840 |
||
4841 |
/*! |
|
4842 |
\fn void QPainter::drawPolyline(const QPolygon &polygon, int index, int |
|
4843 |
count) |
|
4844 |
||
4845 |
\overload |
|
4846 |
\compat |
|
4847 |
||
4848 |
Draws the polyline defined by the \a count lines of the given \a |
|
4849 |
polygon starting at \a index (\a index defaults to 0). |
|
4850 |
||
4851 |
Use drawPolyline() combined with QPolygon::constData() instead. |
|
4852 |
||
4853 |
\oldcode |
|
4854 |
QPainter painter(this); |
|
4855 |
painter.drawPolyline(polygon, index, count); |
|
4856 |
\newcode |
|
4857 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
4858 |
||
4859 |
QPainter painter(this); |
|
4860 |
painter.drawPolyline(polygon.constData() + index, pointCount); |
|
4861 |
\endcode |
|
4862 |
*/ |
|
4863 |
||
4864 |
/*! |
|
4865 |
\fn void QPainter::drawPolyline(const QPolygonF &points) |
|
4866 |
||
4867 |
\overload |
|
4868 |
||
4869 |
Draws the polyline defined by the given \a points using the |
|
4870 |
current pen. |
|
4871 |
*/ |
|
4872 |
||
4873 |
/*! |
|
4874 |
\fn void QPainter::drawPolyline(const QPolygon &points) |
|
4875 |
||
4876 |
\overload |
|
4877 |
||
4878 |
Draws the polyline defined by the given \a points using the |
|
4879 |
current pen. |
|
4880 |
*/ |
|
4881 |
||
4882 |
/*! |
|
4883 |
Draws the polygon defined by the first \a pointCount points in the |
|
4884 |
array \a points using the current pen and brush. |
|
4885 |
||
4886 |
\table 100% |
|
4887 |
\row |
|
4888 |
\o \inlineimage qpainter-polygon.png |
|
4889 |
\o |
|
4890 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 14 |
|
4891 |
\endtable |
|
4892 |
||
4893 |
The first point is implicitly connected to the last point, and the |
|
4894 |
polygon is filled with the current brush(). |
|
4895 |
||
4896 |
If \a fillRule is Qt::WindingFill, the polygon is filled using the |
|
4897 |
winding fill algorithm. If \a fillRule is Qt::OddEvenFill, the |
|
4898 |
polygon is filled using the odd-even fill algorithm. See |
|
4899 |
\l{Qt::FillRule} for a more detailed description of these fill |
|
4900 |
rules. |
|
4901 |
||
4902 |
\sa drawConvexPolygon(), drawPolyline(), {The Coordinate System} |
|
4903 |
*/ |
|
4904 |
void QPainter::drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule) |
|
4905 |
{ |
|
4906 |
#ifdef QT_DEBUG_DRAW |
|
4907 |
if (qt_show_painter_debug_output) |
|
4908 |
printf("QPainter::drawPolygon(), count=%d\n", pointCount); |
|
4909 |
#endif |
|
4910 |
||
4911 |
Q_D(QPainter); |
|
4912 |
||
4913 |
if (!d->engine || pointCount < 2) |
|
4914 |
return; |
|
4915 |
||
4916 |
if (d->extended) { |
|
4917 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule)); |
|
4918 |
return; |
|
4919 |
} |
|
4920 |
||
4921 |
d->updateState(d->state); |
|
4922 |
||
4923 |
uint emulationSpecifier = d->state->emulationSpecifier; |
|
4924 |
||
4925 |
if (emulationSpecifier) { |
|
4926 |
QPainterPath polygonPath(points[0]); |
|
4927 |
for (int i=1; i<pointCount; ++i) |
|
4928 |
polygonPath.lineTo(points[i]); |
|
4929 |
polygonPath.closeSubpath(); |
|
4930 |
polygonPath.setFillRule(fillRule); |
|
4931 |
d->draw_helper(polygonPath); |
|
4932 |
return; |
|
4933 |
} |
|
4934 |
||
4935 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule)); |
|
4936 |
} |
|
4937 |
||
4938 |
/*! \overload |
|
4939 |
||
4940 |
Draws the polygon defined by the first \a pointCount points in the |
|
4941 |
array \a points. |
|
4942 |
*/ |
|
4943 |
void QPainter::drawPolygon(const QPoint *points, int pointCount, Qt::FillRule fillRule) |
|
4944 |
{ |
|
4945 |
#ifdef QT_DEBUG_DRAW |
|
4946 |
if (qt_show_painter_debug_output) |
|
4947 |
printf("QPainter::drawPolygon(), count=%d\n", pointCount); |
|
4948 |
#endif |
|
4949 |
||
4950 |
Q_D(QPainter); |
|
4951 |
||
4952 |
if (!d->engine || pointCount < 2) |
|
4953 |
return; |
|
4954 |
||
4955 |
if (d->extended) { |
|
4956 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule)); |
|
4957 |
return; |
|
4958 |
} |
|
4959 |
||
4960 |
d->updateState(d->state); |
|
4961 |
||
4962 |
uint emulationSpecifier = d->state->emulationSpecifier; |
|
4963 |
||
4964 |
if (emulationSpecifier) { |
|
4965 |
QPainterPath polygonPath(points[0]); |
|
4966 |
for (int i=1; i<pointCount; ++i) |
|
4967 |
polygonPath.lineTo(points[i]); |
|
4968 |
polygonPath.closeSubpath(); |
|
4969 |
polygonPath.setFillRule(fillRule); |
|
4970 |
d->draw_helper(polygonPath); |
|
4971 |
return; |
|
4972 |
} |
|
4973 |
||
4974 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule)); |
|
4975 |
} |
|
4976 |
||
4977 |
/*! \fn void QPainter::drawPolygon(const QPolygonF &polygon, bool winding, int index = 0, |
|
4978 |
int count = -1) |
|
4979 |
\compat |
|
4980 |
\overload |
|
4981 |
||
4982 |
Use drawPolygon() combined with QPolygonF::constData() instead. |
|
4983 |
||
4984 |
\oldcode |
|
4985 |
QPainter painter(this); |
|
4986 |
painter.drawPolygon(polygon, winding, index, count); |
|
4987 |
\newcode |
|
4988 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
4989 |
int fillRule = winding ? Qt::WindingFill : Qt::OddEvenFill; |
|
4990 |
||
4991 |
QPainter painter(this); |
|
4992 |
painter.drawPolygon( polygon.constData() + index, pointCount, fillRule); |
|
4993 |
\endcode |
|
4994 |
*/ |
|
4995 |
||
4996 |
/*! \fn void QPainter::drawPolygon(const QPolygon &polygon, bool winding, |
|
4997 |
int index = 0, int count = -1) |
|
4998 |
||
4999 |
\compat |
|
5000 |
\overload |
|
5001 |
||
5002 |
Use drawPolygon() combined with QPolygon::constData() instead. |
|
5003 |
||
5004 |
\oldcode |
|
5005 |
QPainter painter(this); |
|
5006 |
painter.drawPolygon(polygon, winding, index, count); |
|
5007 |
\newcode |
|
5008 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
5009 |
int fillRule = winding ? Qt::WindingFill : Qt::OddEvenFill; |
|
5010 |
||
5011 |
QPainter painter(this); |
|
5012 |
painter.drawPolygon( polygon.constData() + index, pointCount, fillRule); |
|
5013 |
\endcode |
|
5014 |
*/ |
|
5015 |
||
5016 |
/*! \fn void QPainter::drawPolygon(const QPolygonF &points, Qt::FillRule fillRule) |
|
5017 |
||
5018 |
\overload |
|
5019 |
||
5020 |
Draws the polygon defined by the given \a points using the fill |
|
5021 |
rule \a fillRule. |
|
5022 |
*/ |
|
5023 |
||
5024 |
/*! \fn void QPainter::drawPolygon(const QPolygon &points, Qt::FillRule fillRule) |
|
5025 |
||
5026 |
\overload |
|
5027 |
||
5028 |
Draws the polygon defined by the given \a points using the fill |
|
5029 |
rule \a fillRule. |
|
5030 |
*/ |
|
5031 |
||
5032 |
/*! |
|
5033 |
\fn void QPainter::drawConvexPolygon(const QPointF *points, int pointCount) |
|
5034 |
||
5035 |
Draws the convex polygon defined by the first \a pointCount points |
|
5036 |
in the array \a points using the current pen. |
|
5037 |
||
5038 |
\table 100% |
|
5039 |
\row |
|
5040 |
\o \inlineimage qpainter-polygon.png |
|
5041 |
\o |
|
5042 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 15 |
|
5043 |
\endtable |
|
5044 |
||
5045 |
The first point is implicitly connected to the last point, and the |
|
5046 |
polygon is filled with the current brush(). If the supplied |
|
5047 |
polygon is not convex, i.e. it contains at least one angle larger |
|
5048 |
than 180 degrees, the results are undefined. |
|
5049 |
||
5050 |
On some platforms (e.g. X11), the drawConvexPolygon() function can |
|
5051 |
be faster than the drawPolygon() function. |
|
5052 |
||
5053 |
\sa drawPolygon(), drawPolyline(), {The Coordinate System} |
|
5054 |
*/ |
|
5055 |
||
5056 |
/*! |
|
5057 |
\fn void QPainter::drawConvexPolygon(const QPoint *points, int pointCount) |
|
5058 |
\overload |
|
5059 |
||
5060 |
Draws the convex polygon defined by the first \a pointCount points |
|
5061 |
in the array \a points using the current pen. |
|
5062 |
*/ |
|
5063 |
||
5064 |
/*! |
|
5065 |
\fn void QPainter::drawConvexPolygon(const QPolygonF &polygon) |
|
5066 |
||
5067 |
\overload |
|
5068 |
||
5069 |
Draws the convex polygon defined by \a polygon using the current |
|
5070 |
pen and brush. |
|
5071 |
*/ |
|
5072 |
||
5073 |
/*! |
|
5074 |
\fn void QPainter::drawConvexPolygon(const QPolygon &polygon) |
|
5075 |
\overload |
|
5076 |
||
5077 |
Draws the convex polygon defined by \a polygon using the current |
|
5078 |
pen and brush. |
|
5079 |
*/ |
|
5080 |
||
5081 |
/*! |
|
5082 |
\fn void QPainter::drawConvexPolygon(const QPolygonF &polygon, int |
|
5083 |
index, int count) |
|
5084 |
||
5085 |
\compat |
|
5086 |
\overload |
|
5087 |
||
5088 |
Use drawConvexPolygon() combined with QPolygonF::constData() |
|
5089 |
instead. |
|
5090 |
||
5091 |
\oldcode |
|
5092 |
QPainter painter(this); |
|
5093 |
painter.drawConvexPolygon(polygon, index, count); |
|
5094 |
\newcode |
|
5095 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
5096 |
||
5097 |
QPainter painter(this); |
|
5098 |
painter.drawConvexPolygon(polygon.constData() + index, pointCount); |
|
5099 |
\endcode |
|
5100 |
*/ |
|
5101 |
||
5102 |
/*! |
|
5103 |
\fn void QPainter::drawConvexPolygon(const QPolygon &polygon, int |
|
5104 |
index, int count) |
|
5105 |
||
5106 |
\compat |
|
5107 |
\overload |
|
5108 |
||
5109 |
Use drawConvexPolygon() combined with QPolygon::constData() |
|
5110 |
instead. |
|
5111 |
||
5112 |
\oldcode |
|
5113 |
QPainter painter(this); |
|
5114 |
painter.drawConvexPolygon(polygon, index, count); |
|
5115 |
\newcode |
|
5116 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
5117 |
||
5118 |
QPainter painter(this); |
|
5119 |
painter.drawConvexPolygon(polygon.constData() + index, pointCount); |
|
5120 |
\endcode |
|
5121 |
*/ |
|
5122 |
||
5123 |
void QPainter::drawConvexPolygon(const QPoint *points, int pointCount) |
|
5124 |
{ |
|
5125 |
#ifdef QT_DEBUG_DRAW |
|
5126 |
if (qt_show_painter_debug_output) |
|
5127 |
printf("QPainter::drawConvexPolygon(), count=%d\n", pointCount); |
|
5128 |
#endif |
|
5129 |
||
5130 |
Q_D(QPainter); |
|
5131 |
||
5132 |
if (!d->engine || pointCount < 2) |
|
5133 |
return; |
|
5134 |
||
5135 |
if (d->extended) { |
|
5136 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::ConvexMode); |
|
5137 |
return; |
|
5138 |
} |
|
5139 |
||
5140 |
d->updateState(d->state); |
|
5141 |
||
5142 |
uint emulationSpecifier = d->state->emulationSpecifier; |
|
5143 |
||
5144 |
if (emulationSpecifier) { |
|
5145 |
QPainterPath polygonPath(points[0]); |
|
5146 |
for (int i=1; i<pointCount; ++i) |
|
5147 |
polygonPath.lineTo(points[i]); |
|
5148 |
polygonPath.closeSubpath(); |
|
5149 |
polygonPath.setFillRule(Qt::WindingFill); |
|
5150 |
d->draw_helper(polygonPath); |
|
5151 |
return; |
|
5152 |
} |
|
5153 |
||
5154 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::ConvexMode); |
|
5155 |
} |
|
5156 |
||
5157 |
void QPainter::drawConvexPolygon(const QPointF *points, int pointCount) |
|
5158 |
{ |
|
5159 |
#ifdef QT_DEBUG_DRAW |
|
5160 |
if (qt_show_painter_debug_output) |
|
5161 |
printf("QPainter::drawConvexPolygon(), count=%d\n", pointCount); |
|
5162 |
#endif |
|
5163 |
||
5164 |
Q_D(QPainter); |
|
5165 |
||
5166 |
if (!d->engine || pointCount < 2) |
|
5167 |
return; |
|
5168 |
||
5169 |
if (d->extended) { |
|
5170 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::ConvexMode); |
|
5171 |
return; |
|
5172 |
} |
|
5173 |
||
5174 |
d->updateState(d->state); |
|
5175 |
||
5176 |
uint emulationSpecifier = d->state->emulationSpecifier; |
|
5177 |
||
5178 |
if (emulationSpecifier) { |
|
5179 |
QPainterPath polygonPath(points[0]); |
|
5180 |
for (int i=1; i<pointCount; ++i) |
|
5181 |
polygonPath.lineTo(points[i]); |
|
5182 |
polygonPath.closeSubpath(); |
|
5183 |
polygonPath.setFillRule(Qt::WindingFill); |
|
5184 |
d->draw_helper(polygonPath); |
|
5185 |
return; |
|
5186 |
} |
|
5187 |
||
5188 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::ConvexMode); |
|
5189 |
} |
|
5190 |
||
5191 |
static inline QPointF roundInDeviceCoordinates(const QPointF &p, const QTransform &m) |
|
5192 |
{ |
|
5193 |
return m.inverted().map(QPointF(m.map(p).toPoint())); |
|
5194 |
} |
|
5195 |
||
5196 |
/*! |
|
5197 |
\fn void QPainter::drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source) |
|
5198 |
||
5199 |
Draws the rectangular portion \a source of the given \a pixmap |
|
5200 |
into the given \a target in the paint device. |
|
5201 |
||
5202 |
\note The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree. |
|
5203 |
||
5204 |
\table 100% |
|
5205 |
\row |
|
5206 |
\o |
|
5207 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 16 |
|
5208 |
\endtable |
|
5209 |
||
5210 |
If \a pixmap is a QBitmap it is drawn with the bits that are "set" |
|
5211 |
using the pens color. If backgroundMode is Qt::OpaqueMode, the |
|
5212 |
"unset" bits are drawn using the color of the background brush; if |
|
5213 |
backgroundMode is Qt::TransparentMode, the "unset" bits are |
|
5214 |
transparent. Drawing bitmaps with gradient or texture colors is |
|
5215 |
not supported. |
|
5216 |
||
5217 |
\sa drawImage() |
|
5218 |
*/ |
|
5219 |
void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm) |
|
5220 |
{ |
|
5221 |
#if defined QT_DEBUG_DRAW |
|
5222 |
if (qt_show_painter_debug_output) |
|
5223 |
printf("QPainter::drawPixmap(), p=[%.2f,%.2f], pix=[%d,%d]\n", |
|
5224 |
p.x(), p.y(), |
|
5225 |
pm.width(), pm.height()); |
|
5226 |
#endif |
|
5227 |
||
5228 |
Q_D(QPainter); |
|
5229 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5230 |
if (!d->engine || pm.isNull()) |
0 | 5231 |
return; |
5232 |
||
5233 |
#ifndef QT_NO_DEBUG |
|
5234 |
qt_painter_thread_test(d->device->devType(), "drawPixmap()"); |
|
5235 |
#endif |
|
5236 |
||
5237 |
if (d->extended) { |
|
5238 |
d->extended->drawPixmap(p, pm); |
|
5239 |
return; |
|
5240 |
} |
|
5241 |
||
5242 |
qreal x = p.x(); |
|
5243 |
qreal y = p.y(); |
|
5244 |
||
5245 |
int w = pm.width(); |
|
5246 |
int h = pm.height(); |
|
5247 |
||
5248 |
if (w <= 0) |
|
5249 |
return; |
|
5250 |
||
5251 |
// Emulate opaque background for bitmaps |
|
5252 |
if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap()) { |
|
5253 |
fillRect(QRectF(x, y, w, h), d->state->bgBrush.color()); |
|
5254 |
} |
|
5255 |
||
5256 |
d->updateState(d->state); |
|
5257 |
||
5258 |
if ((d->state->matrix.type() > QTransform::TxTranslate |
|
5259 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) |
|
5260 |
|| (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform)) |
|
5261 |
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) |
|
5262 |
{ |
|
5263 |
save(); |
|
5264 |
// If there is no rotation involved we have to make sure we use the |
|
5265 |
// antialiased and not the aliased coordinate system by rounding the coordinates. |
|
5266 |
if (d->state->matrix.type() <= QTransform::TxScale) { |
|
5267 |
const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); |
|
5268 |
x = p.x(); |
|
5269 |
y = p.y(); |
|
5270 |
} |
|
5271 |
translate(x, y); |
|
5272 |
setBackgroundMode(Qt::TransparentMode); |
|
5273 |
setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); |
|
5274 |
QBrush brush(d->state->pen.color(), pm); |
|
5275 |
setBrush(brush); |
|
5276 |
setPen(Qt::NoPen); |
|
5277 |
setBrushOrigin(QPointF(0, 0)); |
|
5278 |
||
5279 |
drawRect(pm.rect()); |
|
5280 |
restore(); |
|
5281 |
} else { |
|
5282 |
if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) { |
|
5283 |
x += d->state->matrix.dx(); |
|
5284 |
y += d->state->matrix.dy(); |
|
5285 |
} |
|
5286 |
d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(0, 0, w, h)); |
|
5287 |
} |
|
5288 |
} |
|
5289 |
||
5290 |
void QPainter::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) |
|
5291 |
{ |
|
5292 |
#if defined QT_DEBUG_DRAW |
|
5293 |
if (qt_show_painter_debug_output) |
|
5294 |
printf("QPainter::drawPixmap(), target=[%.2f,%.2f,%.2f,%.2f], pix=[%d,%d], source=[%.2f,%.2f,%.2f,%.2f]\n", |
|
5295 |
r.x(), r.y(), r.width(), r.height(), |
|
5296 |
pm.width(), pm.height(), |
|
5297 |
sr.x(), sr.y(), sr.width(), sr.height()); |
|
5298 |
#endif |
|
5299 |
||
5300 |
Q_D(QPainter); |
|
5301 |
if (!d->engine || pm.isNull()) |
|
5302 |
return; |
|
5303 |
#ifndef QT_NO_DEBUG |
|
5304 |
qt_painter_thread_test(d->device->devType(), "drawPixmap()"); |
|
5305 |
#endif |
|
5306 |
||
5307 |
qreal x = r.x(); |
|
5308 |
qreal y = r.y(); |
|
5309 |
qreal w = r.width(); |
|
5310 |
qreal h = r.height(); |
|
5311 |
qreal sx = sr.x(); |
|
5312 |
qreal sy = sr.y(); |
|
5313 |
qreal sw = sr.width(); |
|
5314 |
qreal sh = sr.height(); |
|
5315 |
||
5316 |
// Sanity-check clipping |
|
5317 |
if (sw <= 0) |
|
5318 |
sw = pm.width() - sx; |
|
5319 |
||
5320 |
if (sh <= 0) |
|
5321 |
sh = pm.height() - sy; |
|
5322 |
||
5323 |
if (w < 0) |
|
5324 |
w = sw; |
|
5325 |
if (h < 0) |
|
5326 |
h = sh; |
|
5327 |
||
5328 |
if (sx < 0) { |
|
5329 |
qreal w_ratio = sx * w/sw; |
|
5330 |
x -= w_ratio; |
|
5331 |
w += w_ratio; |
|
5332 |
sw += sx; |
|
5333 |
sx = 0; |
|
5334 |
} |
|
5335 |
||
5336 |
if (sy < 0) { |
|
5337 |
qreal h_ratio = sy * h/sh; |
|
5338 |
y -= h_ratio; |
|
5339 |
h += h_ratio; |
|
5340 |
sh += sy; |
|
5341 |
sy = 0; |
|
5342 |
} |
|
5343 |
||
5344 |
if (sw + sx > pm.width()) { |
|
5345 |
qreal delta = sw - (pm.width() - sx); |
|
5346 |
qreal w_ratio = delta * w/sw; |
|
5347 |
sw -= delta; |
|
5348 |
w -= w_ratio; |
|
5349 |
} |
|
5350 |
||
5351 |
if (sh + sy > pm.height()) { |
|
5352 |
qreal delta = sh - (pm.height() - sy); |
|
5353 |
qreal h_ratio = delta * h/sh; |
|
5354 |
sh -= delta; |
|
5355 |
h -= h_ratio; |
|
5356 |
} |
|
5357 |
||
5358 |
if (w == 0 || h == 0 || sw <= 0 || sh <= 0) |
|
5359 |
return; |
|
5360 |
||
5361 |
if (d->extended) { |
|
5362 |
d->extended->drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh)); |
|
5363 |
return; |
|
5364 |
} |
|
5365 |
||
5366 |
// Emulate opaque background for bitmaps |
|
5367 |
if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap()) |
|
5368 |
fillRect(QRectF(x, y, w, h), d->state->bgBrush.color()); |
|
5369 |
||
5370 |
d->updateState(d->state); |
|
5371 |
||
5372 |
if ((d->state->matrix.type() > QTransform::TxTranslate |
|
5373 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) |
|
5374 |
|| (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform)) |
|
5375 |
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)) |
|
5376 |
|| ((sw != w || sh != h) && !d->engine->hasFeature(QPaintEngine::PixmapTransform))) |
|
5377 |
{ |
|
5378 |
save(); |
|
5379 |
// If there is no rotation involved we have to make sure we use the |
|
5380 |
// antialiased and not the aliased coordinate system by rounding the coordinates. |
|
5381 |
if (d->state->matrix.type() <= QTransform::TxScale) { |
|
5382 |
const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); |
|
5383 |
x = p.x(); |
|
5384 |
y = p.y(); |
|
5385 |
} |
|
5386 |
||
5387 |
if (d->state->matrix.type() <= QTransform::TxTranslate && sw == w && sh == h) { |
|
5388 |
sx = qRound(sx); |
|
5389 |
sy = qRound(sy); |
|
5390 |
sw = qRound(sw); |
|
5391 |
sh = qRound(sh); |
|
5392 |
} |
|
5393 |
||
5394 |
translate(x, y); |
|
5395 |
scale(w / sw, h / sh); |
|
5396 |
setBackgroundMode(Qt::TransparentMode); |
|
5397 |
setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); |
|
5398 |
QBrush brush(d->state->pen.color(), pm); |
|
5399 |
setBrush(brush); |
|
5400 |
setPen(Qt::NoPen); |
|
5401 |
setBrushOrigin(QPointF(-sx, -sy)); |
|
5402 |
||
5403 |
drawRect(QRectF(0, 0, sw, sh)); |
|
5404 |
restore(); |
|
5405 |
} else { |
|
5406 |
if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) { |
|
5407 |
x += d->state->matrix.dx(); |
|
5408 |
y += d->state->matrix.dy(); |
|
5409 |
} |
|
5410 |
d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh)); |
|
5411 |
} |
|
5412 |
} |
|
5413 |
||
5414 |
||
5415 |
/*! |
|
5416 |
\fn void QPainter::drawPixmap(const QRect &target, const QPixmap &pixmap, |
|
5417 |
const QRect &source) |
|
5418 |
\overload |
|
5419 |
||
5420 |
Draws the rectangular portion \a source of the given \a pixmap |
|
5421 |
into the given \a target in the paint device. |
|
5422 |
||
5423 |
\note The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree. |
|
5424 |
*/ |
|
5425 |
||
5426 |
/*! |
|
5427 |
\fn void QPainter::drawPixmap(const QPointF &point, const QPixmap &pixmap, |
|
5428 |
const QRectF &source) |
|
5429 |
\overload |
|
5430 |
||
5431 |
Draws the rectangular portion \a source of the given \a pixmap |
|
5432 |
with its origin at the given \a point. |
|
5433 |
*/ |
|
5434 |
||
5435 |
/*! |
|
5436 |
\fn void QPainter::drawPixmap(const QPoint &point, const QPixmap &pixmap, |
|
5437 |
const QRect &source) |
|
5438 |
||
5439 |
\overload |
|
5440 |
||
5441 |
Draws the rectangular portion \a source of the given \a pixmap |
|
5442 |
with its origin at the given \a point. |
|
5443 |
*/ |
|
5444 |
||
5445 |
/*! |
|
5446 |
\fn void QPainter::drawPixmap(const QPointF &point, const QPixmap &pixmap) |
|
5447 |
\overload |
|
5448 |
||
5449 |
Draws the given \a pixmap with its origin at the given \a point. |
|
5450 |
*/ |
|
5451 |
||
5452 |
/*! |
|
5453 |
\fn void QPainter::drawPixmap(const QPoint &point, const QPixmap &pixmap) |
|
5454 |
\overload |
|
5455 |
||
5456 |
Draws the given \a pixmap with its origin at the given \a point. |
|
5457 |
*/ |
|
5458 |
||
5459 |
/*! |
|
5460 |
\fn void QPainter::drawPixmap(int x, int y, const QPixmap &pixmap) |
|
5461 |
||
5462 |
\overload |
|
5463 |
||
5464 |
Draws the given \a pixmap at position (\a{x}, \a{y}). |
|
5465 |
*/ |
|
5466 |
||
5467 |
/*! |
|
5468 |
\fn void QPainter::drawPixmap(const QRect &rectangle, const QPixmap &pixmap) |
|
5469 |
\overload |
|
5470 |
||
5471 |
Draws the given \a pixmap into the given \a rectangle. |
|
5472 |
||
5473 |
\note The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree. |
|
5474 |
*/ |
|
5475 |
||
5476 |
/*! |
|
5477 |
\fn void QPainter::drawPixmap(int x, int y, int width, int height, |
|
5478 |
const QPixmap &pixmap) |
|
5479 |
||
5480 |
\overload |
|
5481 |
||
5482 |
Draws the \a pixmap into the rectangle at position (\a{x}, \a{y}) |
|
5483 |
with the given \a width and \a height. |
|
5484 |
*/ |
|
5485 |
||
5486 |
/*! |
|
5487 |
\fn void QPainter::drawPixmap(int x, int y, int w, int h, const QPixmap &pixmap, |
|
5488 |
int sx, int sy, int sw, int sh) |
|
5489 |
||
5490 |
\overload |
|
5491 |
||
5492 |
Draws the rectangular portion with the origin (\a{sx}, \a{sy}), |
|
5493 |
width \a sw and height \a sh, of the given \a pixmap , at the |
|
5494 |
point (\a{x}, \a{y}), with a width of \a w and a height of \a h. |
|
5495 |
If sw or sh are equal to zero the width/height of the pixmap |
|
5496 |
is used and adjusted by the offset sx/sy; |
|
5497 |
*/ |
|
5498 |
||
5499 |
/*! |
|
5500 |
\fn void QPainter::drawPixmap(int x, int y, const QPixmap &pixmap, |
|
5501 |
int sx, int sy, int sw, int sh) |
|
5502 |
||
5503 |
\overload |
|
5504 |
||
5505 |
Draws a pixmap at (\a{x}, \a{y}) by copying a part of the given \a |
|
5506 |
pixmap into the paint device. |
|
5507 |
||
5508 |
(\a{x}, \a{y}) specifies the top-left point in the paint device that is |
|
5509 |
to be drawn onto. (\a{sx}, \a{sy}) specifies the top-left point in \a |
|
5510 |
pixmap that is to be drawn. The default is (0, 0). |
|
5511 |
||
5512 |
(\a{sw}, \a{sh}) specifies the size of the pixmap that is to be drawn. |
|
5513 |
The default, (0, 0) (and negative) means all the way to the |
|
5514 |
bottom-right of the pixmap. |
|
5515 |
*/ |
|
5516 |
||
5517 |
void QPainter::drawImage(const QPointF &p, const QImage &image) |
|
5518 |
{ |
|
5519 |
Q_D(QPainter); |
|
5520 |
||
5521 |
if (!d->engine || image.isNull()) |
|
5522 |
return; |
|
5523 |
||
5524 |
if (d->extended) { |
|
5525 |
d->extended->drawImage(p, image); |
|
5526 |
return; |
|
5527 |
} |
|
5528 |
||
5529 |
qreal x = p.x(); |
|
5530 |
qreal y = p.y(); |
|
5531 |
||
5532 |
int w = image.width(); |
|
5533 |
int h = image.height(); |
|
5534 |
||
5535 |
d->updateState(d->state); |
|
5536 |
||
5537 |
if (((d->state->matrix.type() > QTransform::TxTranslate) |
|
5538 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) |
|
5539 |
|| (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform)) |
|
5540 |
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) |
|
5541 |
{ |
|
5542 |
save(); |
|
5543 |
// If there is no rotation involved we have to make sure we use the |
|
5544 |
// antialiased and not the aliased coordinate system by rounding the coordinates. |
|
5545 |
if (d->state->matrix.type() <= QTransform::TxScale) { |
|
5546 |
const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); |
|
5547 |
x = p.x(); |
|
5548 |
y = p.y(); |
|
5549 |
} |
|
5550 |
translate(x, y); |
|
5551 |
setBackgroundMode(Qt::TransparentMode); |
|
5552 |
setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); |
|
5553 |
QBrush brush(image); |
|
5554 |
setBrush(brush); |
|
5555 |
setPen(Qt::NoPen); |
|
5556 |
setBrushOrigin(QPointF(0, 0)); |
|
5557 |
||
5558 |
drawRect(image.rect()); |
|
5559 |
restore(); |
|
5560 |
return; |
|
5561 |
} |
|
5562 |
||
5563 |
if (d->state->matrix.type() == QTransform::TxTranslate |
|
5564 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) { |
|
5565 |
x += d->state->matrix.dx(); |
|
5566 |
y += d->state->matrix.dy(); |
|
5567 |
} |
|
5568 |
||
5569 |
d->engine->drawImage(QRectF(x, y, w, h), image, QRectF(0, 0, w, h), Qt::AutoColor); |
|
5570 |
} |
|
5571 |
||
5572 |
void QPainter::drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, |
|
5573 |
Qt::ImageConversionFlags flags) |
|
5574 |
{ |
|
5575 |
Q_D(QPainter); |
|
5576 |
||
5577 |
if (!d->engine || image.isNull()) |
|
5578 |
return; |
|
5579 |
||
5580 |
qreal x = targetRect.x(); |
|
5581 |
qreal y = targetRect.y(); |
|
5582 |
qreal w = targetRect.width(); |
|
5583 |
qreal h = targetRect.height(); |
|
5584 |
qreal sx = sourceRect.x(); |
|
5585 |
qreal sy = sourceRect.y(); |
|
5586 |
qreal sw = sourceRect.width(); |
|
5587 |
qreal sh = sourceRect.height(); |
|
5588 |
||
5589 |
// Sanity-check clipping |
|
5590 |
if (sw <= 0) |
|
5591 |
sw = image.width() - sx; |
|
5592 |
||
5593 |
if (sh <= 0) |
|
5594 |
sh = image.height() - sy; |
|
5595 |
||
5596 |
if (w < 0) |
|
5597 |
w = sw; |
|
5598 |
if (h < 0) |
|
5599 |
h = sh; |
|
5600 |
||
5601 |
if (sx < 0) { |
|
5602 |
qreal w_ratio = sx * w/sw; |
|
5603 |
x -= w_ratio; |
|
5604 |
w += w_ratio; |
|
5605 |
sw += sx; |
|
5606 |
sx = 0; |
|
5607 |
} |
|
5608 |
||
5609 |
if (sy < 0) { |
|
5610 |
qreal h_ratio = sy * h/sh; |
|
5611 |
y -= h_ratio; |
|
5612 |
h += h_ratio; |
|
5613 |
sh += sy; |
|
5614 |
sy = 0; |
|
5615 |
} |
|
5616 |
||
5617 |
if (sw + sx > image.width()) { |
|
5618 |
qreal delta = sw - (image.width() - sx); |
|
5619 |
qreal w_ratio = delta * w/sw; |
|
5620 |
sw -= delta; |
|
5621 |
w -= w_ratio; |
|
5622 |
} |
|
5623 |
||
5624 |
if (sh + sy > image.height()) { |
|
5625 |
qreal delta = sh - (image.height() - sy); |
|
5626 |
qreal h_ratio = delta * h/sh; |
|
5627 |
sh -= delta; |
|
5628 |
h -= h_ratio; |
|
5629 |
} |
|
5630 |
||
5631 |
if (w == 0 || h == 0 || sw <= 0 || sh <= 0) |
|
5632 |
return; |
|
5633 |
||
5634 |
if (d->extended) { |
|
5635 |
d->extended->drawImage(QRectF(x, y, w, h), image, QRectF(sx, sy, sw, sh), flags); |
|
5636 |
return; |
|
5637 |
} |
|
5638 |
||
5639 |
d->updateState(d->state); |
|
5640 |
||
5641 |
if (((d->state->matrix.type() > QTransform::TxTranslate || (sw != w || sh != h)) |
|
5642 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) |
|
5643 |
|| (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform)) |
|
5644 |
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) |
|
5645 |
{ |
|
5646 |
save(); |
|
5647 |
// If there is no rotation involved we have to make sure we use the |
|
5648 |
// antialiased and not the aliased coordinate system by rounding the coordinates. |
|
5649 |
if (d->state->matrix.type() <= QTransform::TxScale) { |
|
5650 |
const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); |
|
5651 |
x = p.x(); |
|
5652 |
y = p.y(); |
|
5653 |
} |
|
5654 |
||
5655 |
if (d->state->matrix.type() <= QTransform::TxTranslate && sw == w && sh == h) { |
|
5656 |
sx = qRound(sx); |
|
5657 |
sy = qRound(sy); |
|
5658 |
sw = qRound(sw); |
|
5659 |
sh = qRound(sh); |
|
5660 |
} |
|
5661 |
translate(x, y); |
|
5662 |
scale(w / sw, h / sh); |
|
5663 |
setBackgroundMode(Qt::TransparentMode); |
|
5664 |
setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); |
|
5665 |
QBrush brush(image); |
|
5666 |
setBrush(brush); |
|
5667 |
setPen(Qt::NoPen); |
|
5668 |
setBrushOrigin(QPointF(-sx, -sy)); |
|
5669 |
||
5670 |
drawRect(QRectF(0, 0, sw, sh)); |
|
5671 |
restore(); |
|
5672 |
return; |
|
5673 |
} |
|
5674 |
||
5675 |
if (d->state->matrix.type() == QTransform::TxTranslate |
|
5676 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) { |
|
5677 |
x += d->state->matrix.dx(); |
|
5678 |
y += d->state->matrix.dy(); |
|
5679 |
} |
|
5680 |
||
5681 |
d->engine->drawImage(QRectF(x, y, w, h), image, QRectF(sx, sy, sw, sh), flags); |
|
5682 |
} |
|
5683 |
||
5684 |
/*! |
|
5685 |
\fn void QPainter::drawText(const QPointF &position, const QString &text) |
|
5686 |
||
5687 |
Draws the given \a text with the currently defined text direction, |
|
5688 |
beginning at the given \a position. |
|
5689 |
||
5690 |
This function does not handle the newline character (\n), as it cannot |
|
5691 |
break text into multiple lines, and it cannot display the newline character. |
|
5692 |
Use the QPainter::drawText() overload that takes a rectangle instead |
|
5693 |
if you want to draw multiple lines of text with the newline character, or |
|
5694 |
if you want the text to be wrapped. |
|
5695 |
||
5696 |
By default, QPainter draws text anti-aliased. |
|
5697 |
||
5698 |
\note The y-position is used as the baseline of the font. |
|
5699 |
*/ |
|
5700 |
||
5701 |
void QPainter::drawText(const QPointF &p, const QString &str) |
|
5702 |
{ |
|
5703 |
drawText(p, str, 0, 0); |
|
5704 |
} |
|
5705 |
||
5706 |
/*! |
|
5707 |
\internal |
|
5708 |
*/ |
|
5709 |
void QPainter::drawText(const QPointF &p, const QString &str, int tf, int justificationPadding) |
|
5710 |
{ |
|
5711 |
#ifdef QT_DEBUG_DRAW |
|
5712 |
if (qt_show_painter_debug_output) |
|
5713 |
printf("QPainter::drawText(), pos=[%.2f,%.2f], str='%s'\n", p.x(), p.y(), str.toLatin1().constData()); |
|
5714 |
#endif |
|
5715 |
||
5716 |
Q_D(QPainter); |
|
5717 |
||
5718 |
if (!d->engine || str.isEmpty() || pen().style() == Qt::NoPen) |
|
5719 |
return; |
|
5720 |
||
5721 |
QStackTextEngine engine(str, d->state->font); |
|
5722 |
engine.option.setTextDirection(d->state->layoutDirection); |
|
5723 |
if (tf & (Qt::TextForceLeftToRight|Qt::TextForceRightToLeft)) { |
|
5724 |
engine.ignoreBidi = true; |
|
5725 |
engine.option.setTextDirection((tf & Qt::TextForceLeftToRight) ? Qt::LeftToRight : Qt::RightToLeft); |
|
5726 |
} |
|
5727 |
engine.itemize(); |
|
5728 |
QScriptLine line; |
|
5729 |
line.length = str.length(); |
|
5730 |
engine.shapeLine(line); |
|
5731 |
||
5732 |
int nItems = engine.layoutData->items.size(); |
|
5733 |
QVarLengthArray<int> visualOrder(nItems); |
|
5734 |
QVarLengthArray<uchar> levels(nItems); |
|
5735 |
for (int i = 0; i < nItems; ++i) |
|
5736 |
levels[i] = engine.layoutData->items[i].analysis.bidiLevel; |
|
5737 |
QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data()); |
|
5738 |
||
5739 |
if (justificationPadding > 0) { |
|
5740 |
engine.option.setAlignment(Qt::AlignJustify); |
|
5741 |
engine.forceJustification = true; |
|
5742 |
// this works because justify() is only interested in the difference between width and textWidth |
|
5743 |
line.width = justificationPadding; |
|
5744 |
engine.justify(line); |
|
5745 |
} |
|
5746 |
QFixed x = QFixed::fromReal(p.x()); |
|
5747 |
||
5748 |
for (int i = 0; i < nItems; ++i) { |
|
5749 |
int item = visualOrder[i]; |
|
5750 |
const QScriptItem &si = engine.layoutData->items.at(item); |
|
5751 |
if (si.analysis.flags >= QScriptAnalysis::TabOrObject) { |
|
5752 |
x += si.width; |
|
5753 |
continue; |
|
5754 |
} |
|
5755 |
QFont f = engine.font(si); |
|
5756 |
QTextItemInt gf(si, &f); |
|
5757 |
gf.glyphs = engine.shapedGlyphs(&si); |
|
5758 |
gf.chars = engine.layoutData->string.unicode() + si.position; |
|
5759 |
gf.num_chars = engine.length(item); |
|
5760 |
gf.width = si.width; |
|
5761 |
gf.logClusters = engine.logClusters(&si); |
|
5762 |
||
5763 |
drawTextItem(QPointF(x.toReal(), p.y()), gf); |
|
5764 |
||
5765 |
x += si.width; |
|
5766 |
} |
|
5767 |
} |
|
5768 |
||
5769 |
void QPainter::drawText(const QRect &r, int flags, const QString &str, QRect *br) |
|
5770 |
{ |
|
5771 |
#ifdef QT_DEBUG_DRAW |
|
5772 |
if (qt_show_painter_debug_output) |
|
5773 |
printf("QPainter::drawText(), r=[%d,%d,%d,%d], flags=%d, str='%s'\n", |
|
5774 |
r.x(), r.y(), r.width(), r.height(), flags, str.toLatin1().constData()); |
|
5775 |
#endif |
|
5776 |
||
5777 |
Q_D(QPainter); |
|
5778 |
||
5779 |
if (!d->engine || str.length() == 0 || pen().style() == Qt::NoPen) |
|
5780 |
return; |
|
5781 |
||
5782 |
if (!d->extended) |
|
5783 |
d->updateState(d->state); |
|
5784 |
||
5785 |
QRectF bounds; |
|
5786 |
qt_format_text(d->state->font, r, flags, 0, str, br ? &bounds : 0, 0, 0, 0, this); |
|
5787 |
if (br) |
|
5788 |
*br = bounds.toAlignedRect(); |
|
5789 |
} |
|
5790 |
||
5791 |
/*! |
|
5792 |
\fn void QPainter::drawText(const QPoint &position, const QString &text) |
|
5793 |
||
5794 |
\overload |
|
5795 |
||
5796 |
Draws the given \a text with the currently defined text direction, |
|
5797 |
beginning at the given \a position. |
|
5798 |
||
5799 |
By default, QPainter draws text anti-aliased. |
|
5800 |
||
5801 |
\note The y-position is used as the baseline of the font. |
|
5802 |
||
5803 |
*/ |
|
5804 |
||
5805 |
/*! |
|
5806 |
\fn void QPainter::drawText(const QRectF &rectangle, int flags, const QString &text, QRectF *boundingRect) |
|
5807 |
\overload |
|
5808 |
||
5809 |
Draws the given \a text within the provided \a rectangle. |
|
5810 |
||
5811 |
\table 100% |
|
5812 |
\row |
|
5813 |
\o \inlineimage qpainter-text.png |
|
5814 |
\o |
|
5815 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 17 |
|
5816 |
\endtable |
|
5817 |
||
5818 |
The \a boundingRect (if not null) is set to the what the bounding rectangle |
|
5819 |
should be in order to enclose the whole text. The \a flags argument is a bitwise |
|
5820 |
OR of the following flags: |
|
5821 |
||
5822 |
\list |
|
5823 |
\o Qt::AlignLeft |
|
5824 |
\o Qt::AlignRight |
|
5825 |
\o Qt::AlignHCenter |
|
5826 |
\o Qt::AlignJustify |
|
5827 |
\o Qt::AlignTop |
|
5828 |
\o Qt::AlignBottom |
|
5829 |
\o Qt::AlignVCenter |
|
5830 |
\o Qt::AlignCenter |
|
5831 |
\o Qt::TextDontClip |
|
5832 |
\o Qt::TextSingleLine |
|
5833 |
\o Qt::TextExpandTabs |
|
5834 |
\o Qt::TextShowMnemonic |
|
5835 |
\o Qt::TextWordWrap |
|
5836 |
\o Qt::TextIncludeTrailingSpaces |
|
5837 |
\endlist |
|
5838 |
||
5839 |
\sa Qt::AlignmentFlag, Qt::TextFlag, boundingRect(), layoutDirection() |
|
5840 |
||
5841 |
By default, QPainter draws text anti-aliased. |
|
5842 |
||
5843 |
\note The y-coordinate of \a rectangle is used as the top of the font. |
|
5844 |
*/ |
|
5845 |
void QPainter::drawText(const QRectF &r, int flags, const QString &str, QRectF *br) |
|
5846 |
{ |
|
5847 |
#ifdef QT_DEBUG_DRAW |
|
5848 |
if (qt_show_painter_debug_output) |
|
5849 |
printf("QPainter::drawText(), r=[%.2f,%.2f,%.2f,%.2f], flags=%d, str='%s'\n", |
|
5850 |
r.x(), r.y(), r.width(), r.height(), flags, str.toLatin1().constData()); |
|
5851 |
#endif |
|
5852 |
||
5853 |
Q_D(QPainter); |
|
5854 |
||
5855 |
if (!d->engine || str.length() == 0 || pen().style() == Qt::NoPen) |
|
5856 |
return; |
|
5857 |
||
5858 |
if (!d->extended) |
|
5859 |
d->updateState(d->state); |
|
5860 |
||
5861 |
qt_format_text(d->state->font, r, flags, 0, str, br, 0, 0, 0, this); |
|
5862 |
} |
|
5863 |
||
5864 |
/*! |
|
5865 |
\fn void QPainter::drawText(const QRect &rectangle, int flags, const QString &text, QRect *boundingRect) |
|
5866 |
\overload |
|
5867 |
||
5868 |
Draws the given \a text within the provided \a rectangle according |
|
5869 |
to the specified \a flags. The \a boundingRect (if not null) is set to |
|
5870 |
the what the bounding rectangle should be in order to enclose the whole text. |
|
5871 |
||
5872 |
By default, QPainter draws text anti-aliased. |
|
5873 |
||
5874 |
\note The y-coordinate of \a rectangle is used as the top of the font. |
|
5875 |
*/ |
|
5876 |
||
5877 |
/*! |
|
5878 |
\fn void QPainter::drawText(int x, int y, const QString &text) |
|
5879 |
||
5880 |
\overload |
|
5881 |
||
5882 |
Draws the given \a text at position (\a{x}, \a{y}), using the painter's |
|
5883 |
currently defined text direction. |
|
5884 |
||
5885 |
By default, QPainter draws text anti-aliased. |
|
5886 |
||
5887 |
\note The y-position is used as the baseline of the font. |
|
5888 |
||
5889 |
*/ |
|
5890 |
||
5891 |
/*! |
|
5892 |
\fn void QPainter::drawText(int x, int y, int width, int height, int flags, |
|
5893 |
const QString &text, QRect *boundingRect) |
|
5894 |
||
5895 |
\overload |
|
5896 |
||
5897 |
Draws the given \a text within the rectangle with origin (\a{x}, |
|
5898 |
\a{y}), \a width and \a height. |
|
5899 |
||
5900 |
The \a boundingRect (if not null) is set to the actual bounding |
|
5901 |
rectangle of the output. The \a flags argument is a bitwise OR of |
|
5902 |
the following flags: |
|
5903 |
||
5904 |
\list |
|
5905 |
\o Qt::AlignLeft |
|
5906 |
\o Qt::AlignRight |
|
5907 |
\o Qt::AlignHCenter |
|
5908 |
\o Qt::AlignJustify |
|
5909 |
\o Qt::AlignTop |
|
5910 |
\o Qt::AlignBottom |
|
5911 |
\o Qt::AlignVCenter |
|
5912 |
\o Qt::AlignCenter |
|
5913 |
\o Qt::TextSingleLine |
|
5914 |
\o Qt::TextExpandTabs |
|
5915 |
\o Qt::TextShowMnemonic |
|
5916 |
\o Qt::TextWordWrap |
|
5917 |
\endlist |
|
5918 |
||
5919 |
By default, QPainter draws text anti-aliased. |
|
5920 |
||
5921 |
\note The y-position is used as the baseline of the font. |
|
5922 |
||
5923 |
\sa Qt::AlignmentFlag, Qt::TextFlag |
|
5924 |
*/ |
|
5925 |
||
5926 |
/*! |
|
5927 |
\fn void QPainter::drawText(const QRectF &rectangle, const QString &text, |
|
5928 |
const QTextOption &option) |
|
5929 |
\overload |
|
5930 |
||
5931 |
Draws the given \a text in the \a rectangle specified using the \a option |
|
5932 |
to control its positioning and orientation. |
|
5933 |
||
5934 |
By default, QPainter draws text anti-aliased. |
|
5935 |
||
5936 |
\note The y-coordinate of \a rectangle is used as the top of the font. |
|
5937 |
*/ |
|
5938 |
void QPainter::drawText(const QRectF &r, const QString &text, const QTextOption &o) |
|
5939 |
{ |
|
5940 |
#ifdef QT_DEBUG_DRAW |
|
5941 |
if (qt_show_painter_debug_output) |
|
5942 |
printf("QPainter::drawText(), r=[%.2f,%.2f,%.2f,%.2f], str='%s'\n", |
|
5943 |
r.x(), r.y(), r.width(), r.height(), text.toLatin1().constData()); |
|
5944 |
#endif |
|
5945 |
||
5946 |
Q_D(QPainter); |
|
5947 |
||
5948 |
if (!d->engine || text.length() == 0 || pen().style() == Qt::NoPen) |
|
5949 |
return; |
|
5950 |
||
5951 |
if (!d->extended) |
|
5952 |
d->updateState(d->state); |
|
5953 |
||
5954 |
qt_format_text(d->state->font, r, 0, &o, text, 0, 0, 0, 0, this); |
|
5955 |
} |
|
5956 |
||
5957 |
/*! |
|
5958 |
\fn void QPainter::drawTextItem(int x, int y, const QTextItem &ti) |
|
5959 |
||
5960 |
\internal |
|
5961 |
\overload |
|
5962 |
*/ |
|
5963 |
||
5964 |
/*! |
|
5965 |
\fn void QPainter::drawTextItem(const QPoint &p, const QTextItem &ti) |
|
5966 |
||
5967 |
\internal |
|
5968 |
\overload |
|
5969 |
||
5970 |
Draws the text item \a ti at position \a p. |
|
5971 |
*/ |
|
5972 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5973 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5974 |
\fn void QPainter::drawTextItem(const QPointF &p, const QTextItem &ti) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5975 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5976 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5977 |
\since 4.1 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5978 |
|
0 | 5979 |
Draws the text item \a ti at position \a p. |
5980 |
||
5981 |
This method ignores the painters background mode and |
|
5982 |
color. drawText and qt_format_text have to do it themselves, as |
|
5983 |
only they know the extents of the complete string. |
|
5984 |
||
5985 |
It ignores the font set on the painter as the text item has one of its own. |
|
5986 |
||
5987 |
The underline and strikeout parameters of the text items font are |
|
5988 |
ignored aswell. You'll need to pass in the correct flags to get |
|
5989 |
underlining and strikeout. |
|
5990 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5991 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5992 |
static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5993 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5994 |
const qreal radiusBase = qMax(qreal(1), maxRadius); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5995 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5996 |
QString key = QLatin1String("WaveUnderline-"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5997 |
key += pen.color().name(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5998 |
key += QLatin1Char('-'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5999 |
key += QString::number(radiusBase); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6000 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6001 |
QPixmap pixmap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6002 |
if (QPixmapCache::find(key, pixmap)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6003 |
return pixmap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6004 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6005 |
const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6006 |
const int width = qCeil(100 / (2 * halfPeriod)) * (2 * halfPeriod); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6007 |
const int radius = qFloor(radiusBase); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6008 |
|
0 | 6009 |
QPainterPath path; |
6010 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6011 |
qreal xs = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6012 |
qreal ys = radius; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6013 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6014 |
while (xs < width) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6015 |
xs += halfPeriod; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6016 |
ys = -ys; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6017 |
path.quadTo(xs - halfPeriod / 2, ys, xs, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6018 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6019 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6020 |
pixmap = QPixmap(width, radius * 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6021 |
pixmap.fill(Qt::transparent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6022 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6023 |
QPen wavePen = pen; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6024 |
wavePen.setCapStyle(Qt::SquareCap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6025 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6026 |
// This is to protect against making the line too fat, as happens on Mac OS X |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6027 |
// due to it having a rather thick width for the regular underline. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6028 |
const qreal maxPenWidth = .8 * radius; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6029 |
if (wavePen.widthF() > maxPenWidth) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6030 |
wavePen.setWidth(maxPenWidth); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6031 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6032 |
QPainter imgPainter(&pixmap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6033 |
imgPainter.setPen(wavePen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6034 |
imgPainter.setRenderHint(QPainter::Antialiasing); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6035 |
imgPainter.translate(0, radius); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6036 |
imgPainter.drawPath(path); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6037 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6038 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6039 |
QPixmapCache::insert(key, pixmap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6040 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6041 |
return pixmap; |
0 | 6042 |
} |
6043 |
||
6044 |
static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const QTextItemInt &ti) |
|
6045 |
{ |
|
6046 |
QTextCharFormat::UnderlineStyle underlineStyle = ti.underlineStyle; |
|
6047 |
if (underlineStyle == QTextCharFormat::NoUnderline |
|
6048 |
&& !(ti.flags & (QTextItem::StrikeOut | QTextItem::Overline))) |
|
6049 |
return; |
|
6050 |
||
6051 |
QFontEngine *fe = ti.fontEngine; |
|
6052 |
||
6053 |
const QPen oldPen = painter->pen(); |
|
6054 |
const QBrush oldBrush = painter->brush(); |
|
6055 |
painter->setBrush(Qt::NoBrush); |
|
6056 |
QPen pen = oldPen; |
|
6057 |
pen.setStyle(Qt::SolidLine); |
|
6058 |
pen.setWidthF(fe->lineThickness().toReal()); |
|
6059 |
pen.setCapStyle(Qt::FlatCap); |
|
6060 |
||
6061 |
QLineF line(pos.x(), pos.y(), pos.x() + ti.width.toReal(), pos.y()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6062 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6063 |
const qreal underlineOffset = fe->underlinePosition().toReal(); |
0 | 6064 |
// deliberately ceil the offset to avoid the underline coming too close to |
6065 |
// the text above it. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6066 |
const qreal underlinePos = pos.y() + qCeil(underlineOffset); |
0 | 6067 |
|
6068 |
if (underlineStyle == QTextCharFormat::SpellCheckUnderline) { |
|
6069 |
underlineStyle = QTextCharFormat::UnderlineStyle(QApplication::style()->styleHint(QStyle::SH_SpellCheckUnderlineStyle)); |
|
6070 |
} |
|
6071 |
||
6072 |
if (underlineStyle == QTextCharFormat::WaveUnderline) { |
|
6073 |
painter->save(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6074 |
painter->translate(0, pos.y() + 1); |
0 | 6075 |
|
6076 |
QColor uc = ti.charFormat.underlineColor(); |
|
6077 |
if (uc.isValid()) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6078 |
pen.setColor(uc); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6079 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6080 |
// Adapt wave to underlineOffset or pen width, whatever is larger, to make it work on all platforms |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6081 |
const QPixmap wave = generateWavyPixmap(qMax(underlineOffset, pen.widthF()), pen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6082 |
const int descent = (int) ti.descent.toReal(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6083 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6084 |
painter->setBrushOrigin(painter->brushOrigin().x(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6085 |
painter->fillRect(pos.x(), 0, qCeil(ti.width.toReal()), qMin(wave.height(), descent), wave); |
0 | 6086 |
painter->restore(); |
6087 |
} else if (underlineStyle != QTextCharFormat::NoUnderline) { |
|
6088 |
QLineF underLine(line.x1(), underlinePos, line.x2(), underlinePos); |
|
6089 |
||
6090 |
QColor uc = ti.charFormat.underlineColor(); |
|
6091 |
if (uc.isValid()) |
|
6092 |
pen.setColor(uc); |
|
6093 |
||
6094 |
pen.setStyle((Qt::PenStyle)(underlineStyle)); |
|
6095 |
painter->setPen(pen); |
|
6096 |
painter->drawLine(underLine); |
|
6097 |
} |
|
6098 |
||
6099 |
pen.setStyle(Qt::SolidLine); |
|
6100 |
pen.setColor(oldPen.color()); |
|
6101 |
||
6102 |
if (ti.flags & QTextItem::StrikeOut) { |
|
6103 |
QLineF strikeOutLine = line; |
|
6104 |
strikeOutLine.translate(0., - fe->ascent().toReal() / 3.); |
|
6105 |
painter->setPen(pen); |
|
6106 |
painter->drawLine(strikeOutLine); |
|
6107 |
} |
|
6108 |
||
6109 |
if (ti.flags & QTextItem::Overline) { |
|
6110 |
QLineF overLine = line; |
|
6111 |
overLine.translate(0., - fe->ascent().toReal()); |
|
6112 |
painter->setPen(pen); |
|
6113 |
painter->drawLine(overLine); |
|
6114 |
} |
|
6115 |
||
6116 |
painter->setPen(oldPen); |
|
6117 |
painter->setBrush(oldBrush); |
|
6118 |
} |
|
6119 |
||
6120 |
void QPainter::drawTextItem(const QPointF &p, const QTextItem &_ti) |
|
6121 |
{ |
|
6122 |
#ifdef QT_DEBUG_DRAW |
|
6123 |
if (qt_show_painter_debug_output) |
|
6124 |
printf("QPainter::drawTextItem(), pos=[%.f,%.f], str='%s'\n", |
|
6125 |
p.x(), p.y(), qPrintable(_ti.text())); |
|
6126 |
#endif |
|
6127 |
||
6128 |
Q_D(QPainter); |
|
6129 |
||
6130 |
if (!d->engine) |
|
6131 |
return; |
|
6132 |
||
6133 |
#ifndef QT_NO_DEBUG |
|
6134 |
qt_painter_thread_test(d->device->devType(), |
|
6135 |
"text and fonts", |
|
6136 |
QFontDatabase::supportsThreadedFontRendering()); |
|
6137 |
#endif |
|
6138 |
||
6139 |
QTextItemInt &ti = const_cast<QTextItemInt &>(static_cast<const QTextItemInt &>(_ti)); |
|
6140 |
||
6141 |
if (!d->extended && d->state->bgMode == Qt::OpaqueMode) { |
|
6142 |
QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal()); |
|
6143 |
fillRect(rect, d->state->bgBrush); |
|
6144 |
} |
|
6145 |
||
6146 |
if (pen().style() == Qt::NoPen) |
|
6147 |
return; |
|
6148 |
||
6149 |
const RenderHints oldRenderHints = d->state->renderHints; |
|
6150 |
if (!d->state->renderHints & QPainter::Antialiasing && d->state->matrix.type() >= QTransform::TxScale) { |
|
6151 |
// draw antialias decoration (underline/overline/strikeout) with |
|
6152 |
// transformed text |
|
6153 |
||
6154 |
bool aa = true; |
|
6155 |
const QTransform &m = d->state->matrix; |
|
6156 |
if (d->state->matrix.type() < QTransform::TxShear) { |
|
6157 |
bool isPlain90DegreeRotation = |
|
6158 |
(qFuzzyIsNull(m.m11()) |
|
6159 |
&& qFuzzyIsNull(m.m12() - qreal(1)) |
|
6160 |
&& qFuzzyIsNull(m.m21() + qreal(1)) |
|
6161 |
&& qFuzzyIsNull(m.m22()) |
|
6162 |
) |
|
6163 |
|| |
|
6164 |
(qFuzzyIsNull(m.m11() + qreal(1)) |
|
6165 |
&& qFuzzyIsNull(m.m12()) |
|
6166 |
&& qFuzzyIsNull(m.m21()) |
|
6167 |
&& qFuzzyIsNull(m.m22() + qreal(1)) |
|
6168 |
) |
|
6169 |
|| |
|
6170 |
(qFuzzyIsNull(m.m11()) |
|
6171 |
&& qFuzzyIsNull(m.m12() + qreal(1)) |
|
6172 |
&& qFuzzyIsNull(m.m21() - qreal(1)) |
|
6173 |
&& qFuzzyIsNull(m.m22()) |
|
6174 |
) |
|
6175 |
; |
|
6176 |
aa = !isPlain90DegreeRotation; |
|
6177 |
} |
|
6178 |
if (aa) |
|
6179 |
setRenderHint(QPainter::Antialiasing, true); |
|
6180 |
} |
|
6181 |
||
6182 |
if (!d->extended) |
|
6183 |
d->updateState(d->state); |
|
6184 |
||
6185 |
if (!ti.glyphs.numGlyphs) { |
|
6186 |
// nothing to do |
|
6187 |
} else if (ti.fontEngine->type() == QFontEngine::Multi) { |
|
6188 |
QFontEngineMulti *multi = static_cast<QFontEngineMulti *>(ti.fontEngine); |
|
6189 |
||
6190 |
const QGlyphLayout &glyphs = ti.glyphs; |
|
6191 |
int which = glyphs.glyphs[0] >> 24; |
|
6192 |
||
6193 |
qreal x = p.x(); |
|
6194 |
qreal y = p.y(); |
|
6195 |
||
6196 |
int start = 0; |
|
6197 |
int end, i; |
|
6198 |
for (end = 0; end < ti.glyphs.numGlyphs; ++end) { |
|
6199 |
const int e = glyphs.glyphs[end] >> 24; |
|
6200 |
if (e == which) |
|
6201 |
continue; |
|
6202 |
||
6203 |
||
6204 |
QTextItemInt ti2 = ti.midItem(multi->engine(which), start, end - start); |
|
6205 |
ti2.width = 0; |
|
6206 |
// set the high byte to zero and calc the width |
|
6207 |
for (i = start; i < end; ++i) { |
|
6208 |
glyphs.glyphs[i] = glyphs.glyphs[i] & 0xffffff; |
|
6209 |
ti2.width += ti.glyphs.effectiveAdvance(i); |
|
6210 |
} |
|
6211 |
||
6212 |
d->engine->drawTextItem(QPointF(x, y), ti2); |
|
6213 |
||
6214 |
// reset the high byte for all glyphs and advance to the next sub-string |
|
6215 |
const int hi = which << 24; |
|
6216 |
for (i = start; i < end; ++i) { |
|
6217 |
glyphs.glyphs[i] = hi | glyphs.glyphs[i]; |
|
6218 |
} |
|
6219 |
x += ti2.width.toReal(); |
|
6220 |
||
6221 |
// change engine |
|
6222 |
start = end; |
|
6223 |
which = e; |
|
6224 |
} |
|
6225 |
||
6226 |
QTextItemInt ti2 = ti.midItem(multi->engine(which), start, end - start); |
|
6227 |
ti2.width = 0; |
|
6228 |
// set the high byte to zero and calc the width |
|
6229 |
for (i = start; i < end; ++i) { |
|
6230 |
glyphs.glyphs[i] = glyphs.glyphs[i] & 0xffffff; |
|
6231 |
ti2.width += ti.glyphs.effectiveAdvance(i); |
|
6232 |
} |
|
6233 |
||
6234 |
if (d->extended) |
|
6235 |
d->extended->drawTextItem(QPointF(x, y), ti2); |
|
6236 |
else |
|
6237 |
d->engine->drawTextItem(QPointF(x,y), ti2); |
|
6238 |
||
6239 |
// reset the high byte for all glyphs |
|
6240 |
const int hi = which << 24; |
|
6241 |
for (i = start; i < end; ++i) |
|
6242 |
glyphs.glyphs[i] = hi | glyphs.glyphs[i]; |
|
6243 |
||
6244 |
} else { |
|
6245 |
if (d->extended) |
|
6246 |
d->extended->drawTextItem(p, ti); |
|
6247 |
else |
|
6248 |
d->engine->drawTextItem(p, ti); |
|
6249 |
} |
|
6250 |
drawTextItemDecoration(this, p, ti); |
|
6251 |
||
6252 |
if (d->state->renderHints != oldRenderHints) { |
|
6253 |
d->state->renderHints = oldRenderHints; |
|
6254 |
if (d->extended) |
|
6255 |
d->extended->renderHintsChanged(); |
|
6256 |
else |
|
6257 |
d->state->dirtyFlags |= QPaintEngine::DirtyHints; |
|
6258 |
} |
|
6259 |
} |
|
6260 |
||
6261 |
/*! |
|
6262 |
\fn QRectF QPainter::boundingRect(const QRectF &rectangle, int flags, const QString &text) |
|
6263 |
||
6264 |
Returns the bounding rectangle of the \a text as it will appear |
|
6265 |
when drawn inside the given \a rectangle with the specified \a |
|
6266 |
flags using the currently set font(); i.e the function tells you |
|
6267 |
where the drawText() function will draw when given the same |
|
6268 |
arguments. |
|
6269 |
||
6270 |
If the \a text does not fit within the given \a rectangle using |
|
6271 |
the specified \a flags, the function returns the required |
|
6272 |
rectangle. |
|
6273 |
||
6274 |
The \a flags argument is a bitwise OR of the following flags: |
|
6275 |
\list |
|
6276 |
\o Qt::AlignLeft |
|
6277 |
\o Qt::AlignRight |
|
6278 |
\o Qt::AlignHCenter |
|
6279 |
\o Qt::AlignTop |
|
6280 |
\o Qt::AlignBottom |
|
6281 |
\o Qt::AlignVCenter |
|
6282 |
\o Qt::AlignCenter |
|
6283 |
\o Qt::TextSingleLine |
|
6284 |
\o Qt::TextExpandTabs |
|
6285 |
\o Qt::TextShowMnemonic |
|
6286 |
\o Qt::TextWordWrap |
|
6287 |
\o Qt::TextIncludeTrailingSpaces |
|
6288 |
\endlist |
|
6289 |
If several of the horizontal or several of the vertical alignment |
|
6290 |
flags are set, the resulting alignment is undefined. |
|
6291 |
||
6292 |
\sa drawText(), Qt::Alignment, Qt::TextFlag |
|
6293 |
*/ |
|
6294 |
||
6295 |
/*! |
|
6296 |
\fn QRect QPainter::boundingRect(const QRect &rectangle, int flags, |
|
6297 |
const QString &text) |
|
6298 |
||
6299 |
\overload |
|
6300 |
||
6301 |
Returns the bounding rectangle of the \a text as it will appear |
|
6302 |
when drawn inside the given \a rectangle with the specified \a |
|
6303 |
flags using the currently set font(). |
|
6304 |
*/ |
|
6305 |
||
6306 |
/*! |
|
6307 |
\fn QRect QPainter::boundingRect(int x, int y, int w, int h, int flags, |
|
6308 |
const QString &text); |
|
6309 |
||
6310 |
\overload |
|
6311 |
||
6312 |
Returns the bounding rectangle of the given \a text as it will |
|
6313 |
appear when drawn inside the rectangle beginning at the point |
|
6314 |
(\a{x}, \a{y}) with width \a w and height \a h. |
|
6315 |
*/ |
|
6316 |
QRect QPainter::boundingRect(const QRect &rect, int flags, const QString &str) |
|
6317 |
{ |
|
6318 |
if (str.isEmpty()) |
|
6319 |
return QRect(rect.x(),rect.y(), 0,0); |
|
6320 |
QRect brect; |
|
6321 |
drawText(rect, flags | Qt::TextDontPrint, str, &brect); |
|
6322 |
return brect; |
|
6323 |
} |
|
6324 |
||
6325 |
||
6326 |
||
6327 |
QRectF QPainter::boundingRect(const QRectF &rect, int flags, const QString &str) |
|
6328 |
{ |
|
6329 |
if (str.isEmpty()) |
|
6330 |
return QRectF(rect.x(),rect.y(), 0,0); |
|
6331 |
QRectF brect; |
|
6332 |
drawText(rect, flags | Qt::TextDontPrint, str, &brect); |
|
6333 |
return brect; |
|
6334 |
} |
|
6335 |
||
6336 |
/*! |
|
6337 |
\fn QRectF QPainter::boundingRect(const QRectF &rectangle, |
|
6338 |
const QString &text, const QTextOption &option) |
|
6339 |
||
6340 |
\overload |
|
6341 |
||
6342 |
Instead of specifying flags as a bitwise OR of the |
|
6343 |
Qt::AlignmentFlag and Qt::TextFlag, this overloaded function takes |
|
6344 |
an \a option argument. The QTextOption class provides a |
|
6345 |
description of general rich text properties. |
|
6346 |
||
6347 |
\sa QTextOption |
|
6348 |
*/ |
|
6349 |
QRectF QPainter::boundingRect(const QRectF &r, const QString &text, const QTextOption &o) |
|
6350 |
{ |
|
6351 |
Q_D(QPainter); |
|
6352 |
||
6353 |
if (!d->engine || text.length() == 0) |
|
6354 |
return QRectF(r.x(),r.y(), 0,0); |
|
6355 |
||
6356 |
QRectF br; |
|
6357 |
qt_format_text(d->state->font, r, Qt::TextDontPrint, &o, text, &br, 0, 0, 0, this); |
|
6358 |
return br; |
|
6359 |
} |
|
6360 |
||
6361 |
/*! |
|
6362 |
\fn void QPainter::drawTiledPixmap(const QRectF &rectangle, const QPixmap &pixmap, const QPointF &position) |
|
6363 |
||
6364 |
Draws a tiled \a pixmap, inside the given \a rectangle with its |
|
6365 |
origin at the given \a position. |
|
6366 |
||
6367 |
Calling drawTiledPixmap() is similar to calling drawPixmap() |
|
6368 |
several times to fill (tile) an area with a pixmap, but is |
|
6369 |
potentially much more efficient depending on the underlying window |
|
6370 |
system. |
|
6371 |
||
6372 |
\sa drawPixmap() |
|
6373 |
*/ |
|
6374 |
void QPainter::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &sp) |
|
6375 |
{ |
|
6376 |
#ifdef QT_DEBUG_DRAW |
|
6377 |
if (qt_show_painter_debug_output) |
|
6378 |
printf("QPainter::drawTiledPixmap(), target=[%.2f,%.2f,%.2f,%.2f], pix=[%d,%d], offset=[%.2f,%.2f]\n", |
|
6379 |
r.x(), r.y(), r.width(), r.height(), |
|
6380 |
pixmap.width(), pixmap.height(), |
|
6381 |
sp.x(), sp.y()); |
|
6382 |
#endif |
|
6383 |
||
6384 |
Q_D(QPainter); |
|
6385 |
if (!d->engine || pixmap.isNull() || r.isEmpty()) |
|
6386 |
return; |
|
6387 |
||
6388 |
#ifndef QT_NO_DEBUG |
|
6389 |
qt_painter_thread_test(d->device->devType(), "drawTiledPixmap()"); |
|
6390 |
#endif |
|
6391 |
||
6392 |
qreal sw = pixmap.width(); |
|
6393 |
qreal sh = pixmap.height(); |
|
6394 |
qreal sx = sp.x(); |
|
6395 |
qreal sy = sp.y(); |
|
6396 |
if (sx < 0) |
|
6397 |
sx = qRound(sw) - qRound(-sx) % qRound(sw); |
|
6398 |
else |
|
6399 |
sx = qRound(sx) % qRound(sw); |
|
6400 |
if (sy < 0) |
|
6401 |
sy = qRound(sh) - -qRound(sy) % qRound(sh); |
|
6402 |
else |
|
6403 |
sy = qRound(sy) % qRound(sh); |
|
6404 |
||
6405 |
||
6406 |
if (d->extended) { |
|
6407 |
d->extended->drawTiledPixmap(r, pixmap, QPointF(sx, sy)); |
|
6408 |
return; |
|
6409 |
} |
|
6410 |
||
6411 |
if (d->state->bgMode == Qt::OpaqueMode && pixmap.isQBitmap()) |
|
6412 |
fillRect(r, d->state->bgBrush); |
|
6413 |
||
6414 |
d->updateState(d->state); |
|
6415 |
if ((d->state->matrix.type() > QTransform::TxTranslate |
|
6416 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) |
|
6417 |
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) |
|
6418 |
{ |
|
6419 |
save(); |
|
6420 |
setBackgroundMode(Qt::TransparentMode); |
|
6421 |
setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); |
|
6422 |
setBrush(QBrush(d->state->pen.color(), pixmap)); |
|
6423 |
setPen(Qt::NoPen); |
|
6424 |
||
6425 |
// If there is no rotation involved we have to make sure we use the |
|
6426 |
// antialiased and not the aliased coordinate system by rounding the coordinates. |
|
6427 |
if (d->state->matrix.type() <= QTransform::TxScale) { |
|
6428 |
const QPointF p = roundInDeviceCoordinates(r.topLeft(), d->state->matrix); |
|
6429 |
||
6430 |
if (d->state->matrix.type() <= QTransform::TxTranslate) { |
|
6431 |
sx = qRound(sx); |
|
6432 |
sy = qRound(sy); |
|
6433 |
} |
|
6434 |
||
6435 |
setBrushOrigin(QPointF(r.x()-sx, r.y()-sy)); |
|
6436 |
drawRect(QRectF(p, r.size())); |
|
6437 |
} else { |
|
6438 |
setBrushOrigin(QPointF(r.x()-sx, r.y()-sy)); |
|
6439 |
drawRect(r); |
|
6440 |
} |
|
6441 |
restore(); |
|
6442 |
return; |
|
6443 |
} |
|
6444 |
||
6445 |
qreal x = r.x(); |
|
6446 |
qreal y = r.y(); |
|
6447 |
if (d->state->matrix.type() == QTransform::TxTranslate |
|
6448 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) { |
|
6449 |
x += d->state->matrix.dx(); |
|
6450 |
y += d->state->matrix.dy(); |
|
6451 |
} |
|
6452 |
||
6453 |
d->engine->drawTiledPixmap(QRectF(x, y, r.width(), r.height()), pixmap, QPointF(sx, sy)); |
|
6454 |
} |
|
6455 |
||
6456 |
/*! |
|
6457 |
\fn QPainter::drawTiledPixmap(const QRect &rectangle, const QPixmap &pixmap, |
|
6458 |
const QPoint &position = QPoint()) |
|
6459 |
\overload |
|
6460 |
||
6461 |
Draws a tiled \a pixmap, inside the given \a rectangle with its |
|
6462 |
origin at the given \a position. |
|
6463 |
*/ |
|
6464 |
||
6465 |
/*! |
|
6466 |
\fn void QPainter::drawTiledPixmap(int x, int y, int width, int height, const |
|
6467 |
QPixmap &pixmap, int sx, int sy); |
|
6468 |
\overload |
|
6469 |
||
6470 |
Draws a tiled \a pixmap in the specified rectangle. |
|
6471 |
||
6472 |
(\a{x}, \a{y}) specifies the top-left point in the paint device |
|
6473 |
that is to be drawn onto; with the given \a width and \a |
|
6474 |
height. (\a{sx}, \a{sy}) specifies the top-left point in the \a |
|
6475 |
pixmap that is to be drawn; this defaults to (0, 0). |
|
6476 |
*/ |
|
6477 |
||
6478 |
#ifndef QT_NO_PICTURE |
|
6479 |
||
6480 |
/*! |
|
6481 |
\fn void QPainter::drawPicture(const QPointF &point, const QPicture &picture) |
|
6482 |
||
6483 |
Replays the given \a picture at the given \a point. |
|
6484 |
||
6485 |
The QPicture class is a paint device that records and replays |
|
6486 |
QPainter commands. A picture serializes the painter commands to an |
|
6487 |
IO device in a platform-independent format. Everything that can be |
|
6488 |
painted on a widget or pixmap can also be stored in a picture. |
|
6489 |
||
6490 |
This function does exactly the same as QPicture::play() when |
|
6491 |
called with \a point = QPoint(0, 0). |
|
6492 |
||
6493 |
\table 100% |
|
6494 |
\row |
|
6495 |
\o |
|
6496 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 18 |
|
6497 |
\endtable |
|
6498 |
||
6499 |
\sa QPicture::play() |
|
6500 |
*/ |
|
6501 |
||
6502 |
void QPainter::drawPicture(const QPointF &p, const QPicture &picture) |
|
6503 |
{ |
|
6504 |
Q_D(QPainter); |
|
6505 |
||
6506 |
if (!d->engine) |
|
6507 |
return; |
|
6508 |
||
6509 |
if (!d->extended) |
|
6510 |
d->updateState(d->state); |
|
6511 |
||
6512 |
save(); |
|
6513 |
translate(p); |
|
6514 |
const_cast<QPicture *>(&picture)->play(this); |
|
6515 |
restore(); |
|
6516 |
} |
|
6517 |
||
6518 |
/*! |
|
6519 |
\fn void QPainter::drawPicture(const QPoint &point, const QPicture &picture) |
|
6520 |
\overload |
|
6521 |
||
6522 |
Replays the given \a picture at the given \a point. |
|
6523 |
*/ |
|
6524 |
||
6525 |
/*! |
|
6526 |
\fn void QPainter::drawPicture(int x, int y, const QPicture &picture) |
|
6527 |
\overload |
|
6528 |
||
6529 |
Draws the given \a picture at point (\a x, \a y). |
|
6530 |
*/ |
|
6531 |
||
6532 |
#endif // QT_NO_PICTURE |
|
6533 |
||
6534 |
/*! |
|
6535 |
\fn void QPainter::eraseRect(const QRectF &rectangle) |
|
6536 |
||
6537 |
Erases the area inside the given \a rectangle. Equivalent to |
|
6538 |
calling |
|
6539 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 19 |
|
6540 |
||
6541 |
\sa fillRect() |
|
6542 |
*/ |
|
6543 |
void QPainter::eraseRect(const QRectF &r) |
|
6544 |
{ |
|
6545 |
Q_D(QPainter); |
|
6546 |
||
6547 |
fillRect(r, d->state->bgBrush); |
|
6548 |
} |
|
6549 |
||
6550 |
static inline bool needsResolving(const QBrush &brush) |
|
6551 |
{ |
|
6552 |
Qt::BrushStyle s = brush.style(); |
|
6553 |
return ((s == Qt::LinearGradientPattern || s == Qt::RadialGradientPattern || |
|
6554 |
s == Qt::ConicalGradientPattern) && |
|
6555 |
brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode); |
|
6556 |
} |
|
6557 |
||
6558 |
/*! |
|
6559 |
\fn void QPainter::eraseRect(const QRect &rectangle) |
|
6560 |
\overload |
|
6561 |
||
6562 |
Erases the area inside the given \a rectangle. |
|
6563 |
*/ |
|
6564 |
||
6565 |
/*! |
|
6566 |
\fn void QPainter::eraseRect(int x, int y, int width, int height) |
|
6567 |
\overload |
|
6568 |
||
6569 |
Erases the area inside the rectangle beginning at (\a x, \a y) |
|
6570 |
with the given \a width and \a height. |
|
6571 |
*/ |
|
6572 |
||
6573 |
||
6574 |
/*! |
|
6575 |
\fn void QPainter::fillRect(int x, int y, int width, int height, Qt::BrushStyle style) |
|
6576 |
\overload |
|
6577 |
||
6578 |
Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a |
|
6579 |
width and \a height, using the brush \a style specified. |
|
6580 |
||
6581 |
\since 4.5 |
|
6582 |
*/ |
|
6583 |
||
6584 |
/*! |
|
6585 |
\fn void QPainter::fillRect(const QRect &rectangle, Qt::BrushStyle style) |
|
6586 |
\overload |
|
6587 |
||
6588 |
Fills the given \a rectangle with the brush \a style specified. |
|
6589 |
||
6590 |
\since 4.5 |
|
6591 |
*/ |
|
6592 |
||
6593 |
/*! |
|
6594 |
\fn void QPainter::fillRect(const QRectF &rectangle, Qt::BrushStyle style) |
|
6595 |
\overload |
|
6596 |
||
6597 |
Fills the given \a rectangle with the brush \a style specified. |
|
6598 |
||
6599 |
\since 4.5 |
|
6600 |
*/ |
|
6601 |
||
6602 |
/*! |
|
6603 |
\fn void QPainter::fillRect(const QRectF &rectangle, const QBrush &brush) |
|
6604 |
||
6605 |
Fills the given \a rectangle with the \a brush specified. |
|
6606 |
||
6607 |
Alternatively, you can specify a QColor instead of a QBrush; the |
|
6608 |
QBrush constructor (taking a QColor argument) will automatically |
|
6609 |
create a solid pattern brush. |
|
6610 |
||
6611 |
\sa drawRect() |
|
6612 |
*/ |
|
6613 |
void QPainter::fillRect(const QRectF &r, const QBrush &brush) |
|
6614 |
{ |
|
6615 |
Q_D(QPainter); |
|
6616 |
||
6617 |
if (!d->engine) |
|
6618 |
return; |
|
6619 |
||
6620 |
if (d->extended) { |
|
6621 |
const QGradient *g = brush.gradient(); |
|
6622 |
if (!g || g->coordinateMode() == QGradient::LogicalMode) { |
|
6623 |
d->extended->fillRect(r, brush); |
|
6624 |
return; |
|
6625 |
} |
|
6626 |
} |
|
6627 |
||
6628 |
QPen oldPen = pen(); |
|
6629 |
QBrush oldBrush = this->brush(); |
|
6630 |
setPen(Qt::NoPen); |
|
6631 |
if (brush.style() == Qt::SolidPattern) { |
|
6632 |
d->colorBrush.setStyle(Qt::SolidPattern); |
|
6633 |
d->colorBrush.setColor(brush.color()); |
|
6634 |
setBrush(d->colorBrush); |
|
6635 |
} else { |
|
6636 |
setBrush(brush); |
|
6637 |
} |
|
6638 |
||
6639 |
drawRect(r); |
|
6640 |
setBrush(oldBrush); |
|
6641 |
setPen(oldPen); |
|
6642 |
} |
|
6643 |
||
6644 |
/*! |
|
6645 |
\fn void QPainter::fillRect(const QRect &rectangle, const QBrush &brush) |
|
6646 |
\overload |
|
6647 |
||
6648 |
Fills the given \a rectangle with the specified \a brush. |
|
6649 |
*/ |
|
6650 |
||
6651 |
void QPainter::fillRect(const QRect &r, const QBrush &brush) |
|
6652 |
{ |
|
6653 |
Q_D(QPainter); |
|
6654 |
||
6655 |
if (!d->engine) |
|
6656 |
return; |
|
6657 |
||
6658 |
if (d->extended) { |
|
6659 |
const QGradient *g = brush.gradient(); |
|
6660 |
if (!g || g->coordinateMode() == QGradient::LogicalMode) { |
|
6661 |
d->extended->fillRect(r, brush); |
|
6662 |
return; |
|
6663 |
} |
|
6664 |
} |
|
6665 |
||
6666 |
QPen oldPen = pen(); |
|
6667 |
QBrush oldBrush = this->brush(); |
|
6668 |
setPen(Qt::NoPen); |
|
6669 |
if (brush.style() == Qt::SolidPattern) { |
|
6670 |
d->colorBrush.setStyle(Qt::SolidPattern); |
|
6671 |
d->colorBrush.setColor(brush.color()); |
|
6672 |
setBrush(d->colorBrush); |
|
6673 |
} else { |
|
6674 |
setBrush(brush); |
|
6675 |
} |
|
6676 |
||
6677 |
drawRect(r); |
|
6678 |
setBrush(oldBrush); |
|
6679 |
setPen(oldPen); |
|
6680 |
} |
|
6681 |
||
6682 |
||
6683 |
||
6684 |
/*! |
|
6685 |
\fn void QPainter::fillRect(const QRect &rectangle, const QColor &color) |
|
6686 |
\overload |
|
6687 |
||
6688 |
Fills the given \a rectangle with the \a color specified. |
|
6689 |
||
6690 |
\since 4.5 |
|
6691 |
*/ |
|
6692 |
void QPainter::fillRect(const QRect &r, const QColor &color) |
|
6693 |
{ |
|
6694 |
Q_D(QPainter); |
|
6695 |
||
6696 |
if (!d->engine) |
|
6697 |
return; |
|
6698 |
||
6699 |
if (d->extended) { |
|
6700 |
d->extended->fillRect(r, color); |
|
6701 |
return; |
|
6702 |
} |
|
6703 |
||
6704 |
fillRect(r, QBrush(color)); |
|
6705 |
} |
|
6706 |
||
6707 |
||
6708 |
/*! |
|
6709 |
\fn void QPainter::fillRect(const QRectF &rectangle, const QColor &color) |
|
6710 |
\overload |
|
6711 |
||
6712 |
Fills the given \a rectangle with the \a color specified. |
|
6713 |
||
6714 |
\since 4.5 |
|
6715 |
*/ |
|
6716 |
void QPainter::fillRect(const QRectF &r, const QColor &color) |
|
6717 |
{ |
|
6718 |
Q_D(QPainter); |
|
6719 |
||
6720 |
if (!d->engine) |
|
6721 |
return; |
|
6722 |
||
6723 |
if (d->extended) { |
|
6724 |
d->extended->fillRect(r, color); |
|
6725 |
return; |
|
6726 |
} |
|
6727 |
||
6728 |
fillRect(r, QBrush(color)); |
|
6729 |
} |
|
6730 |
||
6731 |
/*! |
|
6732 |
\fn void QPainter::fillRect(int x, int y, int width, int height, const QBrush &brush) |
|
6733 |
||
6734 |
\overload |
|
6735 |
||
6736 |
Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a |
|
6737 |
width and \a height, using the given \a brush. |
|
6738 |
*/ |
|
6739 |
||
6740 |
/*! |
|
6741 |
\fn void QPainter::fillRect(int x, int y, int width, int height, const QColor &color) |
|
6742 |
||
6743 |
\overload |
|
6744 |
||
6745 |
Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a |
|
6746 |
width and \a height, using the given \a color. |
|
6747 |
||
6748 |
\since 4.5 |
|
6749 |
*/ |
|
6750 |
||
6751 |
/*! |
|
6752 |
\fn void QPainter::fillRect(int x, int y, int width, int height, Qt::GlobalColor color) |
|
6753 |
||
6754 |
\overload |
|
6755 |
||
6756 |
Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a |
|
6757 |
width and \a height, using the given \a color. |
|
6758 |
||
6759 |
\since 4.5 |
|
6760 |
*/ |
|
6761 |
||
6762 |
/*! |
|
6763 |
\fn void QPainter::fillRect(const QRect &rectangle, Qt::GlobalColor color); |
|
6764 |
||
6765 |
\overload |
|
6766 |
||
6767 |
Fills the given \a rectangle with the specified \a color. |
|
6768 |
||
6769 |
\since 4.5 |
|
6770 |
*/ |
|
6771 |
||
6772 |
/*! |
|
6773 |
\fn void QPainter::fillRect(const QRectF &rectangle, Qt::GlobalColor color); |
|
6774 |
||
6775 |
\overload |
|
6776 |
||
6777 |
Fills the given \a rectangle with the specified \a color. |
|
6778 |
||
6779 |
\since 4.5 |
|
6780 |
*/ |
|
6781 |
||
6782 |
/*! |
|
6783 |
Sets the given render \a hint on the painter if \a on is true; |
|
6784 |
otherwise clears the render hint. |
|
6785 |
||
6786 |
\sa setRenderHints(), renderHints(), {QPainter#Rendering |
|
6787 |
Quality}{Rendering Quality} |
|
6788 |
*/ |
|
6789 |
void QPainter::setRenderHint(RenderHint hint, bool on) |
|
6790 |
{ |
|
6791 |
#ifdef QT_DEBUG_DRAW |
|
6792 |
if (qt_show_painter_debug_output) |
|
6793 |
printf("QPainter::setRenderHint: hint=%x, %s\n", hint, on ? "on" : "off"); |
|
6794 |
#endif |
|
6795 |
||
6796 |
#ifndef QT_NO_DEBUG |
|
6797 |
static const bool antialiasingDisabled = qgetenv("QT_NO_ANTIALIASING").toInt(); |
|
6798 |
if (hint == QPainter::Antialiasing && antialiasingDisabled) |
|
6799 |
return; |
|
6800 |
#endif |
|
6801 |
||
6802 |
setRenderHints(hint, on); |
|
6803 |
} |
|
6804 |
||
6805 |
/*! |
|
6806 |
\since 4.2 |
|
6807 |
||
6808 |
Sets the given render \a hints on the painter if \a on is true; |
|
6809 |
otherwise clears the render hints. |
|
6810 |
||
6811 |
\sa setRenderHint(), renderHints(), {QPainter#Rendering |
|
6812 |
Quality}{Rendering Quality} |
|
6813 |
*/ |
|
6814 |
||
6815 |
void QPainter::setRenderHints(RenderHints hints, bool on) |
|
6816 |
{ |
|
6817 |
Q_D(QPainter); |
|
6818 |
||
6819 |
if (!d->engine) { |
|
6820 |
qWarning("QPainter::setRenderHint: Painter must be active to set rendering hints"); |
|
6821 |
return; |
|
6822 |
} |
|
6823 |
||
6824 |
if (on) |
|
6825 |
d->state->renderHints |= hints; |
|
6826 |
else |
|
6827 |
d->state->renderHints &= ~hints; |
|
6828 |
||
6829 |
if (d->extended) |
|
6830 |
d->extended->renderHintsChanged(); |
|
6831 |
else |
|
6832 |
d->state->dirtyFlags |= QPaintEngine::DirtyHints; |
|
6833 |
} |
|
6834 |
||
6835 |
/*! |
|
6836 |
Returns a flag that specifies the rendering hints that are set for |
|
6837 |
this painter. |
|
6838 |
||
6839 |
\sa testRenderHint(), {QPainter#Rendering Quality}{Rendering Quality} |
|
6840 |
*/ |
|
6841 |
QPainter::RenderHints QPainter::renderHints() const |
|
6842 |
{ |
|
6843 |
Q_D(const QPainter); |
|
6844 |
||
6845 |
if (!d->engine) |
|
6846 |
return 0; |
|
6847 |
||
6848 |
return d->state->renderHints; |
|
6849 |
} |
|
6850 |
||
6851 |
/*! |
|
6852 |
\fn bool QPainter::testRenderHint(RenderHint hint) const |
|
6853 |
\since 4.3 |
|
6854 |
||
6855 |
Returns true if \a hint is set; otherwise returns false. |
|
6856 |
||
6857 |
\sa renderHints(), setRenderHint() |
|
6858 |
*/ |
|
6859 |
||
6860 |
/*! |
|
6861 |
Returns true if view transformation is enabled; otherwise returns |
|
6862 |
false. |
|
6863 |
||
6864 |
\sa setViewTransformEnabled(), worldTransform() |
|
6865 |
*/ |
|
6866 |
||
6867 |
bool QPainter::viewTransformEnabled() const |
|
6868 |
{ |
|
6869 |
Q_D(const QPainter); |
|
6870 |
if (!d->engine) { |
|
6871 |
qWarning("QPainter::viewTransformEnabled: Painter not active"); |
|
6872 |
return false; |
|
6873 |
} |
|
6874 |
return d->state->VxF; |
|
6875 |
} |
|
6876 |
||
6877 |
/*! |
|
6878 |
\fn void QPainter::setWindow(const QRect &rectangle) |
|
6879 |
||
6880 |
Sets the painter's window to the given \a rectangle, and enables |
|
6881 |
view transformations. |
|
6882 |
||
6883 |
The window rectangle is part of the view transformation. The |
|
6884 |
window specifies the logical coordinate system. Its sister, the |
|
6885 |
viewport(), specifies the device coordinate system. |
|
6886 |
||
6887 |
The default window rectangle is the same as the device's |
|
6888 |
rectangle. |
|
6889 |
||
6890 |
\sa window(), viewTransformEnabled(), {The Coordinate |
|
6891 |
System#Window-Viewport Conversion}{Window-Viewport Conversion} |
|
6892 |
*/ |
|
6893 |
||
6894 |
/*! |
|
6895 |
\fn void QPainter::setWindow(int x, int y, int width, int height) |
|
6896 |
\overload |
|
6897 |
||
6898 |
Sets the painter's window to the rectangle beginning at (\a x, \a |
|
6899 |
y) and the given \a width and \a height. |
|
6900 |
*/ |
|
6901 |
||
6902 |
void QPainter::setWindow(const QRect &r) |
|
6903 |
{ |
|
6904 |
#ifdef QT_DEBUG_DRAW |
|
6905 |
if (qt_show_painter_debug_output) |
|
6906 |
printf("QPainter::setWindow(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height()); |
|
6907 |
#endif |
|
6908 |
||
6909 |
Q_D(QPainter); |
|
6910 |
||
6911 |
if (!d->engine) { |
|
6912 |
qWarning("QPainter::setWindow: Painter not active"); |
|
6913 |
return; |
|
6914 |
} |
|
6915 |
||
6916 |
d->state->wx = r.x(); |
|
6917 |
d->state->wy = r.y(); |
|
6918 |
d->state->ww = r.width(); |
|
6919 |
d->state->wh = r.height(); |
|
6920 |
||
6921 |
d->state->VxF = true; |
|
6922 |
d->updateMatrix(); |
|
6923 |
} |
|
6924 |
||
6925 |
/*! |
|
6926 |
Returns the window rectangle. |
|
6927 |
||
6928 |
\sa setWindow(), setViewTransformEnabled() |
|
6929 |
*/ |
|
6930 |
||
6931 |
QRect QPainter::window() const |
|
6932 |
{ |
|
6933 |
Q_D(const QPainter); |
|
6934 |
if (!d->engine) { |
|
6935 |
qWarning("QPainter::window: Painter not active"); |
|
6936 |
return QRect(); |
|
6937 |
} |
|
6938 |
return QRect(d->state->wx, d->state->wy, d->state->ww, d->state->wh); |
|
6939 |
} |
|
6940 |
||
6941 |
/*! |
|
6942 |
\fn void QPainter::setViewport(const QRect &rectangle) |
|
6943 |
||
6944 |
Sets the painter's viewport rectangle to the given \a rectangle, |
|
6945 |
and enables view transformations. |
|
6946 |
||
6947 |
The viewport rectangle is part of the view transformation. The |
|
6948 |
viewport specifies the device coordinate system. Its sister, the |
|
6949 |
window(), specifies the logical coordinate system. |
|
6950 |
||
6951 |
The default viewport rectangle is the same as the device's |
|
6952 |
rectangle. |
|
6953 |
||
6954 |
\sa viewport(), viewTransformEnabled() {The Coordinate |
|
6955 |
System#Window-Viewport Conversion}{Window-Viewport Conversion} |
|
6956 |
*/ |
|
6957 |
||
6958 |
/*! |
|
6959 |
\fn void QPainter::setViewport(int x, int y, int width, int height) |
|
6960 |
\overload |
|
6961 |
||
6962 |
Sets the painter's viewport rectangle to be the rectangle |
|
6963 |
beginning at (\a x, \a y) with the given \a width and \a height. |
|
6964 |
*/ |
|
6965 |
||
6966 |
void QPainter::setViewport(const QRect &r) |
|
6967 |
{ |
|
6968 |
#ifdef QT_DEBUG_DRAW |
|
6969 |
if (qt_show_painter_debug_output) |
|
6970 |
printf("QPainter::setViewport(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height()); |
|
6971 |
#endif |
|
6972 |
||
6973 |
Q_D(QPainter); |
|
6974 |
||
6975 |
if (!d->engine) { |
|
6976 |
qWarning("QPainter::setViewport: Painter not active"); |
|
6977 |
return; |
|
6978 |
} |
|
6979 |
||
6980 |
d->state->vx = r.x(); |
|
6981 |
d->state->vy = r.y(); |
|
6982 |
d->state->vw = r.width(); |
|
6983 |
d->state->vh = r.height(); |
|
6984 |
||
6985 |
d->state->VxF = true; |
|
6986 |
d->updateMatrix(); |
|
6987 |
} |
|
6988 |
||
6989 |
/*! |
|
6990 |
Returns the viewport rectangle. |
|
6991 |
||
6992 |
\sa setViewport(), setViewTransformEnabled() |
|
6993 |
*/ |
|
6994 |
||
6995 |
QRect QPainter::viewport() const |
|
6996 |
{ |
|
6997 |
Q_D(const QPainter); |
|
6998 |
if (!d->engine) { |
|
6999 |
qWarning("QPainter::viewport: Painter not active"); |
|
7000 |
return QRect(); |
|
7001 |
} |
|
7002 |
return QRect(d->state->vx, d->state->vy, d->state->vw, d->state->vh); |
|
7003 |
} |
|
7004 |
||
7005 |
/*! \fn bool QPainter::hasViewXForm() const |
|
7006 |
\compat |
|
7007 |
||
7008 |
Use viewTransformEnabled() instead. |
|
7009 |
*/ |
|
7010 |
||
7011 |
/*! \fn bool QPainter::hasWorldXForm() const |
|
7012 |
\compat |
|
7013 |
||
7014 |
Use worldMatrixEnabled() instead. |
|
7015 |
*/ |
|
7016 |
||
7017 |
/*! \fn void QPainter::resetXForm() |
|
7018 |
\compat |
|
7019 |
||
7020 |
Use resetTransform() instead. |
|
7021 |
*/ |
|
7022 |
||
7023 |
/*! \fn void QPainter::setViewXForm(bool enabled) |
|
7024 |
\compat |
|
7025 |
||
7026 |
Use setViewTransformEnabled() instead. |
|
7027 |
*/ |
|
7028 |
||
7029 |
/*! \fn void QPainter::setWorldXForm(bool enabled) |
|
7030 |
\compat |
|
7031 |
||
7032 |
Use setWorldMatrixEnabled() instead. |
|
7033 |
*/ |
|
7034 |
/*! |
|
7035 |
Enables view transformations if \a enable is true, or disables |
|
7036 |
view transformations if \a enable is false. |
|
7037 |
||
7038 |
\sa viewTransformEnabled(), {The Coordinate System#Window-Viewport |
|
7039 |
Conversion}{Window-Viewport Conversion} |
|
7040 |
*/ |
|
7041 |
||
7042 |
void QPainter::setViewTransformEnabled(bool enable) |
|
7043 |
{ |
|
7044 |
#ifdef QT_DEBUG_DRAW |
|
7045 |
if (qt_show_painter_debug_output) |
|
7046 |
printf("QPainter::setViewTransformEnabled(), enable=%d\n", enable); |
|
7047 |
#endif |
|
7048 |
||
7049 |
Q_D(QPainter); |
|
7050 |
||
7051 |
if (!d->engine) { |
|
7052 |
qWarning("QPainter::setViewTransformEnabled: Painter not active"); |
|
7053 |
return; |
|
7054 |
} |
|
7055 |
||
7056 |
if (enable == d->state->VxF) |
|
7057 |
return; |
|
7058 |
||
7059 |
d->state->VxF = enable; |
|
7060 |
d->updateMatrix(); |
|
7061 |
} |
|
7062 |
||
7063 |
#ifdef QT3_SUPPORT |
|
7064 |
||
7065 |
/*! |
|
7066 |
\obsolete |
|
7067 |
||
7068 |
Use the worldTransform() combined with QTransform::dx() instead. |
|
7069 |
||
7070 |
\oldcode |
|
7071 |
QPainter painter(this); |
|
7072 |
qreal x = painter.translationX(); |
|
7073 |
\newcode |
|
7074 |
QPainter painter(this); |
|
7075 |
qreal x = painter.worldTransform().dx(); |
|
7076 |
\endcode |
|
7077 |
*/ |
|
7078 |
qreal QPainter::translationX() const |
|
7079 |
{ |
|
7080 |
Q_D(const QPainter); |
|
7081 |
if (!d->engine) { |
|
7082 |
qWarning("QPainter::translationX: Painter not active"); |
|
7083 |
return 0.0; |
|
7084 |
} |
|
7085 |
return d->state->worldMatrix.dx(); |
|
7086 |
} |
|
7087 |
||
7088 |
/*! |
|
7089 |
\obsolete |
|
7090 |
||
7091 |
Use the worldTransform() combined with QTransform::dy() instead. |
|
7092 |
||
7093 |
\oldcode |
|
7094 |
QPainter painter(this); |
|
7095 |
qreal y = painter.translationY(); |
|
7096 |
\newcode |
|
7097 |
QPainter painter(this); |
|
7098 |
qreal y = painter.worldTransform().dy(); |
|
7099 |
\endcode |
|
7100 |
*/ |
|
7101 |
qreal QPainter::translationY() const |
|
7102 |
{ |
|
7103 |
Q_D(const QPainter); |
|
7104 |
if (!d->engine) { |
|
7105 |
qWarning("QPainter::translationY: Painter not active"); |
|
7106 |
return 0.0; |
|
7107 |
} |
|
7108 |
return d->state->worldMatrix.dy(); |
|
7109 |
} |
|
7110 |
||
7111 |
/*! |
|
7112 |
\fn void QPainter::map(int x, int y, int *rx, int *ry) const |
|
7113 |
||
7114 |
\internal |
|
7115 |
||
7116 |
Sets (\a{rx}, \a{ry}) to the point that results from applying the |
|
7117 |
painter's current transformation on the point (\a{x}, \a{y}). |
|
7118 |
*/ |
|
7119 |
void QPainter::map(int x, int y, int *rx, int *ry) const |
|
7120 |
{ |
|
7121 |
QPoint p(x, y); |
|
7122 |
p = p * combinedMatrix(); |
|
7123 |
*rx = p.x(); |
|
7124 |
*ry = p.y(); |
|
7125 |
} |
|
7126 |
||
7127 |
/*! |
|
7128 |
\fn QPoint QPainter::xForm(const QPoint &point) const |
|
7129 |
||
7130 |
Use combinedTransform() instead. |
|
7131 |
*/ |
|
7132 |
||
7133 |
QPoint QPainter::xForm(const QPoint &p) const |
|
7134 |
{ |
|
7135 |
Q_D(const QPainter); |
|
7136 |
if (!d->engine) { |
|
7137 |
qWarning("QPainter::xForm: Painter not active"); |
|
7138 |
return QPoint(); |
|
7139 |
} |
|
7140 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7141 |
return p; |
|
7142 |
return p * combinedMatrix(); |
|
7143 |
} |
|
7144 |
||
7145 |
||
7146 |
/*! |
|
7147 |
\fn QRect QPainter::xForm(const QRect &rectangle) const |
|
7148 |
\overload |
|
7149 |
||
7150 |
Use combinedTransform() instead of this function and call |
|
7151 |
mapRect() on the result to obtain a QRect. |
|
7152 |
*/ |
|
7153 |
||
7154 |
QRect QPainter::xForm(const QRect &r) const |
|
7155 |
{ |
|
7156 |
Q_D(const QPainter); |
|
7157 |
if (!d->engine) { |
|
7158 |
qWarning("QPainter::xForm: Painter not active"); |
|
7159 |
return QRect(); |
|
7160 |
} |
|
7161 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7162 |
return r; |
|
7163 |
return combinedMatrix().mapRect(r); |
|
7164 |
} |
|
7165 |
||
7166 |
/*! |
|
7167 |
\fn QPolygon QPainter::xForm(const QPolygon &polygon) const |
|
7168 |
\overload |
|
7169 |
||
7170 |
Use combinedTransform() instead. |
|
7171 |
*/ |
|
7172 |
||
7173 |
QPolygon QPainter::xForm(const QPolygon &a) const |
|
7174 |
{ |
|
7175 |
Q_D(const QPainter); |
|
7176 |
if (!d->engine) { |
|
7177 |
qWarning("QPainter::xForm: Painter not active"); |
|
7178 |
return QPolygon(); |
|
7179 |
} |
|
7180 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7181 |
return a; |
|
7182 |
return a * combinedMatrix(); |
|
7183 |
} |
|
7184 |
||
7185 |
/*! |
|
7186 |
\fn QPolygon QPainter::xForm(const QPolygon &polygon, int index, int count) const |
|
7187 |
\overload |
|
7188 |
||
7189 |
Use combinedTransform() combined with QPolygon::mid() instead. |
|
7190 |
||
7191 |
\oldcode |
|
7192 |
QPainter painter(this); |
|
7193 |
QPolygon transformed = painter.xForm(polygon, index, count) |
|
7194 |
\newcode |
|
7195 |
QPainter painter(this); |
|
7196 |
QPolygon transformed = polygon.mid(index, count) * painter.combinedTransform(); |
|
7197 |
\endcode |
|
7198 |
*/ |
|
7199 |
||
7200 |
QPolygon QPainter::xForm(const QPolygon &av, int index, int npoints) const |
|
7201 |
{ |
|
7202 |
int lastPoint = npoints < 0 ? av.size() : index+npoints; |
|
7203 |
QPolygon a(lastPoint-index); |
|
7204 |
memcpy(a.data(), av.data()+index, (lastPoint-index)*sizeof(QPoint)); |
|
7205 |
return a * combinedMatrix(); |
|
7206 |
} |
|
7207 |
||
7208 |
/*! |
|
7209 |
\fn QPoint QPainter::xFormDev(const QPoint &point) const |
|
7210 |
\overload |
|
7211 |
\obsolete |
|
7212 |
||
7213 |
Use combinedTransform() combined with QTransform::inverted() instead. |
|
7214 |
||
7215 |
\oldcode |
|
7216 |
QPainter painter(this); |
|
7217 |
QPoint transformed = painter.xFormDev(point); |
|
7218 |
\newcode |
|
7219 |
QPainter painter(this); |
|
7220 |
QPoint transformed = point * painter.combinedTransform().inverted(); |
|
7221 |
\endcode |
|
7222 |
*/ |
|
7223 |
||
7224 |
QPoint QPainter::xFormDev(const QPoint &p) const |
|
7225 |
{ |
|
7226 |
Q_D(const QPainter); |
|
7227 |
if (!d->engine) { |
|
7228 |
qWarning("QPainter::xFormDev: Painter not active"); |
|
7229 |
return QPoint(); |
|
7230 |
} |
|
7231 |
if(d->state->matrix.type() == QTransform::TxNone) |
|
7232 |
return p; |
|
7233 |
return p * combinedMatrix().inverted(); |
|
7234 |
} |
|
7235 |
||
7236 |
/*! |
|
7237 |
\fn QRect QPainter::xFormDev(const QRect &rectangle) const |
|
7238 |
\overload |
|
7239 |
\obsolete |
|
7240 |
||
7241 |
Use combinedTransform() combined with QTransform::inverted() instead. |
|
7242 |
||
7243 |
\oldcode |
|
7244 |
QPainter painter(this); |
|
7245 |
QRect transformed = painter.xFormDev(rectangle); |
|
7246 |
\newcode |
|
7247 |
QPainter painter(this); |
|
7248 |
QRegion region = QRegion(rectangle) * painter.combinedTransform().inverted(); |
|
7249 |
QRect transformed = region.boundingRect(); |
|
7250 |
\endcode |
|
7251 |
*/ |
|
7252 |
||
7253 |
QRect QPainter::xFormDev(const QRect &r) const |
|
7254 |
{ |
|
7255 |
Q_D(const QPainter); |
|
7256 |
if (!d->engine) { |
|
7257 |
qWarning("QPainter::xFormDev: Painter not active"); |
|
7258 |
return QRect(); |
|
7259 |
} |
|
7260 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7261 |
return r; |
|
7262 |
return combinedMatrix().inverted().mapRect(r); |
|
7263 |
} |
|
7264 |
||
7265 |
/*! |
|
7266 |
\overload |
|
7267 |
||
7268 |
\fn QPoint QPainter::xFormDev(const QPolygon &polygon) const |
|
7269 |
\obsolete |
|
7270 |
||
7271 |
Use combinedTransform() combined with QTransform::inverted() instead. |
|
7272 |
||
7273 |
\oldcode |
|
7274 |
QPainter painter(this); |
|
7275 |
QPolygon transformed = painter.xFormDev(rectangle); |
|
7276 |
\newcode |
|
7277 |
QPainter painter(this); |
|
7278 |
QPolygon transformed = polygon * painter.combinedTransform().inverted(); |
|
7279 |
\endcode |
|
7280 |
*/ |
|
7281 |
||
7282 |
QPolygon QPainter::xFormDev(const QPolygon &a) const |
|
7283 |
{ |
|
7284 |
Q_D(const QPainter); |
|
7285 |
if (!d->engine) { |
|
7286 |
qWarning("QPainter::xFormDev: Painter not active"); |
|
7287 |
return QPolygon(); |
|
7288 |
} |
|
7289 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7290 |
return a; |
|
7291 |
return a * combinedMatrix().inverted(); |
|
7292 |
} |
|
7293 |
||
7294 |
/*! |
|
7295 |
\fn QPolygon QPainter::xFormDev(const QPolygon &polygon, int index, int count) const |
|
7296 |
\overload |
|
7297 |
\obsolete |
|
7298 |
||
7299 |
Use combinedTransform() combined with QPolygon::mid() and QTransform::inverted() instead. |
|
7300 |
||
7301 |
\oldcode |
|
7302 |
QPainter painter(this); |
|
7303 |
QPolygon transformed = painter.xFormDev(polygon, index, count); |
|
7304 |
\newcode |
|
7305 |
QPainter painter(this); |
|
7306 |
QPolygon transformed = polygon.mid(index, count) * painter.combinedTransform().inverted(); |
|
7307 |
\endcode |
|
7308 |
*/ |
|
7309 |
||
7310 |
QPolygon QPainter::xFormDev(const QPolygon &ad, int index, int npoints) const |
|
7311 |
{ |
|
7312 |
Q_D(const QPainter); |
|
7313 |
int lastPoint = npoints < 0 ? ad.size() : index+npoints; |
|
7314 |
QPolygon a(lastPoint-index); |
|
7315 |
memcpy(a.data(), ad.data()+index, (lastPoint-index)*sizeof(QPoint)); |
|
7316 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7317 |
return a; |
|
7318 |
return a * combinedMatrix().inverted(); |
|
7319 |
} |
|
7320 |
||
7321 |
/*! |
|
7322 |
\fn void QPainter::drawCubicBezier(const QPolygon &controlPoints, int index) |
|
7323 |
||
7324 |
Draws a cubic Bezier curve defined by the \a controlPoints, |
|
7325 |
starting at \a{controlPoints}\e{[index]} (\a index defaults to 0). |
|
7326 |
Points after \a{controlPoints}\e{[index + 3]} are ignored. Nothing |
|
7327 |
happens if there aren't enough control points. |
|
7328 |
||
7329 |
Use strokePath() instead. |
|
7330 |
||
7331 |
\oldcode |
|
7332 |
QPainter painter(this); |
|
7333 |
painter.drawCubicBezier(controlPoints, index) |
|
7334 |
\newcode |
|
7335 |
QPainterPath path; |
|
7336 |
path.moveTo(controlPoints.at(index)); |
|
7337 |
path.cubicTo(controlPoints.at(index+1), |
|
7338 |
controlPoints.at(index+2), |
|
7339 |
controlPoints.at(index+3)); |
|
7340 |
||
7341 |
QPainter painter(this); |
|
7342 |
painter.strokePath(path, painter.pen()); |
|
7343 |
\endcode |
|
7344 |
*/ |
|
7345 |
void QPainter::drawCubicBezier(const QPolygon &a, int index) |
|
7346 |
{ |
|
7347 |
Q_D(QPainter); |
|
7348 |
||
7349 |
if (!d->engine) |
|
7350 |
return; |
|
7351 |
||
7352 |
if ((int)a.size() - index < 4) { |
|
7353 |
qWarning("QPainter::drawCubicBezier: Cubic Bezier needs 4 control " |
|
7354 |
"points"); |
|
7355 |
return; |
|
7356 |
} |
|
7357 |
||
7358 |
QPainterPath path; |
|
7359 |
path.moveTo(a.at(index)); |
|
7360 |
path.cubicTo(a.at(index+1), a.at(index+2), a.at(index+3)); |
|
7361 |
strokePath(path, d->state->pen); |
|
7362 |
} |
|
7363 |
#endif |
|
7364 |
||
7365 |
struct QPaintDeviceRedirection |
|
7366 |
{ |
|
7367 |
QPaintDeviceRedirection() : device(0), replacement(0), internalWidgetRedirectionIndex(-1) {} |
|
7368 |
QPaintDeviceRedirection(const QPaintDevice *device, QPaintDevice *replacement, |
|
7369 |
const QPoint& offset, int internalWidgetRedirectionIndex) |
|
7370 |
: device(device), replacement(replacement), offset(offset), |
|
7371 |
internalWidgetRedirectionIndex(internalWidgetRedirectionIndex) { } |
|
7372 |
const QPaintDevice *device; |
|
7373 |
QPaintDevice *replacement; |
|
7374 |
QPoint offset; |
|
7375 |
int internalWidgetRedirectionIndex; |
|
7376 |
bool operator==(const QPaintDevice *pdev) const { return device == pdev; } |
|
7377 |
Q_DUMMY_COMPARISON_OPERATOR(QPaintDeviceRedirection) |
|
7378 |
}; |
|
7379 |
||
7380 |
typedef QList<QPaintDeviceRedirection> QPaintDeviceRedirectionList; |
|
7381 |
Q_GLOBAL_STATIC(QPaintDeviceRedirectionList, globalRedirections) |
|
7382 |
Q_GLOBAL_STATIC(QMutex, globalRedirectionsMutex) |
|
7383 |
||
7384 |
/*! |
|
7385 |
\threadsafe |
|
7386 |
||
7387 |
Redirects all paint commands for the given paint \a device, to the |
|
7388 |
\a replacement device. The optional point \a offset defines an |
|
7389 |
offset within the source device. |
|
7390 |
||
7391 |
The redirection will not be effective until the begin() function |
|
7392 |
has been called; make sure to call end() for the given \a |
|
7393 |
device's painter (if any) before redirecting. Call |
|
7394 |
restoreRedirected() to restore the previous redirection. |
|
7395 |
||
7396 |
In general, you'll probably find that calling |
|
7397 |
QPixmap::grabWidget() or QPixmap::grabWindow() is an easier |
|
7398 |
solution. |
|
7399 |
||
7400 |
\sa redirected(), restoreRedirected() |
|
7401 |
*/ |
|
7402 |
void QPainter::setRedirected(const QPaintDevice *device, |
|
7403 |
QPaintDevice *replacement, |
|
7404 |
const QPoint &offset) |
|
7405 |
{ |
|
7406 |
Q_ASSERT(device != 0); |
|
7407 |
||
7408 |
bool hadInternalWidgetRedirection = false; |
|
7409 |
if (device->devType() == QInternal::Widget) { |
|
7410 |
const QWidgetPrivate *widgetPrivate = static_cast<const QWidget *>(device)->d_func(); |
|
7411 |
// This is the case when the widget is in a paint event. |
|
7412 |
if (widgetPrivate->redirectDev) { |
|
7413 |
// Remove internal redirection and put it back into the global redirection list. |
|
7414 |
QPoint oldOffset; |
|
7415 |
QPaintDevice *oldReplacement = widgetPrivate->redirected(&oldOffset); |
|
7416 |
const_cast<QWidgetPrivate *>(widgetPrivate)->restoreRedirected(); |
|
7417 |
setRedirected(device, oldReplacement, oldOffset); |
|
7418 |
hadInternalWidgetRedirection = true; |
|
7419 |
} |
|
7420 |
} |
|
7421 |
||
7422 |
QPoint roffset; |
|
7423 |
QPaintDevice *rdev = redirected(replacement, &roffset); |
|
7424 |
||
7425 |
QMutexLocker locker(globalRedirectionsMutex()); |
|
7426 |
QPaintDeviceRedirectionList *redirections = globalRedirections(); |
|
7427 |
Q_ASSERT(redirections != 0); |
|
7428 |
*redirections += QPaintDeviceRedirection(device, rdev ? rdev : replacement, offset + roffset, |
|
7429 |
hadInternalWidgetRedirection ? redirections->size() - 1 : -1); |
|
7430 |
} |
|
7431 |
||
7432 |
/*! |
|
7433 |
\threadsafe |
|
7434 |
||
7435 |
Restores the previous redirection for the given \a device after a |
|
7436 |
call to setRedirected(). |
|
7437 |
||
7438 |
\sa redirected() |
|
7439 |
*/ |
|
7440 |
void QPainter::restoreRedirected(const QPaintDevice *device) |
|
7441 |
{ |
|
7442 |
Q_ASSERT(device != 0); |
|
7443 |
QMutexLocker locker(globalRedirectionsMutex()); |
|
7444 |
QPaintDeviceRedirectionList *redirections = globalRedirections(); |
|
7445 |
Q_ASSERT(redirections != 0); |
|
7446 |
for (int i = redirections->size()-1; i >= 0; --i) { |
|
7447 |
if (redirections->at(i) == device) { |
|
7448 |
const int internalWidgetRedirectionIndex = redirections->at(i).internalWidgetRedirectionIndex; |
|
7449 |
redirections->removeAt(i); |
|
7450 |
// Restore the internal widget redirection, i.e. remove it from the global |
|
7451 |
// redirection list and put it back into QWidgetPrivate. The index is only set when |
|
7452 |
// someone call QPainter::setRedirected in a widget's paint event and we internally |
|
7453 |
// have a redirection set (typically set in QWidgetPrivate::drawWidget). |
|
7454 |
if (internalWidgetRedirectionIndex >= 0) { |
|
7455 |
Q_ASSERT(internalWidgetRedirectionIndex < redirections->size()); |
|
7456 |
const QPaintDeviceRedirection &redirectionDevice = redirections->at(internalWidgetRedirectionIndex); |
|
7457 |
QWidget *widget = static_cast<QWidget *>(const_cast<QPaintDevice *>(device)); |
|
7458 |
widget->d_func()->setRedirected(redirectionDevice.replacement, redirectionDevice.offset); |
|
7459 |
redirections->removeAt(internalWidgetRedirectionIndex); |
|
7460 |
} |
|
7461 |
return; |
|
7462 |
} |
|
7463 |
} |
|
7464 |
} |
|
7465 |
||
7466 |
/*! |
|
7467 |
\threadsafe |
|
7468 |
||
7469 |
Returns the replacement for given \a device. The optional out |
|
7470 |
parameter \a offset returns the offset within the replaced device. |
|
7471 |
||
7472 |
\sa setRedirected(), restoreRedirected() |
|
7473 |
*/ |
|
7474 |
QPaintDevice *QPainter::redirected(const QPaintDevice *device, QPoint *offset) |
|
7475 |
{ |
|
7476 |
Q_ASSERT(device != 0); |
|
7477 |
||
7478 |
if (device->devType() == QInternal::Widget) { |
|
7479 |
const QWidgetPrivate *widgetPrivate = static_cast<const QWidget *>(device)->d_func(); |
|
7480 |
if (widgetPrivate->redirectDev) |
|
7481 |
return widgetPrivate->redirected(offset); |
|
7482 |
} |
|
7483 |
||
7484 |
QMutexLocker locker(globalRedirectionsMutex()); |
|
7485 |
QPaintDeviceRedirectionList *redirections = globalRedirections(); |
|
7486 |
Q_ASSERT(redirections != 0); |
|
7487 |
for (int i = redirections->size()-1; i >= 0; --i) |
|
7488 |
if (redirections->at(i) == device) { |
|
7489 |
if (offset) |
|
7490 |
*offset = redirections->at(i).offset; |
|
7491 |
return redirections->at(i).replacement; |
|
7492 |
} |
|
7493 |
if (offset) |
|
7494 |
*offset = QPoint(0, 0); |
|
7495 |
return 0; |
|
7496 |
} |
|
7497 |
||
7498 |
||
7499 |
void qt_painter_removePaintDevice(QPaintDevice *dev) |
|
7500 |
{ |
|
7501 |
QMutex *mutex = 0; |
|
7502 |
QT_TRY { |
|
7503 |
mutex = globalRedirectionsMutex(); |
|
7504 |
} QT_CATCH(...) { |
|
7505 |
// ignore the missing mutex, since we could be called from |
|
7506 |
// a destructor, and destructors shall not throw |
|
7507 |
} |
|
7508 |
QMutexLocker locker(mutex); |
|
7509 |
QPaintDeviceRedirectionList *redirections = 0; |
|
7510 |
QT_TRY { |
|
7511 |
redirections = globalRedirections(); |
|
7512 |
} QT_CATCH(...) { |
|
7513 |
// do nothing - code below is safe with redirections being 0. |
|
7514 |
} |
|
7515 |
if (redirections) { |
|
7516 |
for (int i = 0; i < redirections->size(); ) { |
|
7517 |
if(redirections->at(i) == dev || redirections->at(i).replacement == dev) |
|
7518 |
redirections->removeAt(i); |
|
7519 |
else |
|
7520 |
++i; |
|
7521 |
} |
|
7522 |
} |
|
7523 |
} |
|
7524 |
||
7525 |
void qt_format_text(const QFont &fnt, const QRectF &_r, |
|
7526 |
int tf, const QString& str, QRectF *brect, |
|
7527 |
int tabstops, int *ta, int tabarraylen, |
|
7528 |
QPainter *painter) |
|
7529 |
{ |
|
7530 |
qt_format_text(fnt, _r, |
|
7531 |
tf, 0, str, brect, |
|
7532 |
tabstops, ta, tabarraylen, |
|
7533 |
painter); |
|
7534 |
} |
|
7535 |
void qt_format_text(const QFont &fnt, const QRectF &_r, |
|
7536 |
int tf, const QTextOption *option, const QString& str, QRectF *brect, |
|
7537 |
int tabstops, int *, int tabarraylen, |
|
7538 |
QPainter *painter) |
|
7539 |
{ |
|
7540 |
||
7541 |
Q_ASSERT( !((tf & ~Qt::TextDontPrint)!=0 && option!=0) ); // we either have an option or flags |
|
7542 |
||
7543 |
if (option) { |
|
7544 |
tf |= option->alignment(); |
|
7545 |
if (option->wrapMode() != QTextOption::NoWrap) |
|
7546 |
tf |= Qt::TextWordWrap; |
|
7547 |
||
7548 |
if (option->flags() & QTextOption::IncludeTrailingSpaces) |
|
7549 |
tf |= Qt::TextIncludeTrailingSpaces; |
|
7550 |
||
7551 |
if (option->tabStop() >= 0 || !option->tabArray().isEmpty()) |
|
7552 |
tf |= Qt::TextExpandTabs; |
|
7553 |
} |
|
7554 |
||
7555 |
// we need to copy r here to protect against the case (&r == brect). |
|
7556 |
QRectF r(_r); |
|
7557 |
||
7558 |
bool dontclip = (tf & Qt::TextDontClip); |
|
7559 |
bool wordwrap = (tf & Qt::TextWordWrap) || (tf & Qt::TextWrapAnywhere); |
|
7560 |
bool singleline = (tf & Qt::TextSingleLine); |
|
7561 |
bool showmnemonic = (tf & Qt::TextShowMnemonic); |
|
7562 |
bool hidemnmemonic = (tf & Qt::TextHideMnemonic); |
|
7563 |
||
7564 |
Qt::LayoutDirection layout_direction; |
|
7565 |
if (tf & Qt::TextForceLeftToRight) |
|
7566 |
layout_direction = Qt::LeftToRight; |
|
7567 |
else if (tf & Qt::TextForceRightToLeft) |
|
7568 |
layout_direction = Qt::RightToLeft; |
|
7569 |
else if (option) |
|
7570 |
layout_direction = option->textDirection(); |
|
7571 |
else if (painter) |
|
7572 |
layout_direction = painter->layoutDirection(); |
|
7573 |
else |
|
7574 |
layout_direction = Qt::LeftToRight; |
|
7575 |
||
7576 |
tf = QStyle::visualAlignment(layout_direction, QFlag(tf)); |
|
7577 |
||
7578 |
bool isRightToLeft = layout_direction == Qt::RightToLeft; |
|
7579 |
bool expandtabs = ((tf & Qt::TextExpandTabs) && |
|
7580 |
(((tf & Qt::AlignLeft) && !isRightToLeft) || |
|
7581 |
((tf & Qt::AlignRight) && isRightToLeft))); |
|
7582 |
||
7583 |
if (!painter) |
|
7584 |
tf |= Qt::TextDontPrint; |
|
7585 |
||
7586 |
uint maxUnderlines = 0; |
|
7587 |
int numUnderlines = 0; |
|
7588 |
QVarLengthArray<int, 32> underlinePositions(1); |
|
7589 |
||
7590 |
QFontMetricsF fm(fnt); |
|
7591 |
QString text = str; |
|
7592 |
int offset = 0; |
|
7593 |
start_lengthVariant: |
|
7594 |
bool hasMoreLengthVariants = false; |
|
7595 |
// compatible behaviour to the old implementation. Replace |
|
7596 |
// tabs by spaces |
|
7597 |
int old_offset = offset; |
|
7598 |
for (; offset < text.length(); offset++) { |
|
7599 |
QChar chr = text.at(offset); |
|
7600 |
if (chr == QLatin1Char('\r') || (singleline && chr == QLatin1Char('\n'))) { |
|
7601 |
text[offset] = QLatin1Char(' '); |
|
7602 |
} else if (chr == QLatin1Char('\n')) { |
|
7603 |
text[offset] = QChar::LineSeparator; |
|
7604 |
} else if (chr == QLatin1Char('&')) { |
|
7605 |
++maxUnderlines; |
|
7606 |
} else if (chr == QLatin1Char('\t')) { |
|
7607 |
if (!expandtabs) { |
|
7608 |
text[offset] = QLatin1Char(' '); |
|
7609 |
} else if (!tabarraylen && !tabstops) { |
|
7610 |
tabstops = qRound(fm.width(QLatin1Char('x'))*8); |
|
7611 |
} |
|
7612 |
} else if (chr == QChar(ushort(0x9c))) { |
|
7613 |
// string with multiple length variants |
|
7614 |
hasMoreLengthVariants = true; |
|
7615 |
break; |
|
7616 |
} |
|
7617 |
} |
|
7618 |
||
7619 |
int length = offset - old_offset; |
|
7620 |
if ((hidemnmemonic || showmnemonic) && maxUnderlines > 0) { |
|
7621 |
underlinePositions.resize(maxUnderlines + 1); |
|
7622 |
||
7623 |
QChar *cout = text.data() + old_offset; |
|
7624 |
QChar *cin = cout; |
|
7625 |
int l = length; |
|
7626 |
while (l) { |
|
7627 |
if (*cin == QLatin1Char('&')) { |
|
7628 |
++cin; |
|
7629 |
--length; |
|
7630 |
--l; |
|
7631 |
if (!l) |
|
7632 |
break; |
|
7633 |
if (*cin != QLatin1Char('&') && !hidemnmemonic) |
|
7634 |
underlinePositions[numUnderlines++] = cout - text.data() - old_offset; |
|
7635 |
} |
|
7636 |
*cout = *cin; |
|
7637 |
++cout; |
|
7638 |
++cin; |
|
7639 |
--l; |
|
7640 |
} |
|
7641 |
} |
|
7642 |
||
7643 |
// no need to do extra work for underlines if we don't paint |
|
7644 |
if (tf & Qt::TextDontPrint) |
|
7645 |
numUnderlines = 0; |
|
7646 |
||
7647 |
underlinePositions[numUnderlines] = -1; |
|
7648 |
qreal height = 0; |
|
7649 |
qreal width = 0; |
|
7650 |
||
7651 |
QString finalText = text.mid(old_offset, length); |
|
7652 |
QStackTextEngine engine(finalText, fnt); |
|
7653 |
if (option) { |
|
7654 |
engine.option = *option; |
|
7655 |
} |
|
7656 |
||
7657 |
engine.option.setTextDirection(layout_direction); |
|
7658 |
if (tf & Qt::AlignJustify) |
|
7659 |
engine.option.setAlignment(Qt::AlignJustify); |
|
7660 |
else |
|
7661 |
engine.option.setAlignment(Qt::AlignLeft); // do not do alignment twice |
|
7662 |
||
7663 |
if (!option && (tf & Qt::TextWrapAnywhere)) |
|
7664 |
engine.option.setWrapMode(QTextOption::WrapAnywhere); |
|
7665 |
||
7666 |
if (tf & Qt::TextJustificationForced) |
|
7667 |
engine.forceJustification = true; |
|
7668 |
QTextLayout textLayout(&engine); |
|
7669 |
textLayout.setCacheEnabled(true); |
|
7670 |
textLayout.engine()->underlinePositions = underlinePositions.data(); |
|
7671 |
||
7672 |
if (finalText.isEmpty()) { |
|
7673 |
height = fm.height(); |
|
7674 |
width = 0; |
|
7675 |
tf |= Qt::TextDontPrint; |
|
7676 |
} else { |
|
7677 |
qreal lineWidth = 0x01000000; |
|
7678 |
if (wordwrap || (tf & Qt::TextJustificationForced)) |
|
7679 |
lineWidth = qMax<qreal>(0, r.width()); |
|
7680 |
if(!wordwrap) |
|
7681 |
tf |= Qt::TextIncludeTrailingSpaces; |
|
7682 |
textLayout.engine()->ignoreBidi = bool(tf & Qt::TextDontPrint); |
|
7683 |
textLayout.beginLayout(); |
|
7684 |
||
7685 |
qreal leading = fm.leading(); |
|
7686 |
height = -leading; |
|
7687 |
||
7688 |
while (1) { |
|
7689 |
QTextLine l = textLayout.createLine(); |
|
7690 |
if (!l.isValid()) |
|
7691 |
break; |
|
7692 |
||
7693 |
l.setLineWidth(lineWidth); |
|
7694 |
height += leading; |
|
7695 |
l.setPosition(QPointF(0., height)); |
|
7696 |
height += l.height(); |
|
7697 |
width = qMax(width, l.naturalTextWidth()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7698 |
if (!dontclip && !brect && height >= r.height()) |
0 | 7699 |
break; |
7700 |
} |
|
7701 |
textLayout.endLayout(); |
|
7702 |
} |
|
7703 |
||
7704 |
qreal yoff = 0; |
|
7705 |
qreal xoff = 0; |
|
7706 |
if (tf & Qt::AlignBottom) { |
|
7707 |
yoff = r.height() - height; |
|
7708 |
} else if (tf & Qt::AlignVCenter) { |
|
7709 |
yoff = (r.height() - height)/2; |
|
7710 |
if (painter) { |
|
7711 |
QTransform::TransformationType type = painter->transform().type(); |
|
7712 |
if (type <= QTransform::TxScale) { |
|
7713 |
// do the rounding manually to work around inconsistencies |
|
7714 |
// in the paint engines when drawing on floating point offsets |
|
7715 |
const qreal scale = painter->transform().m22(); |
|
7716 |
if (scale != 0) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7717 |
yoff = -qRound(-yoff * scale) / scale; |
0 | 7718 |
} |
7719 |
} |
|
7720 |
} |
|
7721 |
if (tf & Qt::AlignRight) { |
|
7722 |
xoff = r.width() - width; |
|
7723 |
} else if (tf & Qt::AlignHCenter) { |
|
7724 |
xoff = (r.width() - width)/2; |
|
7725 |
if (painter) { |
|
7726 |
QTransform::TransformationType type = painter->transform().type(); |
|
7727 |
if (type <= QTransform::TxScale) { |
|
7728 |
// do the rounding manually to work around inconsistencies |
|
7729 |
// in the paint engines when drawing on floating point offsets |
|
7730 |
const qreal scale = painter->transform().m11(); |
|
7731 |
if (scale != 0) |
|
7732 |
xoff = qRound(xoff * scale) / scale; |
|
7733 |
} |
|
7734 |
} |
|
7735 |
} |
|
7736 |
QRectF bounds = QRectF(r.x() + xoff, r.y() + yoff, width, height); |
|
7737 |
||
7738 |
if (hasMoreLengthVariants && !(tf & Qt::TextLongestVariant) && !r.contains(bounds)) { |
|
7739 |
offset++; |
|
7740 |
goto start_lengthVariant; |
|
7741 |
} |
|
7742 |
if (brect) |
|
7743 |
*brect = bounds; |
|
7744 |
||
7745 |
if (!(tf & Qt::TextDontPrint)) { |
|
7746 |
bool restore = false; |
|
7747 |
if (!dontclip && !r.contains(bounds)) { |
|
7748 |
restore = true; |
|
7749 |
painter->save(); |
|
7750 |
painter->setClipRect(r, Qt::IntersectClip); |
|
7751 |
} |
|
7752 |
||
7753 |
for (int i = 0; i < textLayout.lineCount(); i++) { |
|
7754 |
QTextLine line = textLayout.lineAt(i); |
|
7755 |
||
7756 |
if (tf & Qt::AlignRight) |
|
7757 |
xoff = r.width() - line.naturalTextWidth(); |
|
7758 |
else if (tf & Qt::AlignHCenter) |
|
7759 |
xoff = (r.width() - line.naturalTextWidth())/2; |
|
7760 |
||
7761 |
line.draw(painter, QPointF(r.x() + xoff + line.x(), r.y() + yoff)); |
|
7762 |
} |
|
7763 |
||
7764 |
if (restore) { |
|
7765 |
painter->restore(); |
|
7766 |
} |
|
7767 |
} |
|
7768 |
} |
|
7769 |
||
7770 |
/*! |
|
7771 |
Sets the layout direction used by the painter when drawing text, |
|
7772 |
to the specified \a direction. |
|
7773 |
||
7774 |
\sa layoutDirection(), drawText(), {QPainter#Settings}{Settings} |
|
7775 |
*/ |
|
7776 |
void QPainter::setLayoutDirection(Qt::LayoutDirection direction) |
|
7777 |
{ |
|
7778 |
Q_D(QPainter); |
|
7779 |
if (d->state) |
|
7780 |
d->state->layoutDirection = direction; |
|
7781 |
} |
|
7782 |
||
7783 |
/*! |
|
7784 |
Returns the layout direction used by the painter when drawing text. |
|
7785 |
||
7786 |
\sa setLayoutDirection(), drawText(), {QPainter#Settings}{Settings} |
|
7787 |
*/ |
|
7788 |
Qt::LayoutDirection QPainter::layoutDirection() const |
|
7789 |
{ |
|
7790 |
Q_D(const QPainter); |
|
7791 |
return d->state ? d->state->layoutDirection : Qt::LeftToRight; |
|
7792 |
} |
|
7793 |
||
7794 |
QPainterState::QPainterState(const QPainterState *s) |
|
7795 |
: brushOrigin(s->brushOrigin), font(s->font), deviceFont(s->deviceFont), |
|
7796 |
pen(s->pen), brush(s->brush), bgBrush(s->bgBrush), |
|
7797 |
clipRegion(s->clipRegion), clipPath(s->clipPath), |
|
7798 |
clipOperation(s->clipOperation), |
|
7799 |
renderHints(s->renderHints), clipInfo(s->clipInfo), |
|
7800 |
worldMatrix(s->worldMatrix), matrix(s->matrix), redirectionMatrix(s->redirectionMatrix), |
|
7801 |
wx(s->wx), wy(s->wy), ww(s->ww), wh(s->wh), |
|
7802 |
vx(s->vx), vy(s->vy), vw(s->vw), vh(s->vh), |
|
7803 |
opacity(s->opacity), WxF(s->WxF), VxF(s->VxF), |
|
7804 |
clipEnabled(s->clipEnabled), bgMode(s->bgMode), painter(s->painter), |
|
7805 |
layoutDirection(s->layoutDirection), |
|
7806 |
composition_mode(s->composition_mode), |
|
7807 |
emulationSpecifier(s->emulationSpecifier), changeFlags(0) |
|
7808 |
{ |
|
7809 |
dirtyFlags = s->dirtyFlags; |
|
7810 |
} |
|
7811 |
||
7812 |
QPainterState::QPainterState() |
|
7813 |
: brushOrigin(0, 0), bgBrush(Qt::white), clipOperation(Qt::NoClip), |
|
7814 |
renderHints(0), |
|
7815 |
wx(0), wy(0), ww(0), wh(0), vx(0), vy(0), vw(0), vh(0), |
|
7816 |
opacity(1), WxF(false), VxF(false), clipEnabled(true), |
|
7817 |
bgMode(Qt::TransparentMode), painter(0), |
|
7818 |
layoutDirection(QApplication::layoutDirection()), |
|
7819 |
composition_mode(QPainter::CompositionMode_SourceOver), |
|
7820 |
emulationSpecifier(0), changeFlags(0) |
|
7821 |
{ |
|
7822 |
dirtyFlags = 0; |
|
7823 |
} |
|
7824 |
||
7825 |
QPainterState::~QPainterState() |
|
7826 |
{ |
|
7827 |
} |
|
7828 |
||
7829 |
void QPainterState::init(QPainter *p) { |
|
7830 |
bgBrush = Qt::white; |
|
7831 |
bgMode = Qt::TransparentMode; |
|
7832 |
WxF = false; |
|
7833 |
VxF = false; |
|
7834 |
clipEnabled = true; |
|
7835 |
wx = wy = ww = wh = 0; |
|
7836 |
vx = vy = vw = vh = 0; |
|
7837 |
painter = p; |
|
7838 |
pen = QPen(); |
|
7839 |
brushOrigin = QPointF(0, 0); |
|
7840 |
brush = QBrush(); |
|
7841 |
font = deviceFont = QFont(); |
|
7842 |
clipRegion = QRegion(); |
|
7843 |
clipPath = QPainterPath(); |
|
7844 |
clipOperation = Qt::NoClip; |
|
7845 |
clipInfo.clear(); |
|
7846 |
worldMatrix.reset(); |
|
7847 |
matrix.reset(); |
|
7848 |
layoutDirection = QApplication::layoutDirection(); |
|
7849 |
composition_mode = QPainter::CompositionMode_SourceOver; |
|
7850 |
emulationSpecifier = 0; |
|
7851 |
dirtyFlags = 0; |
|
7852 |
changeFlags = 0; |
|
7853 |
renderHints = 0; |
|
7854 |
opacity = 1; |
|
7855 |
} |
|
7856 |
||
7857 |
#ifdef QT3_SUPPORT |
|
7858 |
static void bitBlt_helper(QPaintDevice *dst, const QPoint &dp, |
|
7859 |
const QPaintDevice *src, const QRect &sr, bool) |
|
7860 |
{ |
|
7861 |
Q_ASSERT(dst); |
|
7862 |
Q_ASSERT(src); |
|
7863 |
||
7864 |
if (src->devType() == QInternal::Pixmap) { |
|
7865 |
const QPixmap *pixmap = static_cast<const QPixmap *>(src); |
|
7866 |
QPainter pt(dst); |
|
7867 |
pt.drawPixmap(dp, *pixmap, sr); |
|
7868 |
||
7869 |
} else { |
|
7870 |
qWarning("QPainter: bitBlt only works when source is of type pixmap"); |
|
7871 |
} |
|
7872 |
} |
|
7873 |
||
7874 |
void bitBlt(QPaintDevice *dst, int dx, int dy, |
|
7875 |
const QPaintDevice *src, int sx, int sy, int sw, int sh, |
|
7876 |
bool ignoreMask ) |
|
7877 |
{ |
|
7878 |
bitBlt_helper(dst, QPoint(dx, dy), src, QRect(sx, sy, sw, sh), ignoreMask); |
|
7879 |
} |
|
7880 |
||
7881 |
void bitBlt(QPaintDevice *dst, const QPoint &dp, const QPaintDevice *src, const QRect &sr, bool ignoreMask) |
|
7882 |
{ |
|
7883 |
bitBlt_helper(dst, dp, src, sr, ignoreMask); |
|
7884 |
} |
|
7885 |
||
7886 |
void bitBlt(QPaintDevice *dst, int dx, int dy, |
|
7887 |
const QImage *src, int sx, int sy, int sw, int sh, int fl) |
|
7888 |
{ |
|
7889 |
Qt::ImageConversionFlags flags(fl); |
|
7890 |
QPixmap srcPixmap = QPixmap::fromImage(*src, flags); |
|
7891 |
bitBlt_helper(dst, QPoint(dx, dy), &srcPixmap, QRect(sx, sy, sw, sh), false); |
|
7892 |
} |
|
7893 |
||
7894 |
#endif // QT3_SUPPORT |
|
7895 |
||
7896 |
/*! |
|
7897 |
\fn void QPainter::setBackgroundColor(const QColor &color) |
|
7898 |
||
7899 |
Use setBackground() instead. |
|
7900 |
*/ |
|
7901 |
||
7902 |
/*! |
|
7903 |
\fn const QColor &QPainter::backgroundColor() const |
|
7904 |
||
7905 |
Use background() and QBrush::color() instead. |
|
7906 |
||
7907 |
\oldcode |
|
7908 |
QColor myColor = backgroundColor(); |
|
7909 |
\newcode |
|
7910 |
QColor myColor = background().color(); |
|
7911 |
\endcode |
|
7912 |
||
7913 |
Note that the background can be a complex brush such as a texture |
|
7914 |
or a gradient. |
|
7915 |
*/ |
|
7916 |
||
7917 |
/*! |
|
7918 |
\fn void QPainter::drawText(int x, int y, const QString &text, int pos, int length) |
|
7919 |
\compat |
|
7920 |
||
7921 |
Use drawText() combined with QString::mid() instead. |
|
7922 |
||
7923 |
\oldcode |
|
7924 |
QPainter painter(this); |
|
7925 |
painter.drawText(x, y, text, pos, length); |
|
7926 |
\newcode |
|
7927 |
QPainter painter(this); |
|
7928 |
painter.drawText(x, y, text.mid(pos, length)); |
|
7929 |
\endcode |
|
7930 |
*/ |
|
7931 |
||
7932 |
/*! |
|
7933 |
\fn void QPainter::drawText(const QPoint &point, const QString &text, int pos, int length) |
|
7934 |
\compat |
|
7935 |
||
7936 |
Use drawText() combined with QString::mid() instead. |
|
7937 |
||
7938 |
\oldcode |
|
7939 |
QPainter painter(this); |
|
7940 |
painter.drawText(point, text, pos, length); |
|
7941 |
\newcode |
|
7942 |
QPainter painter(this); |
|
7943 |
painter.drawText(point, text.mid(pos, length)); |
|
7944 |
\endcode |
|
7945 |
*/ |
|
7946 |
||
7947 |
/*! |
|
7948 |
\fn void QPainter::drawText(int x, int y, const QString &text, int length) |
|
7949 |
\compat |
|
7950 |
||
7951 |
Use drawText() combined with QString::left() instead. |
|
7952 |
||
7953 |
\oldcode |
|
7954 |
QPainter painter(this); |
|
7955 |
painter.drawText(x, y, text, length); |
|
7956 |
\newcode |
|
7957 |
QPainter painter(this); |
|
7958 |
painter.drawText(x, y, text.left(length)); |
|
7959 |
\endcode |
|
7960 |
*/ |
|
7961 |
||
7962 |
/*! |
|
7963 |
\fn void QPainter::drawText(const QPoint &point, const QString &text, int length) |
|
7964 |
\compat |
|
7965 |
||
7966 |
Use drawText() combined with QString::left() instead. |
|
7967 |
||
7968 |
\oldcode |
|
7969 |
QPainter painter(this); |
|
7970 |
painter.drawText(point, text, length); |
|
7971 |
\newcode |
|
7972 |
QPainter painter(this); |
|
7973 |
painter.drawText(point, text.left(length)); |
|
7974 |
\endcode |
|
7975 |
*/ |
|
7976 |
||
7977 |
/*! |
|
7978 |
\fn bool QPainter::begin(QPaintDevice *device, const QWidget *init) |
|
7979 |
\compat |
|
7980 |
||
7981 |
Use begin() instead. |
|
7982 |
||
7983 |
If the paint \a device is a QWidget, QPainter is initialized after |
|
7984 |
the widget's settings automatically. Otherwise, you must call the |
|
7985 |
initFrom() function to initialize the painters pen, background and |
|
7986 |
font to the same as any given widget. |
|
7987 |
||
7988 |
\oldcode |
|
7989 |
QPainter painter(this); |
|
7990 |
painter.begin(device, init); |
|
7991 |
\newcode |
|
7992 |
QPainter painter(this); |
|
7993 |
painter.begin(device); |
|
7994 |
painter.initFrom(init); |
|
7995 |
\endcode |
|
7996 |
*/ |
|
7997 |
||
7998 |
/*! |
|
7999 |
\fn void QPainter::drawImage(const QRectF &target, const QImage &image, const QRectF &source, |
|
8000 |
Qt::ImageConversionFlags flags) |
|
8001 |
||
8002 |
Draws the rectangular portion \a source of the given \a image |
|
8003 |
into the \a target rectangle in the paint device. |
|
8004 |
||
8005 |
\note The image is scaled to fit the rectangle, if both the image and rectangle size disagree. |
|
8006 |
||
8007 |
If the image needs to be modified to fit in a lower-resolution |
|
8008 |
result (e.g. converting from 32-bit to 8-bit), use the \a flags to |
|
8009 |
specify how you would prefer this to happen. |
|
8010 |
||
8011 |
\table 100% |
|
8012 |
\row |
|
8013 |
\o |
|
8014 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 20 |
|
8015 |
\endtable |
|
8016 |
||
8017 |
\sa drawPixmap() |
|
8018 |
*/ |
|
8019 |
||
8020 |
/*! |
|
8021 |
\fn void QPainter::drawImage(const QRect &target, const QImage &image, const QRect &source, |
|
8022 |
Qt::ImageConversionFlags flags) |
|
8023 |
\overload |
|
8024 |
||
8025 |
Draws the rectangular portion \a source of the given \a image |
|
8026 |
into the \a target rectangle in the paint device. |
|
8027 |
||
8028 |
\note The image is scaled to fit the rectangle, if both the image and rectangle size disagree. |
|
8029 |
*/ |
|
8030 |
||
8031 |
/*! |
|
8032 |
\fn void QPainter::drawImage(const QPointF &point, const QImage &image) |
|
8033 |
||
8034 |
\overload |
|
8035 |
||
8036 |
Draws the given \a image at the given \a point. |
|
8037 |
*/ |
|
8038 |
||
8039 |
/*! |
|
8040 |
\fn void QPainter::drawImage(const QPoint &point, const QImage &image) |
|
8041 |
||
8042 |
\overload |
|
8043 |
||
8044 |
Draws the given \a image at the given \a point. |
|
8045 |
*/ |
|
8046 |
||
8047 |
/*! |
|
8048 |
\fn void QPainter::drawImage(const QPointF &point, const QImage &image, const QRectF &source, |
|
8049 |
Qt::ImageConversionFlags flags = 0) |
|
8050 |
||
8051 |
\overload |
|
8052 |
||
8053 |
Draws the rectangular portion \a source of the given \a image with |
|
8054 |
its origin at the given \a point. |
|
8055 |
*/ |
|
8056 |
||
8057 |
/*! |
|
8058 |
\fn void QPainter::drawImage(const QPoint &point, const QImage &image, const QRect &source, |
|
8059 |
Qt::ImageConversionFlags flags = 0) |
|
8060 |
\overload |
|
8061 |
||
8062 |
Draws the rectangular portion \a source of the given \a image with |
|
8063 |
its origin at the given \a point. |
|
8064 |
*/ |
|
8065 |
||
8066 |
/*! |
|
8067 |
\fn void QPainter::drawImage(const QRectF &rectangle, const QImage &image) |
|
8068 |
||
8069 |
\overload |
|
8070 |
||
8071 |
Draws the given \a image into the given \a rectangle. |
|
8072 |
||
8073 |
\note The image is scaled to fit the rectangle, if both the image and rectangle size disagree. |
|
8074 |
*/ |
|
8075 |
||
8076 |
/*! |
|
8077 |
\fn void QPainter::drawImage(const QRect &rectangle, const QImage &image) |
|
8078 |
||
8079 |
\overload |
|
8080 |
||
8081 |
Draws the given \a image into the given \a rectangle. |
|
8082 |
||
8083 |
\note The image is scaled to fit the rectangle, if both the image and rectangle size disagree. |
|
8084 |
*/ |
|
8085 |
||
8086 |
/*! |
|
8087 |
\fn void QPainter::drawImage(int x, int y, const QImage &image, |
|
8088 |
int sx, int sy, int sw, int sh, |
|
8089 |
Qt::ImageConversionFlags flags) |
|
8090 |
\overload |
|
8091 |
||
8092 |
Draws an image at (\a{x}, \a{y}) by copying a part of \a image into |
|
8093 |
the paint device. |
|
8094 |
||
8095 |
(\a{x}, \a{y}) specifies the top-left point in the paint device that is |
|
8096 |
to be drawn onto. (\a{sx}, \a{sy}) specifies the top-left point in \a |
|
8097 |
image that is to be drawn. The default is (0, 0). |
|
8098 |
||
8099 |
(\a{sw}, \a{sh}) specifies the size of the image that is to be drawn. |
|
8100 |
The default, (0, 0) (and negative) means all the way to the |
|
8101 |
bottom-right of the image. |
|
8102 |
*/ |
|
8103 |
||
8104 |
/*! |
|
8105 |
\fn void QPainter::redirect(QPaintDevice *pdev, QPaintDevice *replacement) |
|
8106 |
||
8107 |
Use setRedirected() instead. |
|
8108 |
*/ |
|
8109 |
||
8110 |
/*! |
|
8111 |
\fn QPaintDevice *QPainter::redirect(QPaintDevice *pdev) |
|
8112 |
||
8113 |
Use redirected() instead. |
|
8114 |
*/ |
|
8115 |
||
8116 |
/*! |
|
8117 |
\fn QRect QPainter::boundingRect(const QRect &rectangle, int flags, |
|
8118 |
const QString &text, int length) |
|
8119 |
\compat |
|
8120 |
||
8121 |
Returns the bounding rectangle for the given \a length of the \a |
|
8122 |
text constrained by the provided \a rectangle. |
|
8123 |
||
8124 |
Use boundingRect() combined with QString::left() instead. |
|
8125 |
||
8126 |
\oldcode |
|
8127 |
QRect rectangle = boundingRect(rect, flags, text, length); |
|
8128 |
\newcode |
|
8129 |
QRect rectangle = boundingRect(rect, flags, text.left(length)); |
|
8130 |
\endcode |
|
8131 |
*/ |
|
8132 |
||
8133 |
/*! |
|
8134 |
\fn void QPainter::drawText(const QRect &rectangle, int flags, const QString &text, |
|
8135 |
int length, QRect *br) |
|
8136 |
\compat |
|
8137 |
||
8138 |
Use drawText() combined with QString::left() instead. |
|
8139 |
||
8140 |
\oldcode |
|
8141 |
QPainter painter(this); |
|
8142 |
painter.drawText(rectangle, flags, text, length, br ); |
|
8143 |
\newcode |
|
8144 |
QPainter painter(this); |
|
8145 |
painter.drawText(rectangle, flags, text.left(length), br ); |
|
8146 |
\endcode |
|
8147 |
*/ |
|
8148 |
||
8149 |
/*! |
|
8150 |
\fn QRect QPainter::boundingRect(int x, int y, int width, int height, int flags, |
|
8151 |
const QString &text, int length); |
|
8152 |
||
8153 |
\compat |
|
8154 |
||
8155 |
Returns the bounding rectangle for the given \a length of the \a |
|
8156 |
text constrained by the rectangle that begins at point (\a{x}, |
|
8157 |
\a{y}) with the given \a width and \a height. |
|
8158 |
||
8159 |
Use boundingRect() combined with QString::left() instead. |
|
8160 |
||
8161 |
\oldcode |
|
8162 |
QRect rectangle = boundingRect(x, y, width, height, flags, text, length); |
|
8163 |
\newcode |
|
8164 |
QRect rectangle = boundingRect(x, y, width, height, flags, text.left(length)); |
|
8165 |
\endcode |
|
8166 |
*/ |
|
8167 |
||
8168 |
/*! |
|
8169 |
\fn void QPainter::drawText(int x, int y, int width, int height, int flags, |
|
8170 |
const QString &text, int length, QRect *br) |
|
8171 |
||
8172 |
\compat |
|
8173 |
||
8174 |
Use drawText() combined with QString::left() instead. |
|
8175 |
||
8176 |
\oldcode |
|
8177 |
QPainter painter(this); |
|
8178 |
painter.drawText(x, y, width, height, flags, text, length, br ); |
|
8179 |
\newcode |
|
8180 |
QPainter painter(this); |
|
8181 |
painter.drawText(x, y, width, height, flags, text.left(length), br ); |
|
8182 |
\endcode |
|
8183 |
*/ |
|
8184 |
||
8185 |
||
8186 |
/*! |
|
8187 |
\class QPaintEngineState |
|
8188 |
\since 4.1 |
|
8189 |
||
8190 |
\brief The QPaintEngineState class provides information about the |
|
8191 |
active paint engine's current state. |
|
8192 |
\reentrant |
|
8193 |
||
8194 |
QPaintEngineState records which properties that have changed since |
|
8195 |
the last time the paint engine was updated, as well as their |
|
8196 |
current value. |
|
8197 |
||
8198 |
Which properties that have changed can at any time be retrieved |
|
8199 |
using the state() function. This function returns an instance of |
|
8200 |
the QPaintEngine::DirtyFlags type which stores an OR combination |
|
8201 |
of QPaintEngine::DirtyFlag values. The QPaintEngine::DirtyFlag |
|
8202 |
enum defines whether a property has changed since the last update |
|
8203 |
or not. |
|
8204 |
||
8205 |
If a property is marked with a dirty flag, its current value can |
|
8206 |
be retrieved using the corresponding get function: |
|
8207 |
||
8208 |
\target GetFunction |
|
8209 |
||
8210 |
\table |
|
8211 |
\header \o Property Flag \o Current Property Value |
|
8212 |
\row \o QPaintEngine::DirtyBackground \o backgroundBrush() |
|
8213 |
\row \o QPaintEngine::DirtyBackgroundMode \o backgroundMode() |
|
8214 |
\row \o QPaintEngine::DirtyBrush \o brush() |
|
8215 |
\row \o QPaintEngine::DirtyBrushOrigin \o brushOrigin() |
|
8216 |
\row \o QPaintEngine::DirtyClipRegion \e or QPaintEngine::DirtyClipPath |
|
8217 |
\o clipOperation() |
|
8218 |
\row \o QPaintEngine::DirtyClipPath \o clipPath() |
|
8219 |
\row \o QPaintEngine::DirtyClipRegion \o clipRegion() |
|
8220 |
\row \o QPaintEngine::DirtyCompositionMode \o compositionMode() |
|
8221 |
\row \o QPaintEngine::DirtyFont \o font() |
|
8222 |
\row \o QPaintEngine::DirtyTransform \o transform() |
|
8223 |
\row \o QPaintEngine::DirtyClipEnabled \o isClipEnabled() |
|
8224 |
\row \o QPaintEngine::DirtyPen \o pen() |
|
8225 |
\row \o QPaintEngine::DirtyHints \o renderHints() |
|
8226 |
\endtable |
|
8227 |
||
8228 |
The QPaintEngineState class also provide the painter() function |
|
8229 |
which returns a pointer to the painter that is currently updating |
|
8230 |
the paint engine. |
|
8231 |
||
8232 |
An instance of this class, representing the current state of the |
|
8233 |
active paint engine, is passed as argument to the |
|
8234 |
QPaintEngine::updateState() function. The only situation in which |
|
8235 |
you will have to use this class directly is when implementing your |
|
8236 |
own paint engine. |
|
8237 |
||
8238 |
\sa QPaintEngine |
|
8239 |
*/ |
|
8240 |
||
8241 |
||
8242 |
/*! |
|
8243 |
\fn QPaintEngine::DirtyFlags QPaintEngineState::state() const |
|
8244 |
||
8245 |
Returns a combination of flags identifying the set of properties |
|
8246 |
that need to be updated when updating the paint engine's state |
|
8247 |
(i.e. during a call to the QPaintEngine::updateState() function). |
|
8248 |
||
8249 |
\sa QPaintEngine::updateState() |
|
8250 |
*/ |
|
8251 |
||
8252 |
||
8253 |
/*! |
|
8254 |
Returns the pen in the current paint engine state. |
|
8255 |
||
8256 |
This variable should only be used when the state() returns a |
|
8257 |
combination which includes the QPaintEngine::DirtyPen flag. |
|
8258 |
||
8259 |
\sa state(), QPaintEngine::updateState() |
|
8260 |
*/ |
|
8261 |
||
8262 |
QPen QPaintEngineState::pen() const |
|
8263 |
{ |
|
8264 |
return static_cast<const QPainterState *>(this)->pen; |
|
8265 |
} |
|
8266 |
||
8267 |
/*! |
|
8268 |
Returns the brush in the current paint engine state. |
|
8269 |
||
8270 |
This variable should only be used when the state() returns a |
|
8271 |
combination which includes the QPaintEngine::DirtyBrush flag. |
|
8272 |
||
8273 |
\sa state(), QPaintEngine::updateState() |
|
8274 |
*/ |
|
8275 |
||
8276 |
QBrush QPaintEngineState::brush() const |
|
8277 |
{ |
|
8278 |
return static_cast<const QPainterState *>(this)->brush; |
|
8279 |
} |
|
8280 |
||
8281 |
/*! |
|
8282 |
Returns the brush origin in the current paint engine state. |
|
8283 |
||
8284 |
This variable should only be used when the state() returns a |
|
8285 |
combination which includes the QPaintEngine::DirtyBrushOrigin flag. |
|
8286 |
||
8287 |
\sa state(), QPaintEngine::updateState() |
|
8288 |
*/ |
|
8289 |
||
8290 |
QPointF QPaintEngineState::brushOrigin() const |
|
8291 |
{ |
|
8292 |
return static_cast<const QPainterState *>(this)->brushOrigin; |
|
8293 |
} |
|
8294 |
||
8295 |
/*! |
|
8296 |
Returns the background brush in the current paint engine state. |
|
8297 |
||
8298 |
This variable should only be used when the state() returns a |
|
8299 |
combination which includes the QPaintEngine::DirtyBackground flag. |
|
8300 |
||
8301 |
\sa state(), QPaintEngine::updateState() |
|
8302 |
*/ |
|
8303 |
||
8304 |
QBrush QPaintEngineState::backgroundBrush() const |
|
8305 |
{ |
|
8306 |
return static_cast<const QPainterState *>(this)->bgBrush; |
|
8307 |
} |
|
8308 |
||
8309 |
/*! |
|
8310 |
Returns the background mode in the current paint engine |
|
8311 |
state. |
|
8312 |
||
8313 |
This variable should only be used when the state() returns a |
|
8314 |
combination which includes the QPaintEngine::DirtyBackgroundMode flag. |
|
8315 |
||
8316 |
\sa state(), QPaintEngine::updateState() |
|
8317 |
*/ |
|
8318 |
||
8319 |
Qt::BGMode QPaintEngineState::backgroundMode() const |
|
8320 |
{ |
|
8321 |
return static_cast<const QPainterState *>(this)->bgMode; |
|
8322 |
} |
|
8323 |
||
8324 |
/*! |
|
8325 |
Returns the font in the current paint engine |
|
8326 |
state. |
|
8327 |
||
8328 |
This variable should only be used when the state() returns a |
|
8329 |
combination which includes the QPaintEngine::DirtyFont flag. |
|
8330 |
||
8331 |
\sa state(), QPaintEngine::updateState() |
|
8332 |
*/ |
|
8333 |
||
8334 |
QFont QPaintEngineState::font() const |
|
8335 |
{ |
|
8336 |
return static_cast<const QPainterState *>(this)->font; |
|
8337 |
} |
|
8338 |
||
8339 |
/*! |
|
8340 |
\since 4.2 |
|
8341 |
\obsolete |
|
8342 |
||
8343 |
Returns the matrix in the current paint engine |
|
8344 |
state. |
|
8345 |
||
8346 |
\note It is advisable to use transform() instead of this function to |
|
8347 |
preserve the properties of perspective transformations. |
|
8348 |
||
8349 |
This variable should only be used when the state() returns a |
|
8350 |
combination which includes the QPaintEngine::DirtyTransform flag. |
|
8351 |
||
8352 |
\sa state(), QPaintEngine::updateState() |
|
8353 |
*/ |
|
8354 |
||
8355 |
QMatrix QPaintEngineState::matrix() const |
|
8356 |
{ |
|
8357 |
const QPainterState *st = static_cast<const QPainterState *>(this); |
|
8358 |
||
8359 |
return st->matrix.toAffine(); |
|
8360 |
} |
|
8361 |
||
8362 |
/*! |
|
8363 |
\since 4.3 |
|
8364 |
||
8365 |
Returns the matrix in the current paint engine state. |
|
8366 |
||
8367 |
This variable should only be used when the state() returns a |
|
8368 |
combination which includes the QPaintEngine::DirtyTransform flag. |
|
8369 |
||
8370 |
\sa state(), QPaintEngine::updateState() |
|
8371 |
*/ |
|
8372 |
||
8373 |
||
8374 |
QTransform QPaintEngineState::transform() const |
|
8375 |
{ |
|
8376 |
const QPainterState *st = static_cast<const QPainterState *>(this); |
|
8377 |
||
8378 |
return st->matrix; |
|
8379 |
} |
|
8380 |
||
8381 |
||
8382 |
/*! |
|
8383 |
Returns the clip operation in the current paint engine |
|
8384 |
state. |
|
8385 |
||
8386 |
This variable should only be used when the state() returns a |
|
8387 |
combination which includes either the QPaintEngine::DirtyClipPath |
|
8388 |
or the QPaintEngine::DirtyClipRegion flag. |
|
8389 |
||
8390 |
\sa state(), QPaintEngine::updateState() |
|
8391 |
*/ |
|
8392 |
||
8393 |
Qt::ClipOperation QPaintEngineState::clipOperation() const |
|
8394 |
{ |
|
8395 |
return static_cast<const QPainterState *>(this)->clipOperation; |
|
8396 |
} |
|
8397 |
||
8398 |
/*! |
|
8399 |
\since 4.3 |
|
8400 |
||
8401 |
Returns whether the coordinate of the fill have been specified |
|
8402 |
as bounded by the current rendering operation and have to be |
|
8403 |
resolved (about the currently rendered primitive). |
|
8404 |
*/ |
|
8405 |
bool QPaintEngineState::brushNeedsResolving() const |
|
8406 |
{ |
|
8407 |
const QBrush &brush = static_cast<const QPainterState *>(this)->brush; |
|
8408 |
return needsResolving(brush); |
|
8409 |
} |
|
8410 |
||
8411 |
||
8412 |
/*! |
|
8413 |
\since 4.3 |
|
8414 |
||
8415 |
Returns whether the coordinate of the stroke have been specified |
|
8416 |
as bounded by the current rendering operation and have to be |
|
8417 |
resolved (about the currently rendered primitive). |
|
8418 |
*/ |
|
8419 |
bool QPaintEngineState::penNeedsResolving() const |
|
8420 |
{ |
|
8421 |
const QPen &pen = static_cast<const QPainterState *>(this)->pen; |
|
8422 |
return needsResolving(pen.brush()); |
|
8423 |
} |
|
8424 |
||
8425 |
/*! |
|
8426 |
Returns the clip region in the current paint engine state. |
|
8427 |
||
8428 |
This variable should only be used when the state() returns a |
|
8429 |
combination which includes the QPaintEngine::DirtyClipRegion flag. |
|
8430 |
||
8431 |
\sa state(), QPaintEngine::updateState() |
|
8432 |
*/ |
|
8433 |
||
8434 |
QRegion QPaintEngineState::clipRegion() const |
|
8435 |
{ |
|
8436 |
return static_cast<const QPainterState *>(this)->clipRegion; |
|
8437 |
} |
|
8438 |
||
8439 |
/*! |
|
8440 |
Returns the clip path in the current paint engine state. |
|
8441 |
||
8442 |
This variable should only be used when the state() returns a |
|
8443 |
combination which includes the QPaintEngine::DirtyClipPath flag. |
|
8444 |
||
8445 |
\sa state(), QPaintEngine::updateState() |
|
8446 |
*/ |
|
8447 |
||
8448 |
QPainterPath QPaintEngineState::clipPath() const |
|
8449 |
{ |
|
8450 |
return static_cast<const QPainterState *>(this)->clipPath; |
|
8451 |
} |
|
8452 |
||
8453 |
/*! |
|
8454 |
Returns wether clipping is enabled or not in the current paint |
|
8455 |
engine state. |
|
8456 |
||
8457 |
This variable should only be used when the state() returns a |
|
8458 |
combination which includes the QPaintEngine::DirtyClipEnabled |
|
8459 |
flag. |
|
8460 |
||
8461 |
\sa state(), QPaintEngine::updateState() |
|
8462 |
*/ |
|
8463 |
||
8464 |
bool QPaintEngineState::isClipEnabled() const |
|
8465 |
{ |
|
8466 |
return static_cast<const QPainterState *>(this)->clipEnabled; |
|
8467 |
} |
|
8468 |
||
8469 |
/*! |
|
8470 |
Returns the render hints in the current paint engine state. |
|
8471 |
||
8472 |
This variable should only be used when the state() returns a |
|
8473 |
combination which includes the QPaintEngine::DirtyHints |
|
8474 |
flag. |
|
8475 |
||
8476 |
\sa state(), QPaintEngine::updateState() |
|
8477 |
*/ |
|
8478 |
||
8479 |
QPainter::RenderHints QPaintEngineState::renderHints() const |
|
8480 |
{ |
|
8481 |
return static_cast<const QPainterState *>(this)->renderHints; |
|
8482 |
} |
|
8483 |
||
8484 |
/*! |
|
8485 |
Returns the composition mode in the current paint engine state. |
|
8486 |
||
8487 |
This variable should only be used when the state() returns a |
|
8488 |
combination which includes the QPaintEngine::DirtyCompositionMode |
|
8489 |
flag. |
|
8490 |
||
8491 |
\sa state(), QPaintEngine::updateState() |
|
8492 |
*/ |
|
8493 |
||
8494 |
QPainter::CompositionMode QPaintEngineState::compositionMode() const |
|
8495 |
{ |
|
8496 |
return static_cast<const QPainterState *>(this)->composition_mode; |
|
8497 |
} |
|
8498 |
||
8499 |
||
8500 |
/*! |
|
8501 |
Returns a pointer to the painter currently updating the paint |
|
8502 |
engine. |
|
8503 |
*/ |
|
8504 |
||
8505 |
QPainter *QPaintEngineState::painter() const |
|
8506 |
{ |
|
8507 |
return static_cast<const QPainterState *>(this)->painter; |
|
8508 |
} |
|
8509 |
||
8510 |
||
8511 |
/*! |
|
8512 |
\since 4.2 |
|
8513 |
||
8514 |
Returns the opacity in the current paint engine state. |
|
8515 |
*/ |
|
8516 |
||
8517 |
qreal QPaintEngineState::opacity() const |
|
8518 |
{ |
|
8519 |
return static_cast<const QPainterState *>(this)->opacity; |
|
8520 |
} |
|
8521 |
||
8522 |
/*! |
|
8523 |
\since 4.3 |
|
8524 |
||
8525 |
Sets the world transformation matrix. |
|
8526 |
If \a combine is true, the specified \a transform is combined with |
|
8527 |
the current matrix; otherwise it replaces the current matrix. |
|
8528 |
||
8529 |
\sa transform() setWorldTransform() |
|
8530 |
*/ |
|
8531 |
||
8532 |
void QPainter::setTransform(const QTransform &transform, bool combine ) |
|
8533 |
{ |
|
8534 |
setWorldTransform(transform, combine); |
|
8535 |
} |
|
8536 |
||
8537 |
/*! |
|
8538 |
Returns the world transformation matrix. |
|
8539 |
||
8540 |
\sa worldTransform() |
|
8541 |
*/ |
|
8542 |
||
8543 |
const QTransform & QPainter::transform() const |
|
8544 |
{ |
|
8545 |
return worldTransform(); |
|
8546 |
} |
|
8547 |
||
8548 |
||
8549 |
/*! |
|
8550 |
Returns the matrix that transforms from logical coordinates to |
|
8551 |
device coordinates of the platform dependent paint device. |
|
8552 |
||
8553 |
This function is \e only needed when using platform painting |
|
8554 |
commands on the platform dependent handle (Qt::HANDLE), and the |
|
8555 |
platform does not do transformations nativly. |
|
8556 |
||
8557 |
The QPaintEngine::PaintEngineFeature enum can be queried to |
|
8558 |
determine whether the platform performs the transformations or |
|
8559 |
not. |
|
8560 |
||
8561 |
\sa worldTransform(), QPaintEngine::hasFeature(), |
|
8562 |
*/ |
|
8563 |
||
8564 |
const QTransform & QPainter::deviceTransform() const |
|
8565 |
{ |
|
8566 |
Q_D(const QPainter); |
|
8567 |
if (!d->engine) { |
|
8568 |
qWarning("QPainter::deviceTransform: Painter not active"); |
|
8569 |
return d->fakeState()->transform; |
|
8570 |
} |
|
8571 |
return d->state->matrix; |
|
8572 |
} |
|
8573 |
||
8574 |
||
8575 |
/*! |
|
8576 |
Resets any transformations that were made using translate(), |
|
8577 |
scale(), shear(), rotate(), setWorldTransform(), setViewport() |
|
8578 |
and setWindow(). |
|
8579 |
||
8580 |
\sa {Coordinate Transformations} |
|
8581 |
*/ |
|
8582 |
||
8583 |
void QPainter::resetTransform() |
|
8584 |
{ |
|
8585 |
Q_D(QPainter); |
|
8586 |
#ifdef QT_DEBUG_DRAW |
|
8587 |
if (qt_show_painter_debug_output) |
|
8588 |
printf("QPainter::resetMatrix()\n"); |
|
8589 |
#endif |
|
8590 |
if (!d->engine) { |
|
8591 |
qWarning("QPainter::resetMatrix: Painter not active"); |
|
8592 |
return; |
|
8593 |
} |
|
8594 |
||
8595 |
d->state->wx = d->state->wy = d->state->vx = d->state->vy = 0; // default view origins |
|
8596 |
d->state->ww = d->state->vw = d->device->metric(QPaintDevice::PdmWidth); |
|
8597 |
d->state->wh = d->state->vh = d->device->metric(QPaintDevice::PdmHeight); |
|
8598 |
d->state->worldMatrix = QTransform(); |
|
8599 |
setMatrixEnabled(false); |
|
8600 |
setViewTransformEnabled(false); |
|
8601 |
if (d->extended) |
|
8602 |
d->extended->transformChanged(); |
|
8603 |
else |
|
8604 |
d->state->dirtyFlags |= QPaintEngine::DirtyTransform; |
|
8605 |
} |
|
8606 |
||
8607 |
/*! |
|
8608 |
Sets the world transformation matrix. |
|
8609 |
If \a combine is true, the specified \a matrix is combined with the current matrix; |
|
8610 |
otherwise it replaces the current matrix. |
|
8611 |
||
8612 |
\sa transform(), setTransform() |
|
8613 |
*/ |
|
8614 |
||
8615 |
void QPainter::setWorldTransform(const QTransform &matrix, bool combine ) |
|
8616 |
{ |
|
8617 |
Q_D(QPainter); |
|
8618 |
||
8619 |
if (!d->engine) { |
|
8620 |
qWarning("QPainter::setWorldTransform: Painter not active"); |
|
8621 |
return; |
|
8622 |
} |
|
8623 |
||
8624 |
if (combine) |
|
8625 |
d->state->worldMatrix = matrix * d->state->worldMatrix; // combines |
|
8626 |
else |
|
8627 |
d->state->worldMatrix = matrix; // set new matrix |
|
8628 |
||
8629 |
d->state->WxF = true; |
|
8630 |
d->updateMatrix(); |
|
8631 |
} |
|
8632 |
||
8633 |
/*! |
|
8634 |
Returns the world transformation matrix. |
|
8635 |
*/ |
|
8636 |
||
8637 |
const QTransform & QPainter::worldTransform() const |
|
8638 |
{ |
|
8639 |
Q_D(const QPainter); |
|
8640 |
if (!d->engine) { |
|
8641 |
qWarning("QPainter::worldTransform: Painter not active"); |
|
8642 |
return d->fakeState()->transform; |
|
8643 |
} |
|
8644 |
return d->state->worldMatrix; |
|
8645 |
} |
|
8646 |
||
8647 |
/*! |
|
8648 |
Returns the transformation matrix combining the current |
|
8649 |
window/viewport and world transformation. |
|
8650 |
||
8651 |
\sa setWorldTransform(), setWindow(), setViewport() |
|
8652 |
*/ |
|
8653 |
||
8654 |
QTransform QPainter::combinedTransform() const |
|
8655 |
{ |
|
8656 |
Q_D(const QPainter); |
|
8657 |
if (!d->engine) { |
|
8658 |
qWarning("QPainter::combinedTransform: Painter not active"); |
|
8659 |
return QTransform(); |
|
8660 |
} |
|
8661 |
return d->state->worldMatrix * d->viewTransform(); |
|
8662 |
} |
|
8663 |
||
8664 |
void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation) |
|
8665 |
{ |
|
8666 |
p->draw_helper(path, operation); |
|
8667 |
} |
|
8668 |
||
8669 |
/*! \fn Display *QPaintDevice::x11Display() const |
|
8670 |
Use QX11Info::display() instead. |
|
8671 |
||
8672 |
\oldcode |
|
8673 |
Display *display = widget->x11Display(); |
|
8674 |
\newcode |
|
8675 |
Display *display = QX11Info::display(); |
|
8676 |
\endcode |
|
8677 |
||
8678 |
\sa QWidget::x11Info(), QX11Info::display() |
|
8679 |
*/ |
|
8680 |
||
8681 |
/*! \fn int QPaintDevice::x11Screen() const |
|
8682 |
Use QX11Info::screen() instead. |
|
8683 |
||
8684 |
\oldcode |
|
8685 |
int screen = widget->x11Screen(); |
|
8686 |
\newcode |
|
8687 |
int screen = widget->x11Info().screen(); |
|
8688 |
\endcode |
|
8689 |
||
8690 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8691 |
*/ |
|
8692 |
||
8693 |
/*! \fn void *QPaintDevice::x11Visual() const |
|
8694 |
Use QX11Info::visual() instead. |
|
8695 |
||
8696 |
\oldcode |
|
8697 |
void *visual = widget->x11Visual(); |
|
8698 |
\newcode |
|
8699 |
void *visual = widget->x11Info().visual(); |
|
8700 |
\endcode |
|
8701 |
||
8702 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8703 |
*/ |
|
8704 |
||
8705 |
/*! \fn int QPaintDevice::x11Depth() const |
|
8706 |
Use QX11Info::depth() instead. |
|
8707 |
||
8708 |
\oldcode |
|
8709 |
int depth = widget->x11Depth(); |
|
8710 |
\newcode |
|
8711 |
int depth = widget->x11Info().depth(); |
|
8712 |
\endcode |
|
8713 |
||
8714 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8715 |
*/ |
|
8716 |
||
8717 |
/*! \fn int QPaintDevice::x11Cells() const |
|
8718 |
Use QX11Info::cells() instead. |
|
8719 |
||
8720 |
\oldcode |
|
8721 |
int cells = widget->x11Cells(); |
|
8722 |
\newcode |
|
8723 |
int cells = widget->x11Info().cells(); |
|
8724 |
\endcode |
|
8725 |
||
8726 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8727 |
*/ |
|
8728 |
||
8729 |
/*! \fn Qt::HANDLE QPaintDevice::x11Colormap() const |
|
8730 |
Use QX11Info::colormap() instead. |
|
8731 |
||
8732 |
\oldcode |
|
8733 |
unsigned long screen = widget->x11Colormap(); |
|
8734 |
\newcode |
|
8735 |
unsigned long screen = widget->x11Info().colormap(); |
|
8736 |
\endcode |
|
8737 |
||
8738 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8739 |
*/ |
|
8740 |
||
8741 |
/*! \fn bool QPaintDevice::x11DefaultColormap() const |
|
8742 |
Use QX11Info::defaultColormap() instead. |
|
8743 |
||
8744 |
\oldcode |
|
8745 |
bool isDefault = widget->x11DefaultColormap(); |
|
8746 |
\newcode |
|
8747 |
bool isDefault = widget->x11Info().defaultColormap(); |
|
8748 |
\endcode |
|
8749 |
||
8750 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8751 |
*/ |
|
8752 |
||
8753 |
/*! \fn bool QPaintDevice::x11DefaultVisual() const |
|
8754 |
Use QX11Info::defaultVisual() instead. |
|
8755 |
||
8756 |
\oldcode |
|
8757 |
bool isDefault = widget->x11DefaultVisual(); |
|
8758 |
\newcode |
|
8759 |
bool isDefault = widget->x11Info().defaultVisual(); |
|
8760 |
\endcode |
|
8761 |
||
8762 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8763 |
*/ |
|
8764 |
||
8765 |
/*! \fn void *QPaintDevice::x11AppVisual(int screen) |
|
8766 |
Use QX11Info::visual() instead. |
|
8767 |
||
8768 |
\oldcode |
|
8769 |
void *visual = QPaintDevice::x11AppVisual(screen); |
|
8770 |
\newcode |
|
8771 |
void *visual = qApp->x11Info(screen).visual(); |
|
8772 |
\endcode |
|
8773 |
||
8774 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8775 |
*/ |
|
8776 |
||
8777 |
/*! \fn Qt::HANDLE QPaintDevice::x11AppColormap(int screen) |
|
8778 |
Use QX11Info::colormap() instead. |
|
8779 |
||
8780 |
\oldcode |
|
8781 |
unsigned long colormap = QPaintDevice::x11AppColormap(screen); |
|
8782 |
\newcode |
|
8783 |
unsigned long colormap = qApp->x11Info(screen).colormap(); |
|
8784 |
\endcode |
|
8785 |
||
8786 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8787 |
*/ |
|
8788 |
||
8789 |
/*! \fn Display *QPaintDevice::x11AppDisplay() |
|
8790 |
Use QX11Info::display() instead. |
|
8791 |
||
8792 |
\oldcode |
|
8793 |
Display *display = QPaintDevice::x11AppDisplay(); |
|
8794 |
\newcode |
|
8795 |
Display *display = qApp->x11Info().display(); |
|
8796 |
\endcode |
|
8797 |
||
8798 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8799 |
*/ |
|
8800 |
||
8801 |
/*! \fn int QPaintDevice::x11AppScreen() |
|
8802 |
Use QX11Info::screen() instead. |
|
8803 |
||
8804 |
\oldcode |
|
8805 |
int screen = QPaintDevice::x11AppScreen(); |
|
8806 |
\newcode |
|
8807 |
int screen = qApp->x11Info().screen(); |
|
8808 |
\endcode |
|
8809 |
||
8810 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8811 |
*/ |
|
8812 |
||
8813 |
/*! \fn int QPaintDevice::x11AppDepth(int screen) |
|
8814 |
Use QX11Info::depth() instead. |
|
8815 |
||
8816 |
\oldcode |
|
8817 |
int depth = QPaintDevice::x11AppDepth(screen); |
|
8818 |
\newcode |
|
8819 |
int depth = qApp->x11Info(screen).depth(); |
|
8820 |
\endcode |
|
8821 |
||
8822 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8823 |
*/ |
|
8824 |
||
8825 |
/*! \fn int QPaintDevice::x11AppCells(int screen) |
|
8826 |
Use QX11Info::cells() instead. |
|
8827 |
||
8828 |
\oldcode |
|
8829 |
int cells = QPaintDevice::x11AppCells(screen); |
|
8830 |
\newcode |
|
8831 |
int cells = qApp->x11Info(screen).cells(); |
|
8832 |
\endcode |
|
8833 |
||
8834 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8835 |
*/ |
|
8836 |
||
8837 |
/*! \fn Qt::HANDLE QPaintDevice::x11AppRootWindow(int screen) |
|
8838 |
Use QX11Info::appRootWindow() instead. |
|
8839 |
||
8840 |
\oldcode |
|
8841 |
unsigned long window = QPaintDevice::x11AppRootWindow(screen); |
|
8842 |
\newcode |
|
8843 |
unsigned long window = qApp->x11Info(screen).appRootWindow(); |
|
8844 |
\endcode |
|
8845 |
||
8846 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8847 |
*/ |
|
8848 |
||
8849 |
/*! \fn bool QPaintDevice::x11AppDefaultColormap(int screen) |
|
8850 |
Use QX11Info::defaultColormap() instead. |
|
8851 |
||
8852 |
\oldcode |
|
8853 |
bool isDefault = QPaintDevice::x11AppDefaultColormap(screen); |
|
8854 |
\newcode |
|
8855 |
bool isDefault = qApp->x11Info(screen).defaultColormap(); |
|
8856 |
\endcode |
|
8857 |
||
8858 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8859 |
*/ |
|
8860 |
||
8861 |
/*! \fn bool QPaintDevice::x11AppDefaultVisual(int screen) |
|
8862 |
Use QX11Info::defaultVisual() instead. |
|
8863 |
||
8864 |
\oldcode |
|
8865 |
bool isDefault = QPaintDevice::x11AppDefaultVisual(screen); |
|
8866 |
\newcode |
|
8867 |
bool isDefault = qApp->x11Info(screen).defaultVisual(); |
|
8868 |
\endcode |
|
8869 |
||
8870 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8871 |
*/ |
|
8872 |
||
8873 |
/*! \fn void QPaintDevice::x11SetAppDpiX(int dpi, int screen) |
|
8874 |
Use QX11Info::setAppDpiX() instead. |
|
8875 |
*/ |
|
8876 |
||
8877 |
/*! \fn void QPaintDevice::x11SetAppDpiY(int dpi, int screen) |
|
8878 |
Use QX11Info::setAppDpiY() instead. |
|
8879 |
*/ |
|
8880 |
||
8881 |
/*! \fn int QPaintDevice::x11AppDpiX(int screen) |
|
8882 |
Use QX11Info::appDpiX() instead. |
|
8883 |
||
8884 |
\oldcode |
|
8885 |
bool isDefault = QPaintDevice::x11AppDpiX(screen); |
|
8886 |
\newcode |
|
8887 |
bool isDefault = qApp->x11Info(screen).appDpiX(); |
|
8888 |
\endcode |
|
8889 |
||
8890 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8891 |
*/ |
|
8892 |
||
8893 |
/*! \fn int QPaintDevice::x11AppDpiY(int screen) |
|
8894 |
Use QX11Info::appDpiY() instead. |
|
8895 |
||
8896 |
\oldcode |
|
8897 |
bool isDefault = QPaintDevice::x11AppDpiY(screen); |
|
8898 |
\newcode |
|
8899 |
bool isDefault = qApp->x11Info(screen).appDpiY(); |
|
8900 |
\endcode |
|
8901 |
||
8902 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8903 |
*/ |
|
8904 |
||
8905 |
/*! \fn HDC QPaintDevice::getDC() const |
|
8906 |
\internal |
|
8907 |
*/ |
|
8908 |
||
8909 |
/*! \fn void QPaintDevice::releaseDC(HDC) const |
|
8910 |
\internal |
|
8911 |
*/ |
|
8912 |
||
8913 |
/*! \fn QWSDisplay *QPaintDevice::qwsDisplay() |
|
8914 |
\internal |
|
8915 |
*/ |
|
8916 |
||
8917 |
QT_END_NAMESPACE |