Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qpaintdevicewindow.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qpaintdevicewindow_p.h" | - | ||||||||||||
35 | - | |||||||||||||
36 | #include <QtGui/QGuiApplication> | - | ||||||||||||
37 | #include <QtGui/QScreen> | - | ||||||||||||
38 | - | |||||||||||||
39 | QT_BEGIN_NAMESPACE | - | ||||||||||||
40 | - | |||||||||||||
41 | /*! | - | ||||||||||||
42 | \class QPaintDeviceWindow | - | ||||||||||||
43 | \inmodule QtGui | - | ||||||||||||
44 | \since 5.4 | - | ||||||||||||
45 | \brief Convenience subclass of QWindow that is also a QPaintDevice. | - | ||||||||||||
46 | - | |||||||||||||
47 | QPaintDeviceWindow is like a regular QWindow, with the added functionality | - | ||||||||||||
48 | of being a paint device too. Whenever the content needs to be updated, | - | ||||||||||||
49 | the virtual paintEvent() function is called. Subclasses, that reimplement | - | ||||||||||||
50 | this function, can then simply open a QPainter on the window. | - | ||||||||||||
51 | - | |||||||||||||
52 | \note This class cannot directly be used in applications. It rather serves | - | ||||||||||||
53 | as a base for subclasses like QOpenGLWindow. | - | ||||||||||||
54 | - | |||||||||||||
55 | \sa QOpenGLWindow | - | ||||||||||||
56 | */ | - | ||||||||||||
57 | - | |||||||||||||
58 | /*! | - | ||||||||||||
59 | Marks the entire window as dirty and schedules a repaint. | - | ||||||||||||
60 | - | |||||||||||||
61 | \note Subsequent calls to this function before the next paint | - | ||||||||||||
62 | event will get ignored. | - | ||||||||||||
63 | - | |||||||||||||
64 | \note For non-exposed windows the update is deferred until the | - | ||||||||||||
65 | window becomes exposed again. | - | ||||||||||||
66 | */ | - | ||||||||||||
67 | void QPaintDeviceWindow::update() | - | ||||||||||||
68 | { | - | ||||||||||||
69 | update(QRect(QPoint(0,0), size())); | - | ||||||||||||
70 | } never executed: end of block | 0 | ||||||||||||
71 | - | |||||||||||||
72 | /*! | - | ||||||||||||
73 | Marks the \a rect of the window as dirty and schedules a repaint. | - | ||||||||||||
74 | - | |||||||||||||
75 | \note Subsequent calls to this function before the next paint | - | ||||||||||||
76 | event will get ignored, but \a rect is added to the region to update. | - | ||||||||||||
77 | - | |||||||||||||
78 | \note For non-exposed windows the update is deferred until the | - | ||||||||||||
79 | window becomes exposed again. | - | ||||||||||||
80 | */ | - | ||||||||||||
81 | void QPaintDeviceWindow::update(const QRect &rect) | - | ||||||||||||
82 | { | - | ||||||||||||
83 | Q_D(QPaintDeviceWindow); | - | ||||||||||||
84 | d->dirtyRegion += rect; | - | ||||||||||||
85 | if (isExposed())
| 0 | ||||||||||||
86 | requestUpdate(); never executed: requestUpdate(); | 0 | ||||||||||||
87 | } never executed: end of block | 0 | ||||||||||||
88 | - | |||||||||||||
89 | /*! | - | ||||||||||||
90 | Marks the \a region of the window as dirty and schedules a repaint. | - | ||||||||||||
91 | - | |||||||||||||
92 | \note Subsequent calls to this function before the next paint | - | ||||||||||||
93 | event will get ignored, but \a region is added to the region to update. | - | ||||||||||||
94 | - | |||||||||||||
95 | \note For non-exposed windows the update is deferred until the | - | ||||||||||||
96 | window becomes exposed again. | - | ||||||||||||
97 | */ | - | ||||||||||||
98 | void QPaintDeviceWindow::update(const QRegion ®ion) | - | ||||||||||||
99 | { | - | ||||||||||||
100 | Q_D(QPaintDeviceWindow); | - | ||||||||||||
101 | d->dirtyRegion += region; | - | ||||||||||||
102 | if (isExposed())
| 0 | ||||||||||||
103 | requestUpdate(); never executed: requestUpdate(); | 0 | ||||||||||||
104 | } never executed: end of block | 0 | ||||||||||||
105 | - | |||||||||||||
106 | /*! | - | ||||||||||||
107 | Handles paint events passed in the \a event parameter. | - | ||||||||||||
108 | - | |||||||||||||
109 | The default implementation does nothing. Reimplement this function to | - | ||||||||||||
110 | perform painting. If necessary, the dirty area is retrievable from | - | ||||||||||||
111 | the \a event. | - | ||||||||||||
112 | */ | - | ||||||||||||
113 | void QPaintDeviceWindow::paintEvent(QPaintEvent *event) | - | ||||||||||||
114 | { | - | ||||||||||||
115 | Q_UNUSED(event); | - | ||||||||||||
116 | // Do nothing | - | ||||||||||||
117 | } never executed: end of block | 0 | ||||||||||||
118 | - | |||||||||||||
119 | /*! | - | ||||||||||||
120 | \internal | - | ||||||||||||
121 | */ | - | ||||||||||||
122 | int QPaintDeviceWindow::metric(PaintDeviceMetric metric) const | - | ||||||||||||
123 | { | - | ||||||||||||
124 | QScreen *screen = this->screen(); | - | ||||||||||||
125 | if (!screen && QGuiApplication::primaryScreen())
| 0 | ||||||||||||
126 | screen = QGuiApplication::primaryScreen(); never executed: screen = QGuiApplication::primaryScreen(); | 0 | ||||||||||||
127 | - | |||||||||||||
128 | switch (metric) { | - | ||||||||||||
129 | case PdmWidth: never executed: case PdmWidth: | 0 | ||||||||||||
130 | return width(); never executed: return width(); | 0 | ||||||||||||
131 | case PdmWidthMM: never executed: case PdmWidthMM: | 0 | ||||||||||||
132 | if (screen)
| 0 | ||||||||||||
133 | return width() * screen->physicalSize().width() / screen->geometry().width(); never executed: return width() * screen->physicalSize().width() / screen->geometry().width(); | 0 | ||||||||||||
134 | break; never executed: break; | 0 | ||||||||||||
135 | case PdmHeight: never executed: case PdmHeight: | 0 | ||||||||||||
136 | return height(); never executed: return height(); | 0 | ||||||||||||
137 | case PdmHeightMM: never executed: case PdmHeightMM: | 0 | ||||||||||||
138 | if (screen)
| 0 | ||||||||||||
139 | return height() * screen->physicalSize().height() / screen->geometry().height(); never executed: return height() * screen->physicalSize().height() / screen->geometry().height(); | 0 | ||||||||||||
140 | break; never executed: break; | 0 | ||||||||||||
141 | case PdmDpiX: never executed: case PdmDpiX: | 0 | ||||||||||||
142 | if (screen)
| 0 | ||||||||||||
143 | return qRound(screen->logicalDotsPerInchX()); never executed: return qRound(screen->logicalDotsPerInchX()); | 0 | ||||||||||||
144 | break; never executed: break; | 0 | ||||||||||||
145 | case PdmDpiY: never executed: case PdmDpiY: | 0 | ||||||||||||
146 | if (screen)
| 0 | ||||||||||||
147 | return qRound(screen->logicalDotsPerInchY()); never executed: return qRound(screen->logicalDotsPerInchY()); | 0 | ||||||||||||
148 | break; never executed: break; | 0 | ||||||||||||
149 | case PdmPhysicalDpiX: never executed: case PdmPhysicalDpiX: | 0 | ||||||||||||
150 | if (screen)
| 0 | ||||||||||||
151 | return qRound(screen->physicalDotsPerInchX()); never executed: return qRound(screen->physicalDotsPerInchX()); | 0 | ||||||||||||
152 | break; never executed: break; | 0 | ||||||||||||
153 | case PdmPhysicalDpiY: never executed: case PdmPhysicalDpiY: | 0 | ||||||||||||
154 | if (screen)
| 0 | ||||||||||||
155 | return qRound(screen->physicalDotsPerInchY()); never executed: return qRound(screen->physicalDotsPerInchY()); | 0 | ||||||||||||
156 | break; never executed: break; | 0 | ||||||||||||
157 | case PdmDevicePixelRatio: never executed: case PdmDevicePixelRatio: | 0 | ||||||||||||
158 | return int(QWindow::devicePixelRatio()); never executed: return int(QWindow::devicePixelRatio()); | 0 | ||||||||||||
159 | break; dead code: break; | - | ||||||||||||
160 | case PdmDevicePixelRatioScaled: never executed: case PdmDevicePixelRatioScaled: | 0 | ||||||||||||
161 | return int(QWindow::devicePixelRatio() * devicePixelRatioFScale()); never executed: return int(QWindow::devicePixelRatio() * devicePixelRatioFScale()); | 0 | ||||||||||||
162 | break; dead code: break; | - | ||||||||||||
163 | default: never executed: default: | 0 | ||||||||||||
164 | break; never executed: break; | 0 | ||||||||||||
165 | } | - | ||||||||||||
166 | - | |||||||||||||
167 | return QPaintDevice::metric(metric); never executed: return QPaintDevice::metric(metric); | 0 | ||||||||||||
168 | } | - | ||||||||||||
169 | - | |||||||||||||
170 | /*! | - | ||||||||||||
171 | \internal | - | ||||||||||||
172 | */ | - | ||||||||||||
173 | void QPaintDeviceWindow::exposeEvent(QExposeEvent *exposeEvent) | - | ||||||||||||
174 | { | - | ||||||||||||
175 | Q_UNUSED(exposeEvent); | - | ||||||||||||
176 | Q_D(QPaintDeviceWindow); | - | ||||||||||||
177 | if (isExposed()) {
| 0 | ||||||||||||
178 | d->markWindowAsDirty(); | - | ||||||||||||
179 | // Do not rely on exposeEvent->region() as it has some issues for the | - | ||||||||||||
180 | // time being, namely that it is sometimes in local coordinates, | - | ||||||||||||
181 | // sometimes relative to the parent, depending on the platform plugin. | - | ||||||||||||
182 | // We require local coords here. | - | ||||||||||||
183 | d->doFlush(QRect(QPoint(0, 0), size())); | - | ||||||||||||
184 | } else if (!d->dirtyRegion.isEmpty()) { never executed: end of block
| 0 | ||||||||||||
185 | // Updates while non-exposed were ignored. Schedule an update now. | - | ||||||||||||
186 | requestUpdate(); | - | ||||||||||||
187 | } never executed: end of block | 0 | ||||||||||||
188 | } never executed: end of block | 0 | ||||||||||||
189 | - | |||||||||||||
190 | /*! | - | ||||||||||||
191 | \internal | - | ||||||||||||
192 | */ | - | ||||||||||||
193 | bool QPaintDeviceWindow::event(QEvent *event) | - | ||||||||||||
194 | { | - | ||||||||||||
195 | Q_D(QPaintDeviceWindow); | - | ||||||||||||
196 | - | |||||||||||||
197 | if (event->type() == QEvent::UpdateRequest) {
| 0 | ||||||||||||
198 | if (handle()) // platform window may be gone when the window is closed during app exit
| 0 | ||||||||||||
199 | d->handleUpdateEvent(); never executed: d->handleUpdateEvent(); | 0 | ||||||||||||
200 | return true; never executed: return true; | 0 | ||||||||||||
201 | } | - | ||||||||||||
202 | - | |||||||||||||
203 | return QWindow::event(event); never executed: return QWindow::event(event); | 0 | ||||||||||||
204 | } | - | ||||||||||||
205 | - | |||||||||||||
206 | /*! | - | ||||||||||||
207 | \internal | - | ||||||||||||
208 | */ | - | ||||||||||||
209 | QPaintDeviceWindow::QPaintDeviceWindow(QPaintDeviceWindowPrivate &dd, QWindow *parent) | - | ||||||||||||
210 | : QWindow(dd, parent) | - | ||||||||||||
211 | { | - | ||||||||||||
212 | } never executed: end of block | 0 | ||||||||||||
213 | - | |||||||||||||
214 | /*! | - | ||||||||||||
215 | \internal | - | ||||||||||||
216 | */ | - | ||||||||||||
217 | QPaintEngine *QPaintDeviceWindow::paintEngine() const | - | ||||||||||||
218 | { | - | ||||||||||||
219 | return 0; never executed: return 0; | 0 | ||||||||||||
220 | } | - | ||||||||||||
221 | - | |||||||||||||
222 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |