1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | // W A R N I N G |
5 | // ------------- |
6 | // |
7 | // This file is not part of the Qt Chart API. It exists purely as an |
8 | // implementation detail. This header file may change from version to |
9 | // version without notice, or even be removed. |
10 | // |
11 | // We mean it. |
12 | |
13 | #ifndef CHARTTHEMEMANAGER_H |
14 | #define CHARTTHEMEMANAGER_H |
15 | |
16 | #include <QtCharts/QChartGlobal> |
17 | #include <QtCharts/QChart> |
18 | #include <QtGui/QColor> |
19 | #include <QtGui/QGradientStops> |
20 | #include <QtCharts/private/qchartglobal_p.h> |
21 | #include <QtCore/qmap.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | class ChartTheme; |
25 | |
26 | class Q_CHARTS_PRIVATE_EXPORT ChartThemeManager: public QObject |
27 | { |
28 | Q_OBJECT |
29 | public: |
30 | enum BackgroundShadesMode { |
31 | BackgroundShadesNone = 0, |
32 | BackgroundShadesVertical, |
33 | BackgroundShadesHorizontal, |
34 | BackgroundShadesBoth |
35 | }; |
36 | |
37 | public: |
38 | explicit ChartThemeManager(QChart* chart); |
39 | void setTheme(QChart::ChartTheme theme); |
40 | ChartTheme* theme() const { return m_theme.data(); } |
41 | void decorateChart(QChart *chart, ChartTheme* theme) const; |
42 | void decorateLegend(QLegend *legend, ChartTheme* theme) const; |
43 | void updateSeries(QAbstractSeries *series); |
44 | QMap<QAbstractSeries *, int> seriesMap() const { return m_seriesMap; } |
45 | |
46 | public: |
47 | static QList<QGradient> generateSeriesGradients(const QList<QColor>& colors); |
48 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); |
49 | static QColor colorAt(const QGradient &gradient, qreal pos); |
50 | |
51 | private: |
52 | int createIndexKey(const QList<int> &keys) const; |
53 | int seriesCount(QAbstractSeries::SeriesType type) const; |
54 | |
55 | public Q_SLOTS: |
56 | void handleSeriesAdded(QAbstractSeries *series); |
57 | void handleSeriesRemoved(QAbstractSeries *series); |
58 | void handleAxisAdded(QAbstractAxis *axis); |
59 | void handleAxisRemoved(QAbstractAxis *axis); |
60 | |
61 | protected: |
62 | QScopedPointer<ChartTheme> m_theme; |
63 | QMap<QAbstractSeries *,int> m_seriesMap; |
64 | QList<QAbstractAxis *> m_axisList; |
65 | QChart* m_chart; |
66 | }; |
67 | |
68 | QT_END_NAMESPACE |
69 | |
70 | #endif // CHARTTHEME_H |
71 | |