| 1 | // Copyright (C) 2017 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 "qquickuniversaltheme_p.h" | 
| 5 | #include "qquickuniversalstyle_p.h" | 
| 6 | |
| 7 | #include <QtCore/qmutex.h> | 
| 8 | #include <QtGui/qfontdatabase.h> | 
| 9 | #include <QtQuickTemplates2/private/qquicktheme_p.h> | 
| 10 | |
| 11 | QT_BEGIN_NAMESPACE | 
| 12 | |
| 13 | struct QQuickUniversalThemePrivate | 
| 14 | { | 
| 15 | static inline void addSystemStyle(QPointer<QQuickUniversalStyle> style); | 
| 16 | static inline void removeSystemStyle(QPointer<QQuickUniversalStyle> style); | 
| 17 | static inline void updateSystemStyles(); | 
| 18 | static inline std::vector<QPointer<QQuickUniversalStyle>> systemStyles = {}; | 
| 19 | static inline QMutex mutex; | 
| 20 | }; | 
| 21 | |
| 22 | void QQuickUniversalThemePrivate::addSystemStyle(QPointer<QQuickUniversalStyle> style) | 
| 23 | { | 
| 24 | QMutexLocker locker{&mutex}; | 
| 25 | auto it = std::find(first: systemStyles.begin(), last: systemStyles.end(), val: style); | 
| 26 | if (it == systemStyles.end()) | 
| 27 | systemStyles.push_back(x: style); | 
| 28 | } | 
| 29 | void QQuickUniversalThemePrivate::removeSystemStyle(QPointer<QQuickUniversalStyle> style) | 
| 30 | { | 
| 31 | QMutexLocker locker{&mutex}; | 
| 32 | auto it = std::find(first: systemStyles.begin(), last: systemStyles.end(), val: style); | 
| 33 | if (it != systemStyles.end()) | 
| 34 | systemStyles.erase(position: it); | 
| 35 | } | 
| 36 | void QQuickUniversalThemePrivate::updateSystemStyles() | 
| 37 | { | 
| 38 | QMutexLocker locker{&mutex}; | 
| 39 | for (auto it = systemStyles.begin(); it != systemStyles.end(); ) { | 
| 40 | if (it->isNull()) { | 
| 41 | it = systemStyles.erase(position: it); | 
| 42 | } else { | 
| 43 | (*it)->setTheme(QQuickUniversalStyle::System); | 
| 44 | ++it; | 
| 45 | } | 
| 46 | } | 
| 47 | } | 
| 48 | |
| 49 | void QQuickUniversalTheme::initialize(QQuickTheme *theme) | 
| 50 | { | 
| 51 | QFont systemFont; | 
| 52 | QFont groupBoxTitleFont; | 
| 53 | QFont tabButtonFont; | 
| 54 | |
| 55 |     const QLatin1String segoeUiFamilyName("Segoe UI");  | 
| 56 | if (QFontDatabase::families().contains(str: segoeUiFamilyName)) { | 
| 57 | const QFont font(segoeUiFamilyName); | 
| 58 | const QStringList families{font.family()}; | 
| 59 | systemFont.setFamilies(families); | 
| 60 | groupBoxTitleFont.setFamilies(families); | 
| 61 | tabButtonFont.setFamilies(families); | 
| 62 | } | 
| 63 | |
| 64 | systemFont.setPixelSize(15); | 
| 65 | theme->setFont(scope: QQuickTheme::System, font: systemFont); | 
| 66 | |
| 67 | groupBoxTitleFont.setPixelSize(15); | 
| 68 | groupBoxTitleFont.setWeight(QFont::DemiBold); | 
| 69 | theme->setFont(scope: QQuickTheme::GroupBox, font: groupBoxTitleFont); | 
| 70 | |
| 71 | tabButtonFont.setPixelSize(24); | 
| 72 | tabButtonFont.setWeight(QFont::Light); | 
| 73 | theme->setFont(scope: QQuickTheme::TabBar, font: tabButtonFont); | 
| 74 | } | 
| 75 | |
| 76 | void QQuickUniversalTheme::registerSystemStyle(QQuickUniversalStyle *style) | 
| 77 | { | 
| 78 | QQuickUniversalThemePrivate::addSystemStyle(style: QPointer{style}); | 
| 79 | } | 
| 80 | |
| 81 | void QQuickUniversalTheme::unregisterSystemStyle(QQuickUniversalStyle *style) | 
| 82 | { | 
| 83 | QQuickUniversalThemePrivate::removeSystemStyle(style: QPointer{style}); | 
| 84 | } | 
| 85 | |
| 86 | void QQuickUniversalTheme::updateTheme() | 
| 87 | { | 
| 88 | QQuickUniversalThemePrivate::updateSystemStyles(); | 
| 89 | } | 
| 90 | |
| 91 | QT_END_NAMESPACE | 
| 92 | 
