Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qplatformscreen.h" | - |
41 | #include <QtCore/qdebug.h> | - |
42 | #include <QtGui/qguiapplication.h> | - |
43 | #include <qpa/qplatformcursor.h> | - |
44 | #include <QtGui/private/qguiapplication_p.h> | - |
45 | #include <qpa/qplatformscreen_p.h> | - |
46 | #include <qpa/qplatformintegration.h> | - |
47 | #include <QtGui/qscreen.h> | - |
48 | #include <QtGui/qwindow.h> | - |
49 | #include <private/qhighdpiscaling_p.h> | - |
50 | | - |
51 | QT_BEGIN_NAMESPACE | - |
52 | | - |
53 | QPlatformScreen::QPlatformScreen() | - |
54 | : d_ptr(new QPlatformScreenPrivate) | - |
55 | { | - |
56 | Q_D(QPlatformScreen); | - |
57 | d->screen = 0; | - |
58 | } | - |
59 | | - |
60 | QPlatformScreen::~QPlatformScreen() | - |
61 | { | - |
62 | Q_D(QPlatformScreen); | - |
63 | if (d->screen) { | - |
64 | qWarning("Manually deleting a QPlatformScreen. Call QPlatformIntegration::destroyScreen instead."); | - |
65 | QGuiApplicationPrivate::platformIntegration()->removeScreen(d->screen); | - |
66 | delete d->screen; | - |
67 | } | - |
68 | } | - |
69 | | - |
70 | | - |
71 | | - |
72 | | - |
73 | | - |
74 | | - |
75 | | - |
76 | | - |
77 | | - |
78 | QPixmap QPlatformScreen::grabWindow(WId window, int x, int y, int width, int height) const | - |
79 | { | - |
80 | Q_UNUSED(window); | - |
81 | Q_UNUSED(x); | - |
82 | Q_UNUSED(y); | - |
83 | Q_UNUSED(width); | - |
84 | Q_UNUSED(height); | - |
85 | return QPixmap(); | - |
86 | } | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | | - |
92 | | - |
93 | | - |
94 | QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const | - |
95 | { | - |
96 | const QWindowList list = QGuiApplication::topLevelWindows(); | - |
97 | for (int i = list.size()-1; i >= 0; --i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
98 | QWindow *w = list[i]; | - |
99 | if (w->isVisible() && QHighDpi::toNativePixels(w->geometry(), w).contains(pos))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
100 | return w; never executed: return w; | 0 |
101 | } never executed: end of block | 0 |
102 | | - |
103 | return 0; never executed: return 0; | 0 |
104 | } | - |
105 | | - |
106 | | - |
107 | | - |
108 | | - |
109 | | - |
110 | | - |
111 | const QPlatformScreen *QPlatformScreen::screenForPosition(const QPoint &point) const | - |
112 | { | - |
113 | if (!geometry().contains(point)) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
114 | Q_FOREACHconst auto screens = virtualSiblings(); | - |
115 | for (const QPlatformScreen *screen , virtualSiblings()): screens) { | - |
116 | if (screen->geometry().contains(point))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
117 | return screen; never executed: return screen; | 0 |
118 | } never executed: end of block | 0 |
119 | } never executed: end of block | 0 |
120 | return this; never executed: return this; | 0 |
121 | } | - |
122 | | - |
123 | | - |
124 | | - |
125 | | - |
126 | | - |
127 | | - |
128 | | - |
129 | | - |
130 | | - |
131 | QList<QPlatformScreen *> QPlatformScreen::virtualSiblings() const | - |
132 | { | - |
133 | QList<QPlatformScreen *> list; | - |
134 | list << const_cast<QPlatformScreen *>(this); | - |
135 | return list; | - |
136 | } | - |
137 | | - |
138 | QScreen *QPlatformScreen::screen() const | - |
139 | { | - |
140 | Q_D(const QPlatformScreen); | - |
141 | return d->screen; | - |
142 | } | - |
143 | | - |
144 | | - |
145 | | - |
146 | | - |
147 | | - |
148 | | - |
149 | | - |
150 | | - |
151 | | - |
152 | | - |
153 | | - |
154 | | - |
155 | | - |
156 | QSizeF QPlatformScreen::physicalSize() const | - |
157 | { | - |
158 | static const int dpi = 100; | - |
159 | return QSizeF(geometry().size()) / dpi * qreal(25.4); | - |
160 | } | - |
161 | | - |
162 | | - |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | | - |
169 | | - |
170 | | - |
171 | | - |
172 | | - |
173 | | - |
174 | QDpi QPlatformScreen::logicalDpi() const | - |
175 | { | - |
176 | QSizeF ps = physicalSize(); | - |
177 | QSize s = geometry().size(); | - |
178 | | - |
179 | return QDpi(25.4 * s.width() / ps.width(), | - |
180 | 25.4 * s.height() / ps.height()); | - |
181 | } | - |
182 | | - |
183 | | - |
184 | | - |
185 | | - |
186 | | - |
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | qreal QPlatformScreen::devicePixelRatio() const | - |
193 | { | - |
194 | return 1.0; | - |
195 | } | - |
196 | | - |
197 | | - |
198 | | - |
199 | | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | | - |
206 | | - |
207 | | - |
208 | | - |
209 | | - |
210 | qreal QPlatformScreen::pixelDensity() const | - |
211 | { | - |
212 | return 1.0; | - |
213 | } | - |
214 | | - |
215 | | - |
216 | | - |
217 | | - |
218 | | - |
219 | | - |
220 | | - |
221 | qreal QPlatformScreen::refreshRate() const | - |
222 | { | - |
223 | return 60; | - |
224 | } | - |
225 | | - |
226 | | - |
227 | | - |
228 | | - |
229 | | - |
230 | | - |
231 | | - |
232 | | - |
233 | Qt::ScreenOrientation QPlatformScreen::nativeOrientation() const | - |
234 | { | - |
235 | return Qt::PrimaryOrientation; | - |
236 | } | - |
237 | | - |
238 | | - |
239 | | - |
240 | | - |
241 | | - |
242 | | - |
243 | | - |
244 | | - |
245 | Qt::ScreenOrientation QPlatformScreen::orientation() const | - |
246 | { | - |
247 | return Qt::PrimaryOrientation; | - |
248 | } | - |
249 | | - |
250 | | - |
251 | | - |
252 | | - |
253 | | - |
254 | | - |
255 | | - |
256 | | - |
257 | | - |
258 | | - |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | | - |
266 | | - |
267 | | - |
268 | void QPlatformScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask) | - |
269 | { | - |
270 | Q_UNUSED(mask); | - |
271 | } | - |
272 | | - |
273 | QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window) | - |
274 | { | - |
275 | | - |
276 | | - |
277 | if (!window->screen()) | - |
278 | return 0; | - |
279 | return window->screen()->handle(); | - |
280 | } | - |
281 | | - |
282 | | - |
283 | | - |
284 | | - |
285 | | - |
286 | | - |
287 | | - |
288 | | - |
289 | | - |
290 | | - |
291 | | - |
292 | | - |
293 | | - |
294 | | - |
295 | | - |
296 | | - |
297 | | - |
298 | | - |
299 | | - |
300 | | - |
301 | | - |
302 | | - |
303 | | - |
304 | | - |
305 | | - |
306 | | - |
307 | | - |
308 | | - |
309 | | - |
310 | | - |
311 | | - |
312 | | - |
313 | | - |
314 | | - |
315 | | - |
316 | | - |
317 | | - |
318 | | - |
319 | | - |
320 | | - |
321 | | - |
322 | QPlatformCursor *QPlatformScreen::cursor() const | - |
323 | { | - |
324 | return 0; | - |
325 | } | - |
326 | | - |
327 | | - |
328 | | - |
329 | | - |
330 | | - |
331 | void QPlatformScreen::resizeMaximizedWindows() | - |
332 | { | - |
333 | QList<QWindow*> windows = QGuiApplication::allWindows(); | - |
334 | | - |
335 | | - |
336 | const QRect oldGeometry = screen()->geometry(); | - |
337 | const QRect oldAvailableGeometry = screen()->availableGeometry(); | - |
338 | const QRect newGeometry = deviceIndependentGeometry(); | - |
339 | const QRect newAvailableGeometry = QHighDpi::fromNative(availableGeometry(), QHighDpiScaling::factor(this), newGeometry.topLeft()); | - |
340 | | - |
341 | | - |
342 | for (int i = 0; i < windows.size(); ++i) { | - |
343 | QWindow *w = windows.at(i); | - |
344 | | - |
345 | | - |
346 | if (!w->handle()) | - |
347 | continue; | - |
348 | | - |
349 | if (platformScreenForWindow(w) != this) | - |
350 | continue; | - |
351 | | - |
352 | if (w->windowState() & Qt::WindowMaximized || w->geometry() == oldAvailableGeometry) | - |
353 | w->setGeometry(newAvailableGeometry); | - |
354 | else if (w->windowState() & Qt::WindowFullScreen || w->geometry() == oldGeometry) | - |
355 | w->setGeometry(newGeometry); | - |
356 | } | - |
357 | } | - |
358 | | - |
359 | | - |
360 | static int log2(uint i) | - |
361 | { | - |
362 | if (i == 0) | - |
363 | return -1; | - |
364 | | - |
365 | int result = 0; | - |
366 | while (!(i & 1)) { | - |
367 | ++result; | - |
368 | i >>= 1; | - |
369 | } | - |
370 | return result; | - |
371 | } | - |
372 | | - |
373 | int QPlatformScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) | - |
374 | { | - |
375 | if (a == Qt::PrimaryOrientation || b == Qt::PrimaryOrientation) { | - |
376 | qWarning("Use QScreen version of %sBetween() when passing Qt::PrimaryOrientation", "angle"); | - |
377 | return 0; | - |
378 | } | - |
379 | | - |
380 | if (a == b) | - |
381 | return 0; | - |
382 | | - |
383 | int ia = log2(uint(a)); | - |
384 | int ib = log2(uint(b)); | - |
385 | | - |
386 | int delta = ia - ib; | - |
387 | | - |
388 | if (delta < 0) | - |
389 | delta = delta + 4; | - |
390 | | - |
391 | int angles[] = { 0, 90, 180, 270 }; | - |
392 | return angles[delta]; | - |
393 | } | - |
394 | | - |
395 | QTransform QPlatformScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target) | - |
396 | { | - |
397 | if (a == Qt::PrimaryOrientation || b == Qt::PrimaryOrientation) { | - |
398 | qWarning("Use QScreen version of %sBetween() when passing Qt::PrimaryOrientation", "transform"); | - |
399 | return QTransform(); | - |
400 | } | - |
401 | | - |
402 | if (a == b) | - |
403 | return QTransform(); | - |
404 | | - |
405 | int angle = angleBetween(a, b); | - |
406 | | - |
407 | QTransform result; | - |
408 | switch (angle) { | - |
409 | case 90: | - |
410 | result.translate(target.width(), 0); | - |
411 | break; | - |
412 | case 180: | - |
413 | result.translate(target.width(), target.height()); | - |
414 | break; | - |
415 | case 270: | - |
416 | result.translate(0, target.height()); | - |
417 | break; | - |
418 | default: | - |
419 | Q_ASSERT(false); | - |
420 | } | - |
421 | result.rotate(angle); | - |
422 | | - |
423 | return result; | - |
424 | } | - |
425 | | - |
426 | QRect QPlatformScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect) | - |
427 | { | - |
428 | if (a == Qt::PrimaryOrientation || b == Qt::PrimaryOrientation) { | - |
429 | qWarning("Use QScreen version of %sBetween() when passing Qt::PrimaryOrientation", "map"); | - |
430 | return rect; | - |
431 | } | - |
432 | | - |
433 | if (a == b) | - |
434 | return rect; | - |
435 | | - |
436 | if ((a == Qt::PortraitOrientation || a == Qt::InvertedPortraitOrientation) | - |
437 | != (b == Qt::PortraitOrientation || b == Qt::InvertedPortraitOrientation)) | - |
438 | { | - |
439 | return QRect(rect.y(), rect.x(), rect.height(), rect.width()); | - |
440 | } | - |
441 | | - |
442 | return rect; | - |
443 | } | - |
444 | | - |
445 | QRect QPlatformScreen::deviceIndependentGeometry() const | - |
446 | { | - |
447 | qreal scaleFactor = QHighDpiScaling::factor(this); | - |
448 | QRect nativeGeometry = geometry(); | - |
449 | return QRect(nativeGeometry.topLeft(), QHighDpi::fromNative(nativeGeometry.size(), scaleFactor)); | - |
450 | } | - |
451 | | - |
452 | | - |
453 | | - |
454 | | - |
455 | | - |
456 | | - |
457 | | - |
458 | | - |
459 | QPlatformScreen::SubpixelAntialiasingType QPlatformScreen::subpixelAntialiasingTypeHint() const | - |
460 | { | - |
461 | static int type = -1; | - |
462 | if (type == -1) { | - |
463 | QByteArray env = qgetenv("QT_SUBPIXEL_AA_TYPE"); | - |
464 | if (env == "RGB") | - |
465 | type = QPlatformScreen::Subpixel_RGB; | - |
466 | else if (env == "BGR") | - |
467 | type = QPlatformScreen::Subpixel_BGR; | - |
468 | else if (env == "VRGB") | - |
469 | type = QPlatformScreen::Subpixel_VRGB; | - |
470 | else if (env == "VBGR") | - |
471 | type = QPlatformScreen::Subpixel_VBGR; | - |
472 | else | - |
473 | type = QPlatformScreen::Subpixel_None; | - |
474 | } | - |
475 | | - |
476 | return static_cast<QPlatformScreen::SubpixelAntialiasingType>(type); | - |
477 | } | - |
478 | | - |
479 | | - |
480 | | - |
481 | | - |
482 | | - |
483 | | - |
484 | QPlatformScreen::PowerState QPlatformScreen::powerState() const | - |
485 | { | - |
486 | return PowerStateOn; | - |
487 | } | - |
488 | | - |
489 | | - |
490 | | - |
491 | | - |
492 | void QPlatformScreen::setPowerState(PowerState state) | - |
493 | { | - |
494 | Q_UNUSED(state); | - |
495 | } | - |
496 | | - |
497 | QT_END_NAMESPACE | - |
| | |