aboutsummaryrefslogtreecommitdiffstats
path: root/src/labs/stylekit/qqstylekitstyle_p.h
blob: 2aba7ddbf587792e272594c9aa9cb24a09531253 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default

#ifndef QQSTYLEKITSTYLE_P_H
#define QQSTYLEKITSTYLE_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include "qqstylekitreader_p.h"
#include "qqstylekitcontrols_p.h"
#include "qqstylekitcustomtheme_p.h"
#include "qqstylekitdebug_p.h"
#include "qqstylekitstyleandthemebase_p.h"

#include <QtQml/QtQml>
#include <QtQuickTemplates2/private/qquickdeferredpointer_p_p.h>

QT_BEGIN_NAMESPACE

class QQStyleKitTheme;
class QQStyleKitPropertyResolver;

class QQStyleKitStyle : public QQStyleKitStyleAndThemeBase
{
    Q_OBJECT
    Q_PROPERTY(QQuickPalette *palette READ palette NOTIFY paletteChanged FINAL)
    Q_PROPERTY(QQStyleKitStyle *fallbackStyle READ fallbackStyle WRITE setFallbackStyle NOTIFY fallbackStyleChanged FINAL)
    Q_PROPERTY(QQmlComponent *light READ light WRITE setLight NOTIFY lightChanged FINAL)
    Q_PROPERTY(QQmlComponent *dark READ dark WRITE setDark NOTIFY darkChanged FINAL)
    Q_PROPERTY(QString themeName READ themeName WRITE setThemeName NOTIFY themeNameChanged FINAL)
    Q_PROPERTY(QStringList themeNames READ themeNames NOTIFY themeNamesChanged FINAL)
    Q_PROPERTY(QStringList customThemeNames READ customThemeNames NOTIFY customThemeNamesChanged FINAL)
    Q_PROPERTY(QQStyleKitTheme *theme READ theme NOTIFY themeChanged FINAL)

    Q_CLASSINFO("DeferredPropertyNames", "fallbackStyle")
    QML_NAMED_ELEMENT(BaseStyle)

public:
    enum Contstants {
        Stretch = -1,
    };
    Q_ENUM(Contstants)

    QQStyleKitStyle(QObject *parent = nullptr);
    ~QQStyleKitStyle();

    QQuickPalette *palette() const;

    QQStyleKitStyle *fallbackStyle() const;
    void setFallbackStyle(QQStyleKitStyle *fallbackStyle);

    QQmlComponent *light() const;
    void setLight(QQmlComponent *lightTheme);

    QQmlComponent *dark() const;
    void setDark(QQmlComponent *darkTheme);

    QList<QQStyleKitCustomTheme *> customThemes() const;
    QStringList themeNames() const;
    QStringList customThemeNames() const;

    void setThemeName(const QString &themeName);
    QString themeName() const;
    QQStyleKitTheme *theme() const;

    bool loaded() const;

    static QQStyleKitStyle *current();

    QFont fontForReader(QQStyleKitReader *reader) const;

    // For now, used by qqcontrolstowidgetstyle
    Q_INVOKABLE QList<QObject *> customThemesAsList();

signals:
    void paletteChanged();
    void fallbackStyleChanged();
    void lightChanged();
    void darkChanged();
    void themeChanged();
    void themeNameChanged();
    void themeNamesChanged();
    void customThemeNamesChanged();

protected:
    void componentComplete() override;

private:
    void parseThemes();
    void recreateTheme();
    void executeFallbackStyle(bool complete = false);
    void setPalette(QQuickPalette *palette);

private:
    Q_DISABLE_COPY(QQStyleKitStyle)

    bool m_completed = false;
    bool m_isUpdatingPalette = false;

    QQuickDeferredPointer<QQStyleKitStyle> m_fallbackStyle;
    QPointer<QQmlComponent> m_light;
    QPointer<QQmlComponent> m_dark;
    QPointer<QQStyleKitTheme> m_theme;
    QPointer<QQmlComponent> m_currentThemeComponent;
    QPointer<QQuickPalette> m_palette;
    QString m_themeName;
    QString m_effectiveThemeName;
    QStringList m_themeNames;
    QStringList m_customThemeNames;

    friend class QQStyleKitAttached;
    friend class QQStyleKitPropertyGroup;
    friend class QQStyleKitPropertyResolver;
};

QT_END_NAMESPACE

#endif // QQSTYLEKITSTYLE_P_H