1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the QtGraphs API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13
14#ifndef DECLARATIVETHEME_P_H
15#define DECLARATIVETHEME_P_H
16
17#include <private/graphsglobal_p.h>
18#include <private/q3dtheme_p.h>
19
20#include "declarativecolor_p.h"
21#include "colorgradient_p.h"
22
23#include <QtQml/qqml.h>
24#include <QtQml/qqmlparserstatus.h>
25
26QT_BEGIN_NAMESPACE
27
28class DeclarativeTheme3D : public Q3DTheme, public QQmlParserStatus
29{
30 Q_OBJECT
31 Q_INTERFACES(QQmlParserStatus)
32 Q_PROPERTY(QQmlListProperty<QObject> themeChildren READ themeChildren CONSTANT)
33 Q_PROPERTY(QQmlListProperty<DeclarativeColor> baseColors READ baseColors CONSTANT)
34 Q_PROPERTY(QQmlListProperty<ColorGradient> baseGradients READ baseGradients CONSTANT)
35 Q_PROPERTY(ColorGradient *singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged)
36 Q_PROPERTY(ColorGradient *multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged)
37 Q_CLASSINFO("DefaultProperty", "themeChildren")
38 QML_NAMED_ELEMENT(Theme3D)
39
40public:
41 DeclarativeTheme3D(QObject *parent = 0);
42 virtual ~DeclarativeTheme3D();
43
44 QQmlListProperty<QObject> themeChildren();
45 static void appendThemeChildren(QQmlListProperty<QObject> *list, QObject *element);
46
47 QQmlListProperty<DeclarativeColor> baseColors();
48 static void appendBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list,
49 DeclarativeColor *color);
50 static qsizetype countBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list);
51 static DeclarativeColor *atBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list,
52 qsizetype index);
53 static void clearBaseColorsFunc(QQmlListProperty<DeclarativeColor> *list);
54
55 QQmlListProperty<ColorGradient> baseGradients();
56 static void appendBaseGradientsFunc(QQmlListProperty<ColorGradient> *list,
57 ColorGradient *gradient);
58 static qsizetype countBaseGradientsFunc(QQmlListProperty<ColorGradient> *list);
59 static ColorGradient *atBaseGradientsFunc(QQmlListProperty<ColorGradient> *list,
60 qsizetype index);
61 static void clearBaseGradientsFunc(QQmlListProperty<ColorGradient> *list);
62
63 void setSingleHighlightGradient(ColorGradient *gradient);
64 ColorGradient *singleHighlightGradient() const;
65
66 void setMultiHighlightGradient(ColorGradient *gradient);
67 ColorGradient *multiHighlightGradient() const;
68
69 // From QQmlParserStatus
70 void classBegin() override;
71 void componentComplete() override;
72
73Q_SIGNALS:
74 void singleHighlightGradientChanged(ColorGradient *gradient);
75 void multiHighlightGradientChanged(ColorGradient *gradient);
76
77protected:
78 void handleTypeChange(Theme themeType);
79 void handleBaseColorUpdate();
80 void handleBaseGradientUpdate();
81 void handleSingleHLGradientUpdate();
82 void handleMultiHLGradientUpdate();
83
84 enum GradientType {
85 GradientTypeBase = 0,
86 GradientTypeSingleHL,
87 GradientTypeMultiHL
88 };
89
90private:
91 void addColor(DeclarativeColor *color);
92 QList<DeclarativeColor *> colorList();
93 void clearColors();
94 void clearDummyColors();
95
96 void addGradient(ColorGradient *gradient);
97 QList<ColorGradient *> gradientList();
98 void clearGradients();
99 void clearDummyGradients();
100
101 void setThemeGradient(ColorGradient *gradient, GradientType type);
102 QLinearGradient convertGradient(ColorGradient *gradient);
103 ColorGradient *convertGradient(const QLinearGradient &gradient);
104
105 QList<DeclarativeColor *> m_colors; // Not owned
106 QList<ColorGradient *> m_gradients; // Not owned
107 ColorGradient *m_singleHLGradient; // Not owned
108 ColorGradient *m_multiHLGradient; // Not owned
109
110 bool m_dummyGradients;
111 bool m_dummyColors;
112};
113
114QT_END_NAMESPACE
115
116#endif
117

source code of qtgraphs/src/graphs/qml/declarativetheme_p.h