add support for shortcuts CTRL-/ (stop run) and CTRL-Q (quit) to most windows

This commit is contained in:
Axel Kohlmeyer
2023-10-03 21:13:06 -04:00
parent 6ff7050d2d
commit a3c843f590
10 changed files with 104 additions and 17 deletions

View File

@ -12,9 +12,12 @@
------------------------------------------------------------------------- */
#include "imageviewer.h"
#include "lammpsgui.h"
#include "lammpswrapper.h"
#include <QAction>
#include <QApplication>
#include <QDialogButtonBox>
#include <QDir>
#include <QFileDialog>
@ -510,15 +513,11 @@ void ImageViewer::createImage()
QImageReader reader(dumpfile.fileName());
reader.setAutoTransform(true);
const QImage newImage = reader.read();
if (newImage.isNull()) {
QMessageBox::warning(
this, QGuiApplication::applicationDisplayName(),
QString("Cannot load %1: %2").arg(dumpfile.fileName(), reader.errorString()));
return;
}
dumpfile.remove();
// read of new image failed. Don't try to scale and load it.
if (newImage.isNull()) return;
// scale back to achieve antialiasing
image = newImage.scaled(xsize, ysize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
imageLabel->setPixmap(QPixmap::fromImage(image));
@ -536,6 +535,14 @@ void ImageViewer::saveAs()
void ImageViewer::copy() {}
void ImageViewer::quit()
{
LammpsGui *main;
for (QWidget *widget : QApplication::topLevelWidgets())
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
main->quit();
}
void ImageViewer::saveFile(const QString &fileName)
{
if (!fileName.isEmpty()) image.save(fileName);
@ -557,6 +564,9 @@ void ImageViewer::createActions()
QAction *exitAct = fileMenu->addAction("&Close", this, &QWidget::close);
exitAct->setIcon(QIcon(":/icons/window-close.png"));
exitAct->setShortcut(QKeySequence::fromString("Ctrl+W"));
QAction *quitAct = fileMenu->addAction("&Quit", this, &ImageViewer::quit);
quitAct->setIcon(QIcon(":/icons/application-exit.png"));
quitAct->setShortcut(QKeySequence::fromString("Ctrl+Q"));
}
void ImageViewer::updateActions()