diff --git a/telldus-gui/Plugins/Sensors/CMakeLists.txt b/telldus-gui/Plugins/Sensors/CMakeLists.txt index bfd56a32..535ccc85 100644 --- a/telldus-gui/Plugins/Sensors/CMakeLists.txt +++ b/telldus-gui/Plugins/Sensors/CMakeLists.txt @@ -24,9 +24,15 @@ SET( Plugin_MOC_HDRS SET( Plugin_PATH "com.telldus.sensors" ) SET( Plugin_EXTRA + header_bg.png icon.png + icon_humidity.png + icon_temp.png main.qml + HeaderTitle.qml + row_bg.png qmldir + SensorValue.qml ) INCLUDE( ../TelldusCenterPlugin.cmake NO_POLICY_SCOPE ) diff --git a/telldus-gui/Plugins/Sensors/HeaderTitle.qml b/telldus-gui/Plugins/Sensors/HeaderTitle.qml new file mode 100644 index 00000000..0d7ae213 --- /dev/null +++ b/telldus-gui/Plugins/Sensors/HeaderTitle.qml @@ -0,0 +1,10 @@ +import Qt 4.7 + +Text { + id: headerTitle + text: "Name" + color: "white" + font.weight: Font.Bold + height: parent.height + verticalAlignment: Text.AlignVCenter +} diff --git a/telldus-gui/Plugins/Sensors/SensorValue.qml b/telldus-gui/Plugins/Sensors/SensorValue.qml new file mode 100644 index 00000000..7198c9ff --- /dev/null +++ b/telldus-gui/Plugins/Sensors/SensorValue.qml @@ -0,0 +1,32 @@ +import Qt 4.7 + +Item { + property alias text: text.text + property alias icon: icon.source + property date lastUpdated: new Date() + + id: sensorValue + width: parent.width + height: 40 + Image { + id: icon + anchors.verticalCenter: parent.verticalCenter + } + Text { + id: text + anchors.left: icon.right + anchors.leftMargin: 10 + anchors.verticalCenter: parent.verticalCenter + color: "#004275" + } + Text { + id: timestamp + anchors.right: parent.right + anchors.rightMargin: 10 + anchors.verticalCenter: parent.verticalCenter + text: Qt.formatDateTime(lastUpdated, Qt.DefaultLocaleShortDate); + color: "#004275" + font.pointSize: text.font.pointSize - 1 + font.italic: true + } +} diff --git a/telldus-gui/Plugins/Sensors/__init__.js b/telldus-gui/Plugins/Sensors/__init__.js index b6b11054..c20bfb67 100644 --- a/telldus-gui/Plugins/Sensors/__init__.js +++ b/telldus-gui/Plugins/Sensors/__init__.js @@ -27,9 +27,8 @@ com.telldus.sensors = function() { } - //com.telldus.core.sensorEvent.connect(sensorEvent); - view = new com.telldus.qml.view({ - }); + com.telldus.core.sensorEvent.connect(sensorEvent); + view = new com.telldus.qml.view({}); view.setProperty('sensorModel', sensorList); view.load("main.qml"); @@ -63,13 +62,8 @@ com.telldus.sensors = function() { print("Update"); } - if (dataType == com.telldus.core.TELLSTICK_TEMPERATURE) { - sensor.temperature = value; - } else if (dataType == com.telldus.core.TELLSTICK_HUMIDITY) { - sensor.humidity = value; - } - print("Sensor event", protocol, model, id, dataType, value, timestamp); + sensor.setValue(dataType, value, timestamp); } return { //Public functions diff --git a/telldus-gui/Plugins/Sensors/header_bg.png b/telldus-gui/Plugins/Sensors/header_bg.png new file mode 100644 index 00000000..564a158b Binary files /dev/null and b/telldus-gui/Plugins/Sensors/header_bg.png differ diff --git a/telldus-gui/Plugins/Sensors/icon_humidity.png b/telldus-gui/Plugins/Sensors/icon_humidity.png new file mode 100644 index 00000000..29b02e26 Binary files /dev/null and b/telldus-gui/Plugins/Sensors/icon_humidity.png differ diff --git a/telldus-gui/Plugins/Sensors/icon_temp.png b/telldus-gui/Plugins/Sensors/icon_temp.png new file mode 100644 index 00000000..67a720db Binary files /dev/null and b/telldus-gui/Plugins/Sensors/icon_temp.png differ diff --git a/telldus-gui/Plugins/Sensors/main.qml b/telldus-gui/Plugins/Sensors/main.qml index 620403e8..8be6755d 100644 --- a/telldus-gui/Plugins/Sensors/main.qml +++ b/telldus-gui/Plugins/Sensors/main.qml @@ -3,17 +3,72 @@ import Qt 4.7 Item { id: main + Component { + id: sensorView + BorderImage { + source: "row_bg.png" + border.left: 5; border.top: 5 + border.right: 5; border.bottom: 5 + height: sensorInfo.height + width: parent.width + + Text { + anchors.left: parent.left + anchors.leftMargin: 15 + height: 40 + verticalAlignment: Text.AlignVCenter + text: modelData.name; + color: "#004275" + } + Column { + id: sensorInfo + anchors.right: parent.right + width: 250 + SensorValue { + visible: modelData.hasTemperature + text: visible ? modelData.sensorValue(1).value + '°C' : '' + icon: "icon_temp.png" + lastUpdated: visible ? modelData.sensorValue(1).lastUpdated : new Date() + } + SensorValue { + visible: modelData.hasHumidity + text: visible ? modelData.sensorValue(2).value + '%' : '' + icon: "icon_humidity.png" + lastUpdated: visible ? modelData.sensorValue(2).lastUpdated : new Date() + } + } + } + } + Column { + spacing: 1 + BorderImage { + id: header + source: "header_bg.png" + width: parent.width; height: 40 + border.left: 5; border.top: 5 + border.right: 5; border.bottom: 5 + + HeaderTitle { + text: "Name" + anchors.left: parent.left + anchors.leftMargin: 15 + } + HeaderTitle { + text: "Sensor information" + width: 150 + anchors.right: timestampTitle.left + } + HeaderTitle { + id: timestampTitle + text: "Last updated" + width: 100 + anchors.right: parent.right + } + } Repeater { model: sensorModel - delegate: Row { - spacing: 10 - Text { text: modelData.name } - Text { text: modelData.protocol } - Text { text: modelData.model } - Text { text: modelData.temperature + '°C'; visible: modelData.hasTemperature } - Text { text: modelData.humidity + "%"; visible: modelData.hasHumidity } - } + delegate: sensorView } anchors.fill: parent } diff --git a/telldus-gui/Plugins/Sensors/qmldir b/telldus-gui/Plugins/Sensors/qmldir index e69de29b..19c8cb6f 100644 --- a/telldus-gui/Plugins/Sensors/qmldir +++ b/telldus-gui/Plugins/Sensors/qmldir @@ -0,0 +1,2 @@ +HeaderTitle 1.0 HeaderTitle.qml +SensorValue 1.0 SensorValue.qml diff --git a/telldus-gui/Plugins/Sensors/row_bg.png b/telldus-gui/Plugins/Sensors/row_bg.png new file mode 100644 index 00000000..06f9d82d Binary files /dev/null and b/telldus-gui/Plugins/Sensors/row_bg.png differ diff --git a/telldus-gui/Plugins/Sensors/sensorsplugin.cpp b/telldus-gui/Plugins/Sensors/sensorsplugin.cpp index 51d869c3..4891b7ad 100644 --- a/telldus-gui/Plugins/Sensors/sensorsplugin.cpp +++ b/telldus-gui/Plugins/Sensors/sensorsplugin.cpp @@ -1,6 +1,8 @@ #include "sensorsplugin.h" #include "sensor.h" +#include "sensorvalue.h" #include +#include QScriptValue SensorCTor(QScriptContext *context, QScriptEngine *engine) { if (!context->isCalledAsConstructor()) { @@ -12,6 +14,7 @@ QScriptValue SensorCTor(QScriptContext *context, QScriptEngine *engine) { SensorsPlugin::SensorsPlugin ( QObject * parent ) :QScriptExtensionPlugin( parent ) { + qmlRegisterType("Telldus", 1, 0, "SensorValue"); } SensorsPlugin::~SensorsPlugin() {