QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskPlatform.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskPlatform.h"
7#include "QskInternalMacros.h"
8
9#include <qguiapplication.h>
10#include <qquickwindow.h>
11#include <qscreen.h>
12
13QSK_QT_PRIVATE_BEGIN
14#include <private/qguiapplication_p.h>
15#include <private/qhighdpiscaling_p.h>
16QSK_QT_PRIVATE_END
17
18#include <qpa/qplatformintegration.h>
19#include <qpa/qplatformscreen.h>
20
21qreal qskGlobalScaleFactor()
22{
23 // The value of QT_SCALE_FACTOR
24 const QScreen* noScreen = nullptr;
25 return QHighDpiScaling::factor( noScreen );
26}
27
28const QPlatformIntegration* qskPlatformIntegration()
29{
30 return QGuiApplicationPrivate::platformIntegration();
31}
32
33const QPlatformTheme* qskPlatformTheme()
34{
35 return QGuiApplicationPrivate::platformTheme();
36}
37
38bool qskMaybeDesktopPlatform()
39{
40#if QT_CONFIG(cursor)
41 if ( const auto platform = QGuiApplicationPrivate::platformIntegration() )
42 return platform->hasCapability( QPlatformIntegration::MultipleWindows );
43#endif
44
45 return false;
46}
47
48QRect qskPlatformScreenGeometry( const QScreen* screen )
49{
50 if ( screen == nullptr )
51 return QRect();
52
53 return screen->handle()->geometry();
54}
55
56static inline qreal qskWindowDpi( const QWindow* window )
57{
58 QScreen* screen = nullptr;
59 if ( window )
60 screen = window->screen();
61
62 if ( screen == nullptr )
63 screen = QGuiApplication::primaryScreen();
64
65 return QHighDpiScaling::logicalDpi( screen ).first;
66}
67
68qreal qskInchesToPixels( const QQuickWindow* window, qreal inches )
69{
70 return qskWindowDpi( window ) * inches;
71}
72
73qreal qskMMToPixels( const QQuickWindow* window, qreal mm )
74{
75 return qskWindowDpi( window ) * mm / 25.4;
76}