diff --git a/hive/client/hive_client/hive_client.pro b/hive/client/hive_client/hive_client.pro index 6dfe4b7b..4d6dd3ad 100644 --- a/hive/client/hive_client/hive_client.pro +++ b/hive/client/hive_client/hive_client.pro @@ -3,7 +3,7 @@ folder_01.source = qml/hive_client folder_01.target = qml DEPLOYMENTFOLDERS = folder_01 -QT += core qml quick +QT += core qml quick declarative # Additional import path used to resolve QML modules in Creator's code model diff --git a/hive/client/hive_client/hiveclientcore.cpp b/hive/client/hive_client/hiveclientcore.cpp index 341a802c..c59deb84 100644 --- a/hive/client/hive_client/hiveclientcore.cpp +++ b/hive/client/hive_client/hiveclientcore.cpp @@ -1,29 +1,28 @@ #include "hiveclientcore.h" #include #include -#include +#include HiveClientCore::HiveClientCore(QObject *parent) : QObject(parent) { m_id = 0; - - m_settings = new Settings(this); m_client = new Client(this); + // QML Typs + qmlRegisterType("hive",1,0,"Settings"); // QML application window m_engine = new QQmlApplicationEngine(this); m_engine->load(QUrl("qml/hive_client/main.qml")); + m_engine->rootContext()->setContextProperty("client", m_client); - m_engine->rootContext()->setContextProperty("settings", m_settings); topLevel = m_engine->rootObjects().value(0); QQuickWindow *window = qobject_cast(topLevel); window->show(); - connect(m_client,SIGNAL(connected()),this,SLOT(onConnected())); } diff --git a/hive/client/hive_client/hiveclientcore.h b/hive/client/hive_client/hiveclientcore.h index 43b50c83..c6f4458f 100644 --- a/hive/client/hive_client/hiveclientcore.h +++ b/hive/client/hive_client/hiveclientcore.h @@ -3,7 +3,6 @@ #include #include -#include #include "client.h" #include "settings.h" @@ -16,7 +15,7 @@ public: private: Client *m_client; - Settings *m_settings; + //Settings *m_settings; QQmlApplicationEngine *m_engine; QObject *topLevel; diff --git a/hive/client/hive_client/qml/hive_client/AddDevicePage.qml b/hive/client/hive_client/qml/hive_client/AddDevicePage.qml new file mode 100644 index 00000000..edbcfba7 --- /dev/null +++ b/hive/client/hive_client/qml/hive_client/AddDevicePage.qml @@ -0,0 +1,115 @@ +import QtQuick 2.0 +import QtQuick.Controls 1.0 +import QtQuick.Layouts 1.0 + +Component { + + Rectangle{ + anchors.fill: parent + + ColumnLayout{ + id: addDeviceColumn + + anchors.horizontalCenter: parent.horizontalCenter + + GroupBox{ + id: nameGroupBox + title: "Name" + + Row{ + spacing: 5 + Text{ + anchors.verticalCenter: parent.verticalCenter + text: "Name:" + } + + TextField{ + id: nameText + anchors.verticalCenter: parent.verticalCenter + placeholderText: "Device Name" + } + } + + } + GroupBox{ + id: deviceTypeGroupBox + title: "Device Type" + + ComboBox { + id: deviceComboBox + model: ["actor","sensor"] + } + } + GroupBox{ + id: communicationTypeGroupBox + title: "Communication Type" + + ComboBox { + id: communicationTypeComboBox + model: ["RC433","RC868","ZigBee"] + } + } + GroupBox{ + id: linecodeGroupBox + title: "Linecode" + visible: communicationTypeComboBox.currentText == "RC868" || communicationTypeComboBox.currentText == "RC433" ? true : false + + ComboBox { + id: linecodeComboBox + model: ["Switch","Light","Unicode","Manchester","Differential Manchester"] + } + } + GroupBox{ + id: switchGroupBox + title: "Switchsettings" + visible: (linecodeComboBox.currentText == "Switch") && (communicationTypeComboBox.currentText == "RC868" || communicationTypeComboBox.currentText == "RC433") ? true : false + + RowLayout{ + GridLayout{ + columns: 6 + Label{ + text: "1" + } + Label{ + text: "2" + } + Label{ + text: "3" + } + Label{ + text: "4" + } + Label{ + text: "5" + } + Label{ + text: "6" + } + CheckBox{ + id: channel1 + } + CheckBox{ + id: channel2 + } + CheckBox{ + id: channel3 + } + CheckBox{ + id: channel4 + } + CheckBox{ + id: channel5 + } + CheckBox{ + id: channel6 + } + } + ComboBox { + id: switchComboBox + model: ["A","B","C","D","E"] + } + } + } + } + } +} diff --git a/hive/client/hive_client/qml/hive_client/ConnectionPage.qml b/hive/client/hive_client/qml/hive_client/ConnectionPage.qml new file mode 100644 index 00000000..400366ae --- /dev/null +++ b/hive/client/hive_client/qml/hive_client/ConnectionPage.qml @@ -0,0 +1,53 @@ +import QtQuick 2.0 +import QtQuick.Controls 1.0 +import QtQuick.Layouts 1.0 + +Component { + Rectangle{ + anchors.fill: parent + + GroupBox { + id: connectionGroupBox + anchors.centerIn: parent + + title: "Connection" + + RowLayout{ + anchors.fill: parent + Button{ + id: connectButton + text: "Connect" + onClicked: { + settings.ipaddress = ipTextInput.text + settings.port = portTextInput.text + client.connectToHost(ipTextInput.text,portTextInput.text) + } + } + Text { + id: ipLable + text: "IP:" + horizontalAlignment: Text.AlignHCenter + } + TextField { + id: ipTextInput + text: settings.ipaddress + horizontalAlignment: TextInput.AlignHCenter + font.pointSize: 9 + } + Text { + id: portLable + text: "Port:" + wrapMode: Text.NoWrap + verticalAlignment: Text.AlignTop + horizontalAlignment: Text.AlignHCenter + } + TextField { + id: portTextInput + text: settings.port + horizontalAlignment: TextInput.AlignHCenter + font.pointSize: 9 + } + } + } + } +} diff --git a/hive/client/hive_client/qml/hive_client/MainPage.qml b/hive/client/hive_client/qml/hive_client/MainPage.qml new file mode 100644 index 00000000..0f0b7450 --- /dev/null +++ b/hive/client/hive_client/qml/hive_client/MainPage.qml @@ -0,0 +1,43 @@ +import QtQuick 2.0 +import QtQuick.Controls 1.0 +import QtQuick.Layouts 1.0 + +Component { + + Rectangle{ + anchors.fill: parent + + Column{ + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: parent.top + anchors.topMargin: 30 + + Rectangle{ + id: addDeviceButton + width: 150 + height: 70 + color: "#c8c8c8" + border.color: "black" + radius: 10 + Text{ + anchors.centerIn: parent + text: "Add Device" + } + MouseArea{ + id: addDeviceButtonMousArea + anchors.fill: parent + onPressed: addDeviceButton.color = "steelblue" + onReleased: addDeviceButton.color = "#c8c8c8" + onClicked: stackView.push(addDevicePage) + } + + } + + } + + + } + + +} + diff --git a/hive/client/hive_client/qml/hive_client/main.qml b/hive/client/hive_client/qml/hive_client/main.qml index 9fe7c191..9e2c6b12 100644 --- a/hive/client/hive_client/qml/hive_client/main.qml +++ b/hive/client/hive_client/qml/hive_client/main.qml @@ -2,6 +2,8 @@ import QtQuick 2.0 import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 +import hive 1.0 + ApplicationWindow{ id: mainWindow menuBar: MenuBar{ @@ -13,6 +15,11 @@ ApplicationWindow{ shortcut: "Ctrl+Q" onTriggered: mainWindow.close() } + MenuItem { + text: "Disconnect" + shortcut: "Ctrl+D" + onTriggered: client.disconnectFromHost() + } } } statusBar: StatusBar { @@ -25,79 +32,41 @@ ApplicationWindow{ width: 600 height: 500 + StackView { + id: stackView + anchors.fill: parent + initialItem: connectionPage + } - GroupBox { - id: connectionGroupBox - anchors.right: parent.right - anchors.left: parent.left - anchors.margins: 20 - title: "Connection" - - RowLayout{ - anchors.fill: parent - Button{ - id: connectButton - text: "Connect" - onClicked: { - settings.setIPaddress(ipTextInput.text) - settings.setPort(portTextInput.text) - client.connectToHost(ipTextInput.text,portTextInput.text) - } - } - Text { - id: ipLable - text: "IP:" - horizontalAlignment: Text.AlignHCenter - } - TextField { - id: ipTextInput - text: "10.10.10.40" - horizontalAlignment: TextInput.AlignHCenter - font.pointSize: 9 - } - Text { - id: portLable - text: "Port:" - wrapMode: Text.NoWrap - verticalAlignment: Text.AlignTop - horizontalAlignment: Text.AlignHCenter - } - TextField { - id: portTextInput - text: "1234" - horizontalAlignment: TextInput.AlignHCenter - font.pointSize: 9 + Connections{ + target: client + onConnectionChanged:{ + print("connection changed",client.isConnected) + if(client.isConnected){ + stackView.push(mainPage) + }else{ + stackView.clear() + stackView.push(connectionPage) } } } - TabView{ - id: tabView - anchors.right: parent.right - anchors.rightMargin: 20 - anchors.left: parent.left - anchors.leftMargin: 20 - anchors.top: connectionGroupBox.bottom - anchors.bottom: statusBar.top - - Tab{ - id: actorTab - title: "Actor" - - } - Tab{ - id: sensorTab - title: "Sensor" - } - Tab{ - id: ruleTab - title: "Rules" - } - Tab{ - id: settingsTab - title: "Settings" - } + Settings{ + id: settings } + + ConnectionPage{ + id: connectionPage + } + + MainPage{ + id: mainPage + } + + AddDevicePage{ + id: addDevicePage + } + } diff --git a/hive/client/hive_client/settings.cpp b/hive/client/hive_client/settings.cpp index a1349f40..2cc62e6e 100644 --- a/hive/client/hive_client/settings.cpp +++ b/hive/client/hive_client/settings.cpp @@ -4,28 +4,31 @@ Settings::Settings(QObject *parent) : QObject(parent) { - m_settings = new QSettings(QString(),"hiveClient",this); } -QString Settings::ipaddress() +QString Settings::ipaddress() const { - return m_settings->value("server","10.10.10.40").toString(); + QSettings settings("hive"); + return settings.value("server","10.10.10.40").toString(); } void Settings::setIPaddress(QString ipaddress) { - m_settings->setValue("server",ipaddress); + QSettings settings("hive"); + settings.setValue("server",ipaddress); emit ipaddressChanged(); } -QString Settings::port() +int Settings::port() const { - return m_settings->value("port","1234").toString(); + QSettings settings("hive"); + return settings.value("port","1234").toInt(); } -void Settings::setPort(QString port) +void Settings::setPort(int port) { - m_settings->setValue("port",port); + QSettings settings("hive"); + settings.setValue("port",port); emit ipaddressChanged(); } diff --git a/hive/client/hive_client/settings.h b/hive/client/hive_client/settings.h index 69534fb1..7f8d7a85 100644 --- a/hive/client/hive_client/settings.h +++ b/hive/client/hive_client/settings.h @@ -7,25 +7,26 @@ class Settings : public QObject { Q_OBJECT + Q_PROPERTY(QString ipaddress READ ipaddress WRITE setIPaddress NOTIFY ipaddressChanged) + Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged) public: explicit Settings(QObject *parent = 0); + QString ipaddress() const; + void setIPaddress(QString ipaddress); + int port() const; + void setPort(int port); private: - QSettings* m_settings; signals: void ipaddressChanged(); void portChanged(); public slots: - QString ipaddress(); - QString port(); - void setIPaddress(QString ipaddress); - void setPort(QString port); }; diff --git a/hive/libhive/client.cpp b/hive/libhive/client.cpp index 6cb76264..88e5130a 100644 --- a/hive/libhive/client.cpp +++ b/hive/libhive/client.cpp @@ -6,10 +6,15 @@ Client::Client(QObject *parent) : QObject(parent) { m_tcpSocket = new QTcpSocket(this); - + m_connectionStatus = false; connect(m_tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionError(QAbstractSocket::SocketError))); - connect(m_tcpSocket, SIGNAL(connected()),this, SLOT(connectedToHost())); + connect(m_tcpSocket, SIGNAL(connected()),this, SLOT(connected())); + connect(m_tcpSocket, SIGNAL(disconnected()),this, SLOT(disconneted())); +} +bool Client::isConnected() +{ + return m_connectionStatus; } void Client::connectionError(QAbstractSocket::SocketError error) @@ -30,10 +35,18 @@ void Client::readData() } } -void Client::connectedToHost() +void Client::connected() { qDebug() << "connected to hive server"; - emit connected(); + m_connectionStatus = true; + emit connectionChanged(); +} + +void Client::disconneted() +{ + qDebug() << "disconnect from hive server"; + m_connectionStatus = false; + emit connectionChanged(); } void Client::connectToHost(QString ipAddress, QString port) diff --git a/hive/libhive/client.h b/hive/libhive/client.h index e3bedc7a..bd585ec3 100644 --- a/hive/libhive/client.h +++ b/hive/libhive/client.h @@ -8,26 +8,32 @@ class Client : public QObject { Q_OBJECT + Q_PROPERTY(bool isConnected READ isConnected NOTIFY connectionChanged) public: explicit Client(QObject *parent = 0); - + bool isConnected(); + + private: QTcpSocket *m_tcpSocket; QString m_tcpBuffer; + bool m_connectionStatus; + signals: - void connected(); void jsonDataAvailable(const QByteArray &data); + void connectionChanged(); private slots: void connectionError(QAbstractSocket::SocketError error); void readData(); - void connectedToHost(); - + void connected(); + void disconneted(); + public slots: void connectToHost(QString ipAddress, QString port); void disconnectFromHost(); diff --git a/hive/libhive/devicemanager.h b/hive/libhive/devicemanager.h index 32f3920d..576f0ce3 100644 --- a/hive/libhive/devicemanager.h +++ b/hive/libhive/devicemanager.h @@ -20,8 +20,6 @@ public: }; - - signals: public slots: diff --git a/hive/server/hive_pi/hivecore.cpp b/hive/server/hive_pi/hivecore.cpp index 8f62ccab..09392aa2 100644 --- a/hive/server/hive_pi/hivecore.cpp +++ b/hive/server/hive_pi/hivecore.cpp @@ -8,8 +8,7 @@ HiveCore::HiveCore(QObject *parent) : m_server = new Server(this); m_server->startServer(); - m_deviceManager = new DeviceManager(this); - m_deviceManager->getDevices(); + //m_deviceManager = new DeviceManager(this); m_jsonHandler = new JsonHandler(this); diff --git a/hive/server/hive_pi/hivecore.h b/hive/server/hive_pi/hivecore.h index 77eab66a..d704c43b 100644 --- a/hive/server/hive_pi/hivecore.h +++ b/hive/server/hive_pi/hivecore.h @@ -18,7 +18,7 @@ private: Server *m_server; //RadioReciver *m_reciver; //RadioSender *m_sender; - //DeviceManager *m_deviceManager; + DeviceManager *m_deviceManager; JsonHandler *m_jsonHandler; signals: