From a2851653e383df5d5edbe75a4f5face4ea4df336 Mon Sep 17 00:00:00 2001 From: Leopixelo Date: Sat, 28 Jun 2025 22:31:35 +0200 Subject: [PATCH] add more shortcuts to main window and graphing window --- re/graphingwindow.cpp | 90 ++++++++++++++++++++++++++++++++++++++++--- re/graphingwindow.h | 6 +++ ui/mainwindow.ui | 18 +++++++++ 3 files changed, 108 insertions(+), 6 deletions(-) diff --git a/re/graphingwindow.cpp b/re/graphingwindow.cpp index 647047c..7099fba 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -9,6 +9,9 @@ #include #include +#define MOVE_FACTOR (1.0 / 2.0) +#define MOVE_FACTOR_FINE (1.0 / 10.0) + GraphingWindow::GraphingWindow(const QVector *frames, QWidget *parent) : QDialog(parent), ui(new Ui::GraphingWindow) @@ -112,6 +115,8 @@ GraphingWindow::GraphingWindow(const QVector *frames, QWidget *parent) needScaleSetup = true; followGraphEnd = true; + xPressed = false; + yPressed = false; } GraphingWindow::~GraphingWindow() @@ -465,16 +470,47 @@ void GraphingWindow::mouseWheel() bool GraphingWindow::eventFilter(QObject *obj, QEvent *event) { - if (event->type() == QEvent::KeyRelease) { + if (event->type() == QEvent::KeyRelease || event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(event); + switch (keyEvent->key()) + { + case Qt::Key_X: + xPressed = event->type() == QEvent::KeyPress; + break; + case Qt::Key_Y: + yPressed = event->type() == QEvent::KeyPress; + break; + } + if (event->type() != QEvent::KeyRelease) + { + return true; + } + switch (keyEvent->key()) { case Qt::Key_Plus: + case Qt::Key_PageUp: zoomIn(); break; case Qt::Key_Minus: + case Qt::Key_PageDown: zoomOut(); break; + case Qt::Key_Up: + moveUp(QApplication::keyboardModifiers() == Qt::ShiftModifier); + break; + case Qt::Key_Down: + moveDown(QApplication::keyboardModifiers() == Qt::ShiftModifier); + break; + case Qt::Key_Left: + moveLeft(QApplication::keyboardModifiers() == Qt::ShiftModifier); + break; + case Qt::Key_Right: + moveRight(QApplication::keyboardModifiers() == Qt::ShiftModifier); + break; + case Qt::Key_F: + toggleFollowMode(); + break; case Qt::Key_F1: HelpWindow::getRef()->showHelp("graphwindow.md"); break; @@ -526,12 +562,12 @@ void GraphingWindow::zoomIn() { QCPRange xrange = ui->graphingView->xAxis->range(); QCPRange yrange = ui->graphingView->yAxis->range(); - if (ui->graphingView->xAxis->selectedParts().testFlag(QCPAxis::spAxis)) + if (ui->graphingView->xAxis->selectedParts().testFlag(QCPAxis::spAxis) || xPressed) { ui->graphingView->xAxis->scaleRange(0.666, xrange.center()); } - else if (ui->graphingView->yAxis->selectedParts().testFlag(QCPAxis::spAxis)) + else if (ui->graphingView->yAxis->selectedParts().testFlag(QCPAxis::spAxis) || yPressed) { ui->graphingView->yAxis->scaleRange(0.666, yrange.center()); } @@ -547,12 +583,12 @@ void GraphingWindow::zoomOut() { QCPRange xrange = ui->graphingView->xAxis->range(); QCPRange yrange = ui->graphingView->yAxis->range(); - if (ui->graphingView->xAxis->selectedParts().testFlag(QCPAxis::spAxis)) + if (ui->graphingView->xAxis->selectedParts().testFlag(QCPAxis::spAxis) || xPressed) { ui->graphingView->xAxis->scaleRange(1.5, xrange.center()); } - else if (ui->graphingView->yAxis->selectedParts().testFlag(QCPAxis::spAxis)) + else if (ui->graphingView->yAxis->selectedParts().testFlag(QCPAxis::spAxis) || yPressed) { ui->graphingView->yAxis->scaleRange(1.5, yrange.center()); } @@ -564,6 +600,47 @@ void GraphingWindow::zoomOut() ui->graphingView->replot(); } +void GraphingWindow::moveUp(bool fine) +{ + QCPRange range = ui->graphingView->yAxis->range(); + double diff = (range.upper - range.lower); + if (fine) diff *= MOVE_FACTOR_FINE; + else diff *= MOVE_FACTOR; + ui->graphingView->yAxis->moveRange(diff); + ui->graphingView->replot(); +} + +void GraphingWindow::moveDown(bool fine) +{ + QCPRange range = ui->graphingView->yAxis->range(); + double diff = (range.upper - range.lower); + if (fine) diff *= MOVE_FACTOR_FINE; + else diff *= MOVE_FACTOR; + ui->graphingView->yAxis->moveRange(-diff); + ui->graphingView->replot(); +} + +void GraphingWindow::moveLeft(bool fine) +{ + QCPRange range = ui->graphingView->xAxis->range(); + double diff = (range.upper - range.lower); + if (fine) diff *= MOVE_FACTOR_FINE; + else diff *= MOVE_FACTOR; + ui->graphingView->xAxis->moveRange(-diff); + ui->graphingView->replot(); +} + +void GraphingWindow::moveRight(bool fine) +{ + QCPRange range = ui->graphingView->xAxis->range(); + double diff = (range.upper - range.lower); + if (fine) diff *= MOVE_FACTOR_FINE; + else diff *= MOVE_FACTOR; + ui->graphingView->xAxis->moveRange(diff); + ui->graphingView->replot(); +} + + void GraphingWindow::removeSelectedGraph() { if (ui->graphingView->selectedGraphs().size() > 0) @@ -671,7 +748,8 @@ void GraphingWindow::contextMenuRequest(QPoint pos) menu->addAction(tr("Save graph definitions to file"), this, SLOT(saveDefinitions())); menu->addAction(tr("Load graph definitions from file"), this, SLOT(loadDefinitions())); menu->addAction(tr("Save spreadsheet of data"), this, SLOT(saveSpreadsheet())); - QAction *act = menu->addAction(tr("Follow end of graph"), this, SLOT(toggleFollowMode())); + QKeySequence followShortcut = QKeySequence("F"); + QAction *act = menu->addAction(tr("Follow end of graph"), this, SLOT(toggleFollowMode()), followShortcut); act->setCheckable(true); act->setChecked(followGraphEnd); menu->addAction(tr("Add new graph"), this, SLOT(addNewGraph())); diff --git a/re/graphingwindow.h b/re/graphingwindow.h index d82584a..0b2ba81 100644 --- a/re/graphingwindow.h +++ b/re/graphingwindow.h @@ -87,6 +87,10 @@ private slots: void resetView(); void zoomIn(); void zoomOut(); + void moveUp(bool fine); + void moveDown(bool fine); + void moveLeft(bool fine); + void moveRight(bool fine); signals: void sendCenterTimeID(uint32_t ID, double timestamp); @@ -104,6 +108,8 @@ private: bool needScaleSetup; //do we need to set x,y graphing extents? bool useOpenGL; bool followGraphEnd; + bool xPressed; + bool yPressed; void showParamsDialog(int idx); void closeEvent(QCloseEvent *event); diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index c369540..a901f1c 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -461,6 +461,9 @@ Playback + + Ctrl+P + @@ -481,6 +484,9 @@ New Graphing Window + + Ctrl+G + @@ -494,6 +500,9 @@ Save Log File + + Ctrl+S + @@ -534,6 +543,9 @@ Preferences + + Ctrl+, + @@ -559,6 +571,9 @@ Open Connection Window + + Ctrl+Shift+C + @@ -584,6 +599,9 @@ DBC File Manager + + Ctrl+D +