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
698QPixmap QScreen::grabWindow(WId window,
int x,
int y,
int width,
int height)
700 const QPlatformScreen *platformScreen = handle();
701 if (!platformScreen) {
702 qWarning(
"invoked with handle==0");
705 const qreal factor = QHighDpiScaling::factor(
this);
706 if (qFuzzyCompare(factor, 1))
707 return platformScreen->grabWindow(window, x, y, width, height);
709 const QPoint nativePos = QHighDpi::toNative(QPoint(x, y), factor);
710 QSize nativeSize(width, height);
711 if (nativeSize.isValid())
712 nativeSize = QHighDpi::toNative(nativeSize, factor);
714 platformScreen->grabWindow(window, nativePos.x(), nativePos.y(),
715 nativeSize.width(), nativeSize.height());
716 result.setDevicePixelRatio(result.devicePixelRatio() * factor);
721
722
723
724
725
726
727
728
729
730
731
733void *QScreen::resolveInterface(
const char *name,
int revision)
const
735 using namespace QNativeInterface;
736 using namespace QNativeInterface::Private;
738 auto *platformScreen = handle();
739 Q_UNUSED(platformScreen);
744 QT_NATIVE_INTERFACE_RETURN_IF(QXcbScreen, platformScreen);
748 QT_NATIVE_INTERFACE_RETURN_IF(QVsp2Screen, platformScreen);
751#if defined(Q_OS_WEBOS)
752 QT_NATIVE_INTERFACE_RETURN_IF(QWebOSScreen, platformScreen);
755#if defined(Q_OS_WIN32)
756 QT_NATIVE_INTERFACE_RETURN_IF(QWindowsScreen, platformScreen);
759#if defined(Q_OS_ANDROID)
760 QT_NATIVE_INTERFACE_RETURN_IF(QAndroidScreen, platformScreen);
763#if QT_CONFIG(wayland)
764 QT_NATIVE_INTERFACE_RETURN_IF(QWaylandScreen, platformScreen);
767#if defined(Q_OS_MACOS)
768 QT_NATIVE_INTERFACE_RETURN_IF(QCocoaScreen, platformScreen);
774#ifndef QT_NO_DEBUG_STREAM
775Q_GUI_EXPORT
QDebug operator<<(QDebug debug,
const QScreen *screen)
777 const QDebugStateSaver saver(debug);
779 debug <<
"QScreen(" << (
const void *)screen;
781 debug <<
", name=" << screen->name();
782 if (debug.verbosity() > 2) {
783 if (screen == QGuiApplication::primaryScreen())
784 debug <<
", primary";
785 debug <<
", geometry=" << screen->geometry();
786 debug <<
", available=" << screen->availableGeometry();
787 debug <<
", logical DPI=" << screen->logicalDotsPerInchX()
788 <<
',' << screen->logicalDotsPerInchY()
789 <<
", physical DPI=" << screen->physicalDotsPerInchX()
790 <<
',' << screen->physicalDotsPerInchY()
791 <<
", devicePixelRatio=" << screen->devicePixelRatio()
792 <<
", orientation=" << screen->orientation()
793 <<
", physical size=" << screen->physicalSize().width()
794 <<
'x' << screen->physicalSize().height() <<
"mm";
804 initialState.platformScreen = screen->handle();
811 initialState.logicalDpi = QDpi{
812 screen->logicalDotsPerInchX(),
813 screen->logicalDotsPerInchY()
815 initialState.geometry = screen->geometry();
816 initialState.availableGeometry = screen->availableGeometry();
817 initialState.primaryOrientation = screen->primaryOrientation();
822 QScreen *screen = initialState.platformScreen->screen();
824 const auto logicalDotsPerInch = QDpi{
825 screen->logicalDotsPerInchX(),
826 screen->logicalDotsPerInchY()
828 if (logicalDotsPerInch != initialState.logicalDpi)
829 emit screen->logicalDotsPerInchChanged(screen->logicalDotsPerInch());
831 const auto geometry = screen->geometry();
832 const auto geometryChanged = geometry != initialState.geometry;
834 emit screen->geometryChanged(geometry);
836 const auto availableGeometry = screen->availableGeometry();
837 const auto availableGeometryChanged = availableGeometry != initialState.availableGeometry;
838 if (availableGeometryChanged)
839 emit screen->availableGeometryChanged(availableGeometry);
841 if (geometryChanged || availableGeometryChanged) {
842 const auto siblings = screen->virtualSiblings();
843 for (QScreen* sibling : siblings)
844 emit sibling->virtualGeometryChanged(sibling->virtualGeometry());
847 if (geometryChanged) {
848 emit screen->physicalDotsPerInchChanged(screen->physicalDotsPerInch());
850 const auto primaryOrientation = screen->primaryOrientation();
851 if (primaryOrientation != initialState.primaryOrientation)
852 emit screen->primaryOrientationChanged(primaryOrientation);
858#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)