[Settings] add new menu, store and restore settings from previous session

This commit is contained in:
Jan Grewe 2021-02-26 18:42:06 +01:00
parent 3ca0b4c671
commit a87070e43f
2 changed files with 57 additions and 4 deletions

View File

@ -17,7 +17,6 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QStatusBar> #include <QStatusBar>
#include <QToolBar> #include <QToolBar>
#include <QSettings>
#include <iostream> #include <iostream>
#include <chrono> #include <chrono>
#include <cmath> #include <cmath>
@ -109,8 +108,10 @@ PylonRecorder::PylonRecorder(QWidget *parent)
statusBar()->addWidget(fileHeader); statusBar()->addWidget(fileHeader);
statusBar()->addWidget(fileLabel); statusBar()->addWidget(fileLabel);
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5); resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
applySettings();
} }
PylonRecorder::~PylonRecorder(){ PylonRecorder::~PylonRecorder(){
if (grabber->isRunning()) { if (grabber->isRunning()) {
grabber->requestStop(); grabber->requestStop();
@ -120,10 +121,38 @@ PylonRecorder::~PylonRecorder(){
writer->forceStop(); writer->forceStop();
writer->wait(1000); writer->wait(1000);
} }
storeSettings();
delete pylon; delete pylon;
delete buffer; delete buffer;
delete grabber; delete grabber;
delete writer; delete writer;
delete settings;
}
void PylonRecorder::applySettings() {
int bufferSize = settings->value("recorder/buffersize", defaultBufferSize).toInt();
int exposureTime = settings->value("camera/exposure", defaultExposureTime).toInt();
int frameRate = settings->value("camera/framerate", defaultFrameRate).toInt();
int gain = settings->value("camera/gain", defaultGain).toInt();
storageLocation = settings->value("recorder/storagelocation", "").toString();
if (!storageLocation.isEmpty()) {
selectStorageAction->setStatusTip(tr("Default storage location: ") + storageLocation);
}
buffersizeSpinner->setValue(bufferSize);
exposureSpinner->setValue(exposureTime);
gainSpinner->setValue(gain);
framerateSpinner->setValue(frameRate);
}
void PylonRecorder::storeSettings() {
settings->setValue("camera/exposure", exposureSpinner->value());
settings->setValue("camera/framerate", framerateSpinner->value());
settings->setValue("camera/gain", gainSpinner->value());
settings->setValue("recorder/buffersize", buffersizeSpinner->value());
settings->setValue("recorder/storagelocation", storageLocation);
} }
@ -384,8 +413,19 @@ void PylonRecorder::createActions() {
grab_stop_action = camera_menu->addAction(stop_icon, tr("&stop grabbing"), this, &PylonRecorder::stopRecording); grab_stop_action = camera_menu->addAction(stop_icon, tr("&stop grabbing"), this, &PylonRecorder::stopRecording);
grab_stop_action->setShortcut(tr("Ctrl+Shift+Enter")); grab_stop_action->setShortcut(tr("Ctrl+Shift+Enter"));
selectStorageAction = new QAction(tr("storage location"), this);
selectStorageAction->setStatusTip(tr("Select a storage location for the recorded videos"));
selectStorageAction->setToolTip(tr("Select a storage location for the recorded videos"));
connect(selectStorageAction, &QAction::triggered, this, &PylonRecorder::selectStorageLocation);
storeSettingsAction = new QAction(tr("store settings"), this);
storeSettingsAction->setStatusTip(tr("store current settings as defaults"));
connect(storeSettingsAction, &QAction::triggered, this, &PylonRecorder::storeSettings);
QMenu *settingsMenu = menuBar()->addMenu(tr("&Settings")); QMenu *settingsMenu = menuBar()->addMenu(tr("&Settings"));
settingsMenu->addAction(tr("Storage location"), this, &PylonRecorder::selectStorageLocation); settingsMenu->addAction(selectStorageAction);
settingsMenu->addAction(storeSettingsAction);
settingsMenu->setToolTipsVisible(true);
QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(tr("&About"), this, &PylonRecorder::about); helpMenu->addAction(tr("&About"), this, &PylonRecorder::about);
@ -674,5 +714,13 @@ void PylonRecorder::grabStillFromPylon() {
} }
void PylonRecorder::selectStorageLocation() { void PylonRecorder::selectStorageLocation() {
std::cerr << "Select folder!!! " << std::endl; QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
"/home",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
if (!dir.isEmpty()) {
this->storageLocation = dir;
selectStorageAction->setStatusTip(tr("Storage location: ") + storageLocation);
}
} }

View File

@ -5,6 +5,7 @@
#include <QTimer> #include <QTimer>
#include <QSpinBox> #include <QSpinBox>
#include <QCheckBox> #include <QCheckBox>
#include <QSettings>
#include "pylonwrapper.h" #include "pylonwrapper.h"
#include "imagebuffer.h" #include "imagebuffer.h"
@ -66,6 +67,8 @@ private slots:
private: private:
void createActions(); void createActions();
void updateActions(); void updateActions();
void applySettings();
void storeSettings();
QColor progressColor(int value); QColor progressColor(int value);
std::string createFilename(); std::string createFilename();
@ -76,6 +79,7 @@ private:
void adjustScrollBar(QScrollBar *scrollBar, double factor); void adjustScrollBar(QScrollBar *scrollBar, double factor);
int defaultBufferSize = 3000, defaultFrameRate = 30, movieCount = 0, defaultExposureTime = 6000, defaultGain=13; int defaultBufferSize = 3000, defaultFrameRate = 30, movieCount = 0, defaultExposureTime = 6000, defaultGain=13;
QSettings *settings = new QSettings;
QImage image; QImage image;
QTimer *frameTimer, *preassureTimer, *labelTimer; QTimer *frameTimer, *preassureTimer, *labelTimer;
QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel, *fileLabel; QLabel *imageLabel, *writingLabel, *grabbingLabel, *cameraConnectedLabel, *fileLabel;
@ -94,7 +98,8 @@ private:
QString activeLabelStyleLow = "QLabel { font-size: 10px;font-family: Arial; color : cmyk(0, 255, 255, 0, 50); }"; QString activeLabelStyleLow = "QLabel { font-size: 10px;font-family: Arial; color : cmyk(0, 255, 255, 0, 50); }";
QString inactiveLabelStyle = ("QLabel { font-size: 10px;font-family: Arial; color :gray; }"); QString inactiveLabelStyle = ("QLabel { font-size: 10px;font-family: Arial; color :gray; }");
QSpinBox *framerateSpinner, *buffersizeSpinner, *exposureSpinner, *gainSpinner; QSpinBox *framerateSpinner, *buffersizeSpinner, *exposureSpinner, *gainSpinner;
QAction *selectStorageAction, *storeSettingsAction;
QString storageLocation = "";
#if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer) #if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer)
QPrinter printer; QPrinter printer;