##// END OF EJS Templates
Handles key modifiers for zoom...
Alexandre Leroux -
r166:765885a6f6ff
parent child
Show More
@@ -34,6 +34,10 private:
34 34
35 35 class VisualizationGraphWidgetPrivate;
36 36 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
37
38 private slots:
39 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
40 void onMouseWheel(QWheelEvent *event) noexcept;
37 41 };
38 42
39 43 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -5,6 +5,16
5 5
6 6 #include <unordered_map>
7 7
8 namespace {
9
10 /// Key pressed to enable zoom on horizontal axis
11 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
12
13 /// Key pressed to enable zoom on vertical axis
14 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
15
16 } // namespace
17
8 18 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
9 19
10 20 // 1 variable -> n qcpplot
@@ -21,7 +31,9 VisualizationGraphWidget::VisualizationGraphWidget(QWidget *parent)
21 31
22 32 // Set qcpplot properties :
23 33 // - Drag and zoom are enabled
34 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
24 35 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
36 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
25 37 }
26 38
27 39 VisualizationGraphWidget::~VisualizationGraphWidget()
@@ -49,3 +61,20 QString VisualizationGraphWidget::name() const
49 61 {
50 62 return QStringLiteral("MainView");
51 63 }
64
65 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
66 {
67 auto zoomOrientations = QFlags<Qt::Orientation>{};
68
69 // Lambda that enables a zoom orientation if the key modifier related to this orientation has
70 // been pressed
71 auto enableOrientation
72 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
73 auto orientationEnabled = event->modifiers().testFlag(modifier);
74 zoomOrientations.setFlag(orientation, orientationEnabled);
75 };
76 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
77 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
78
79 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
80 }
General Comments 0
You need to be logged in to leave comments. Login now