Debian Codegraph @

examples/widgets/painting/shared/hoverpoints.h

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4 #ifndef HOVERPOINTS_H
5 #define HOVERPOINTS_H
6
7 #include <QtWidgets>
8
9 QT_FORWARD_DECLARE_CLASS(QBypassWidget)
10
11 class HoverPoints : public QObject
12 {
13 Q_OBJECT
14 public:
15 enum PointShape {
16 CircleShape,
17 RectangleShape
18 };
19
20 enum LockType {
21 LockToLeft = 0x01,
22 LockToRight = 0x02,
23 LockToTop = 0x04,
24 LockToBottom = 0x08
25 };
26
27 enum SortType {
28 NoSort,
29 XSort,
30 YSort
31 };
32
33 enum ConnectionType {
34 NoConnection,
35 LineConnection,
36 CurveConnection
37 };
38
39 HoverPoints(QWidget *widget, PointShape shape);
40
41 bool eventFilter(QObject *object, QEvent *event) override;
42
43 void paintPoints();
44
45 inline QRectF boundingRect() const;
46 void setBoundingRect(const QRectF &boundingRect) { m_bounds = boundingRect; }
47
48 QPolygonF points() const { return m_points; }
49 void setPoints(const QPolygonF &points);
50
51 QSizeF pointSize() const { return m_pointSize; }
52 void setPointSize(const QSizeF &size) { m_pointSize = size; }
53
54 SortType sortType() const { return m_sortType; }
55 void setSortType(SortType sortType) { m_sortType = sortType; }
56
57 ConnectionType connectionType() const { return m_connectionType; }
58 void setConnectionType(ConnectionType connectionType) { m_connectionType = connectionType; }
59
60 void setConnectionPen(const QPen &pen) { m_connectionPen = pen; }
61 void setShapePen(const QPen &pen) { m_pointPen = pen; }
62 void setShapeBrush(const QBrush &brush) { m_pointBrush = brush; }
63
64 void setPointLock(int pos, LockType lock) { m_locks[pos] = lock; }
65
66 void setEditable(bool editable) { m_editable = editable; }
67 bool editable() const { return m_editable; }
68
69 public slots:
70 void setEnabled(bool enabled);
71 void setDisabled(bool disabled) { setEnabled(!disabled); }
72
73 signals:
74 void pointsChanged(const QPolygonF &points);
75
76 public:
77 void firePointChange();
78
79 private:
80 inline QRectF pointBoundingRect(const QPointF &p) const;
81 void movePoint(qsizetype i, const QPointF &newPos, bool emitChange = true);
82
83 QWidget *m_widget;
84
85 QPolygonF m_points;
86 QRectF m_bounds;
87 PointShape m_shape;
88 SortType m_sortType = NoSort;
89 ConnectionType m_connectionType = CurveConnection;
90
91 QList<uint> m_locks;
92
93 QSizeF m_pointSize{11, 11};
94 qsizetype m_currentIndex= -1;
95 bool m_editable = true;
96 bool m_enabled = true;
97
98 QHash<int, qsizetype> m_fingerPointMapping;
99
100 QPen m_pointPen{QColor(255, 255, 255, 191), 1};
101 QBrush m_pointBrush{QColor(191, 191, 191, 127)};
102 QPen m_connectionPen{QColor(255, 255, 255, 127), 2};
103 };
104
105 inline QRectF HoverPoints::pointBoundingRect(const QPointF &p) const
106 {
107 qreal w = m_pointSize.width();
108 qreal h = m_pointSize.height();
109 qreal x = p.x() - w / 2;
110 qreal y = p.y() - h / 2;
111 return QRectF(x, y, w, h);
112 }
113
114 inline QRectF HoverPoints::boundingRect() const
115 {
116 if (m_bounds.isEmpty())
117 return m_widget->rect();
118 else
119 return m_bounds;
120 }
121
122 #endif // HOVERPOINTS_H