aboutsummaryrefslogtreecommitdiffstats
path: root/src/labs/stylekit/qqstylekitcontrol_p.h
blob: 548b390c0f791ec1e953913e1963df641cde7239 (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
// 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 QQSTYLEKITCONTROL_P_H
#define QQSTYLEKITCONTROL_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 <QtQml/QtQml>
#include "qqstylekitcontrolstate_p.h"
#include "qqstylekitstorage_p.h"
#include "qqstylekitreader_p.h"

QT_BEGIN_NAMESPACE

class QQStyleKitVariation;
class QQStyleKitControlAttached;

class QQStyleKitControl : public QQStyleKitControlState
{
    Q_OBJECT
    Q_PROPERTY(QQmlListProperty<QQStyleKitVariation> variations READ variations FINAL)
    QML_NAMED_ELEMENT(StyleKitControl)
    QML_ATTACHED(QQStyleKitControlAttached)

public:
    QQStyleKitControl(QObject *parent = nullptr);

    QQmlListProperty<QQStyleKitVariation> variations();

    static QQStyleKitControlAttached *qmlAttachedProperties(QObject *object);

private:
    QVariant readStyleProperty(PropertyStorageId key) const;
    void writeStyleProperty(PropertyStorageId key, const QVariant &value);

private:
    Q_DISABLE_COPY(QQStyleKitControl)

    QList<QQStyleKitVariation *> m_variations;
    mutable QQStyleKitPropertyStorage m_storage;
    QQSK::State m_writtenStates = QQSK::StateFlag::NoState;

    friend class QQStyleKitPropertyResolver;
    friend class QQStyleKitControls;
};

class QQStyleKitControlAttached : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QStringList variations READ variations WRITE setVariations NOTIFY variationsChanged FINAL)
    Q_PROPERTY(QQStyleKitExtendedControlType controlType READ controlType WRITE setControlType NOTIFY controlTypeChanged FINAL)

public:
    QQStyleKitControlAttached(QObject *parent);

    QStringList variations() const;
    void setVariations(const QStringList &variations);

    QQStyleKitExtendedControlType controlType();
    void setControlType(QQStyleKitExtendedControlType type);

signals:
    void variationsChanged();
    void controlTypeChanged();

private:
    // m_variations is used for resolving in-app QQStyleKitVariations
    QStringList m_variations;
    // m_controlType is used for resolving in-style QQStyleKitVariations
    QQStyleKitExtendedControlType m_controlType = QQStyleKitReader::ControlType::Unspecified;

    static int s_variationCount;

    friend class QQStyleKit;
    friend class QQStyleKitPropertyResolver;
};

QT_END_NAMESPACE

#endif // QQSTYLEKITCONTROL_P_H