summaryrefslogtreecommitdiffstats
path: root/src/timeoutdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/timeoutdialog.cpp')
-rw-r--r--src/timeoutdialog.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/timeoutdialog.cpp b/src/timeoutdialog.cpp
index 6f12ca2..9eefc42 100644
--- a/src/timeoutdialog.cpp
+++ b/src/timeoutdialog.cpp
@@ -6,22 +6,26 @@
#include <QProgressBar>
#include <QDebug>
#include <QPushButton>
+#include <QKeyEvent>
TimeOutDialog::TimeOutDialog(int time, QWidget *parent)
: QDialog(parent), _ui(new Ui::TimeOutDialog), _time(time)
{
_ui->setupUi(this);
+ this->installEventFilter(this);
+ _ui->buttonBox->installEventFilter(this);
+ for (auto b : _ui->buttonBox->buttons()) {
+ b->installEventFilter(this);
+ b->setFocusPolicy(Qt::NoFocus);
+ }
+ this->setFocus();
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
_ui->progressBar->setMaximum(_time);
@@ -37,6 +41,27 @@ void TimeOutDialog::hideEvent(QHideEvent *e)
_timer.stop();
}
+bool TimeOutDialog::eventFilter(QObject *, QEvent *event)
+{
+ if (event->type() != QEvent::KeyPress)
+ return false;
+ if (!_timer.isActive())
+ return false;
+ QKeyEvent *e = static_cast<QKeyEvent *>(event);
+ if (e->key() == Qt::Key_Escape) {
+ // Handle as discard
+ _time = 0;
+ _timer.stop();
+ return true;
+ }
+ if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
+ // Handle as accept
+ _timer.stop();
+ return true;
+ }
+ return false;
+}
+
void TimeOutDialog::update()
{
--_time;