From 2f40f91d79db9e7521b0c11d00ce68b7bc472827 Mon Sep 17 00:00:00 2001 From: rogo Date: Mon, 14 Oct 2019 20:04:40 +0200 Subject: [PATCH] added spacebar support to start timer --- mainwindow.cpp | 24 ++++++++++++++++++++---- mainwindow.h | 1 + style.css | 6 ++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 92dd3cd..8e9d545 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -20,7 +20,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint); #endif - mSettings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "RogoSoftware", "EasyShutdown2"); + mSettings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "RogoSoftware", "shutdown2"); restoreGeometry(mSettings->value("geometry", saveGeometry()).toByteArray()); move(mSettings->value("pos", pos()).toPoint()); @@ -44,6 +44,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->cb_timers->addItem("90"); ui->cb_timers->addItem("120"); ui->cb_timers->addItem("240"); + ui->cb_timers->installEventFilter(this); // init state machine initStateMachine(); @@ -120,22 +121,37 @@ void MainWindow::timerToggled() { updateTime(); mTimer.start(1000); ui->stackedWidget->setCurrentIndex(1); + ui->btn_startstop->setFocus(); } else { mTimeLeft = -1; mTimer.stop(); ui->lbl_timer->setText("--:--:--"); ui->stackedWidget->setCurrentIndex(0); + ui->cb_timers->setFocus(); } } -void MainWindow::keyPressEvent(QKeyEvent *event) +void MainWindow::keyPressEvent(QKeyEvent *e) { - if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { + if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { ui->btn_startstop->click(); // this is needed this way to trigger statemachine transition - event->accept(); + e->accept(); } } +bool MainWindow::eventFilter(QObject *watched, QEvent *e) +{ + if (e->type() == QEvent::KeyPress) { + if (QKeyEvent* ke = dynamic_cast(e)) { + if (ke->key() == Qt::Key_Space) { + ui->btn_startstop->click(); // this is needed this way to trigger statemachine transition + e->accept(); + return true; + } + } + } + return QObject::eventFilter(watched, e); +} } diff --git a/mainwindow.h b/mainwindow.h index c5ae4cb..3b00750 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -33,6 +33,7 @@ private: QTimer mTimer; int mTimeLeft = -1; // in seconds + bool eventFilter(QObject *watched, QEvent *event) override; void initStateMachine(); void triggerCssUpdate(); void keyPressEvent(QKeyEvent *event) override; diff --git a/style.css b/style.css index ba489a1..44e6e21 100644 --- a/style.css +++ b/style.css @@ -46,6 +46,8 @@ QComboBox::drop-down { background-color: #999999; margin: 2px; + padding: 5px; + subcontrol-origin: padding; subcontrol-position: top right; width: 15px; @@ -54,8 +56,8 @@ QComboBox::drop-down { QComboBox::down-arrow { image: url(:/mwicon.png); - width: 48px; - height: 48px; + width: 64px; + height: 64px; } QComboBox QAbstractItemView{