Allow X to close

This commit is contained in:
ArsenArsen 2017-05-15 14:42:40 +02:00
parent 4e2a82f2bd
commit bd2be65e03
3 changed files with 65 additions and 47 deletions

View File

@ -3,6 +3,7 @@
#include "screenshotutil.hpp" #include "screenshotutil.hpp"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QAction> #include <QAction>
#include <QApplication>
#include <QCheckBox> #include <QCheckBox>
#include <QCloseEvent> #include <QCloseEvent>
#include <QCoreApplication> #include <QCoreApplication>
@ -84,6 +85,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
addHotkeyItem("Area image", "area", new std::function<void()>([] { screenshotter::area(); })); addHotkeyItem("Area image", "area", new std::function<void()>([] { screenshotter::area(); }));
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool()); ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool());
} }
MainWindow::~MainWindow() { MainWindow::~MainWindow() {
@ -103,8 +105,11 @@ MainWindow *MainWindow::inst() {
} }
void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::closeEvent(QCloseEvent *event) {
event->ignore(); if (settings::settings().value("hideOnClose", true).toBool()) {
QTimer::singleShot(0, this, &MainWindow::hide); event->ignore();
QTimer::singleShot(0, this, &MainWindow::hide);
} else
QApplication::exit(0);
} }
void MainWindow::quit() { void MainWindow::quit() {
@ -172,3 +177,7 @@ void MainWindow::on_settingsButton_clicked() {
void MainWindow::on_quickMode_clicked(bool checked) { void MainWindow::on_quickMode_clicked(bool checked) {
settings::settings().setValue("quickMode", checked); settings::settings().setValue("quickMode", checked);
} }
void MainWindow::on_hideToTray_clicked(bool checked) {
settings::settings().setValue("hideOnClose", checked);
}

View File

@ -34,6 +34,8 @@ class MainWindow : public QMainWindow {
void on_quickMode_clicked(bool checked); void on_quickMode_clicked(bool checked);
void on_hideToTray_clicked(bool checked);
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>512</width> <width>512</width>
<height>337</height> <height>368</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -25,7 +25,14 @@
</sizepolicy> </sizepolicy>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="7" column="0" colspan="2"> <item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Uploader selection:</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
<property name="text"> <property name="text">
<string>&lt;a href=&quot;https://github.com/ArsenArsen/KShare&quot;&gt;Source code available free for everyone. Forever.&lt;/a&gt; <string>&lt;a href=&quot;https://github.com/ArsenArsen/KShare&quot;&gt;Source code available free for everyone. Forever.&lt;/a&gt;
@ -34,36 +41,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1" rowspan="5">
<widget class="QListWidget" name="hotkeys"/>
</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>
<property name="suffix">
<string>s</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>File name scheme:</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="4" column="0"> <item row="4" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
@ -78,19 +55,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QListWidget" name="uploaderList"/>
</item>
<item row="3" column="0">
<widget class="QLineEdit" name="nameScheme">
<property name="toolTip">
<string>http://doc.qt.io/qt-5/qdatetime.html#toString</string>
</property>
<property name="text">
<string>Screenshot %(yyyy-MM-dd HH:mm:ss)date</string>
</property>
</widget>
</item>
<item row="6" column="0"> <item row="6" column="0">
<widget class="QCheckBox" name="quickMode"> <widget class="QCheckBox" name="quickMode">
<property name="text"> <property name="text">
@ -105,6 +69,49 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QLineEdit" name="nameScheme">
<property name="toolTip">
<string>http://doc.qt.io/qt-5/qdatetime.html#toString</string>
</property>
<property name="text">
<string>Screenshot %(yyyy-MM-dd HH:mm:ss)date</string>
</property>
</widget>
</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>
<property name="suffix">
<string>s</string>
</property>
</widget>
</item>
<item row="1" column="1" rowspan="5">
<widget class="QListWidget" name="hotkeys"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>File name scheme:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QListWidget" name="uploaderList"/>
</item>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="hideToTray">
<property name="text">
<string>Pressing &lt;X&gt; hides to tray</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QMenuBar" name="menuBar"> <widget class="QMenuBar" name="menuBar">