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 PIESLICEITEM_H |
14 | #define PIESLICEITEM_H |
15 | |
16 | #include <QtCharts/QChartGlobal> |
17 | #include <private/charttheme_p.h> |
18 | #include <QtCharts/QPieSeries> |
19 | #include <private/pieslicedata_p.h> |
20 | #include <QtCharts/private/qchartglobal_p.h> |
21 | #include <QtWidgets/QGraphicsItem> |
22 | #include <QtCore/QRectF> |
23 | #include <QtGui/QColor> |
24 | #include <QtGui/QPen> |
25 | |
26 | #define PIESLICE_LABEL_GAP 5 |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | class PieChartItem; |
30 | class PieSliceLabel; |
31 | class QPieSlice; |
32 | |
33 | class Q_CHARTS_PRIVATE_EXPORT PieSliceItem : public QGraphicsObject |
34 | { |
35 | Q_OBJECT |
36 | |
37 | public: |
38 | PieSliceItem(QGraphicsItem *parent = 0); |
39 | ~PieSliceItem(); |
40 | |
41 | // from QGraphicsItem |
42 | QRectF boundingRect() const override; |
43 | QPainterPath shape() const override; |
44 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; |
45 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; |
46 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; |
47 | void mousePressEvent(QGraphicsSceneMouseEvent *event) override; |
48 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; |
49 | void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; |
50 | |
51 | void setLayout(const PieSliceData &sliceData); |
52 | static QPointF sliceCenter(QPointF point, qreal radius, QPieSlice *slice); |
53 | |
54 | Q_SIGNALS: |
55 | void clicked(Qt::MouseButtons buttons); |
56 | void hovered(bool state); |
57 | void pressed(Qt::MouseButtons buttons); |
58 | void released(Qt::MouseButtons buttons); |
59 | void doubleClicked(Qt::MouseButtons buttons); |
60 | |
61 | private: |
62 | void updateGeometry(); |
63 | QPainterPath slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF *armStart); |
64 | QPainterPath labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart); |
65 | |
66 | private: |
67 | PieSliceData m_data; |
68 | QRectF m_boundingRect; |
69 | QPainterPath m_slicePath; |
70 | QPainterPath m_labelArmPath; |
71 | QRectF m_labelTextRect; |
72 | bool m_hovered; |
73 | QGraphicsTextItem *m_labelItem; |
74 | |
75 | bool m_mousePressed; |
76 | |
77 | friend class PieSliceAnimation; |
78 | }; |
79 | |
80 | QT_END_NAMESPACE |
81 | |
82 | #endif // PIESLICEITEM_H |
83 | |