add more shortcuts to main window and graphing window

This commit is contained in:
Leopixelo
2026-06-08 15:10:58 +02:00
parent 37d386f3c9
commit a2851653e3
3 changed files with 108 additions and 6 deletions
+84 -6
View File
@@ -9,6 +9,9 @@
#include <algorithm>
#include <limits>
#define MOVE_FACTOR (1.0 / 2.0)
#define MOVE_FACTOR_FINE (1.0 / 10.0)
GraphingWindow::GraphingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
QDialog(parent),
ui(new Ui::GraphingWindow)
@@ -112,6 +115,8 @@ GraphingWindow::GraphingWindow(const QVector<CANFrame> *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<QKeyEvent *>(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()));
+6
View File
@@ -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);
+18
View File
@@ -461,6 +461,9 @@
<property name="text">
<string>Playback</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
<action name="action_Custom">
<property name="text">
@@ -481,6 +484,9 @@
<property name="text">
<string>New Graphing Window</string>
</property>
<property name="shortcut">
<string>Ctrl+G</string>
</property>
</action>
<action name="actionOpen_Log_File">
<property name="text">
@@ -494,6 +500,9 @@
<property name="text">
<string>Save Log File</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionFrame_Data_Analysis">
<property name="text">
@@ -534,6 +543,9 @@
<property name="text">
<string>Preferences</string>
</property>
<property name="shortcut">
<string>Ctrl+,</string>
</property>
</action>
<action name="actionSave_Filtered_Log_File">
<property name="text">
@@ -559,6 +571,9 @@
<property name="text">
<string>Open Connection Window</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+C</string>
</property>
</action>
<action name="actionConnect">
<property name="text">
@@ -584,6 +599,9 @@
<property name="text">
<string>DBC File Manager</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
<action name="actionFuzzing">
<property name="text">