diff options
author | Simon Rettberg | 2018-09-06 17:28:11 +0200 |
---|---|---|
committer | Simon Rettberg | 2018-09-06 17:28:11 +0200 |
commit | bb00f3e9cf820702b4afd6b747ccba9e5edd2c2e (patch) | |
tree | 01136bb39ed781d97c1f9b4136976a17536d5226 | |
parent | Support waking GUI up via user session bus (diff) | |
download | beamergui-bb00f3e9cf820702b4afd6b747ccba9e5edd2c2e.tar.gz beamergui-bb00f3e9cf820702b4afd6b747ccba9e5edd2c2e.tar.xz beamergui-bb00f3e9cf820702b4afd6b747ccba9e5edd2c2e.zip |
Add own timeout dialog with two buttons
-rw-r--r-- | src/timeoutdialog.cpp | 42 | ||||
-rw-r--r-- | src/timeoutdialog.h | 13 | ||||
-rw-r--r-- | src/timeoutdialog.ui | 97 |
3 files changed, 126 insertions, 26 deletions
diff --git a/src/timeoutdialog.cpp b/src/timeoutdialog.cpp index f9787fb..6f12ca2 100644 --- a/src/timeoutdialog.cpp +++ b/src/timeoutdialog.cpp @@ -2,47 +2,47 @@ // Author: Manuel Schneider <ms1144> #include "timeoutdialog.h" +#include "ui_timeoutdialog.h" #include <QProgressBar> #include <QDebug> +#include <QPushButton> TimeOutDialog::TimeOutDialog(int time, QWidget *parent) - : QProgressDialog(parent), _time(time) + : QDialog(parent), _ui(new Ui::TimeOutDialog), _time(time) { - QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update())); - QObject::connect(this, SIGNAL(canceled()), this, SLOT(cancel())); - + _ui->setupUi(this); + QObject::connect(&_timer, &QTimer::timeout, this, &TimeOutDialog::update); + QObject::connect(_ui->buttonBox, &QDialogButtonBox::clicked, [this](QAbstractButton *button) { + _timer.stop(); + if (button == _ui->buttonBox->button(QDialogButtonBox::Discard)) { + _time = 0; + } + }); + QObject::connect(_ui->buttonBox, &QDialogButtonBox::rejected, [this]() { + _timer.stop(); + _time = 0; // So wasCanceled() returns true + }); // QProgressDialog takes ownership of QProgressBar - QProgressBar *qbar = new QProgressBar(this); - qbar->setFormat(trUtf8("%v seconds")); - qbar->setMaximum(_time); - qbar->setMinimum(0); - qbar->setValue(_time); - setBar(qbar); + _ui->progressBar->setMaximum(_time); + _ui->progressBar->setValue(_time); + setWindowTitle(" "); + setWindowFlag(Qt::WindowStaysOnTopHint, true); _timer.start(1000); } void TimeOutDialog::hideEvent(QHideEvent *e) { - QProgressDialog::hideEvent(e); + QDialog::hideEvent(e); _timer.stop(); } -//___________________________________________________________________________ void TimeOutDialog::update() { --_time; if (_time == 0) { _timer.stop(); - accept(); } else { - setValue(_time); + _ui->progressBar->setValue(_time); } } - - -//___________________________________________________________________________ -void TimeOutDialog::cancel() -{ - _timer.stop(); -} diff --git a/src/timeoutdialog.h b/src/timeoutdialog.h index eb853f3..b70f753 100644 --- a/src/timeoutdialog.h +++ b/src/timeoutdialog.h @@ -7,24 +7,27 @@ #include <QProgressDialog> #include <QTimer> -class TimeOutDialog : public QProgressDialog +namespace Ui { +class TimeOutDialog; +} + +class TimeOutDialog : public QDialog { Q_OBJECT public: - TimeOutDialog(int time, QWidget *parent = 0); + TimeOutDialog(int time, QWidget *parent = nullptr); bool isActive() const { return _timer.isActive(); } + bool wasCanceled() const { return _time > 0; } private: + Ui::TimeOutDialog *_ui; int _time; QTimer _timer; protected: void hideEvent(QHideEvent *event) override; -public slots: - void cancel(); - private slots: void update(); }; diff --git a/src/timeoutdialog.ui b/src/timeoutdialog.ui new file mode 100644 index 0000000..96160bc --- /dev/null +++ b/src/timeoutdialog.ui @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>TimeOutDialog</class> + <widget class="QDialog" name="TimeOutDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>395</width> + <height>114</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Screen configuration changed. Do you want to keep the new settings?</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QProgressBar" name="progressBar"> + <property name="value"> + <number>24</number> + </property> + <property name="format"> + <string>%v seconds</string> + </property> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Apply|QDialogButtonBox::Discard</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>TimeOutDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>TimeOutDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> |