1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #ifndef QLEGEND_H |
31 | #define QLEGEND_H |
32 | |
33 | #include <QtCharts/QChartGlobal> |
34 | #include <QtWidgets/QGraphicsWidget> |
35 | #include <QtGui/QPen> |
36 | #include <QtGui/QBrush> |
37 | |
38 | QT_CHARTS_BEGIN_NAMESPACE |
39 | |
40 | class QChart; |
41 | class QLegendPrivate; |
42 | class QLegendMarker; |
43 | class QAbstractSeries; |
44 | |
45 | class Q_CHARTS_EXPORT QLegend : public QGraphicsWidget |
46 | { |
47 | Q_OBJECT |
48 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
49 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) |
50 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
51 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
52 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
53 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
54 | Q_PROPERTY(bool reverseMarkers READ reverseMarkers WRITE setReverseMarkers NOTIFY reverseMarkersChanged) |
55 | Q_PROPERTY(bool showToolTips READ showToolTips WRITE setShowToolTips NOTIFY showToolTipsChanged) |
56 | Q_PROPERTY(MarkerShape markerShape READ markerShape WRITE setMarkerShape NOTIFY markerShapeChanged) |
57 | |
58 | private: |
59 | explicit QLegend(QChart *chart); |
60 | |
61 | public: |
62 | enum MarkerShape { |
63 | MarkerShapeDefault, |
64 | MarkerShapeRectangle, |
65 | MarkerShapeCircle, |
66 | MarkerShapeFromSeries |
67 | }; |
68 | Q_ENUMS(MarkerShape) |
69 | |
70 | ~QLegend(); |
71 | |
72 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr); |
73 | |
74 | void setBrush(const QBrush &brush); |
75 | QBrush brush() const; |
76 | void setColor(QColor color); |
77 | QColor color(); |
78 | |
79 | void setPen(const QPen &pen); |
80 | QPen pen() const; |
81 | void setBorderColor(QColor color); |
82 | QColor borderColor(); |
83 | |
84 | void setFont(const QFont &font); |
85 | QFont font() const; |
86 | void setLabelBrush(const QBrush &brush); |
87 | QBrush labelBrush() const; |
88 | |
89 | void setLabelColor(QColor color); |
90 | QColor labelColor() const; |
91 | |
92 | void setAlignment(Qt::Alignment alignment); |
93 | Qt::Alignment alignment() const; |
94 | |
95 | void detachFromChart(); |
96 | void attachToChart(); |
97 | bool isAttachedToChart(); |
98 | |
99 | void setBackgroundVisible(bool visible = true); |
100 | bool isBackgroundVisible() const; |
101 | |
102 | QList <QLegendMarker*> markers(QAbstractSeries *series = nullptr) const; |
103 | |
104 | bool reverseMarkers(); |
105 | void setReverseMarkers(bool reverseMarkers = true); |
106 | |
107 | bool showToolTips() const; |
108 | void setShowToolTips(bool show); |
109 | |
110 | MarkerShape markerShape() const; |
111 | void setMarkerShape(MarkerShape shape); |
112 | |
113 | protected: |
114 | void hideEvent(QHideEvent *event); |
115 | void showEvent(QShowEvent *event); |
116 | |
117 | Q_SIGNALS: |
118 | void backgroundVisibleChanged(bool visible); |
119 | void colorChanged(QColor color); |
120 | void borderColorChanged(QColor color); |
121 | void fontChanged(QFont font); |
122 | void labelColorChanged(QColor color); |
123 | void reverseMarkersChanged(bool reverseMarkers); |
124 | void showToolTipsChanged(bool showToolTips); |
125 | void markerShapeChanged(MarkerShape shape); |
126 | |
127 | private: |
128 | QScopedPointer<QLegendPrivate> d_ptr; |
129 | Q_DISABLE_COPY(QLegend) |
130 | friend class LegendScroller; |
131 | friend class LegendLayout; |
132 | friend class ChartLayout; |
133 | friend class LegendMarkerItem; |
134 | friend class QLegendMarkerPrivate; |
135 | }; |
136 | |
137 | QT_CHARTS_END_NAMESPACE |
138 | |
139 | #endif // QLEGEND_H |
140 | |