@@ -0,0 +1,39 | |||
|
1 | #ifndef SCIQLOP_VISUALIZATIONSELECTIONZONEITEM_H | |
|
2 | #define SCIQLOP_VISUALIZATIONSELECTIONZONEITEM_H | |
|
3 | ||
|
4 | #include <Common/spimpl.h> | |
|
5 | #include <Data/SqpRange.h> | |
|
6 | #include <Visualization/qcustomplot.h> | |
|
7 | ||
|
8 | class VisualizationSelectionZoneItem : public QCPItemRect { | |
|
9 | public: | |
|
10 | VisualizationSelectionZoneItem(QCustomPlot *plot); | |
|
11 | virtual ~VisualizationSelectionZoneItem(); | |
|
12 | ||
|
13 | void setName(const QString &name); | |
|
14 | QString name() const; | |
|
15 | ||
|
16 | SqpRange range() const; | |
|
17 | void setRange(double tstart, double tend); | |
|
18 | void setStart(double tstart); | |
|
19 | void setEnd(double tend); | |
|
20 | ||
|
21 | void setColor(const QColor &color); | |
|
22 | ||
|
23 | void setEditionEnabled(bool value); | |
|
24 | bool isEditionEnabled() const; | |
|
25 | ||
|
26 | Qt::CursorShape curshorShapeForPosition(const QPoint &position) const; | |
|
27 | void setHovered(bool value); | |
|
28 | ||
|
29 | protected: | |
|
30 | void mousePressEvent(QMouseEvent *event, const QVariant &details) override; | |
|
31 | void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) override; | |
|
32 | void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) override; | |
|
33 | ||
|
34 | private: | |
|
35 | class VisualizationSelectionZoneItemPrivate; | |
|
36 | spimpl::unique_impl_ptr<VisualizationSelectionZoneItemPrivate> impl; | |
|
37 | }; | |
|
38 | ||
|
39 | #endif // SCIQLOP_VISUALIZATIONSELECTIONZONEITEM_H |
@@ -0,0 +1,271 | |||
|
1 | #include "Visualization/VisualizationSelectionZoneItem.h" | |
|
2 | ||
|
3 | struct VisualizationSelectionZoneItem::VisualizationSelectionZoneItemPrivate { | |
|
4 | ||
|
5 | QCustomPlot *m_Plot; | |
|
6 | double m_T1 = 0; | |
|
7 | double m_T2 = 0; | |
|
8 | QColor m_Color; | |
|
9 | ||
|
10 | bool m_IsEditionEnabled = true; | |
|
11 | double m_MovedOrinalT1 = 0; | |
|
12 | double m_MovedOrinalT2 = 0; | |
|
13 | ||
|
14 | QCPItemStraightLine *m_LeftLine; | |
|
15 | QCPItemStraightLine *m_RightLine; | |
|
16 | QCPItemText *m_NameLabelItem = nullptr; | |
|
17 | ||
|
18 | enum class EditionMode { NoEdition, ResizeLeft, ResizeRight, Move }; | |
|
19 | EditionMode m_CurrentEditionMode; | |
|
20 | ||
|
21 | VisualizationSelectionZoneItemPrivate(QCustomPlot *plot) | |
|
22 | : m_Plot(plot), m_Color(Qt::blue), m_CurrentEditionMode(EditionMode::NoEdition) | |
|
23 | { | |
|
24 | } | |
|
25 | ||
|
26 | void updatePosition(VisualizationSelectionZoneItem *item) | |
|
27 | { | |
|
28 | item->topLeft->setCoords(m_T1, 0); | |
|
29 | item->bottomRight->setCoords(m_T2, 1); | |
|
30 | } | |
|
31 | ||
|
32 | EditionMode getEditionMode(const QPoint &pos, const VisualizationSelectionZoneItem *zoneItem) | |
|
33 | { | |
|
34 | auto distanceLeft = m_LeftLine->selectTest(pos, false); | |
|
35 | auto distanceRight = m_RightLine->selectTest(pos, false); | |
|
36 | auto distance = zoneItem->selectTest(pos, true); | |
|
37 | ||
|
38 | if (distanceRight <= distance) { | |
|
39 | return VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight; | |
|
40 | } | |
|
41 | else if (distanceLeft <= distance) { | |
|
42 | return VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft; | |
|
43 | } | |
|
44 | ||
|
45 | return VisualizationSelectionZoneItemPrivate::EditionMode::Move; | |
|
46 | } | |
|
47 | }; | |
|
48 | ||
|
49 | VisualizationSelectionZoneItem::VisualizationSelectionZoneItem(QCustomPlot *plot) | |
|
50 | : QCPItemRect(plot), | |
|
51 | impl{spimpl::make_unique_impl<VisualizationSelectionZoneItemPrivate>(plot)} | |
|
52 | { | |
|
53 | topLeft->setTypeX(QCPItemPosition::ptPlotCoords); | |
|
54 | topLeft->setTypeY(QCPItemPosition::ptAxisRectRatio); | |
|
55 | bottomRight->setTypeX(QCPItemPosition::ptPlotCoords); | |
|
56 | bottomRight->setTypeY(QCPItemPosition::ptAxisRectRatio); | |
|
57 | ||
|
58 | impl->m_RightLine = new QCPItemStraightLine(plot); | |
|
59 | impl->m_RightLine->point1->setParentAnchor(topRight); | |
|
60 | impl->m_RightLine->point2->setParentAnchor(bottomRight); | |
|
61 | impl->m_RightLine->point1->setTypeX(QCPItemPosition::ptAbsolute); | |
|
62 | impl->m_RightLine->point1->setTypeY(QCPItemPosition::ptAbsolute); | |
|
63 | impl->m_RightLine->point2->setTypeX(QCPItemPosition::ptAbsolute); | |
|
64 | impl->m_RightLine->point2->setTypeY(QCPItemPosition::ptAbsolute); | |
|
65 | ||
|
66 | impl->m_LeftLine = new QCPItemStraightLine(plot); | |
|
67 | impl->m_LeftLine->point1->setParentAnchor(topLeft); | |
|
68 | impl->m_LeftLine->point2->setParentAnchor(bottomLeft); | |
|
69 | impl->m_LeftLine->point1->setTypeX(QCPItemPosition::ptAbsolute); | |
|
70 | impl->m_LeftLine->point1->setTypeY(QCPItemPosition::ptAbsolute); | |
|
71 | impl->m_LeftLine->point2->setTypeX(QCPItemPosition::ptAbsolute); | |
|
72 | impl->m_LeftLine->point2->setTypeY(QCPItemPosition::ptAbsolute); | |
|
73 | ||
|
74 | impl->m_RightLine->setSelectable(false); | |
|
75 | impl->m_LeftLine->setSelectable(false); | |
|
76 | ||
|
77 | // connect(this, &VisualizationSelectionZoneItem::selectionChanged, impl->m_RightLine, | |
|
78 | // &QCPItemStraightLine::setSelected); | |
|
79 | // connect(this, &VisualizationSelectionZoneItem::selectionChanged, impl->m_LeftLine, | |
|
80 | // &QCPItemStraightLine::setSelected); | |
|
81 | ||
|
82 | setColor(QColor("#E79D41")); | |
|
83 | } | |
|
84 | ||
|
85 | VisualizationSelectionZoneItem::~VisualizationSelectionZoneItem() | |
|
86 | { | |
|
87 | impl->m_Plot->removeItem(impl->m_RightLine); | |
|
88 | impl->m_Plot->removeItem(impl->m_LeftLine); | |
|
89 | } | |
|
90 | ||
|
91 | void VisualizationSelectionZoneItem::setName(const QString &name) | |
|
92 | { | |
|
93 | if (name.isEmpty() && impl->m_NameLabelItem) { | |
|
94 | impl->m_Plot->removeItem(impl->m_NameLabelItem); | |
|
95 | impl->m_NameLabelItem = nullptr; | |
|
96 | } | |
|
97 | else if (!impl->m_NameLabelItem) { | |
|
98 | impl->m_NameLabelItem = new QCPItemText(impl->m_Plot); | |
|
99 | impl->m_NameLabelItem->setText(name); | |
|
100 | impl->m_NameLabelItem->setPositionAlignment(Qt::AlignHCenter | Qt::AlignTop); | |
|
101 | impl->m_NameLabelItem->setColor(impl->m_Color); | |
|
102 | impl->m_NameLabelItem->position->setParentAnchor(top); | |
|
103 | } | |
|
104 | } | |
|
105 | ||
|
106 | QString VisualizationSelectionZoneItem::name() const | |
|
107 | { | |
|
108 | if (!impl->m_NameLabelItem) { | |
|
109 | return QString(); | |
|
110 | } | |
|
111 | ||
|
112 | return impl->m_NameLabelItem->text(); | |
|
113 | } | |
|
114 | ||
|
115 | SqpRange VisualizationSelectionZoneItem::range() const | |
|
116 | { | |
|
117 | SqpRange range; | |
|
118 | range.m_TStart = impl->m_T1 <= impl->m_T2 ? impl->m_T1 : impl->m_T2; | |
|
119 | range.m_TEnd = impl->m_T1 > impl->m_T2 ? impl->m_T1 : impl->m_T2; | |
|
120 | return range; | |
|
121 | } | |
|
122 | ||
|
123 | void VisualizationSelectionZoneItem::setRange(double tstart, double tend) | |
|
124 | { | |
|
125 | impl->m_T1 = tstart; | |
|
126 | impl->m_T2 = tend; | |
|
127 | impl->updatePosition(this); | |
|
128 | } | |
|
129 | ||
|
130 | void VisualizationSelectionZoneItem::setStart(double tstart) | |
|
131 | { | |
|
132 | impl->m_T1 = tstart; | |
|
133 | impl->updatePosition(this); | |
|
134 | } | |
|
135 | ||
|
136 | void VisualizationSelectionZoneItem::setEnd(double tend) | |
|
137 | { | |
|
138 | impl->m_T2 = tend; | |
|
139 | impl->updatePosition(this); | |
|
140 | } | |
|
141 | ||
|
142 | void VisualizationSelectionZoneItem::setColor(const QColor &color) | |
|
143 | { | |
|
144 | impl->m_Color = color; | |
|
145 | ||
|
146 | auto brushColor = color; | |
|
147 | brushColor.setAlpha(40); | |
|
148 | setBrush(QBrush(brushColor)); | |
|
149 | setPen(QPen(Qt::NoPen)); | |
|
150 | ||
|
151 | auto selectedBrushColor = brushColor; | |
|
152 | selectedBrushColor.setAlpha(65); | |
|
153 | setSelectedBrush(QBrush(selectedBrushColor)); | |
|
154 | setSelectedPen(QPen(Qt::NoPen)); | |
|
155 | ||
|
156 | auto linePen = QPen(color); | |
|
157 | linePen.setStyle(Qt::SolidLine); | |
|
158 | linePen.setWidth(2); | |
|
159 | ||
|
160 | auto selectedLinePen = linePen; | |
|
161 | selectedLinePen.setColor(color.darker(30)); | |
|
162 | ||
|
163 | impl->m_LeftLine->setPen(linePen); | |
|
164 | impl->m_RightLine->setPen(linePen); | |
|
165 | ||
|
166 | impl->m_LeftLine->setSelectedPen(selectedLinePen); | |
|
167 | impl->m_RightLine->setSelectedPen(selectedLinePen); | |
|
168 | } | |
|
169 | ||
|
170 | void VisualizationSelectionZoneItem::setEditionEnabled(bool value) | |
|
171 | { | |
|
172 | impl->m_IsEditionEnabled = value; | |
|
173 | setSelectable(value); | |
|
174 | if (!value) { | |
|
175 | setSelected(false); | |
|
176 | } | |
|
177 | } | |
|
178 | ||
|
179 | bool VisualizationSelectionZoneItem::isEditionEnabled() const | |
|
180 | { | |
|
181 | return impl->m_IsEditionEnabled; | |
|
182 | } | |
|
183 | ||
|
184 | Qt::CursorShape | |
|
185 | VisualizationSelectionZoneItem::curshorShapeForPosition(const QPoint &position) const | |
|
186 | { | |
|
187 | auto mode = impl->m_CurrentEditionMode | |
|
188 | == VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition | |
|
189 | ? impl->getEditionMode(position, this) | |
|
190 | : impl->m_CurrentEditionMode; | |
|
191 | switch (mode) { | |
|
192 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: | |
|
193 | return Qt::SizeAllCursor; | |
|
194 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: | |
|
195 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: // fallthrough | |
|
196 | return Qt::SizeHorCursor; | |
|
197 | default: | |
|
198 | return Qt::ArrowCursor; | |
|
199 | } | |
|
200 | } | |
|
201 | ||
|
202 | void VisualizationSelectionZoneItem::setHovered(bool value) | |
|
203 | { | |
|
204 | if (value) { | |
|
205 | auto linePen = impl->m_LeftLine->pen(); | |
|
206 | linePen.setStyle(Qt::DotLine); | |
|
207 | linePen.setWidth(3); | |
|
208 | ||
|
209 | auto selectedLinePen = impl->m_LeftLine->selectedPen(); | |
|
210 | ; | |
|
211 | selectedLinePen.setStyle(Qt::DotLine); | |
|
212 | selectedLinePen.setWidth(3); | |
|
213 | ||
|
214 | impl->m_LeftLine->setPen(linePen); | |
|
215 | impl->m_RightLine->setPen(linePen); | |
|
216 | ||
|
217 | impl->m_LeftLine->setSelectedPen(selectedLinePen); | |
|
218 | impl->m_RightLine->setSelectedPen(selectedLinePen); | |
|
219 | } | |
|
220 | else { | |
|
221 | setColor(impl->m_Color); | |
|
222 | } | |
|
223 | } | |
|
224 | ||
|
225 | void VisualizationSelectionZoneItem::mousePressEvent(QMouseEvent *event, const QVariant &details) | |
|
226 | { | |
|
227 | if (isEditionEnabled()) { | |
|
228 | impl->m_CurrentEditionMode = impl->getEditionMode(event->pos(), this); | |
|
229 | ||
|
230 | impl->m_MovedOrinalT1 = impl->m_T1; | |
|
231 | impl->m_MovedOrinalT2 = impl->m_T2; | |
|
232 | } | |
|
233 | else { | |
|
234 | event->ignore(); | |
|
235 | } | |
|
236 | } | |
|
237 | ||
|
238 | void VisualizationSelectionZoneItem::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) | |
|
239 | { | |
|
240 | if (isEditionEnabled()) { | |
|
241 | auto axis = impl->m_Plot->axisRect()->axis(QCPAxis::atBottom); | |
|
242 | auto diff = axis->pixelToCoord(event->pos().x()) - axis->pixelToCoord(startPos.x()); | |
|
243 | ||
|
244 | switch (impl->m_CurrentEditionMode) { | |
|
245 | case VisualizationSelectionZoneItemPrivate::EditionMode::Move: | |
|
246 | setRange(impl->m_MovedOrinalT1 + diff, impl->m_MovedOrinalT2 + diff); | |
|
247 | break; | |
|
248 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeLeft: | |
|
249 | setStart(impl->m_MovedOrinalT1 + diff); | |
|
250 | break; | |
|
251 | case VisualizationSelectionZoneItemPrivate::EditionMode::ResizeRight: | |
|
252 | setEnd(impl->m_MovedOrinalT2 + diff); | |
|
253 | break; | |
|
254 | // default: | |
|
255 | // unknown edition mode | |
|
256 | } | |
|
257 | } | |
|
258 | else { | |
|
259 | event->ignore(); | |
|
260 | } | |
|
261 | } | |
|
262 | ||
|
263 | void VisualizationSelectionZoneItem::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) | |
|
264 | { | |
|
265 | if (isEditionEnabled()) { | |
|
266 | impl->m_CurrentEditionMode = VisualizationSelectionZoneItemPrivate::EditionMode::NoEdition; | |
|
267 | } | |
|
268 | else { | |
|
269 | event->ignore(); | |
|
270 | } | |
|
271 | } |
@@ -82,7 +82,8 gui_sources = [ | |||
|
82 | 82 | 'src/Visualization/VisualizationCursorItem.cpp', |
|
83 | 83 | 'src/Visualization/ColorScaleEditor.cpp', |
|
84 | 84 | 'src/Visualization/SqpColorScale.cpp', |
|
85 | 'src/Visualization/QCPColorMapIterator.cpp' | |
|
85 | 'src/Visualization/QCPColorMapIterator.cpp', | |
|
86 | 'src/Visualization/VisualizationSelectionZoneItem.cpp' | |
|
86 | 87 | ] |
|
87 | 88 | |
|
88 | 89 | gui_inc = include_directories(['include']) |
@@ -48,6 +48,7 void initPointTracerStyle(QCPItemTracer &tracer) noexcept | |||
|
48 | 48 | tracer.setSize(3); |
|
49 | 49 | tracer.setPen(QPen(Qt::black)); |
|
50 | 50 | tracer.setBrush(Qt::black); |
|
51 | tracer.setSelectable(false); | |
|
51 | 52 | } |
|
52 | 53 | |
|
53 | 54 | QPixmap pixmap(const QString &iconPath) noexcept |
@@ -94,6 +95,7 void initTitleTextStyle(QCPItemText &text) noexcept | |||
|
94 | 95 | text.setPositionAlignment(Qt::AlignTop | Qt::AlignLeft); |
|
95 | 96 | text.position->setType(QCPItemPosition::ptAxisRectRatio); |
|
96 | 97 | text.position->setCoords(0.5, 0); |
|
98 | text.setSelectable(false); | |
|
97 | 99 | } |
|
98 | 100 | |
|
99 | 101 | /** |
@@ -4,6 +4,7 | |||
|
4 | 4 | #include "Visualization/VisualizationDefs.h" |
|
5 | 5 | #include "Visualization/VisualizationGraphHelper.h" |
|
6 | 6 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
7 | #include "Visualization/VisualizationSelectionZoneItem.h" | |
|
7 | 8 | #include "Visualization/VisualizationZoneWidget.h" |
|
8 | 9 | #include "ui_VisualizationGraphWidget.h" |
|
9 | 10 | |
@@ -71,38 +72,71 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||
|
71 | 72 | /// Delegate used to attach rendering features to the plot |
|
72 | 73 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; |
|
73 | 74 | |
|
74 | QCPItemRect *m_DrawingRect = nullptr; | |
|
75 | QCPItemRect *m_DrawingZoomRect = nullptr; | |
|
76 | ||
|
75 | 77 | std::unique_ptr<VisualizationCursorItem> m_HorizontalCursor = nullptr; |
|
76 | 78 | std::unique_ptr<VisualizationCursorItem> m_VerticalCursor = nullptr; |
|
77 | 79 | |
|
78 | void configureDrawingRect() | |
|
80 | VisualizationSelectionZoneItem *m_DrawingZone = nullptr; | |
|
81 | VisualizationSelectionZoneItem *m_HoveredZone = nullptr; | |
|
82 | QVector<VisualizationSelectionZoneItem *> m_SelectionZones; | |
|
83 | ||
|
84 | void startDrawingRect(const QPoint &pos, QCustomPlot &plot) | |
|
79 | 85 | { |
|
80 |
|
|
|
86 | removeDrawingRect(plot); | |
|
87 | ||
|
88 | auto axisPos = posToAxisPos(pos, plot); | |
|
89 | ||
|
90 | m_DrawingZoomRect = new QCPItemRect{&plot}; | |
|
81 | 91 |
|
|
82 | 92 |
|
|
83 |
|
|
|
93 | m_DrawingZoomRect->setPen(p); | |
|
94 | ||
|
95 | m_DrawingZoomRect->topLeft->setCoords(axisPos); | |
|
96 | m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
|
97 | } | |
|
98 | ||
|
99 | void removeDrawingRect(QCustomPlot &plot) | |
|
100 | { | |
|
101 | if (m_DrawingZoomRect) { | |
|
102 | plot.removeItem(m_DrawingZoomRect); // the item is deleted by QCustomPlot | |
|
103 | m_DrawingZoomRect = nullptr; | |
|
104 | plot.replot(QCustomPlot::rpQueuedReplot); | |
|
84 | 105 | } |
|
85 | 106 | } |
|
86 | 107 | |
|
87 |
void startDrawing |
|
|
108 | void startDrawingZone(const QPoint &pos, QCustomPlot &plot) | |
|
88 | 109 | { |
|
89 |
|
|
|
110 | endDrawingZone(plot); | |
|
90 | 111 | |
|
91 | 112 | auto axisPos = posToAxisPos(pos, plot); |
|
92 | 113 | |
|
93 |
m_Drawing |
|
|
94 | configureDrawingRect(); | |
|
95 | ||
|
96 | m_DrawingRect->topLeft->setCoords(axisPos); | |
|
97 | m_DrawingRect->bottomRight->setCoords(axisPos); | |
|
114 | m_DrawingZone = new VisualizationSelectionZoneItem{&plot}; | |
|
115 | m_DrawingZone->setRange(axisPos.x(), axisPos.x()); | |
|
116 | m_DrawingZone->setEditionEnabled(false); | |
|
98 | 117 | } |
|
99 | 118 | |
|
100 |
void |
|
|
119 | void endDrawingZone(QCustomPlot &plot) | |
|
101 | 120 | { |
|
102 |
if (m_Drawing |
|
|
103 | plot.removeItem(m_DrawingRect); // the item is deleted by QCustomPlot | |
|
104 | m_DrawingRect = nullptr; | |
|
121 | if (m_DrawingZone) { | |
|
122 | auto drawingZoneRange = m_DrawingZone->range(); | |
|
123 | if (qAbs(drawingZoneRange.m_TEnd - drawingZoneRange.m_TStart) > 0) { | |
|
124 | m_DrawingZone->setEditionEnabled(true); | |
|
125 | m_SelectionZones.append(m_DrawingZone); | |
|
126 | } | |
|
127 | else { | |
|
128 | plot.removeItem(m_DrawingZone); // the item is deleted by QCustomPlot | |
|
129 | } | |
|
130 | ||
|
105 | 131 | plot.replot(QCustomPlot::rpQueuedReplot); |
|
132 | m_DrawingZone = nullptr; | |
|
133 | } | |
|
134 | } | |
|
135 | ||
|
136 | void setSelectionZonesEditionEnabled(bool value) | |
|
137 | { | |
|
138 | for (auto s : m_SelectionZones) { | |
|
139 | s->setEditionEnabled(value); | |
|
106 | 140 | } |
|
107 | 141 | } |
|
108 | 142 | |
@@ -117,7 +151,6 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||
|
117 | 151 | { |
|
118 | 152 | auto axisX = plot.axisRect()->axis(QCPAxis::atBottom); |
|
119 | 153 | auto axisY = plot.axisRect()->axis(QCPAxis::atLeft); |
|
120 | ||
|
121 | 154 | return axisX->range().contains(axisPoint.x()) && axisY->range().contains(axisPoint.y()); |
|
122 | 155 | } |
|
123 | 156 | }; |
@@ -133,7 +166,7 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget | |||
|
133 | 166 | setAttribute(Qt::WA_DeleteOnClose); |
|
134 | 167 | |
|
135 | 168 | // Set qcpplot properties : |
|
136 |
// - |
|
|
169 | // - zoom is enabled | |
|
137 | 170 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
138 | 171 | ui->widget->setInteractions(QCP::iRangeZoom | QCP::iSelectItems); |
|
139 | 172 | |
@@ -428,6 +461,11 void VisualizationGraphWidget::leaveEvent(QEvent *event) | |||
|
428 | 461 | else { |
|
429 | 462 | qCWarning(LOG_VisualizationGraphWidget()) << "leaveEvent: No parent zone widget"; |
|
430 | 463 | } |
|
464 | ||
|
465 | if (impl->m_HoveredZone) { | |
|
466 | impl->m_HoveredZone->setHovered(false); | |
|
467 | impl->m_HoveredZone = nullptr; | |
|
468 | } | |
|
431 | 469 | } |
|
432 | 470 | |
|
433 | 471 | QCustomPlot &VisualizationGraphWidget::plot() noexcept |
@@ -508,10 +546,15 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |||
|
508 | 546 | |
|
509 | 547 | auto axisPos = impl->posToAxisPos(event->pos(), plot()); |
|
510 | 548 | |
|
511 | if (impl->m_DrawingRect) { | |
|
512 | impl->m_DrawingRect->bottomRight->setCoords(axisPos); | |
|
549 | // Zoom box and zone drawing | |
|
550 | if (impl->m_DrawingZoomRect) { | |
|
551 | impl->m_DrawingZoomRect->bottomRight->setCoords(axisPos); | |
|
552 | } | |
|
553 | else if (impl->m_DrawingZone) { | |
|
554 | impl->m_DrawingZone->setEnd(axisPos.x()); | |
|
513 | 555 | } |
|
514 | 556 | |
|
557 | // Cursor | |
|
515 | 558 | if (auto parentZone = parentZoneWidget()) { |
|
516 | 559 | if (impl->pointIsInAxisRect(axisPos, plot())) { |
|
517 | 560 | parentZone->notifyMouseMoveInGraph(event->pos(), axisPos, this); |
@@ -524,6 +567,44 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |||
|
524 | 567 | qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; |
|
525 | 568 | } |
|
526 | 569 | |
|
570 | // Search for the selection zone under the mouse | |
|
571 | VisualizationSelectionZoneItem *selectionZoneItemUnderCursor = nullptr; | |
|
572 | auto minDistanceToZone = -1; | |
|
573 | for (auto zone : impl->m_SelectionZones) { | |
|
574 | auto distanceToZone = zone->selectTest(event->pos(), true); | |
|
575 | if ((minDistanceToZone < 0 || distanceToZone <= minDistanceToZone) && distanceToZone >= 0 | |
|
576 | && distanceToZone < plot().selectionTolerance()) { | |
|
577 | selectionZoneItemUnderCursor = zone; | |
|
578 | } | |
|
579 | } | |
|
580 | ||
|
581 | if (selectionZoneItemUnderCursor && !impl->m_DrawingZone | |
|
582 | && sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones) { | |
|
583 | ||
|
584 | // Sets the appropriate cursor shape | |
|
585 | auto cursorShape = selectionZoneItemUnderCursor->curshorShapeForPosition(event->pos()); | |
|
586 | setCursor(cursorShape); | |
|
587 | ||
|
588 | // Manages the hovered zone | |
|
589 | if (selectionZoneItemUnderCursor != impl->m_HoveredZone) { | |
|
590 | if (impl->m_HoveredZone) { | |
|
591 | impl->m_HoveredZone->setHovered(false); | |
|
592 | } | |
|
593 | selectionZoneItemUnderCursor->setHovered(true); | |
|
594 | impl->m_HoveredZone = selectionZoneItemUnderCursor; | |
|
595 | plot().replot(QCustomPlot::rpQueuedReplot); | |
|
596 | } | |
|
597 | } | |
|
598 | else { | |
|
599 | // There is no zone under the mouse or the interaction mode is not "selection zones" | |
|
600 | if (impl->m_HoveredZone) { | |
|
601 | impl->m_HoveredZone->setHovered(false); | |
|
602 | impl->m_HoveredZone = nullptr; | |
|
603 | } | |
|
604 | ||
|
605 | setCursor(Qt::ArrowCursor); | |
|
606 | } | |
|
607 | ||
|
527 | 608 | VisualizationDragWidget::mouseMoveEvent(event); |
|
528 | 609 | } |
|
529 | 610 | |
@@ -561,24 +642,41 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |||
|
561 | 642 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
562 | 643 | { |
|
563 | 644 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox) { |
|
645 | // Starts a zoom box | |
|
564 | 646 | impl->startDrawingRect(event->pos(), plot()); |
|
565 | 647 | } |
|
648 | else if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones | |
|
649 | && impl->m_DrawingZone == nullptr) { | |
|
650 | // Starts a new selection zone | |
|
651 | auto itemAtPos = plot().itemAt(event->pos(), true); | |
|
652 | if (!itemAtPos) { | |
|
653 | impl->startDrawingZone(event->pos(), plot()); | |
|
654 | } | |
|
655 | } | |
|
656 | ||
|
657 | // Allows mouse panning only in default mode | |
|
658 | plot().setInteraction(QCP::iRangeDrag, sqpApp->plotsInteractionMode() | |
|
659 | == SqpApplication::PlotsInteractionMode::None); | |
|
660 | ||
|
661 | // Allows zone edition only in selection zone mode | |
|
662 | impl->setSelectionZonesEditionEnabled(sqpApp->plotsInteractionMode() | |
|
663 | == SqpApplication::PlotsInteractionMode::SelectionZones); | |
|
566 | 664 | |
|
567 | 665 | VisualizationDragWidget::mousePressEvent(event); |
|
568 | 666 | } |
|
569 | 667 | |
|
570 | 668 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
571 | 669 | { |
|
572 | if (impl->m_DrawingRect) { | |
|
670 | if (impl->m_DrawingZoomRect) { | |
|
573 | 671 | |
|
574 | 672 | auto axisX = plot().axisRect()->axis(QCPAxis::atBottom); |
|
575 | 673 | auto axisY = plot().axisRect()->axis(QCPAxis::atLeft); |
|
576 | 674 | |
|
577 | auto newAxisXRange = QCPRange{impl->m_DrawingRect->topLeft->coords().x(), | |
|
578 | impl->m_DrawingRect->bottomRight->coords().x()}; | |
|
675 | auto newAxisXRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().x(), | |
|
676 | impl->m_DrawingZoomRect->bottomRight->coords().x()}; | |
|
579 | 677 | |
|
580 | auto newAxisYRange = QCPRange{impl->m_DrawingRect->topLeft->coords().y(), | |
|
581 | impl->m_DrawingRect->bottomRight->coords().y()}; | |
|
678 | auto newAxisYRange = QCPRange{impl->m_DrawingZoomRect->topLeft->coords().y(), | |
|
679 | impl->m_DrawingZoomRect->bottomRight->coords().y()}; | |
|
582 | 680 | |
|
583 | 681 | impl->removeDrawingRect(plot()); |
|
584 | 682 | |
@@ -591,6 +689,8 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |||
|
591 | 689 | } |
|
592 | 690 | } |
|
593 | 691 | |
|
692 | impl->endDrawingZone(plot()); | |
|
693 | ||
|
594 | 694 | impl->m_IsCalibration = false; |
|
595 | 695 | } |
|
596 | 696 |
General Comments 0
You need to be logged in to leave comments.
Login now