statemachine and styles
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTime>
|
||||
#include <QStyle>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
class QNetworkReply;
|
||||
namespace shutdown2 {
|
||||
@@ -21,7 +25,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
|
||||
QFile css(":style.css");
|
||||
if (css.open(QFile::ReadOnly | QFile::Text))
|
||||
this->setStyleSheet(css.readAll());
|
||||
mCss = css.readAll();
|
||||
setStyleSheet(mCss);
|
||||
|
||||
// init state machine
|
||||
initStateMachine();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -30,4 +38,37 @@ MainWindow::~MainWindow()
|
||||
delete mSettings;
|
||||
}
|
||||
|
||||
void MainWindow::initStateMachine()
|
||||
{
|
||||
// states
|
||||
QState* on = new QState();
|
||||
on->assignProperty(ui->btn_startstop, "on", false);
|
||||
on->assignProperty(ui->lbl_timer, "on", false);
|
||||
|
||||
QState* off = new QState();
|
||||
off->assignProperty(ui->btn_startstop, "on", true);
|
||||
off->assignProperty(ui->lbl_timer, "on", true);
|
||||
|
||||
// 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::triggerCssUpdate()
|
||||
{
|
||||
qDebug() << QTime::currentTime() << "updating CSS"; // rogo: delete
|
||||
setStyleSheet(mCss);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void shutdown2::MainWindow::on_btn_startstop_clicked()
|
||||
{
|
||||
triggerCssUpdate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user