7#include <QtCore/qapplicationstatic.h>
8#include <QtCore/qloggingcategory.h>
9#include <QtCore/qthread.h>
10#include <QtGui/qguiapplication.h>
11#include <QtGui/qstylehints.h>
13#if defined(Q_OS_MACOS)
14# include "qquickmacstyle_mac_p.h"
15#elif defined(Q_OS_WINDOWS)
16# include "qquickwindowsxpstyle_p.h"
45 QStyle *style() {
return m_style.get(); }
48 std::unique_ptr<QStyle> m_style;
51Q_APPLICATION_STATIC(StyleSingleton, styleSingleton);
53StyleSingleton::StyleSingleton()
55 qCDebug(lcNativeStylePlugin) <<
"Creating native style";
59 if (qEnvironmentVariable(
"QQC2_COMMONSTYLE") == u"true")
60 m_style = std::make_unique<QCommonStyle>();
61 else if (
const QString envStyle = qEnvironmentVariable(
"QQC2_STYLE"); !envStyle.isNull()) {
62 if (envStyle == u"common")
63 m_style = std::make_unique<QCommonStyle>();
64#if defined(Q_OS_MACOS)
65 else if (envStyle == u"mac")
66 m_style.reset(QMacStyle::create());
68#if defined(Q_OS_WINDOWS)
69 else if (envStyle == u"windows")
70 m_style = std::make_unique<QWindowsStyle>();
71 else if (envStyle == u"windowsxp")
72 m_style = std::make_unique<QWindowsXPStyle>();
77#if defined(Q_OS_MACOS)
78 m_style.reset(QMacStyle::create());
79#elif defined(Q_OS_WINDOWS)
80 m_style = std::make_unique<QWindowsXPStyle>();
81 if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
82 qobject_cast<QWindowsStyle *>(m_style.get())->refreshPalette();
87 m_style = std::make_unique<QCommonStyle>();
94 Q_ASSERT(m_style->thread()->isMainThread());
95 QObject::connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, m_style.get(),
97 m_style->handleThemeChange();
101StyleSingleton::~StyleSingleton()
103 qCDebug(lcNativeStylePlugin) <<
"Destroying native style";
112 return styleSingleton()->style();
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")