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// W A R N I N G
31// -------------
32//
33// This file is not part of the Qt Chart API. It exists purely as an
34// implementation detail. This header file may change from version to
35// version without notice, or even be removed.
36//
37// We mean it.
38
39#ifndef LEGENDMARKERITEM_P_H
40#define LEGENDMARKERITEM_P_H
41
42#include <QtCharts/QChartGlobal>
43#include <QtCharts/QLegend>
44#include <QGraphicsObject>
45#include <QtGui/QFont>
46#include <QtGui/QBrush>
47#include <QtGui/QPen>
48#include <QtWidgets/QGraphicsTextItem>
49#include <QtWidgets/QGraphicsLayoutItem>
50#include <QtCharts/private/qchartglobal_p.h>
51
52QT_CHARTS_BEGIN_NAMESPACE
53
54class QLegendMarkerPrivate;
55
56class Q_CHARTS_PRIVATE_EXPORT LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem
57{
58 Q_OBJECT
59 Q_INTERFACES(QGraphicsLayoutItem)
60public:
61 enum ItemType {
62 TypeRect,
63 TypeLine,
64 TypeCircle
65 };
66
67 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = nullptr);
68 ~LegendMarkerItem();
69
70 void setPen(const QPen &pen);
71 QPen pen() const;
72
73 void setBrush(const QBrush &brush);
74 QBrush brush() const;
75
76 void setSeriesPen(const QPen &pen);
77 void setSeriesBrush(const QBrush &brush);
78
79 void setFont(const QFont &font);
80 QFont font() const;
81
82 void setLabel(const QString label);
83 QString label() const;
84
85 void setLabelBrush(const QBrush &brush);
86 QBrush labelBrush() const;
87
88 void setGeometry(const QRectF &rect);
89 QRectF boundingRect() const;
90 QRectF markerRect() const;
91
92 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget = nullptr);
93 QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const;
94
95 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
96 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
97
98 QString displayedLabel() const;
99 void setToolTip(const QString &tooltip);
100
101 QLegend::MarkerShape markerShape() const;
102 void setMarkerShape(QLegend::MarkerShape shape);
103
104 void updateMarkerShapeAndSize();
105 QLegend::MarkerShape effectiveMarkerShape() const;
106 qreal effectiveMarkerWidth() const;
107
108 ItemType itemType() const { return m_itemType; }
109
110Q_SIGNALS:
111 void markerRectChanged();
112
113protected:
114 void setItemBrushAndPen();
115 void setItemRect();
116 bool useMaxWidth() const;
117
118 QLegendMarkerPrivate *m_marker; // Knows
119 QRectF m_defaultMarkerRect;
120 QRectF m_markerRect;
121 QRectF m_boundingRect;
122 QGraphicsTextItem *m_textItem;
123 QGraphicsItem *m_markerItem;
124 qreal m_margin;
125 qreal m_space;
126 QString m_label;
127 QLegend::MarkerShape m_markerShape;
128
129 QBrush m_labelBrush;
130 QPen m_pen;
131 QBrush m_brush;
132 QPen m_seriesPen;
133 QBrush m_seriesBrush;
134 QFont m_font;
135 bool m_hovering;
136
137 ItemType m_itemType;
138
139 friend class QLegendMarker;
140 friend class QLegendMarkerPrivate;
141 friend class LegendLayout;
142};
143
144QT_CHARTS_END_NAMESPACE
145
146#endif // LEGENDMARKERITEM_P_H
147

source code of qtcharts/src/charts/legend/legendmarkeritem_p.h