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