diff --git a/mainwindow.cpp b/mainwindow.cpp index 530a0e7..55f91d8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi statusBar()->showMessage(errors.at(0).what()); else statusBar()->showMessage(QString("Errors visible in console (if present). Count: " + QString::number(errors.size()))); + + // Set delay + if ((settings::settings().contains("delay"))) + ui->delay->setValue(settings::settings().value("delay").toDouble()); + else + ui->delay->setValue(0.25); } MainWindow::~MainWindow() @@ -67,6 +74,11 @@ void MainWindow::setScheme(QString scheme) ui->nameScheme->setText(scheme); } +QDoubleSpinBox *MainWindow::delay() +{ + return ui->delay; +} + MainWindow *MainWindow::inst() { return instance; @@ -103,12 +115,12 @@ void MainWindow::on_actionQuit_triggered() void MainWindow::on_actionFullscreen_triggered() { - QTimer::singleShot(0, &screenshotter::fullscreen); + screenshotter::fullscreenDelayed(); } void MainWindow::on_actionArea_triggered() { - QTimer::singleShot(0, &screenshotter::area); + screenshotter::areaDelayed(); } void MainWindow::on_uploaderList_clicked(const QModelIndex &) @@ -124,3 +136,8 @@ void MainWindow::on_nameScheme_textEdited(const QString &arg1) { settings::settings().setValue("fileFormat", arg1); } + +void MainWindow::on_delay_valueChanged(double arg1) +{ + settings::settings().setValue("delay", arg1); +} diff --git a/mainwindow.hpp b/mainwindow.hpp index 47dbbda..5cd6d20 100644 --- a/mainwindow.hpp +++ b/mainwindow.hpp @@ -1,6 +1,7 @@ #ifndef MAINWINDOW_HPP #define MAINWINDOW_HPP +#include #include #include @@ -25,12 +26,15 @@ class MainWindow : public QMainWindow void on_uploaderList_clicked(const QModelIndex &); void on_nameScheme_textEdited(const QString &arg1); + void on_delay_valueChanged(double arg1); + public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); QSystemTrayIcon *tray; void setScheme(QString scheme); + QDoubleSpinBox *delay(); static MainWindow *inst(); diff --git a/mainwindow.ui b/mainwindow.ui index 5c00ba7..c1443f2 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,7 +6,7 @@ 0 0 - 470 + 471 315 @@ -24,25 +24,49 @@ 0 - - - + + + - Uploader selection: + Delay before taking a screenshot - - - - + File name scheme: - + + + + In seconds + + + A delay before taking a screenshot, in seconds + + + + + + + Uploader selection: + + + + + + + s + + + + + + + http://doc.qt.io/qt-5/qdatetime.html#toString @@ -59,7 +83,7 @@ 0 0 - 470 + 471 24 diff --git a/screenshotter.cpp b/screenshotter.cpp index c6b5810..b21bb69 100644 --- a/screenshotter.cpp +++ b/screenshotter.cpp @@ -1,7 +1,10 @@ #include "screenshotter.hpp" #include "cropeditor/cropeditor.hpp" +#include "mainwindow.hpp" #include "screenshotutil.hpp" #include "uploaders/uploadersingleton.hpp" +#include +#include void screenshotter::area() { @@ -13,3 +16,13 @@ void screenshotter::fullscreen() { UploaderSingleton::inst().upload(screenshotutil::fullscreen()); } + +void screenshotter::areaDelayed() +{ + QTimer::singleShot(MainWindow::inst()->delay()->value() * 1000, &screenshotter::area); +} + +void screenshotter::fullscreenDelayed() +{ + QTimer::singleShot(MainWindow::inst()->delay()->value() * 1000, &screenshotter::fullscreen); +} diff --git a/screenshotter.hpp b/screenshotter.hpp index 00ec27c..c78d2eb 100644 --- a/screenshotter.hpp +++ b/screenshotter.hpp @@ -5,6 +5,8 @@ namespace screenshotter { void fullscreen(); void area(); +void fullscreenDelayed(); +void areaDelayed(); } #endif // SCREENSHOTTER_HPP