##// END OF EJS Templates
Basic mouse wheel interactions + mode drag
trabillard -
r1001:ebb8b3d01eee
parent child
Show More
@@ -4,6 +4,8
4 #include <QApplication>
4 #include <QApplication>
5 #include <QMouseEvent>
5 #include <QMouseEvent>
6
6
7 #include <SqpApplication.h>
8
7 struct VisualizationDragWidget::VisualizationDragWidgetPrivate {
9 struct VisualizationDragWidget::VisualizationDragWidgetPrivate {
8
10
9 QPoint m_DragStartPosition;
11 QPoint m_DragStartPosition;
@@ -38,16 +40,16 void VisualizationDragWidget::mouseMoveEvent(QMouseEvent *event)
38 return;
40 return;
39 }
41 }
40
42
41 if (!event->modifiers().testFlag(Qt::AltModifier)) {
43 if (sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::DragAndDrop
42 return;
44 || event->modifiers().testFlag(Qt::AltModifier)) {
43 }
44
45
45 if ((event->pos() - impl->m_DragStartPosition).manhattanLength()
46 if ((event->pos() - impl->m_DragStartPosition).manhattanLength()
46 < QApplication::startDragDistance()) {
47 < QApplication::startDragDistance()) {
47 return;
48 return;
48 }
49 }
49
50
50 emit dragDetected(this, impl->m_DragStartPosition);
51 emit dragDetected(this, impl->m_DragStartPosition);
52 }
51
53
52 QWidget::mouseMoveEvent(event);
54 QWidget::mouseMoveEvent(event);
53 }
55 }
@@ -23,10 +23,16 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
23 namespace {
23 namespace {
24
24
25 /// Key pressed to enable zoom on horizontal axis
25 /// Key pressed to enable zoom on horizontal axis
26 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
26 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::ControlModifier;
27
27
28 /// Key pressed to enable zoom on vertical axis
28 /// Key pressed to enable zoom on vertical axis
29 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
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 } // namespace
37 } // namespace
32
38
@@ -62,8 +68,7 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
62 // Set qcpplot properties :
68 // Set qcpplot properties :
63 // - Drag (on x-axis) and zoom are enabled
69 // - Drag (on x-axis) and zoom are enabled
64 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
70 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
65 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectItems);
71 ui->widget->setInteractions(QCP::iRangeZoom | QCP::iSelectItems);
66 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
67
72
68 // The delegate must be initialized after the ui as it uses the plot
73 // The delegate must be initialized after the ui as it uses the plot
69 impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this);
74 impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*this);
@@ -344,28 +349,37 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept
344
349
345 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
350 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
346 {
351 {
347 auto zoomOrientations = QFlags<Qt::Orientation>{};
352 auto value = event->angleDelta().x() + event->angleDelta().y();
348
353 if (value != 0) {
349 // Lambda that enables a zoom orientation if the key modifier related to this orientation
354
350 // has
355 auto direction = value > 0 ? 1.0 : -1.0;
351 // been pressed
356 auto isZoomX = event->modifiers().testFlag(HORIZONTAL_ZOOM_MODIFIER);
352 auto enableOrientation
357 auto isZoomY = event->modifiers().testFlag(VERTICAL_ZOOM_MODIFIER);
353 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
358 impl->m_IsCalibration = event->modifiers().testFlag(VERTICAL_PAN_MODIFIER);
354 auto orientationEnabled = event->modifiers().testFlag(modifier);
359
355 zoomOrientations.setFlag(orientation, orientationEnabled);
360 auto zoomOrientations = QFlags<Qt::Orientation>{};
356 };
361 zoomOrientations.setFlag(Qt::Horizontal, isZoomX);
357 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
362 zoomOrientations.setFlag(Qt::Vertical, isZoomY);
358 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
363
359
364 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
360 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 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
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 VisualizationDragWidget::mousePressEvent(event);
383 VisualizationDragWidget::mousePressEvent(event);
370 }
384 }
371
385
General Comments 1
Under Review
author

Auto status change to "Under Review"

You need to be logged in to leave comments. Login now