Delay code cleanup

This commit is contained in:
ArsenArsen 2017-04-25 22:36:33 +02:00
parent 9a90814891
commit 3877799895
5 changed files with 73 additions and 13 deletions

View File

@ -5,6 +5,7 @@
#include <QAction> #include <QAction>
#include <QCloseEvent> #include <QCloseEvent>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDoubleSpinBox>
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QMenu> #include <QMenu>
#include <QStatusBar> #include <QStatusBar>
@ -55,6 +56,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
statusBar()->showMessage(errors.at(0).what()); statusBar()->showMessage(errors.at(0).what());
else else
statusBar()->showMessage(QString("Errors visible in console (if present). Count: " + QString::number(errors.size()))); 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() MainWindow::~MainWindow()
@ -67,6 +74,11 @@ void MainWindow::setScheme(QString scheme)
ui->nameScheme->setText(scheme); ui->nameScheme->setText(scheme);
} }
QDoubleSpinBox *MainWindow::delay()
{
return ui->delay;
}
MainWindow *MainWindow::inst() MainWindow *MainWindow::inst()
{ {
return instance; return instance;
@ -103,12 +115,12 @@ void MainWindow::on_actionQuit_triggered()
void MainWindow::on_actionFullscreen_triggered() void MainWindow::on_actionFullscreen_triggered()
{ {
QTimer::singleShot(0, &screenshotter::fullscreen); screenshotter::fullscreenDelayed();
} }
void MainWindow::on_actionArea_triggered() void MainWindow::on_actionArea_triggered()
{ {
QTimer::singleShot(0, &screenshotter::area); screenshotter::areaDelayed();
} }
void MainWindow::on_uploaderList_clicked(const QModelIndex &) void MainWindow::on_uploaderList_clicked(const QModelIndex &)
@ -124,3 +136,8 @@ void MainWindow::on_nameScheme_textEdited(const QString &arg1)
{ {
settings::settings().setValue("fileFormat", arg1); settings::settings().setValue("fileFormat", arg1);
} }
void MainWindow::on_delay_valueChanged(double arg1)
{
settings::settings().setValue("delay", arg1);
}

View File

@ -1,6 +1,7 @@
#ifndef MAINWINDOW_HPP #ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP #define MAINWINDOW_HPP
#include <QDoubleSpinBox>
#include <QMainWindow> #include <QMainWindow>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
@ -25,12 +26,15 @@ class MainWindow : public QMainWindow
void on_uploaderList_clicked(const QModelIndex &); void on_uploaderList_clicked(const QModelIndex &);
void on_nameScheme_textEdited(const QString &arg1); void on_nameScheme_textEdited(const QString &arg1);
void on_delay_valueChanged(double arg1);
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
QSystemTrayIcon *tray; QSystemTrayIcon *tray;
void setScheme(QString scheme); void setScheme(QString scheme);
QDoubleSpinBox *delay();
static MainWindow *inst(); static MainWindow *inst();

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>470</width> <width>471</width>
<height>315</height> <height>315</height>
</rect> </rect>
</property> </property>
@ -24,25 +24,49 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QGridLayout" name="gridLayout">
<item> <item row="4" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Uploader selection:</string> <string>Delay before taking a screenshot</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="2" column="0">
<widget class="QListWidget" name="uploaderList"/>
</item>
<item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>File name scheme:</string> <string>File name scheme:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="5" column="0">
<widget class="QDoubleSpinBox" name="delay">
<property name="toolTip">
<string>In seconds</string>
</property>
<property name="whatsThis">
<string>A delay before taking a screenshot, in seconds</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Uploader selection:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>s</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QListWidget" name="uploaderList"/>
</item>
<item row="3" column="0">
<widget class="QLineEdit" name="nameScheme"> <widget class="QLineEdit" name="nameScheme">
<property name="toolTip"> <property name="toolTip">
<string>http://doc.qt.io/qt-5/qdatetime.html#toString</string> <string>http://doc.qt.io/qt-5/qdatetime.html#toString</string>
@ -59,7 +83,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>470</width> <width>471</width>
<height>24</height> <height>24</height>
</rect> </rect>
</property> </property>

View File

@ -1,7 +1,10 @@
#include "screenshotter.hpp" #include "screenshotter.hpp"
#include "cropeditor/cropeditor.hpp" #include "cropeditor/cropeditor.hpp"
#include "mainwindow.hpp"
#include "screenshotutil.hpp" #include "screenshotutil.hpp"
#include "uploaders/uploadersingleton.hpp" #include "uploaders/uploadersingleton.hpp"
#include <QDoubleSpinBox>
#include <QTimer>
void screenshotter::area() void screenshotter::area()
{ {
@ -13,3 +16,13 @@ void screenshotter::fullscreen()
{ {
UploaderSingleton::inst().upload(screenshotutil::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);
}

View File

@ -5,6 +5,8 @@ namespace screenshotter
{ {
void fullscreen(); void fullscreen();
void area(); void area();
void fullscreenDelayed();
void areaDelayed();
} }
#endif // SCREENSHOTTER_HPP #endif // SCREENSHOTTER_HPP