statemachine and styles
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -24,7 +24,7 @@ moc_*.cpp
|
||||
qrc_*.cpp
|
||||
ui_*.h
|
||||
Makefile*
|
||||
*-build-*
|
||||
*build-*
|
||||
|
||||
# QtCreator
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSettings>
|
||||
#include <QStateMachine>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@@ -18,10 +19,18 @@ public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
|
||||
private slots:
|
||||
void on_btn_startstop_clicked();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
QSettings* mSettings = nullptr;
|
||||
QStateMachine mState;
|
||||
QByteArray mCss;
|
||||
|
||||
void initStateMachine();
|
||||
void triggerCssUpdate();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>359</width>
|
||||
<height>170</height>
|
||||
<height>361</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
@@ -20,7 +20,84 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QGridLayout" name="gridLayout"/>
|
||||
<layout class="QGridLayout" name="gridLayout" rowstretch="1,4,1">
|
||||
<property name="leftMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="on" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="btn_startstop">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>18</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
<property name="on" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_timer">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>28</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>-- : --</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="on" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.9.2, 2019-08-03T14:14:38. -->
|
||||
<!-- Written by QtCreator 4.9.2, 2019-08-03T15:45:41. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
@@ -71,7 +71,7 @@
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">L:/workspace/build-yremote-Desktop_Qt_5_12_2_MinGW_64_bit-Debug</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">L:/workspace/shutdown2/build-shutdown2-Desktop_Qt_5_12_2_MinGW_64_bit-Debug</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
@@ -305,9 +305,9 @@
|
||||
</valuelist>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">yremote</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">shutdown2</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:L:/workspace/shutdown2/yremote.pro</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:L:/workspace/shutdown2/shutdown2.pro</value>
|
||||
<value type="QString" key="RunConfiguration.Arguments"></value>
|
||||
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
@@ -317,7 +317,7 @@
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">L:/workspace/build-yremote-Desktop_Qt_5_12_2_MinGW_64_bit-Debug</value>
|
||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">L:/workspace/shutdown2/build-shutdown2-Desktop_Qt_5_12_2_MinGW_64_bit-Debug</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||
</valuemap>
|
||||
|
||||
36
style.css
36
style.css
@@ -1,15 +1,29 @@
|
||||
/*
|
||||
green #24e895
|
||||
grey #404040
|
||||
white #edf2f4
|
||||
blue #0077fd
|
||||
red #d63429
|
||||
*/
|
||||
|
||||
|
||||
QMainWindow {
|
||||
background-color: #404040;
|
||||
border-color: #edf2f4;
|
||||
}
|
||||
|
||||
QPushButton {
|
||||
background-color: #404040;
|
||||
QPushButton[on=true] {
|
||||
background-color: #d63429;
|
||||
color: #edf2f4;
|
||||
}
|
||||
|
||||
QPushButton[on=false] {
|
||||
background-color: #24e895;
|
||||
color: #404040;
|
||||
}
|
||||
|
||||
QPushButton:hover {
|
||||
border: 1px solid #0077fd;
|
||||
border: 1px solid #edf2f4;
|
||||
}
|
||||
|
||||
QLineEdit {
|
||||
@@ -26,9 +40,17 @@ QLabel {
|
||||
color: #edf2f4;
|
||||
}
|
||||
|
||||
QLabel#lbl_timer[on=false] {
|
||||
border: 1px solid #d63429;
|
||||
}
|
||||
|
||||
QLabel#lbl_timer[on=true] {
|
||||
border: 1px solid #24e895;
|
||||
}
|
||||
|
||||
QGroupBox {
|
||||
color: #edf2f4;
|
||||
border: 1px solid #0077fd;
|
||||
border: 1px solid #edf2f4;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
@@ -37,7 +59,7 @@ QGroupBox::title {
|
||||
left: 5px;
|
||||
padding: 0px 5px 0px 5px;
|
||||
}
|
||||
|
||||
/*
|
||||
QLabel#lbl_volume:hover {
|
||||
border: 1px solid #0077fd;
|
||||
}
|
||||
border: 1px solid var(--highlight-blue);
|
||||
}*/
|
||||
|
||||
Reference in New Issue
Block a user