1// Copyright (C) 2020 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#ifndef QQUICKPALETTE_H
4#define QQUICKPALETTE_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists for the convenience
11// of QQuickPalette. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtQuick/private/qquickcolorgroup_p.h>
18
19#include <array>
20
21QT_BEGIN_NAMESPACE
22
23class QQuickAbstractPaletteProvider;
24
25class Q_QUICK_PRIVATE_EXPORT QQuickPalette : public QQuickColorGroup
26{
27 Q_OBJECT
28
29 Q_PROPERTY(QQuickColorGroup *active READ active WRITE setActive NOTIFY activeChanged FINAL)
30 Q_PROPERTY(QQuickColorGroup *inactive READ inactive WRITE setInactive NOTIFY inactiveChanged FINAL)
31 Q_PROPERTY(QQuickColorGroup *disabled READ disabled WRITE setDisabled NOTIFY disabledChanged FINAL)
32
33 QML_NAMED_ELEMENT(Palette)
34 QML_ADDED_IN_VERSION(6, 0)
35
36public: // Types
37 using PalettePtr = QPointer<QQuickPalette>;
38
39public:
40 Q_DISABLE_COPY_MOVE(QQuickPalette)
41 explicit QQuickPalette(QObject *parent = nullptr);
42
43 QQuickColorGroup *active() const;
44 QQuickColorGroup *inactive() const;
45 QQuickColorGroup *disabled() const;
46
47 QPalette::ColorGroup currentColorGroup() const override;
48 void setCurrentGroup(QPalette::ColorGroup currentGroup);
49
50 void fromQPalette(QPalette palette);
51 QPalette toQPalette() const;
52
53 const QQuickAbstractPaletteProvider *paletteProvider() const;
54 void setPaletteProvider(const QQuickAbstractPaletteProvider *paletteProvider);
55
56 void reset();
57
58 void inheritPalette(const QPalette &palette);
59
60public Q_SLOTS:
61 void setActive(QQuickColorGroup *active);
62 void setInactive(QQuickColorGroup *inactive);
63 void setDisabled(QQuickColorGroup *disabled);
64
65Q_SIGNALS:
66 void activeChanged();
67 void inactiveChanged();
68 void disabledChanged();
69
70private:
71 void setColorGroup(QPalette::ColorGroup groupTag,
72 const QQuickColorGroup::GroupPtr &group,
73 void (QQuickPalette::*notifier)());
74 QQuickColorGroup::GroupPtr colorGroup(QPalette::ColorGroup groupTag) const;
75 QQuickColorGroup::GroupPtr findColorGroup(QPalette::ColorGroup groupTag) const;
76
77 void registerColorGroup(QQuickColorGroup *group, QPalette::ColorGroup groupTag);
78
79 bool isValidColorGroup(QPalette::ColorGroup groupTag,
80 const QQuickColorGroup::GroupPtr &colorGroup) const;
81
82 static constexpr QPalette::ColorGroup defaultCurrentGroup() { return QPalette::Active; }
83
84private:
85 std::array<QQuickColorGroup::GroupPtr, QPalette::NColorGroups> m_colorGroups = {};
86 QPalette::ColorGroup m_currentGroup;
87};
88
89QT_END_NAMESPACE
90
91QML_DECLARE_TYPE(QQuickPalette)
92
93#endif // QQUICKPALETTE_H
94

source code of qtdeclarative/src/quick/items/qquickpalette_p.h