1// Copyright (C) 2021 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 LEGENDMARKERITEM_P_H
14#define LEGENDMARKERITEM_P_H
15
16#include <QtCharts/QChartGlobal>
17#include <QtCharts/QLegend>
18#include <QGraphicsObject>
19#include <QtGui/QFont>
20#include <QtGui/QBrush>
21#include <QtGui/QPen>
22#include <QtWidgets/QGraphicsTextItem>
23#include <QtWidgets/QGraphicsLayoutItem>
24#include <QtCharts/private/qchartglobal_p.h>
25
26QT_BEGIN_NAMESPACE
27
28class QLegendMarkerPrivate;
29
30class Q_CHARTS_PRIVATE_EXPORT LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem
31{
32 Q_OBJECT
33 Q_INTERFACES(QGraphicsLayoutItem)
34public:
35 enum ItemType {
36 TypeRect,
37 TypeLine,
38 TypeCircle,
39 TypeRotatedRect,
40 TypeTriangle,
41 TypeStar,
42 TypePentagon
43 };
44
45 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = nullptr);
46 ~LegendMarkerItem();
47
48 void setPen(const QPen &pen);
49 QPen pen() const;
50
51 void setBrush(const QBrush &brush);
52 QBrush brush() const;
53
54 void setSeriesPen(const QPen &pen);
55 void setSeriesBrush(const QBrush &brush);
56 void setSeriesLightMarker(const QImage &image);
57
58 void setFont(const QFont &font);
59 QFont font() const;
60
61 void setLabel(const QString label);
62 QString label() const;
63
64 void setLabelBrush(const QBrush &brush);
65 QBrush labelBrush() const;
66
67 void setGeometry(const QRectF &rect) override;
68 QRectF boundingRect() const override;
69 QRectF markerRect() const;
70
71 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget = nullptr) override;
72 QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const override;
73
74 void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
75 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
76
77 QString displayedLabel() const;
78 void setToolTip(const QString &tooltip);
79
80 QLegend::MarkerShape markerShape() const;
81 void setMarkerShape(QLegend::MarkerShape shape);
82
83 void updateMarkerShapeAndSize();
84 QLegend::MarkerShape effectiveMarkerShape() const;
85 qreal effectiveMarkerWidth() const;
86
87 ItemType itemType() const { return m_itemType; }
88
89Q_SIGNALS:
90 void markerRectChanged();
91
92protected:
93 void setItemBrushAndPen();
94 void setItemRect();
95 bool useMaxWidth() const;
96
97 QLegendMarkerPrivate *m_marker; // Knows
98 QRectF m_defaultMarkerRect;
99 QRectF m_markerRect;
100 QRectF m_boundingRect;
101 QGraphicsTextItem *m_textItem;
102 QGraphicsItem *m_markerItem;
103 qreal m_margin;
104 qreal m_space;
105 QString m_label;
106 QLegend::MarkerShape m_markerShape;
107 QImage m_seriesLightMarker;
108
109 QBrush m_labelBrush;
110 QPen m_pen;
111 QBrush m_brush;
112 QPen m_seriesPen;
113 QBrush m_seriesBrush;
114 QFont m_font;
115 bool m_hovering;
116
117 ItemType m_itemType;
118
119 friend class QLegendMarker;
120 friend class QLegendMarkerPrivate;
121 friend class LegendLayout;
122};
123
124QT_END_NAMESPACE
125
126#endif // LEGENDMARKERITEM_P_H
127

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