1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qquickplatformtheme_p.h" |
5 | |
6 | #include <QtGui/private/qguiapplication_p.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | /*! |
11 | \internal |
12 | |
13 | Exposes platform theme hints to QML so that we have a more accurate way of checking |
14 | for platform-specific behavior than \c {Qt.platform.os === "foo"}. |
15 | */ |
16 | QQuickPlatformTheme::QQuickPlatformTheme(QObject *parent) : |
17 | QObject(parent) |
18 | { |
19 | } |
20 | |
21 | QVariant QQuickPlatformTheme::themeHint(QPlatformTheme::ThemeHint themeHint) const |
22 | { |
23 | return getThemeHint(themeHint); |
24 | } |
25 | |
26 | /*! |
27 | \internal |
28 | |
29 | This is static to allow us to call it from C++, as we're only available as a singleton in QML. |
30 | */ |
31 | QVariant QQuickPlatformTheme::getThemeHint(QPlatformTheme::ThemeHint themeHint) |
32 | { |
33 | // Allow tests to force some theme hint values, otherwise they get very messy and difficult to understand. |
34 | switch (themeHint) { |
35 | case QPlatformTheme::ShowDirectoriesFirst: { |
36 | bool isInt = false; |
37 | const int showDirsFirst = qEnvironmentVariableIntValue(varName: "QT_QUICK_DIALOGS_SHOW_DIRS_FIRST", ok: &isInt); |
38 | if (isInt) |
39 | return showDirsFirst != 0; |
40 | break; |
41 | } |
42 | default: |
43 | break; |
44 | } |
45 | return QGuiApplicationPrivate::platformTheme()->themeHint(hint: themeHint); |
46 | } |
47 | |
48 | QT_END_NAMESPACE |
49 | |
50 | #include "moc_qquickplatformtheme_p.cpp" |
51 |