Files
shutdown2/mainwindow.cpp
2019-10-03 14:54:01 +02:00

77 lines
1.8 KiB
C++

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QTime>
#include <QStyle>
#include <QDebug>
class QNetworkReply;
namespace shutdown2 {
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
setFixedSize(size());
#if defined(Q_OS_WIN)
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
#endif
mSettings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "RogoSoftware", "EasyShutdown2");
restoreGeometry(mSettings->value("geometry", saveGeometry()).toByteArray());
move(mSettings->value("pos", pos()).toPoint());
QFile css(":style.css");
if (css.open(QFile::ReadOnly | QFile::Text))
mCss = css.readAll();
setStyleSheet(mCss);
// init state machine
initStateMachine();
}
MainWindow::~MainWindow()
{
delete ui;
delete mSettings;
}
void MainWindow::initStateMachine()
{
// states
QState* on = new QState();
on->assignProperty(ui->btn_startstop, "on", false);
on->assignProperty(ui->lbl_timer, "on", false);
on->assignProperty(ui->btn_startstop, "text", "Stop");
QState* off = new QState();
off->assignProperty(ui->btn_startstop, "on", true);
off->assignProperty(ui->lbl_timer, "on", true);
off->assignProperty(ui->btn_startstop, "text", "Start");
// transistions
on->addTransition(ui->btn_startstop, SIGNAL(clicked()), off);
off->addTransition(ui->btn_startstop, SIGNAL(clicked()), on);
// init
mState.addState(on);
mState.addState(off);
mState.setInitialState(off);
mState.start();
}
void MainWindow::on_btn_startstop_clicked()
{
triggerCssUpdate();
}
void MainWindow::triggerCssUpdate()
{
qDebug() << QTime::currentTime() << "updating CSS"; // rogo: delete
setStyleSheet(mCss);
}
}