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 QPAINTDEVICEWINDOW_P_H |
5 | #define QPAINTDEVICEWINDOW_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 purely as an |
12 | // implementation detail. 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/QPaintDeviceWindow> |
20 | #include <QtCore/QCoreApplication> |
21 | #include <QtGui/private/qwindow_p.h> |
22 | #include <QtGui/QPaintEvent> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class Q_GUI_EXPORT QPaintDeviceWindowPrivate : public QWindowPrivate |
27 | { |
28 | Q_DECLARE_PUBLIC(QPaintDeviceWindow) |
29 | |
30 | public: |
31 | QPaintDeviceWindowPrivate(); |
32 | ~QPaintDeviceWindowPrivate() override; |
33 | |
34 | virtual void beginPaint(const QRegion ®ion) |
35 | { |
36 | Q_UNUSED(region); |
37 | } |
38 | |
39 | virtual void endPaint() |
40 | { |
41 | } |
42 | |
43 | virtual void flush(const QRegion ®ion) |
44 | { |
45 | Q_UNUSED(region); |
46 | } |
47 | |
48 | bool paint(const QRegion ®ion) |
49 | { |
50 | Q_Q(QPaintDeviceWindow); |
51 | QRegion toPaint = region & dirtyRegion; |
52 | if (toPaint.isEmpty()) |
53 | return false; |
54 | |
55 | // Clear the region now. The overridden functions may call update(). |
56 | dirtyRegion -= toPaint; |
57 | |
58 | beginPaint(region: toPaint); |
59 | |
60 | QPaintEvent paintEvent(toPaint); |
61 | q->paintEvent(event: &paintEvent); |
62 | |
63 | endPaint(); |
64 | |
65 | return true; |
66 | } |
67 | |
68 | void doFlush(const QRegion ®ion) |
69 | { |
70 | QRegion toFlush = region; |
71 | if (paint(region: toFlush)) |
72 | flush(region: toFlush); |
73 | } |
74 | |
75 | void handleUpdateEvent() |
76 | { |
77 | if (dirtyRegion.isEmpty()) |
78 | return; |
79 | doFlush(region: dirtyRegion); |
80 | } |
81 | |
82 | void markWindowAsDirty() |
83 | { |
84 | Q_Q(QPaintDeviceWindow); |
85 | dirtyRegion = QRect(QPoint(0, 0), q->size()); |
86 | } |
87 | |
88 | private: |
89 | QRegion dirtyRegion; |
90 | }; |
91 | |
92 | |
93 | QT_END_NAMESPACE |
94 | |
95 | #endif //QPAINTDEVICEWINDOW_P_H |
96 |