1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPAINTENGINE_P_H
5#define QPAINTENGINE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qtguiglobal_p.h>
19#include "QtGui/qpainter.h"
20#include "QtGui/qpaintengine.h"
21#include "QtGui/qregion.h"
22#include "private/qobject_p.h"
23
24QT_BEGIN_NAMESPACE
25
26class QPaintDevice;
27
28class Q_GUI_EXPORT QPaintEnginePrivate
29{
30 Q_DECLARE_PUBLIC(QPaintEngine)
31public:
32 QPaintEnginePrivate() : pdev(nullptr), q_ptr(nullptr), currentClipDevice(nullptr), hasSystemTransform(0),
33 hasSystemViewport(0) {}
34 virtual ~QPaintEnginePrivate();
35
36 QPaintDevice *pdev;
37 QPaintEngine *q_ptr;
38 QRegion baseSystemClip;
39 QRegion systemClip;
40 QRect systemRect;
41 QRegion systemViewport;
42 QTransform systemTransform;
43 QPaintDevice *currentClipDevice;
44 uint hasSystemTransform : 1;
45 uint hasSystemViewport : 1;
46
47 inline void updateSystemClip()
48 {
49 systemClip = baseSystemClip;
50 if (systemClip.isEmpty())
51 return;
52
53 if (hasSystemTransform) {
54 if (systemTransform.type() <= QTransform::TxTranslate)
55 systemClip.translate(dx: qRound(d: systemTransform.dx()), dy: qRound(d: systemTransform.dy()));
56 else
57 systemClip = systemTransform.map(r: systemClip);
58 }
59
60 // Make sure we're inside the viewport.
61 if (hasSystemViewport) {
62 systemClip &= systemViewport;
63 if (systemClip.isEmpty()) {
64 // We don't want to paint without system clip, so set it to 1 pixel :)
65 systemClip = QRect(systemViewport.boundingRect().topLeft(), QSize(1, 1));
66 }
67 }
68 }
69
70 inline void setSystemTransform(const QTransform &xform)
71 {
72 systemTransform = xform;
73 hasSystemTransform = !xform.isIdentity();
74 updateSystemClip();
75 if (q_ptr->state)
76 systemStateChanged();
77 }
78
79 inline void setSystemViewport(const QRegion &region)
80 {
81 systemViewport = region;
82 hasSystemViewport = !systemViewport.isEmpty();
83 updateSystemClip();
84 if (q_ptr->state)
85 systemStateChanged();
86 }
87
88 inline void setSystemTransformAndViewport(const QTransform &xform, const QRegion &region)
89 {
90 systemTransform = xform;
91 hasSystemTransform = !xform.isIdentity();
92 systemViewport = region;
93 hasSystemViewport = !systemViewport.isEmpty();
94 updateSystemClip();
95 if (q_ptr->state)
96 systemStateChanged();
97 }
98
99 virtual void systemStateChanged() { }
100
101 void drawBoxTextItem(const QPointF &p, const QTextItemInt &ti);
102
103 static QPaintEnginePrivate *get(QPaintEngine *paintEngine) { return paintEngine->d_func(); }
104
105 virtual QPaintEngine *aggregateEngine() { return nullptr; }
106 virtual Qt::HANDLE nativeHandle() { return nullptr; }
107};
108
109QT_END_NAMESPACE
110
111#endif // QPAINTENGINE_P_H
112

source code of qtbase/src/gui/painting/qpaintengine_p.h