9#include <qpa/qplatformscreen.h>
10#include <qpa/qplatformscreen_p.h>
12#include <QtCore/QDebug>
13#include <QtCore/private/qobject_p.h>
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
47QScreen::QScreen(QPlatformScreen *platformScreen)
48 : QObject(*
new QScreenPrivate(),
nullptr)
52 d->platformScreen = platformScreen;
53 platformScreen->d_func()->screen =
this;
55 d->orientation = platformScreen->orientation();
56 d->logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi());
57 d->refreshRate = platformScreen->refreshRate();
59 if (d->refreshRate < 1.0)
60 d->refreshRate = 60.0;
63 d->updatePrimaryOrientation();
68 qreal scaleFactor = QHighDpiScaling::factor(platformScreen);
69 QRect nativeGeometry = platformScreen->geometry();
70 geometry = QRect(nativeGeometry.topLeft(), QHighDpi::fromNative(nativeGeometry.size(), scaleFactor));
71 QRect nativeAvailableGeometry = platformScreen->availableGeometry();
72 availableGeometry = QRect(nativeAvailableGeometry.topLeft(), QHighDpi::fromNative(nativeAvailableGeometry.size(), scaleFactor));
76
77
78
79
82 Q_ASSERT_X(!QGuiApplicationPrivate::screen_list.contains(
this),
"QScreen",
83 "QScreens should be removed via QWindowSystemInterface::handleScreenRemoved()");
87
88
89
90
91QPlatformScreen *QScreen::handle()
const
94 return d->platformScreen;
98
99
100
101
102
103
104
105
106
107
108QString QScreen::name()
const
111 return d->platformScreen->name();
115
116
117
118
119
120QString QScreen::manufacturer()
const
123 return d->platformScreen->manufacturer();
127
128
129
130
131
132QString QScreen::model()
const
135 return d->platformScreen->model();
139
140
141
142
143
144QString QScreen::serialNumber()
const
147 return d->platformScreen->serialNumber();
151
152
153
154int QScreen::depth()
const
157 return d->platformScreen->depth();
161
162
163
164QSize QScreen::size()
const
167 return d->geometry.size();
171
172
173
174
175
176
177
178
179
180
181
182
183qreal QScreen::physicalDotsPerInchX()
const
185 return size().width() / physicalSize().width() * qreal(25.4);
189
190
191
192
193
194
195
196
197
198
199
200
201qreal QScreen::physicalDotsPerInchY()
const
203 return size().height() / physicalSize().height() * qreal(25.4);
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223qreal QScreen::physicalDotsPerInch()
const
226 QSizeF psz = physicalSize();
227 return ((sz.height() / psz.height()) + (sz.width() / psz.width())) * qreal(25.4 * 0.5);
231
232
233
234
235
236
237
238qreal QScreen::logicalDotsPerInchX()
const
241 if (QHighDpiScaling::isActive())
242 return QHighDpiScaling::logicalDpi(
this).first;
243 return d->logicalDpi.first;
247
248
249
250
251
252
253
254qreal QScreen::logicalDotsPerInchY()
const
257 if (QHighDpiScaling::isActive())
258 return QHighDpiScaling::logicalDpi(
this).second;
259 return d->logicalDpi.second;
263
264
265
266
267
268
269
270
271
272
273
274qreal QScreen::logicalDotsPerInch()
const
277 QDpi dpi = QHighDpiScaling::isActive() ? QHighDpiScaling::logicalDpi(
this) : d->logicalDpi;
278 return (dpi.first + dpi.second) * qreal(0.5);
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298qreal QScreen::devicePixelRatio()
const
301 return d->platformScreen->devicePixelRatio() * QHighDpiScaling::factor(
this);
305
306
307
308
309
310
311
312
313
314QSizeF QScreen::physicalSize()
const
317 return d->platformScreen->physicalSize();
321
322
323
324
325
326
327QSize QScreen::availableSize()
const
330 return d->availableGeometry.size();
334
335
336
337
338
339
340QRect QScreen::geometry()
const
347
348
349
350
351
352
353
354
355
356
357QRect QScreen::availableGeometry()
const
360 return d->availableGeometry;
364
365
366
367
368
369
370QList<QScreen *> QScreen::virtualSiblings()
const
373 const QList<QPlatformScreen *> platformScreens = d->platformScreen->virtualSiblings();
374 QList<QScreen *> screens;
375 screens.reserve(platformScreens.size());
376 for (QPlatformScreen *platformScreen : platformScreens) {
378 if (
auto *knownScreen = platformScreen->screen())
379 screens << knownScreen;
385
386
387
388
389
390
391
392
393
394QSize QScreen::virtualSize()
const
396 return virtualGeometry().size();
400
401
402
403
404
405
406
407
408
409QRect QScreen::virtualGeometry()
const
412 const auto screens = virtualSiblings();
413 for (QScreen *screen : screens)
414 result |= screen->geometry();
419
420
421
422
423
424
425
426
427
428QSize QScreen::availableVirtualSize()
const
430 return availableVirtualGeometry().size();
434
435
436
437
438
439
440
441
442
443QRect QScreen::availableVirtualGeometry()
const
446 const auto screens = virtualSiblings();
447 for (QScreen *screen : screens)
448 result |= screen->availableGeometry();
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467Qt::ScreenOrientation QScreen::orientation()
const
470 return d->orientation;
474
475
476
477
478
479
480
481
482qreal QScreen::refreshRate()
const
485 return d->refreshRate;
489
490
491
492
493
494
495
496
497
498
499
500
501Qt::ScreenOrientation QScreen::primaryOrientation()
const
504 return d->primaryOrientation;
508
509
510
511
512
513
514
515
516
517
518Qt::ScreenOrientation QScreen::nativeOrientation()
const
521 return d->platformScreen->nativeOrientation();
525
526
527
528
529
530
531
532int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
const
534 if (a == Qt::PrimaryOrientation)
535 a = primaryOrientation();
537 if (b == Qt::PrimaryOrientation)
538 b = primaryOrientation();
540 return QPlatformScreen::angleBetween(a, b);
544
545
546
547
548
549
550
551
552
553
554
555QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b,
const QRect &target)
const
557 if (a == Qt::PrimaryOrientation)
558 a = primaryOrientation();
560 if (b == Qt::PrimaryOrientation)
561 b = primaryOrientation();
563 return QPlatformScreen::transformBetween(a, b, target);
567
568
569
570
571
572
573
574
575QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b,
const QRect &rect)
const
577 if (a == Qt::PrimaryOrientation)
578 a = primaryOrientation();
580 if (b == Qt::PrimaryOrientation)
581 b = primaryOrientation();
583 return QPlatformScreen::mapBetween(a, b, rect);
587
588
589
590
591
592bool QScreen::isPortrait(Qt::ScreenOrientation o)
const
594 return o == Qt::PortraitOrientation || o == Qt::InvertedPortraitOrientation
595 || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::PortraitOrientation);
599
600
601
602
603
604bool QScreen::isLandscape(Qt::ScreenOrientation o)
const
606 return o == Qt::LandscapeOrientation || o == Qt::InvertedLandscapeOrientation
607 || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::LandscapeOrientation);
611
612
613
614
615
616
617
620
621
622
623
624
625
626
630 primaryOrientation = geometry.width() >= geometry.height() ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
634
635
636
637
638
639
640
641
642QScreen *QScreen::virtualSiblingAt(QPoint point)
644 const auto &siblings = virtualSiblings();
645 for (QScreen *sibling : siblings) {
646 if (sibling->geometry().contains(point))
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
712QPixmap QScreen::grabWindow(WId window,
int x,
int y,
int width,
int height)
714 const QPlatformScreen *platformScreen = handle();
715 if (!platformScreen) {
716 qWarning(
"invoked with handle==0");
719 const qreal factor = QHighDpiScaling::factor(
this);
720 if (qFuzzyCompare(factor, 1))
721 return platformScreen->grabWindow(window, x, y, width, height);
723 const QPoint nativePos = QHighDpi::toNative(QPoint(x, y), factor);
724 QSize nativeSize(width, height);
725 if (nativeSize.isValid())
726 nativeSize = QHighDpi::toNative(nativeSize, factor);
728 platformScreen->grabWindow(window, nativePos.x(), nativePos.y(),
729 nativeSize.width(), nativeSize.height());
730 result.setDevicePixelRatio(result.devicePixelRatio() * factor);
735
736
737
738
739
740
741
742
743
744
745
747void *QScreen::resolveInterface(
const char *name,
int revision)
const
749 using namespace QNativeInterface;
750 using namespace QNativeInterface::Private;
752 auto *platformScreen = handle();
753 Q_UNUSED(platformScreen);
758 QT_NATIVE_INTERFACE_RETURN_IF(QXcbScreen, platformScreen);
762 QT_NATIVE_INTERFACE_RETURN_IF(QVsp2Screen, platformScreen);
765#if defined(Q_OS_WEBOS)
766 QT_NATIVE_INTERFACE_RETURN_IF(QWebOSScreen, platformScreen);
769#if defined(Q_OS_WIN32)
770 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsScreen, platformScreen);
773#if defined(Q_OS_ANDROID)
774 QT_NATIVE_INTERFACE_RETURN_IF(QAndroidScreen, platformScreen);
777#if QT_CONFIG(wayland)
778 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandScreen, platformScreen);
781#if defined(Q_OS_MACOS)
782 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaScreen, platformScreen);
788#ifndef QT_NO_DEBUG_STREAM
789Q_GUI_EXPORT
QDebug operator<<(QDebug debug,
const QScreen *screen)
791 const QDebugStateSaver saver(debug);
793 debug <<
"QScreen(" << (
const void *)screen;
795 debug <<
", name=" << screen->name();
796 if (debug.verbosity() > 2) {
797 if (screen == QGuiApplication::primaryScreen())
798 debug <<
", primary";
799 debug <<
", geometry=" << screen->geometry();
800 debug <<
", available=" << screen->availableGeometry();
801 debug <<
", logical DPI=" << screen->logicalDotsPerInchX()
802 <<
',' << screen->logicalDotsPerInchY()
803 <<
", physical DPI=" << screen->physicalDotsPerInchX()
804 <<
',' << screen->physicalDotsPerInchY()
805 <<
", devicePixelRatio=" << screen->devicePixelRatio()
806 <<
", orientation=" << screen->orientation()
807 <<
", physical size=" << screen->physicalSize().width()
808 <<
'x' << screen->physicalSize().height() <<
"mm";
818 initialState.platformScreen = screen->handle();
825 initialState.logicalDpi = QDpi{
826 screen->logicalDotsPerInchX(),
827 screen->logicalDotsPerInchY()
829 initialState.geometry = screen->geometry();
830 initialState.availableGeometry = screen->availableGeometry();
831 initialState.primaryOrientation = screen->primaryOrientation();
836 QScreen *screen = initialState.platformScreen->screen();
838 const auto logicalDotsPerInch = QDpi{
839 screen->logicalDotsPerInchX(),
840 screen->logicalDotsPerInchY()
842 if (logicalDotsPerInch != initialState.logicalDpi)
843 emit screen->logicalDotsPerInchChanged(screen->logicalDotsPerInch());
845 const auto geometry = screen->geometry();
846 const auto geometryChanged = geometry != initialState.geometry;
848 emit screen->geometryChanged(geometry);
850 const auto availableGeometry = screen->availableGeometry();
851 const auto availableGeometryChanged = availableGeometry != initialState.availableGeometry;
852 if (availableGeometryChanged)
853 emit screen->availableGeometryChanged(availableGeometry);
855 if (geometryChanged || availableGeometryChanged) {
856 const auto siblings = screen->virtualSiblings();
857 for (QScreen* sibling : siblings)
858 emit sibling->virtualGeometryChanged(sibling->virtualGeometry());
861 if (geometryChanged) {
862 emit screen->physicalDotsPerInchChanged(screen->physicalDotsPerInch());
864 const auto primaryOrientation = screen->primaryOrientation();
865 if (primaryOrientation != initialState.primaryOrientation)
866 emit screen->primaryOrientationChanged(primaryOrientation);
872#include "moc_qscreen.cpp"
UpdateEmitter(QScreen *screen)
void updatePrimaryOrientation()
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)