ui overhaul

This commit is contained in:
2019-10-14 15:13:05 +02:00
parent 77e61ec029
commit d9f9d24165
6 changed files with 178 additions and 901 deletions

View File

@@ -7,6 +7,7 @@
#include <QDebug>
#include <QKeyEvent>
#include <QLineEdit>
class QNetworkReply;
namespace shutdown2 {
@@ -29,6 +30,21 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
mCss = css.readAll();
setStyleSheet(mCss);
// init timers
QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false);
ui->cb_timers->setValidator(new QIntValidator(0, 99999, this));
ui->cb_timers->setAutoCompletion(false);
ui->cb_timers->lineEdit()->setAlignment(Qt::AlignRight);
ui->cb_timers->addItem("0");
ui->cb_timers->addItem("11");
ui->cb_timers->addItem("22");
ui->cb_timers->addItem("30");
ui->cb_timers->addItem("45");
ui->cb_timers->addItem("60");
ui->cb_timers->addItem("90");
ui->cb_timers->addItem("120");
ui->cb_timers->addItem("240");
// init state machine
initStateMachine();
connect(&mTimer, &QTimer::timeout, this, &MainWindow::updateTime);
@@ -78,6 +94,7 @@ void MainWindow::shutdown()
void MainWindow::updateTime()
{
if (mTimeLeft == 0) {
ui->lbl_timer->setText("00:00");
shutdown();
mTimer.stop();
return;
@@ -93,27 +110,20 @@ void MainWindow::updateTime()
}
void MainWindow::timerToggled() {
if (ui->btn_startstop->property("on").toBool()) {
int time = 0;
foreach (QRadioButton* r, ui->groupBox->findChildren<QRadioButton*>()) {
if (r->isChecked()) {
time = r->property("value").toInt();
break;
}
}
if (time == -1)
time = ui->spinBox->value();
int time = ui->cb_timers->currentText().toInt();
time *= 60; // convert to seconds
mTimeLeft = time;
updateTime();
mTimer.start(1000);
ui->stackedWidget->setCurrentIndex(1);
} else {
mTimeLeft = -2;
mTimeLeft = -1;
mTimer.stop();
ui->lbl_timer->setText("-- : --");
ui->stackedWidget->setCurrentIndex(0);
}
}