added spacebar support to start timer

This commit is contained in:
2019-10-14 20:04:40 +02:00
parent 83dc8913ba
commit 2f40f91d79
3 changed files with 25 additions and 6 deletions

View File

@@ -20,7 +20,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint); setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
#endif #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()); restoreGeometry(mSettings->value("geometry", saveGeometry()).toByteArray());
move(mSettings->value("pos", pos()).toPoint()); 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("90");
ui->cb_timers->addItem("120"); ui->cb_timers->addItem("120");
ui->cb_timers->addItem("240"); ui->cb_timers->addItem("240");
ui->cb_timers->installEventFilter(this);
// init state machine // init state machine
initStateMachine(); initStateMachine();
@@ -120,22 +121,37 @@ void MainWindow::timerToggled() {
updateTime(); updateTime();
mTimer.start(1000); mTimer.start(1000);
ui->stackedWidget->setCurrentIndex(1); ui->stackedWidget->setCurrentIndex(1);
ui->btn_startstop->setFocus();
} else { } else {
mTimeLeft = -1; mTimeLeft = -1;
mTimer.stop(); mTimer.stop();
ui->lbl_timer->setText("--:--:--"); ui->lbl_timer->setText("--:--:--");
ui->stackedWidget->setCurrentIndex(0); 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 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<QKeyEvent*>(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);
}
} }

View File

@@ -33,6 +33,7 @@ private:
QTimer mTimer; QTimer mTimer;
int mTimeLeft = -1; // in seconds int mTimeLeft = -1; // in seconds
bool eventFilter(QObject *watched, QEvent *event) override;
void initStateMachine(); void initStateMachine();
void triggerCssUpdate(); void triggerCssUpdate();
void keyPressEvent(QKeyEvent *event) override; void keyPressEvent(QKeyEvent *event) override;

View File

@@ -46,6 +46,8 @@ QComboBox::drop-down {
background-color: #999999; background-color: #999999;
margin: 2px; margin: 2px;
padding: 5px;
subcontrol-origin: padding; subcontrol-origin: padding;
subcontrol-position: top right; subcontrol-position: top right;
width: 15px; width: 15px;
@@ -54,8 +56,8 @@ QComboBox::drop-down {
QComboBox::down-arrow QComboBox::down-arrow
{ {
image: url(:/mwicon.png); image: url(:/mwicon.png);
width: 48px; width: 64px;
height: 48px; height: 64px;
} }
QComboBox QAbstractItemView{ QComboBox QAbstractItemView{