add support for shortcuts CTRL-/ (stop run) and CTRL-Q (quit) to most windows
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
project(lammps-gui VERSION 1.5.7 LANGUAGES CXX)
|
project(lammps-gui VERSION 1.5.8 LANGUAGES CXX)
|
||||||
|
|
||||||
set(CMAKE_AUTOUIC ON)
|
set(CMAKE_AUTOUIC ON)
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|||||||
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#include "chartviewer.h"
|
#include "chartviewer.h"
|
||||||
|
|
||||||
|
#include "lammpsgui.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLineSeries>
|
#include <QLineSeries>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
@ -40,8 +42,14 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
|
|||||||
exportDatAct = file->addAction("Export data to &Gnuplot...", this, &ChartWindow::exportDat);
|
exportDatAct = file->addAction("Export data to &Gnuplot...", this, &ChartWindow::exportDat);
|
||||||
exportDatAct->setIcon(QIcon(":/icons/application-plot.png"));
|
exportDatAct->setIcon(QIcon(":/icons/application-plot.png"));
|
||||||
file->addSeparator();
|
file->addSeparator();
|
||||||
|
stopAct = file->addAction("Stop &Run", this, &ChartWindow::stop_run);
|
||||||
|
stopAct->setIcon(QIcon(":/icons/process-stop.png"));
|
||||||
|
stopAct->setShortcut(QKeySequence(Qt::Key_Slash, Qt::CTRL));
|
||||||
closeAct = file->addAction("&Close", this, &QWidget::close);
|
closeAct = file->addAction("&Close", this, &QWidget::close);
|
||||||
closeAct->setIcon(QIcon(":/icons/window-close.png"));
|
closeAct->setIcon(QIcon(":/icons/window-close.png"));
|
||||||
|
quitAct = file->addAction("&Quit", this, &ChartWindow::quit);
|
||||||
|
quitAct->setIcon(QIcon(":/icons/application-exit.png"));
|
||||||
|
quitAct->setShortcut(QKeySequence::fromString("Ctrl+Q"));
|
||||||
auto *layout = new QVBoxLayout;
|
auto *layout = new QVBoxLayout;
|
||||||
layout->addLayout(top);
|
layout->addLayout(top);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
@ -92,6 +100,22 @@ void ChartWindow::add_data(int step, double data, int index)
|
|||||||
if (c->get_index() == index) c->add_data(step, data);
|
if (c->get_index() == index) c->add_data(step, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChartWindow::quit()
|
||||||
|
{
|
||||||
|
LammpsGui *main;
|
||||||
|
for (QWidget *widget : QApplication::topLevelWidgets())
|
||||||
|
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
|
||||||
|
main->quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChartWindow::stop_run()
|
||||||
|
{
|
||||||
|
LammpsGui *main;
|
||||||
|
for (QWidget *widget : QApplication::topLevelWidgets())
|
||||||
|
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
|
||||||
|
main->stop_run();
|
||||||
|
}
|
||||||
|
|
||||||
void ChartWindow::saveAs()
|
void ChartWindow::saveAs()
|
||||||
{
|
{
|
||||||
if (charts.empty()) return;
|
if (charts.empty()) return;
|
||||||
|
|||||||
@ -42,6 +42,9 @@ public:
|
|||||||
void add_data(int step, double data, int index);
|
void add_data(int step, double data, int index);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void quit();
|
||||||
|
void stop_run();
|
||||||
|
|
||||||
void saveAs();
|
void saveAs();
|
||||||
void exportDat();
|
void exportDat();
|
||||||
void exportCsv();
|
void exportCsv();
|
||||||
@ -55,10 +58,8 @@ private:
|
|||||||
QMenuBar *menu;
|
QMenuBar *menu;
|
||||||
QMenu *file;
|
QMenu *file;
|
||||||
QComboBox *columns;
|
QComboBox *columns;
|
||||||
QAction *saveAsAct;
|
QAction *saveAsAct, *exportCsvAct, *exportDatAct;
|
||||||
QAction *exportCsvAct;
|
QAction *closeAct, *stopAct, *quitAct;
|
||||||
QAction *exportDatAct;
|
|
||||||
QAction *closeAct;
|
|
||||||
|
|
||||||
QString filename;
|
QString filename;
|
||||||
QList<ChartViewer *> charts;
|
QList<ChartViewer *> charts;
|
||||||
|
|||||||
@ -12,9 +12,12 @@
|
|||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#include "imageviewer.h"
|
#include "imageviewer.h"
|
||||||
|
|
||||||
|
#include "lammpsgui.h"
|
||||||
#include "lammpswrapper.h"
|
#include "lammpswrapper.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QApplication>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@ -510,15 +513,11 @@ void ImageViewer::createImage()
|
|||||||
QImageReader reader(dumpfile.fileName());
|
QImageReader reader(dumpfile.fileName());
|
||||||
reader.setAutoTransform(true);
|
reader.setAutoTransform(true);
|
||||||
const QImage newImage = reader.read();
|
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();
|
dumpfile.remove();
|
||||||
|
|
||||||
|
// read of new image failed. Don't try to scale and load it.
|
||||||
|
if (newImage.isNull()) return;
|
||||||
|
|
||||||
// scale back to achieve antialiasing
|
// scale back to achieve antialiasing
|
||||||
image = newImage.scaled(xsize, ysize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
image = newImage.scaled(xsize, ysize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
imageLabel->setPixmap(QPixmap::fromImage(image));
|
imageLabel->setPixmap(QPixmap::fromImage(image));
|
||||||
@ -536,6 +535,14 @@ void ImageViewer::saveAs()
|
|||||||
|
|
||||||
void ImageViewer::copy() {}
|
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)
|
void ImageViewer::saveFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (!fileName.isEmpty()) image.save(fileName);
|
if (!fileName.isEmpty()) image.save(fileName);
|
||||||
@ -557,6 +564,9 @@ void ImageViewer::createActions()
|
|||||||
QAction *exitAct = fileMenu->addAction("&Close", this, &QWidget::close);
|
QAction *exitAct = fileMenu->addAction("&Close", this, &QWidget::close);
|
||||||
exitAct->setIcon(QIcon(":/icons/window-close.png"));
|
exitAct->setIcon(QIcon(":/icons/window-close.png"));
|
||||||
exitAct->setShortcut(QKeySequence::fromString("Ctrl+W"));
|
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()
|
void ImageViewer::updateActions()
|
||||||
|
|||||||
@ -40,6 +40,7 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void saveAs();
|
void saveAs();
|
||||||
void copy();
|
void copy();
|
||||||
|
void quit();
|
||||||
|
|
||||||
void edit_size();
|
void edit_size();
|
||||||
void reset_view();
|
void reset_view();
|
||||||
|
|||||||
@ -66,6 +66,10 @@ protected:
|
|||||||
void start_lammps();
|
void start_lammps();
|
||||||
void run_done();
|
void run_done();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void quit();
|
||||||
|
void stop_run();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void new_document();
|
void new_document();
|
||||||
void open();
|
void open();
|
||||||
@ -73,7 +77,6 @@ private slots:
|
|||||||
void start_exe();
|
void start_exe();
|
||||||
void save();
|
void save();
|
||||||
void save_as();
|
void save_as();
|
||||||
void quit();
|
|
||||||
void copy();
|
void copy();
|
||||||
void cut();
|
void cut();
|
||||||
void paste();
|
void paste();
|
||||||
@ -82,7 +85,6 @@ private slots:
|
|||||||
void run_buffer() { do_run(true); }
|
void run_buffer() { do_run(true); }
|
||||||
void run_file() { do_run(false); }
|
void run_file() { do_run(false); }
|
||||||
|
|
||||||
void stop_run();
|
|
||||||
void edit_variables();
|
void edit_variables();
|
||||||
void render_image();
|
void render_image();
|
||||||
void view_slides();
|
void view_slides();
|
||||||
|
|||||||
@ -13,7 +13,10 @@
|
|||||||
|
|
||||||
#include "logwindow.h"
|
#include "logwindow.h"
|
||||||
|
|
||||||
|
#include "lammpsgui.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@ -32,8 +35,12 @@ LogWindow::LogWindow(const QString &_filename, QWidget *parent) :
|
|||||||
QSettings settings;
|
QSettings settings;
|
||||||
resize(settings.value("logx", 500).toInt(), settings.value("logy", 320).toInt());
|
resize(settings.value("logx", 500).toInt(), settings.value("logy", 320).toInt());
|
||||||
|
|
||||||
auto action = new QShortcut(QKeySequence("Ctrl+S"), this);
|
auto action = new QShortcut(QKeySequence::fromString("Ctrl+S"), this);
|
||||||
connect(action, &QShortcut::activated, this, &LogWindow::save_as);
|
connect(action, &QShortcut::activated, this, &LogWindow::save_as);
|
||||||
|
action = new QShortcut(QKeySequence::fromString("Ctrl+Q"), this);
|
||||||
|
connect(action, &QShortcut::activated, this, &LogWindow::quit);
|
||||||
|
action = new QShortcut(QKeySequence(Qt::Key_Slash, Qt::CTRL), this);
|
||||||
|
connect(action, &QShortcut::activated, this, &LogWindow::stop_run);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogWindow::closeEvent(QCloseEvent *event)
|
void LogWindow::closeEvent(QCloseEvent *event)
|
||||||
@ -46,6 +53,22 @@ void LogWindow::closeEvent(QCloseEvent *event)
|
|||||||
QPlainTextEdit::closeEvent(event);
|
QPlainTextEdit::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LogWindow::quit()
|
||||||
|
{
|
||||||
|
LammpsGui *main;
|
||||||
|
for (QWidget *widget : QApplication::topLevelWidgets())
|
||||||
|
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
|
||||||
|
main->quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogWindow::stop_run()
|
||||||
|
{
|
||||||
|
LammpsGui *main;
|
||||||
|
for (QWidget *widget : QApplication::topLevelWidgets())
|
||||||
|
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
|
||||||
|
main->stop_run();
|
||||||
|
}
|
||||||
|
|
||||||
void LogWindow::save_as()
|
void LogWindow::save_as()
|
||||||
{
|
{
|
||||||
QString defaultname = filename + ".log";
|
QString defaultname = filename + ".log";
|
||||||
|
|||||||
@ -23,7 +23,9 @@ public:
|
|||||||
LogWindow(const QString &filename, QWidget *parent = nullptr);
|
LogWindow(const QString &filename, QWidget *parent = nullptr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void quit();
|
||||||
void save_as();
|
void save_as();
|
||||||
|
void stop_run();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
|
|||||||
@ -14,7 +14,9 @@
|
|||||||
#include "slideshow.h"
|
#include "slideshow.h"
|
||||||
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
#include "lammpsgui.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@ -48,8 +50,12 @@ SlideShow::SlideShow(const QString &fileName, QWidget *parent) :
|
|||||||
imageName->setAlignment(Qt::AlignCenter);
|
imageName->setAlignment(Qt::AlignCenter);
|
||||||
imageName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
imageName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
|
||||||
auto *shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
auto *shortcut = new QShortcut(QKeySequence::fromString("Ctrl+W"), this);
|
||||||
QObject::connect(shortcut, &QShortcut::activated, this, &SlideShow::close);
|
QObject::connect(shortcut, &QShortcut::activated, this, &QWidget::close);
|
||||||
|
shortcut = new QShortcut(QKeySequence::fromString("Ctrl+/"), this);
|
||||||
|
QObject::connect(shortcut, &QShortcut::activated, this, &SlideShow::stop_run);
|
||||||
|
shortcut = new QShortcut(QKeySequence::fromString("Ctrl+Q"), this);
|
||||||
|
QObject::connect(shortcut, &QShortcut::activated, this, &SlideShow::quit);
|
||||||
|
|
||||||
buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||||
|
|
||||||
@ -190,6 +196,22 @@ void SlideShow::loadImage(int idx)
|
|||||||
} while (idx >= 0);
|
} while (idx >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SlideShow::quit()
|
||||||
|
{
|
||||||
|
LammpsGui *main;
|
||||||
|
for (QWidget *widget : QApplication::topLevelWidgets())
|
||||||
|
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
|
||||||
|
main->quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SlideShow::stop_run()
|
||||||
|
{
|
||||||
|
LammpsGui *main;
|
||||||
|
for (QWidget *widget : QApplication::topLevelWidgets())
|
||||||
|
if (widget->objectName() == "LammpsGui") main = dynamic_cast<LammpsGui *>(widget);
|
||||||
|
main->stop_run();
|
||||||
|
}
|
||||||
|
|
||||||
void SlideShow::movie()
|
void SlideShow::movie()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getSaveFileName(this, "Export to Movie File", ".",
|
QString fileName = QFileDialog::getSaveFileName(this, "Export to Movie File", ".",
|
||||||
|
|||||||
@ -32,6 +32,8 @@ public:
|
|||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void quit();
|
||||||
|
void stop_run();
|
||||||
void movie();
|
void movie();
|
||||||
void first();
|
void first();
|
||||||
void last();
|
void last();
|
||||||
|
|||||||
Reference in New Issue
Block a user