From b71f65e023df6c189e6356cf76df05325efa59b7 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 11 Jul 2018 23:05:42 +0200 Subject: [PATCH] button press feedback --- libnymea-common/types/actiontype.cpp | 4 ++ libnymea-common/types/actiontype.h | 2 +- libnymea-common/types/interfaces.cpp | 3 + nymea-app/resources.qrc | 2 + nymea-app/ui/NewDeviceWizard.qml | 22 ++++++ nymea-app/ui/Nymea.qml | 9 ++- nymea-app/ui/components/ShutterControls.qml | 34 ++++------ .../ui/devicepages/GarageGateDevicePage.qml | 26 +++---- nymea-app/ui/images/DeviceIconBlind.svg | 59 ++++++++++++++++ .../ui/images/DeviceIconRollerShutter.svg | 67 +++++++++++++++++++ nymea-app/ui/mainviews/ScenesView.qml | 56 ++++++++-------- 11 files changed, 215 insertions(+), 69 deletions(-) create mode 100644 nymea-app/ui/images/DeviceIconBlind.svg create mode 100644 nymea-app/ui/images/DeviceIconRollerShutter.svg diff --git a/libnymea-common/types/actiontype.cpp b/libnymea-common/types/actiontype.cpp index f90518e8..88dbea5c 100644 --- a/libnymea-common/types/actiontype.cpp +++ b/libnymea-common/types/actiontype.cpp @@ -74,6 +74,10 @@ ParamTypes *ActionType::paramTypes() const void ActionType::setParamTypes(ParamTypes *paramTypes) { + if (m_paramTypes && m_paramTypes->parent() == this) { + m_paramTypes->deleteLater(); + } m_paramTypes = paramTypes; + m_paramTypes->setParent(this); emit paramTypesChanged(); } diff --git a/libnymea-common/types/actiontype.h b/libnymea-common/types/actiontype.h index 9347e0ca..8f1345a4 100644 --- a/libnymea-common/types/actiontype.h +++ b/libnymea-common/types/actiontype.h @@ -60,7 +60,7 @@ private: QString m_name; QString m_displayName; int m_index; - ParamTypes *m_paramTypes; + ParamTypes *m_paramTypes = nullptr; signals: void paramTypesChanged(); diff --git a/libnymea-common/types/interfaces.cpp b/libnymea-common/types/interfaces.cpp index e49ddc98..d25beef6 100644 --- a/libnymea-common/types/interfaces.cpp +++ b/libnymea-common/types/interfaces.cpp @@ -38,6 +38,9 @@ Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent) addStateType("temperaturesensor", "temperature", QVariant::Double, false, tr("Temperature"), tr("Temperature has changed")); + + addInterface("simpleclosable", tr("Closable things")); + addActionType("simpleclosable", "close", "Close", new ParamTypes()); } int Interfaces::rowCount(const QModelIndex &parent) const diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc index 6fa57de9..7150e544 100644 --- a/nymea-app/resources.qrc +++ b/nymea-app/resources.qrc @@ -227,5 +227,7 @@ ui/images/awning/awning-080.svg ui/images/awning/awning-090.svg ui/magic/NewThingMagicPage.qml + ui/images/DeviceIconBlind.svg + ui/images/DeviceIconRollerShutter.svg diff --git a/nymea-app/ui/NewDeviceWizard.qml b/nymea-app/ui/NewDeviceWizard.qml index 31695ce9..b72b000f 100644 --- a/nymea-app/ui/NewDeviceWizard.qml +++ b/nymea-app/ui/NewDeviceWizard.qml @@ -97,6 +97,7 @@ Page { deviceClasses: Engine.deviceManager.deviceClasses } delegate: MeaListItemDelegate { + id: deviceClassDelegate width: parent.width text: model.displayName iconName: app.interfacesToIcon(deviceClass.interfaces) @@ -118,6 +119,27 @@ Page { print("should setup", deviceClass.name, deviceClass.setupMethod, deviceClass.createMethods, deviceClass["discoveryParamTypes"].count) } + + swipe.enabled: deviceClass.createMethods.indexOf("CreateMethodUser") !== -1 + swipe.right: MouseArea { + height: deviceClassDelegate.height + width: height + anchors.right: parent.right + Rectangle { + anchors.fill: parent + color: "transparent" + } + + ColorIcon { + anchors.fill: parent + anchors.margins: app.margins + name: "../images/add.svg" + } + onClicked: { + d.deviceClass = deviceClass + internalPageStack.push(paramsPage) + } + } } } } diff --git a/nymea-app/ui/Nymea.qml b/nymea-app/ui/Nymea.qml index 26b1904d..1db5a18d 100644 --- a/nymea-app/ui/Nymea.qml +++ b/nymea-app/ui/Nymea.qml @@ -223,10 +223,11 @@ ApplicationWindow { case "outputtrigger": return Qt.resolvedUrl("images/send.svg") case "shutter": - case "blind": case "extendedshutter": + return Qt.resolvedUrl("images/DeviceIconRollerShutter.svg") + case "blind": case "extendedblind": - return Qt.resolvedUrl("images/sort-listitem.svg") + return Qt.resolvedUrl("images/DeviceIconBlind.svg") case "garagegate": return Qt.resolvedUrl("images/shutter/shutter-100.svg") case "extendedawning": @@ -235,6 +236,10 @@ ApplicationWindow { return Qt.resolvedUrl("images/battery/battery-050.svg") case "uncategorized": return Qt.resolvedUrl("images/select-none.svg") + case "simpleclosable": + return Qt.resolvedUrl("images/sort-listitem.svg") + default: + console.warn("InterfaceToIcon: Unhandled interface", name) } return ""; } diff --git a/nymea-app/ui/components/ShutterControls.qml b/nymea-app/ui/components/ShutterControls.qml index f1a09f81..21703243 100644 --- a/nymea-app/ui/components/ShutterControls.qml +++ b/nymea-app/ui/components/ShutterControls.qml @@ -16,54 +16,44 @@ RowLayout { property bool invert: false - Rectangle { + ItemDelegate { Layout.preferredWidth: app.iconSize * 2 Layout.preferredHeight: width - color: root.openState && root.openState.value === "opening" ? Material.accent : Material.foreground - radius: height / 2 ColorIcon { anchors.fill: parent anchors.margins: app.margins name: root.invert ? "../images/down.svg" : "../images/up.svg" + color: root.openState && root.openState.value === "opening" ? Material.accent : keyColor } - MouseArea { - anchors.fill: parent - onClicked: Engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("open").id) - } + onClicked: Engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("open").id) } - Rectangle { + + ItemDelegate { Layout.preferredWidth: app.iconSize * 2 Layout.preferredHeight: width - color: Material.foreground - radius: height / 2 +// color: Material.foreground +// radius: height / 2 ColorIcon { anchors.fill: parent anchors.margins: app.margins - name: "../images/remove.svg" - } - MouseArea { - anchors.fill: parent - onClicked: Engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("stop").id) + name: "../images/media-playback-stop.svg" } + onClicked: Engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("stop").id) } - Rectangle { + ItemDelegate { Layout.preferredWidth: app.iconSize * 2 Layout.preferredHeight: width - color: root.openState && root.openState.value === "closing" ? Material.accent : Material.foreground - radius: height / 2 ColorIcon { anchors.fill: parent anchors.margins: app.margins name: root.invert ? "../images/up.svg" : "../images/down.svg" + color: root.openState && root.openState.value === "closing" ? Material.accent : keyColor } - MouseArea { - anchors.fill: parent - onClicked: Engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("close").id) - } + onClicked: Engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("close").id) } } diff --git a/nymea-app/ui/devicepages/GarageGateDevicePage.qml b/nymea-app/ui/devicepages/GarageGateDevicePage.qml index b82b7011..b0827fbf 100644 --- a/nymea-app/ui/devicepages/GarageGateDevicePage.qml +++ b/nymea-app/ui/devicepages/GarageGateDevicePage.qml @@ -85,29 +85,25 @@ DevicePageBase { device: root.device anchors.centerIn: parent - Rectangle { + ItemDelegate { Layout.preferredWidth: app.iconSize * 2 Layout.preferredHeight: width - color: root.lightState && root.lightState.value === true ? Material.accent : Material.foreground - radius: height / 2 visible: root.lightStateType !== null ColorIcon { anchors.fill: parent anchors.margins: app.margins - name: "../images/torch-" + (root.lightState && root.lightState.value === true ? "on" : "off") + ".svg" + name: "../images/light-" + (root.lightState && root.lightState.value === true ? "on" : "off") + ".svg" + color: root.lightState && root.lightState.value === true ? Material.accent : keyColor } - MouseArea { - anchors.fill: parent - onClicked: { - print("blabla", root.lightState, root.lightState.value, root.lightStateType.name, root.lightState.stateTypeId, root.lightStateType.id) - var params = []; - var param = {}; - param["paramTypeId"] = root.lightStateType.id; - param["value"] = !root.lightState.value; - params.push(param) - Engine.deviceManager.executeAction(root.device.id, root.lightStateType.id, params) - } + onClicked: { + print("blabla", root.lightState, root.lightState.value, root.lightStateType.name, root.lightState.stateTypeId, root.lightStateType.id) + var params = []; + var param = {}; + param["paramTypeId"] = root.lightStateType.id; + param["value"] = !root.lightState.value; + params.push(param) + Engine.deviceManager.executeAction(root.device.id, root.lightStateType.id, params) } } } diff --git a/nymea-app/ui/images/DeviceIconBlind.svg b/nymea-app/ui/images/DeviceIconBlind.svg new file mode 100644 index 00000000..46c17f7c --- /dev/null +++ b/nymea-app/ui/images/DeviceIconBlind.svg @@ -0,0 +1,59 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/nymea-app/ui/images/DeviceIconRollerShutter.svg b/nymea-app/ui/images/DeviceIconRollerShutter.svg new file mode 100644 index 00000000..e99ba932 --- /dev/null +++ b/nymea-app/ui/images/DeviceIconRollerShutter.svg @@ -0,0 +1,67 @@ + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/nymea-app/ui/mainviews/ScenesView.qml b/nymea-app/ui/mainviews/ScenesView.qml index 2011dea0..53958ff7 100644 --- a/nymea-app/ui/mainviews/ScenesView.qml +++ b/nymea-app/ui/mainviews/ScenesView.qml @@ -44,45 +44,43 @@ Item { anchors.fill: parent anchors.margins: app.margins / 2 Material.elevation: 1 - - MouseArea { + padding: 0 + ItemDelegate { anchors.fill: parent onClicked: { Engine.ruleManager.executeActions(model.id) } - } - - ColumnLayout { - width: parent.width - anchors.centerIn: parent - spacing: app.margins - - ColorIcon { - Layout.preferredHeight: app.iconSize * 2 - Layout.preferredWidth: height - Layout.alignment: Qt.AlignHCenter - name: scenesDelegate.iconTag ? "../images/" + scenesDelegate.iconTag.value + ".svg" : "../images/slideshow.svg"; - color: scenesDelegate.colorTag ? scenesDelegate.colorTag.value : app.guhAccent; + contentItem: ColumnLayout { + width: parent.width + anchors.centerIn: parent + spacing: app.margins ColorIcon { - anchors.fill: parent - name: "../images/slideshow.svg" - color: app.guhAccent - visible: parent.status === Image.Error - } - } + Layout.preferredHeight: app.iconSize * 2 + Layout.preferredWidth: height + Layout.alignment: Qt.AlignHCenter + name: scenesDelegate.iconTag ? "../images/" + scenesDelegate.iconTag.value + ".svg" : "../images/slideshow.svg"; + color: scenesDelegate.colorTag ? scenesDelegate.colorTag.value : app.guhAccent; - Label { - Layout.fillWidth: true - text: model.name - wrapMode: Text.WordWrap - horizontalAlignment: Text.AlignHCenter - maximumLineCount: 2 - elide: Text.ElideRight + ColorIcon { + anchors.fill: parent + name: "../images/slideshow.svg" + color: app.guhAccent + visible: parent.status === Image.Error + } + } + + Label { + Layout.fillWidth: true + text: model.name + wrapMode: Text.WordWrap + horizontalAlignment: Text.AlignHCenter + maximumLineCount: 2 + elide: Text.ElideRight + } } } } } } - }