diff options
author | 2016-11-24 17:41:34 +0100 | |
---|---|---|
committer | 2016-11-24 17:41:34 +0100 | |
commit | 85f44017fb18205133d369bf16c5d0022984c510 (patch) | |
tree | e450a257b95e9c60defdfbe851edfdfa820c583a /qml | |
parent | b20eed56b0d712ea59a5f237eb933787e3fdf45d (diff) |
Convert amb hvac plugin to app framework bindings
Change-Id: I7e67c653c7da219beb645d752fb7afca2c968de5
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'qml')
-rw-r--r-- | qml/ClimateButton.qml | 30 | ||||
-rw-r--r-- | qml/FanControl.qml | 54 | ||||
-rw-r--r-- | qml/HVAC.qml | 89 | ||||
-rw-r--r-- | qml/HazardButton.qml | 37 | ||||
-rw-r--r-- | qml/MiddleColumn.qml | 33 | ||||
-rw-r--r-- | qml/SeatHeatButton.qml | 39 | ||||
-rw-r--r-- | qml/TempSlider.qml | 61 | ||||
-rw-r--r-- | qml/TemperatureWheel.qml | 56 | ||||
-rw-r--r-- | qml/hvac-hybrid-qml-app.qml | 87 | ||||
-rw-r--r-- | qml/models/HVACModel.qml | 47 | ||||
-rw-r--r-- | qml/models/TemperatureModel.qml | 28 | ||||
-rw-r--r-- | qml/models/qmldir | 8 |
12 files changed, 569 insertions, 0 deletions
diff --git a/qml/ClimateButton.qml b/qml/ClimateButton.qml new file mode 100644 index 0000000..24802c7 --- /dev/null +++ b/qml/ClimateButton.qml @@ -0,0 +1,30 @@ +/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import QtQuick 2.0 +import "models" + +Rectangle { + id: root + + width: imageItem.width + height: imageItem.height + color: "#aa000000" + + property string target: "" + property string image: "" + property bool value: HVACModel[target] + + Image { + id: imageItem + source: "images/" + image + "_" + (value ? "on" : "off") + ".png" + } + + MouseArea { + anchors.fill: parent + onClicked: HVACModel[target] = !HVACModel[target] + } +} diff --git a/qml/FanControl.qml b/qml/FanControl.qml new file mode 100644 index 0000000..00e6f9e --- /dev/null +++ b/qml/FanControl.qml @@ -0,0 +1,54 @@ +/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import QtQuick 2.0 +import "models" + +Item { + width: childrenRect.width + height: childrenRect.height + + property real value: 0 + + Image { + y: 15 + source: "images/fan_icon_off.png" + } + + Image { + id: fanBar + x: 100 + source: "images/fan_bar_off.png" + } + + Image { + x: 100 + width: value * fanBar.width + fillMode: Image.PreserveAspectCrop + horizontalAlignment: Image.AlignLeft + source: "images/fan_bar_on.png" + + Image { + width: 20 + height: width + anchors.verticalCenter: parent.bottom + anchors.verticalCenterOffset: -1 + anchors.horizontalCenter: parent.right + source: "images/drag_knob.svg" + } + } + + MouseArea { + x: 100 + width: fanBar.width + height: parent.height + + onPositionChanged: { + value = Math.min(Math.max(mouse.x / fanBar.width, 0), 1) + HVACModel.fanSpeed = value; + } + } +} diff --git a/qml/HVAC.qml b/qml/HVAC.qml new file mode 100644 index 0000000..8ca981e --- /dev/null +++ b/qml/HVAC.qml @@ -0,0 +1,89 @@ +/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import QtQuick 2.0 +import system 1.0 +import utils 1.0 +import "models" + +App { + appId: "hvac" + + HazardButton { + id: hazardButton + y: 100 + anchors.horizontalCenter: parent.horizontalCenter + } + + TempSlider { + id: lTempSlider + x: 30 + anchors.top: hazardButton.bottom + anchors.topMargin: 115 + side: "left" + } + + Row { + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: hazardButton.bottom + anchors.topMargin: 90 + spacing: 200 + + MiddleColumn { side: "left" } + MiddleColumn { side: "right" } + } + + TempSlider { + id: rTempSlider + anchors.top: hazardButton.bottom + anchors.topMargin: 115 + anchors.right: parent.right + anchors.rightMargin: 30 + side: "right" + } + + Image { + y: 1057 + source: "images/separator.png" + } + + FanControl { + x: 259 + y: 1092 + } + + Item { + anchors.horizontalCenter: parent.horizontalCenter + width: childrenRect.width + height: childrenRect.height + anchors.bottom: parent.bottom + anchors.bottomMargin: 40 + + Row { + spacing: 20 + + Column { + spacing: 10 + + ClimateButton { image: "fan_dir_down"; target: "fanDown" } + ClimateButton { image: "fan_dir_right"; target: "fanRight" } + ClimateButton { image: "fan_dir_up"; target: "fanUp" } + } + + ClimateButton { y: 156; image: "fan_control_ac"; target: "fanAC" } + ClimateButton { y: 156; image: "fan_control_auto"; target: "fanAuto" } + ClimateButton { y: 156; image: "fan_control_circ"; target: "fanRecirc" } + + Column { + spacing: 10 + + ClimateButton { image: "defrost_max"; target: "defrostMax" } + ClimateButton { image: "defrost_rear"; target: "defrostRear" } + ClimateButton { image: "defrost_front"; target: "defrostFront" } + } + } + } +} diff --git a/qml/HazardButton.qml b/qml/HazardButton.qml new file mode 100644 index 0000000..ffae370 --- /dev/null +++ b/qml/HazardButton.qml @@ -0,0 +1,37 @@ +/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import QtQuick 2.0 + +Rectangle { + id: hazardButton + width: 624 + height: 122 + color: "#aa000000" + border.color: "#ff53b5ce" + + property bool value: false + property bool flash: false + + Image { + id: image + source: "./images/hazard_" + (value ? (flash ? "blink" : "on") : "off") + ".png" + } + + MouseArea { + anchors.fill: parent + onClicked: value = !value + } + + Timer { + id: timer + interval: 500 + repeat: true + running: value + + onTriggered: flash = !flash + } +} diff --git a/qml/MiddleColumn.qml b/qml/MiddleColumn.qml new file mode 100644 index 0000000..89f0ebe --- /dev/null +++ b/qml/MiddleColumn.qml @@ -0,0 +1,33 @@ +/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import QtQuick 2.0 +import components 1.0 +import utils 1.0 + +Item { + id: root + + width: 239 + height: 800 + + property string side: "left" + + Column { + spacing: 50 + + BoxHeading { + color: Style.orangeViv + boxWidth: 45 + boxHeight: 19 + fontSize: 27 + text: (side === "left" ? "L" : "R" ) + " CLIMATE" + } + + SeatHeatButton { side: root.side } + TemperatureWheel { side: root.side } + } +} diff --git a/qml/SeatHeatButton.qml b/qml/SeatHeatButton.qml new file mode 100644 index 0000000..43645fb --- /dev/null +++ b/qml/SeatHeatButton.qml @@ -0,0 +1,39 @@ +/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import QtQuick 2.0 +import "models" + +Rectangle { + width: 239 + height: 194 + color: "#aa000000" + border.color: "#ff53b5ce" + + property string side: "left" + property string propertyName: side + "SeatHeat" + property int seatHeat: HVACModel[propertyName] + + Image { + source: "./images/" + side + "_heat_seat_off.png" + } + + Image { + y: 150 - seatHeat*40 + height: implicitHeight - y + fillMode: Image.Tile + verticalAlignment: Image.AlignBottom + source: "./images/" + side + "_heat_seat_on.png" + } + + MouseArea { + anchors.fill: parent + onClicked: { + var value = HVACModel[propertyName] + HVACModel[propertyName] = value > 0 ? value - 1 : 3 + } + } +} diff --git a/qml/TempSlider.qml b/qml/TempSlider.qml new file mode 100644 index 0000000..f5500e4 --- /dev/null +++ b/qml/TempSlider.qml @@ -0,0 +1,61 @@ +/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import QtQuick 2.0 +import utils 1.0 +import "models" + +Item { + id: root + width: 64 + height: 716 + + property real value: HVACModel[propertyName] + property string propertyName: side + "Temperature" + property string side: "left" + + function setProperty(v) { + HVACModel[propertyName] = Math.min(Math.max(v, 0), 1) + } + + Rectangle { + anchors.fill: parent + color: "#4a53b5ce" + } + + Rectangle { + width: parent.width + height: value * parent.height + color: Style.orangeViv + anchors.bottom: parent.bottom + } + + Rectangle { + x: side === "left" ? parent.width + 30 : -30 + width: 2 + height: value * parent.height + anchors.bottom: parent.bottom + color: Style.orangeLt + + Image { + width: 30 + height: width + anchors.verticalCenter: parent.top + anchors.horizontalCenter: parent.horizontalCenter + source: "images/drag_knob.svg" + } + } + + MouseArea { + x: side === "left" ? 0 : -45 + width: parent.width + 45 + height: parent.height + + onPressed: setProperty(1 - mouse.y / height) + onPositionChanged: setProperty(1 - mouse.y / height) + } +} + diff --git a/qml/TemperatureWheel.qml b/qml/TemperatureWheel.qml new file mode 100644 index 0000000..7a59dde --- /dev/null +++ b/qml/TemperatureWheel.qml @@ -0,0 +1,56 @@ +/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import QtQuick 2.0 +import "models" + +Rectangle { + width: 237 + height: 350 + color: "#aa000000" + + property string side: "left" + property string propertyName: side + "Temperature" + property real value: HVACModel[propertyName] + + ListView { + anchors.fill: parent + clip: true + snapMode: ListView.SnapToItem + model: TemperatureModel + header: Item { height: 120 } + footer: Item { height: 120 } + currentIndex: Math.min(value * count, count - 1) + flickDeceleration: 5000 + onContentYChanged: { + if (dragging || flicking) { + var item = Math.round((contentY + 120) / 110) + item = Math.max(Math.min(item, count - 1), 0) + if (item != currentIndex) { + var temperature = item / (count - 1) + HVACModel[propertyName] = temperature + } + } + } + highlightMoveDuration: 100 + interactive: true + + delegate: Text { + x: side === "right" ? 40 : 10 + height: 110 + verticalAlignment: Text.AlignVCenter + color: "white" + font.pixelSize: 70 + text: model.text + } + } + + Image { + mirror: side === "left" + source: "./images/right_number_cover.svg" + anchors.fill: parent + } +} diff --git a/qml/hvac-hybrid-qml-app.qml b/qml/hvac-hybrid-qml-app.qml new file mode 100644 index 0000000..eded2d0 --- /dev/null +++ b/qml/hvac-hybrid-qml-app.qml @@ -0,0 +1,87 @@ +import QtQuick 2.0 +import QtQuick.Window 2.0 +import QtQuick.Controls 1.4 +import QtWebSockets 1.0 + +Window { + // VARIABLES + + property string port_str: Qt.application.arguments[1] + property string token_str: Qt.application.arguments[2] + property string address_str: "ws://localhost:"+port_str+"/api?token="+token_str + property string request_str: "" + property string status_str: "waiting..." + property var msgid_enu: { "call":2, "retok":3, "reterr":4, "event":5 } + + // WINDOW PROPERTIES + + visible: true + width: 340 + height: 160 + + // WEBSOCKET WIDGET (MAIN LOGIC) + + WebSocket { + id: websocket + url: address_str + onTextMessageReceived: { + // VERB RESPONSE VALIDATION + var message_json = JSON.parse (message) + var request_json = message_json[2].request + if (message_json[0] != msgid_enu.retok) { + console.log ("Return value is not ok !") + status_str = "Bad return value, binding probably not installed" + return + } + // VERB RESPONSE PARSING AND LOGIC + status_str = request_json.info + } + onStatusChanged: { + if (websocket.status == WebSocket.Error) + status_str = "WebSocket error: " + websocket.errorString + } + active: true + } + + // OTHER WIDGETS + + Rectangle { + anchors.left: parent.left + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + anchors.margins: 20 + + // TITLE SECTION + Label { + text: "QML Websocket Sample Application" + font.pixelSize: 18 + font.bold: true + anchors.centerIn: parent + y: 0 + } + Text { + id: url_notifier + text: "<b>URL:</b> " + websocket.url + y: 20 + } + + // PING BUTTON + Button { + text: "Ping!" + onClicked: { + request_str = '[' + msgid_enu.call + ',"99999","xxxxxx/ping", null ]'; + websocket.sendTextMessage (request_str) + } + anchors.horizontalCenter: parent.horizontalCenter + y: 60 + } + + // STATUS SECTION + Text { + id: status_notifier + text: "<b>Status</b>: " + status_str + y: 100 + } + } + +} diff --git a/qml/models/HVACModel.qml b/qml/models/HVACModel.qml new file mode 100644 index 0000000..e737af4 --- /dev/null +++ b/qml/models/HVACModel.qml @@ -0,0 +1,47 @@ +/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +pragma Singleton + +import QtQuick 2.0 +import vehicle 1.0 + +Item { + property bool fanUp: false + property bool fanRight: false + property bool fanDown: false + + property bool fanAC: false + property bool fanAuto: false + property bool fanRecirc: false + + property real fanSpeed: 0 + + property bool defrostMax: false + property bool defrostFront: false + property bool defrostRear: false + + property real leftTemperature: 0 + property real rightTemperature: 0 + + property int leftSeatHeat: 0 + property int rightSeatHeat: 0 + + onFanSpeedChanged: { + var currentFan = ClimateModel.getRangeValue(fanSpeed,ClimateModel.fanStepSize); + ClimateModel.fanSpeed = currentFan; + } + + onLeftTemperatureChanged: { + var temperature = ClimateModel.getRangeValue(leftTemperature,ClimateModel.temperatureStepSize); + ClimateModel.leftTemp = temperature; + } + + onRightTemperatureChanged: { + var temperature = ClimateModel.getRangeValue(rightTemperature,ClimateModel.temperatureStepSize); + ClimateModel.rightTemp = temperature; + } +} diff --git a/qml/models/TemperatureModel.qml b/qml/models/TemperatureModel.qml new file mode 100644 index 0000000..85ca415 --- /dev/null +++ b/qml/models/TemperatureModel.qml @@ -0,0 +1,28 @@ +/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +pragma Singleton + +import QtQuick 2.0 + +ListModel { + ListElement { text: "LO" } + ListElement { text: "16\u00b0" } + ListElement { text: "17\u00b0" } + ListElement { text: "18\u00b0" } + ListElement { text: "19\u00b0" } + ListElement { text: "20\u00b0" } + ListElement { text: "21\u00b0" } + ListElement { text: "22\u00b0" } + ListElement { text: "23\u00b0" } + ListElement { text: "24\u00b0" } + ListElement { text: "25\u00b0" } + ListElement { text: "26\u00b0" } + ListElement { text: "27\u00b0" } + ListElement { text: "28\u00b0" } + ListElement { text: "29\u00b0" } + ListElement { text: "HI" } +} diff --git a/qml/models/qmldir b/qml/models/qmldir new file mode 100644 index 0000000..d757168 --- /dev/null +++ b/qml/models/qmldir @@ -0,0 +1,8 @@ +#/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved. +# * +# * This Source Code Form is subject to the terms of the Mozilla Public +# * License, v. 2.0. If a copy of the MPL was not distributed with this +# * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +singleton HVACModel 1.0 HVACModel.qml +singleton TemperatureModel 1.0 TemperatureModel.qml |