qplatformscreen.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qplatformscreen.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
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 https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
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-
51QT_BEGIN_NAMESPACE-
52-
53QPlatformScreen::QPlatformScreen()-
54 : d_ptr(new QPlatformScreenPrivate)-
55{-
56 Q_D(QPlatformScreen);-
57 d->screen = 0;-
58}-
59-
60QPlatformScreen::~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 \fn QPixmap QPlatformScreen::grabWindow(WId window, int x, int y, int width, int height) const-
72-
73 This function is called when Qt needs to be able to grab the content of a window.-
74-
75 Returnes the content of the window specified with the WId handle within the boundaries of-
76 QRect(x,y,width,height).-
77*/-
78QPixmap 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 Return the given top level window for a given position.-
90-
91 Default implementation retrieves a list of all top level windows and finds the first window-
92 which contains point \a pos-
93*/-
94QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const-
95{-
96 const QWindowList list = QGuiApplication::topLevelWindows();-
97 for (int i = list.size()-1; i >= 0; --i) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
98 QWindow *w = list[i];-
99 if (w->isVisible() && QHighDpi::toNativePixels(w->geometry(), w).contains(pos))
w->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
QHighDpi::toNa....contains(pos)Description
TRUEnever evaluated
FALSEnever 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 Find the sibling screen corresponding to \a globalPos.-
108-
109 Returns this screen if no suitable screen is found at the position.-
110 */-
111const QPlatformScreen *QPlatformScreen::screenForPosition(const QPoint &point) const-
112{-
113 if (!geometry().contains(point)) {
!geometry().contains(point)Description
TRUEnever evaluated
FALSEnever evaluated
0
114 Q_FOREACHconst auto screens = virtualSiblings();-
115 for (const QPlatformScreen *screen , virtualSiblings()): screens) {-
116 if (screen->geometry().contains(point))
screen->geomet...ontains(point)Description
TRUEnever evaluated
FALSEnever 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 Returns a list of all the platform screens that are part of the same-
126 virtual desktop.-
127-
128 Screens part of the same virtual desktop share a common coordinate system,-
129 and windows can be freely moved between them.-
130*/-
131QList<QPlatformScreen *> QPlatformScreen::virtualSiblings() const-
132{-
133 QList<QPlatformScreen *> list;-
134 list << const_cast<QPlatformScreen *>(this);-
135 return list;-
136}-
137-
138QScreen *QPlatformScreen::screen() const-
139{-
140 Q_D(const QPlatformScreen);-
141 return d->screen;-
142}-
143-
144/*!-
145 Reimplement this function in subclass to return the physical size of the-
146 screen, in millimeters. The physical size represents the actual physical-
147 dimensions of the display.-
148-
149 The default implementation takes the pixel size of the screen, considers a-
150 resolution of 100 dots per inch, and returns the calculated physical size.-
151 A device with a screen that has different resolutions will need to be-
152 supported by a suitable reimplementation of this function.-
153-
154 \sa logcalDpi-
155*/-
156QSizeF QPlatformScreen::physicalSize() const-
157{-
158 static const int dpi = 100;-
159 return QSizeF(geometry().size()) / dpi * qreal(25.4);-
160}-
161-
162/*!-
163 Reimplement this function in subclass to return the logical horizontal-
164 and vertical dots per inch metrics of the screen.-
165-
166 The logical dots per inch metrics are used by QFont to convert point sizes-
167 to pixel sizes.-
168-
169 The default implementation uses the screen pixel size and physical size to-
170 compute the metrics.-
171-
172 \sa physicalSize-
173*/-
174QDpi 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 Reimplement this function in subclass to return the device pixel ratio-
185 for the screen. This is the ratio between physical pixels and the-
186 device-independent pixels of the windowing system. The default-
187 implementation returns 1.0.-
188-
189 \sa QPlatformWindow::devicePixelRatio()-
190 \sa QPlatformScreen::pixelDensity()-
191*/-
192qreal QPlatformScreen::devicePixelRatio() const-
193{-
194 return 1.0;-
195}-
196-
197/*!-
198 Reimplement this function in subclass to return the pixel density of the-
199 screen. This is the scale factor needed to make a low-dpi application-
200 usable on this screen. The default implementation returns 1.0.-
201-
202 Returning something else than 1.0 from this function causes Qt to-
203 apply the scale factor to the application's coordinate system.-
204 This is different from devicePixelRatio, which reports a scale-
205 factor already applied by the windowing system. A platform plugin-
206 typically implements one (or none) of these two functions.-
207-
208 \sa QPlatformWindow::devicePixelRatio()-
209*/-
210qreal QPlatformScreen::pixelDensity() const-
211{-
212 return 1.0;-
213}-
214-
215/*!-
216 Reimplement this function in subclass to return the vertical refresh rate-
217 of the screen, in Hz.-
218-
219 The default returns 60, a sensible default for modern displays.-
220*/-
221qreal QPlatformScreen::refreshRate() const-
222{-
223 return 60;-
224}-
225-
226/*!-
227 Reimplement this function in subclass to return the native orientation-
228 of the screen, e.g. the orientation where the logo sticker of the device-
229 appears the right way up.-
230-
231 The default implementation returns Qt::PrimaryOrientation.-
232*/-
233Qt::ScreenOrientation QPlatformScreen::nativeOrientation() const-
234{-
235 return Qt::PrimaryOrientation;-
236}-
237-
238/*!-
239 Reimplement this function in subclass to return the current orientation-
240 of the screen, for example based on accelerometer data to determine-
241 the device orientation.-
242-
243 The default implementation returns Qt::PrimaryOrientation.-
244*/-
245Qt::ScreenOrientation QPlatformScreen::orientation() const-
246{-
247 return Qt::PrimaryOrientation;-
248}-
249-
250/*-
251 Reimplement this function in subclass to filter out unneeded screen-
252 orientation updates.-
253-
254 The orientations will anyway be filtered before QScreen::orientationChanged()-
255 is emitted, but the mask can be used by the platform plugin for example to-
256 prevent having to have an accelerometer sensor running all the time, or to-
257 improve the reported values. As an example of the latter, in case of only-
258 Landscape | InvertedLandscape being set in the mask, on a platform that gets-
259 its orientation readings from an accelerometer sensor embedded in a handheld-
260 device, the platform can report transitions between the two even when the-
261 device is held in an orientation that's closer to portrait.-
262-
263 By default, the orientation update mask is empty, so unless this function-
264 has been called with a non-empty mask the platform does not need to report-
265 any orientation updates through-
266 QWindowSystemInterface::handleScreenOrientationChange().-
267*/-
268void QPlatformScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)-
269{-
270 Q_UNUSED(mask);-
271}-
272-
273QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window)-
274{-
275 // QTBUG 32681: It can happen during the transition between screens-
276 // when one screen is disconnected that the window doesn't have a screen.-
277 if (!window->screen())-
278 return 0;-
279 return window->screen()->handle();-
280}-
281-
282/*!-
283 \class QPlatformScreen-
284 \since 4.8-
285 \internal-
286 \preliminary-
287 \ingroup qpa-
288-
289 \brief The QPlatformScreen class provides an abstraction for visual displays.-
290-
291 Many window systems has support for retrieving information on the attached displays. To be able-
292 to query the display QPA uses QPlatformScreen. Qt its self is most dependent on the-
293 physicalSize() function, since this is the function it uses to calculate the dpi to use when-
294 converting point sizes to pixels sizes. However, this is unfortunate on some systems, as the-
295 native system fakes its dpi size.-
296-
297 QPlatformScreen is also used by the public api QDesktopWidget for information about the desktop.-
298 */-
299-
300/*! \fn QRect QPlatformScreen::geometry() const = 0-
301 Reimplement in subclass to return the pixel geometry of the screen-
302*/-
303-
304/*! \fn QRect QPlatformScreen::availableGeometry() const-
305 Reimplement in subclass to return the pixel geometry of the available space-
306 This normally is the desktop screen minus the task manager, global menubar etc.-
307*/-
308-
309/*! \fn int QPlatformScreen::depth() const = 0-
310 Reimplement in subclass to return current depth of the screen-
311*/-
312-
313/*! \fn QImage::Format QPlatformScreen::format() const = 0-
314 Reimplement in subclass to return the image format which corresponds to the screen format-
315*/-
316-
317/*!-
318 Reimplement this function in subclass to return the cursor of the screen.-
319-
320 The default implementation returns 0.-
321*/-
322QPlatformCursor *QPlatformScreen::cursor() const-
323{-
324 return 0;-
325}-
326-
327/*!-
328 Convenience method to resize all the maximized and fullscreen windows-
329 of this platform screen.-
330*/-
331void QPlatformScreen::resizeMaximizedWindows()-
332{-
333 QList<QWindow*> windows = QGuiApplication::allWindows();-
334-
335 // 'screen()' still has the old geometry info while 'this' has the new geometry info-
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 // make sure maximized and fullscreen windows are updated-
342 for (int i = 0; i < windows.size(); ++i) {-
343 QWindow *w = windows.at(i);-
344-
345 // Skip non-platform windows, e.g., offscreen windows.-
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// i must be power of two-
360static 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-
373int 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-
395QTransform 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-
426QRect 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-
445QRect 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 Returns a hint about this screen's subpixel layout structure.-
454-
455 The default implementation queries the \b{QT_SUBPIXEL_AA_TYPE} env variable.-
456 This is just a hint because most platforms don't have a way to retrieve the correct value from hardware-
457 and instead rely on font configurations.-
458*/-
459QPlatformScreen::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 Returns the current power state.-
481-
482 The default implementation always returns PowerStateOn.-
483*/-
484QPlatformScreen::PowerState QPlatformScreen::powerState() const-
485{-
486 return PowerStateOn;-
487}-
488-
489/*!-
490 Sets the power state for this screen.-
491*/-
492void QPlatformScreen::setPowerState(PowerState state)-
493{-
494 Q_UNUSED(state);-
495}-
496-
497QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9