1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

Use mouse wheel to zoom in / out of charts.

This commit is contained in:
srcejon 2024-04-05 17:30:39 +01:00
parent 3bdba94921
commit c1a2c5cbab

View File

@ -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<QContextMenuEvent *>(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<QWheelEvent *>(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);
}