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 LEGENDMOVERESIZEHANDLER_P_H |
14 | #define LEGENDMOVERESIZEHANDLER_P_H |
15 | |
16 | #include <QtCharts/QChartGlobal> |
17 | #include <QtCore/QPointF> |
18 | #include <QtCharts/qlegend.h> |
19 | #include <QtCharts/private/qlegend_p.h> |
20 | #include <QtCharts/private/qchartglobal_p.h> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | class QGraphicsSceneMouseEvent; |
25 | class QGraphicsSceneHoverEvent; |
26 | |
27 | class Q_CHARTS_PRIVATE_EXPORT LegendMoveResizeHandler |
28 | { |
29 | public: |
30 | LegendMoveResizeHandler(QLegend *legend); |
31 | ~LegendMoveResizeHandler(); |
32 | |
33 | inline bool shouldShowMoveHint() const { return m_mode == MousePosition::Top; } |
34 | void reset(); |
35 | |
36 | void handleMousePressEvent(QGraphicsSceneMouseEvent *event); |
37 | void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event); |
38 | void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
39 | void handleHoverEnterEvent(QGraphicsSceneHoverEvent *event); |
40 | void handleHoverMoveEvent(QGraphicsSceneHoverEvent *event); |
41 | void handleHoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
42 | |
43 | private: |
44 | enum class Action { |
45 | Idle = 0x00, |
46 | Hovered = 0x01, |
47 | Pressed = 0x02, |
48 | Moving = 0x04, |
49 | Resizing= 0x08 |
50 | }; |
51 | |
52 | enum class MousePosition { |
53 | Nowhere, |
54 | TopLeft, |
55 | BottomRight, |
56 | BottomLeft, |
57 | TopRight, |
58 | Top, |
59 | Bottom, |
60 | Left, |
61 | Right |
62 | }; |
63 | |
64 | void setMouseCursor(); |
65 | void setMouseCursor(MousePosition mpos); |
66 | void determineMousePosition(QPointF fromPoint); |
67 | |
68 | QLegend *m_legend{nullptr}; |
69 | QPointF m_moveOffset{0.0,0.0}; |
70 | Action m_action{Action::Idle}; |
71 | MousePosition m_mode{MousePosition::Nowhere}; |
72 | qreal m_reattachThreshold{0.0}; |
73 | }; |
74 | |
75 | QT_END_NAMESPACE |
76 | |
77 | #endif |
78 | |