From c1a2c5cbabaf43583969bf7c7ce24bfb12c2bbef Mon Sep 17 00:00:00 2001 From: srcejon Date: Fri, 5 Apr 2024 17:30:39 +0100 Subject: [PATCH] Use mouse wheel to zoom in / out of charts. --- plugins/feature/sid/sidgui.cpp | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/plugins/feature/sid/sidgui.cpp b/plugins/feature/sid/sidgui.cpp index 167a7c52b..a8a5a0102 100644 --- a/plugins/feature/sid/sidgui.cpp +++ b/plugins/feature/sid/sidgui.cpp @@ -1201,12 +1201,49 @@ bool SIDGUI::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::ContextMenu) { + // Show context menu on chart for GRBs/Flares QContextMenuEvent *contextEvent = static_cast(event); showContextMenu(contextEvent); contextEvent->accept(); return true; } + else if (event->type() == QEvent::Wheel) + { + // Use wheel to zoom in / out of X axis or Y axis if shift held + QWheelEvent *wheelEvent = static_cast(event); + + int delta = wheelEvent->angleDelta().y(); // delta is typically 120 for one click of wheel + + if (wheelEvent->modifiers() & Qt::ShiftModifier) + { + double min = ui->y1Min->value(); + double max = ui->y1Max->value(); + double adj = (max - min) * 0.20 * delta / 120.0; + min += adj; + max -= adj; + ui->y1Min->setValue(min); + ui->y1Max->setValue(max); + } + else + { + QDateTime start = ui->startDateTime->dateTime(); + QDateTime end = ui->endDateTime->dateTime(); + qint64 startMS = start.toMSecsSinceEpoch(); + qint64 endMS = end.toMSecsSinceEpoch(); + qint64 diff = endMS - startMS; + qint64 adj = diff * 0.20 * delta / 120.0; + endMS -= adj; + startMS += adj; + start = QDateTime::fromMSecsSinceEpoch(startMS); + end = QDateTime::fromMSecsSinceEpoch(endMS); + ui->startDateTime->setDateTime(start); + ui->endDateTime->setDateTime(end); + } + + wheelEvent->accept(); + return true; + } } return FeatureGUI::eventFilter(obj, event); }