diff --git a/src/Backend.cpp b/src/Backend.cpp index 2556057..5d8bed0 100644 --- a/src/Backend.cpp +++ b/src/Backend.cpp @@ -48,9 +48,6 @@ void Backend::setBrokerPort(int port) { const QMqttClient::ClientState Backend::brokerState() const { return this->m_client->state(); } -void Backend::setBrokerState(const QMqttClient::ClientState &state) { - this->m_client->setState(state); -} void Backend::onBrokerStateChanged(const QMqttClient::ClientState &state) { qWarning() << "State change" << state; @@ -58,5 +55,9 @@ void Backend::onBrokerStateChanged(const QMqttClient::ClientState &state) { if (state != QMqttClient::Connected) return; - // TODO: subscribe + this->m_client->subscribe(QMqttTopicFilter("/spec"), 1); +} + +const Spec::SpecStatus Backend::specStatus() const { + return this->m_specStatus; } \ No newline at end of file diff --git a/src/Backend.hpp b/src/Backend.hpp index 284284a..feedb5f 100644 --- a/src/Backend.hpp +++ b/src/Backend.hpp @@ -15,16 +15,46 @@ #include #include +namespace Spec { +Q_NAMESPACE + +enum SpecStatus { + SPEC_READY, + SPEC_ACQUIRING, + SPEC_NEEDS_CALIBRATION, + SPEC_ERROR, + SPEC_UNKNOWN, +}; + +enum ConnectionStatus { + BROKER_DISCONNECTED, + BROKER_CONNECTING, + BROKER_CONNECTED, +}; + +Q_ENUM_NS(SpecStatus) +Q_ENUM_NS(ConnectionStatus) + +} // namespace Spec + class Backend : public QObject { Q_OBJECT + + // Broker properties Q_PROPERTY(QString brokerHost READ brokerHost WRITE setBrokerHost NOTIFY brokerHostChanged) Q_PROPERTY(int brokerPort READ brokerPort WRITE setBrokerPort NOTIFY brokerPortChanged) - Q_PROPERTY(QMqttClient::ClientState brokerState READ brokerState WRITE - setBrokerState NOTIFY brokerStateChanged) + Q_PROPERTY(QMqttClient::ClientState brokerState READ brokerState NOTIFY + brokerStateChanged) QML_NAMED_ELEMENT(Backend) + // Spectrometer properties + Q_PROPERTY( + Spec::SpecStatus specStatus READ specStatus NOTIFY specStatusChanged) + + QML_EXTENDED_NAMESPACE(Spec) + public: explicit Backend(QObject *parent = nullptr); @@ -45,12 +75,14 @@ public: void setBrokerPort(int port); const QMqttClient::ClientState brokerState() const; - void setBrokerState(const QMqttClient::ClientState &state); + + const Spec::SpecStatus specStatus() const; signals: void brokerHostChanged(); void brokerPortChanged(); void brokerStateChanged(); + void specStatusChanged(); private slots: void onBrokerStateChanged(const QMqttClient::ClientState &state); @@ -58,4 +90,5 @@ private slots: private: Q_DISABLE_COPY(Backend) QMqttClient *m_client; + Spec::SpecStatus m_specStatus = Spec::SPEC_UNKNOWN; }; \ No newline at end of file diff --git a/src/Gui/Splash.qml b/src/Gui/Splash.qml index 2c5322c..d8b2b48 100644 --- a/src/Gui/Splash.qml +++ b/src/Gui/Splash.qml @@ -7,7 +7,7 @@ import "PStyle" import "Login" import "." -Window { +ApplicationWindow { visible: true width: 640 height: 480 @@ -30,7 +30,10 @@ Window { repeat: false interval: 750 - onTriggered: loader.source = "qrc:/Login/Login.qml" + onTriggered: { + loader.source = "qrc:/Login/Login.qml" + footer.visible = true + } } Timer { @@ -81,4 +84,73 @@ Window { } } } + + footer: ToolBar { + visible: false + + background: PBackground { + color: Qt.lighter(PStyle.backColor) + } + + RowLayout { + anchors.verticalCenter: parent.verticalCenter + width: parent.width + + spacing: 12 + + RowLayout { + PText { + font: PStyle.getFont(10) + text: qsTr("Connection status:") + } + + Rectangle { + Layout.preferredHeight: 12 + Layout.preferredWidth: 12 + color: + App.brokerState == 2 ? "lime" : + App.brokerState == 1 ? "yellow" : + "red" + radius: width / 2 + } + + PText { + font: PStyle.getFont(10) + text: + App.brokerState == 2 ? "connected" : + App.brokerState == 1 ? "connecting" : + "disconnected" + } + } + + RowLayout { + Layout.alignment: Qt.AlignRight + + PText { + font: PStyle.getFont(10) + text: qsTr("Spectrometer status:") + } + + Rectangle { + Layout.preferredHeight: 12 + Layout.preferredWidth: 12 + color: + App.specStatus == App.SPEC_UNKNOWN ? "gray" : + App.specStatus == App.SPEC_ERROR ? "red" : + "lime" + radius: width / 2 + } + + PText { + font: PStyle.getFont(10) + text: + App.specStatus == App.SPEC_ERROR ? "error" : + App.specStatus == App.SPEC_READY ? "ready" : + App.specStatus == App.SPEC_NEEDS_CALIBRATION ? "needs calibration" : + App.specStatus == App.SPEC_ACQUIRING ? "acquiring" : + "unknown" + } + } + } + } } \ No newline at end of file