Auto status change to "Under Review"
@@ -4,6 +4,8 | |||
|
4 | 4 | #include <QApplication> |
|
5 | 5 | #include <QMouseEvent> |
|
6 | 6 | |
|
7 | #include <SqpApplication.h> | |
|
8 | ||
|
7 | 9 | struct VisualizationDragWidget::VisualizationDragWidgetPrivate { |
|
8 | 10 | |
|
9 | 11 | QPoint m_DragStartPosition; |
@@ -38,9 +40,8 void VisualizationDragWidget::mouseMoveEvent(QMouseEvent *event) | |||
|
38 | 40 | return; |
|
39 | 41 | } |
|
40 | 42 | |
|
41 | if (!event->modifiers().testFlag(Qt::AltModifier)) { | |
|
42 | return; | |
|
43 | } | |
|
43 | if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::DragAndDrop | |
|
44 | || event->modifiers().testFlag(Qt::AltModifier)) { | |
|
44 | 45 | |
|
45 | 46 | if ((event->pos() - impl->m_DragStartPosition).manhattanLength() |
|
46 | 47 | < QApplication::startDragDistance()) { |
@@ -48,6 +49,7 void VisualizationDragWidget::mouseMoveEvent(QMouseEvent *event) | |||
|
48 | 49 | } |
|
49 | 50 | |
|
50 | 51 | emit dragDetected(this, impl->m_DragStartPosition); |
|
52 | } | |
|
51 | 53 | |
|
52 | 54 | QWidget::mouseMoveEvent(event); |
|
53 | 55 | } |
@@ -23,10 +23,16 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |||
|
23 | 23 | namespace { |
|
24 | 24 | |
|
25 | 25 | /// Key pressed to enable zoom on horizontal axis |
|
26 |
const auto HORIZONTAL_ZOOM_MODIFIER = Qt:: |
|
|
26 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
|
27 | 27 | |
|
28 | 28 | /// Key pressed to enable zoom on vertical axis |
|
29 |
const auto VERTICAL_ZOOM_MODIFIER = Qt:: |
|
|
29 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ShiftModifier; | |
|
30 | ||
|
31 | /// Speed of a step of a wheel event for a pan, in percentage of the axis range | |
|
32 | const auto PAN_SPEED = 5; | |
|
33 | ||
|
34 | /// Key pressed to enable a calibration pan | |
|
35 | const auto VERTICAL_PAN_MODIFIER = Qt::AltModifier; | |
|
30 | 36 | |
|
31 | 37 | } // namespace |
|
32 | 38 | |
@@ -62,8 +68,7 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget | |||
|
62 | 68 | // Set qcpplot properties : |
|
63 | 69 | // - Drag (on x-axis) and zoom are enabled |
|
64 | 70 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
65 |
ui->widget->setInteractions( |
|
|
66 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
|
71 | ui->widget->setInteractions(QCP::iRangeZoom | QCP::iSelectItems); | |
|
67 | 72 | |
|
68 | 73 | // The delegate must be initialized after the ui as it uses the plot |
|
69 | 74 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this); |
@@ -344,28 +349,37 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |||
|
344 | 349 | |
|
345 | 350 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
346 | 351 | { |
|
347 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
|
352 | auto value = event->angleDelta().x() + event->angleDelta().y(); | |
|
353 | if (value != 0) { | |
|
348 | 354 | |
|
349 | // Lambda that enables a zoom orientation if the key modifier related to this orientation | |
|
350 | // has | |
|
351 | // been pressed | |
|
352 | auto enableOrientation | |
|
353 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
|
354 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
|
355 |
|
|
|
356 | }; | |
|
357 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
|
358 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
|
355 | auto direction = value > 0 ? 1.0 : -1.0; | |
|
356 | auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER); | |
|
357 | auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER); | |
|
358 | impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER); | |
|
359 | ||
|
360 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
|
361 | zoomOrientations.setFlag(Qt::Horizontal, isZoomX); | |
|
362 | zoomOrientations.setFlag(Qt::Vertical, isZoomY); | |
|
359 | 363 | |
|
360 | 364 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
365 | ||
|
366 | if (!isZoomX && !isZoomY) { | |
|
367 | auto axis = plot().axisRect()->axis(QCPAxis::atBottom); | |
|
368 | auto diff = direction * (axis->range().size() * (PAN_SPEED / 100.0)); | |
|
369 | ||
|
370 | axis->setRange(axis->range() + diff); | |
|
371 | ||
|
372 | if (plot().noAntialiasingOnDrag()) { | |
|
373 | plot().setNotAntialiasedElements(QCP::aeAll); | |
|
374 | } | |
|
375 | ||
|
376 | plot().replot(QCustomPlot::rpQueuedReplot); | |
|
377 | } | |
|
378 | } | |
|
361 | 379 | } |
|
362 | 380 | |
|
363 | 381 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
364 | 382 | { |
|
365 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); | |
|
366 | ||
|
367 | plot().setInteraction(QCP::iRangeDrag, !event->modifiers().testFlag(Qt::AltModifier)); | |
|
368 | ||
|
369 | 383 | VisualizationDragWidget::mousePressEvent(event); |
|
370 | 384 | } |
|
371 | 385 |
General Comments 1
You need to be logged in to leave comments.
Login now