Don't allow opening multiple swipe delegates at once

This commit is contained in:
Michael Zanetti 2019-01-28 20:52:26 +01:00
parent 601171daf8
commit c39444b146
4 changed files with 51 additions and 2 deletions

View File

@ -40,6 +40,7 @@
<file>ui/components/FancyHeader.qml</file>
<file>ui/components/MainPageTile.qml</file>
<file>ui/components/BusyOverlay.qml</file>
<file>ui/components/SwipeDelegateGroup.qml</file>
<file>ui/components/AWSPasswordTextField.qml</file>
<file>ui/components/BrightnessSlider.qml</file>
<file>ui/components/SegmentedImage.qml</file>

View File

@ -1,7 +1,8 @@
import QtQuick 2.9
import QtQuick.Controls 2.1
import QtQuick.Controls 2.2
ListView {
id: root
ScrollBar.vertical: ScrollBar {}
@ -12,4 +13,5 @@ ListView {
text: app.interfaceToString(section)
}
SwipeDelegateGroup {}
}

View File

@ -0,0 +1,47 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
Item {
id: swipeGroup
property ListView listView: parent
QtObject {
id: d
property var delegates: swipeGroup.listView.contentItem.children
property var delegateCache: []
onDelegatesChanged: {
for (var i = 0; i < d.delegates.length; i++) {
var thisItem = d.delegates[i];
if (!thisItem.hasOwnProperty("swipe")) {
continue;
}
if (d.delegateCache.indexOf(thisItem) < 0) {
d.delegateCache.push(thisItem);
print("cache is now", d.delegateCache.length)
thisItem.Component.destruction.connect(function() {
print("item destroyed", thisItem)
var idx = d.delegateCache.indexOf(thisItem)
d.delegateCache.splice(idx, 1)
print("cache is now", d.delegateCache.length)
})
thisItem.swipe.opened.connect(function() {
for (var j = 0; j < d.delegates.length; j++) {
var otherItem = d.delegates[j];
if (thisItem === otherItem) {
continue;
}
if (!otherItem.hasOwnProperty("swipe")) {
continue;
}
otherItem.swipe.close();
}
})
}
}
}
}
}

View File

@ -19,5 +19,4 @@ MeaListItemDelegate {
readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
readonly property bool batteryCritical: deviceClass && deviceClass.interfaces.indexOf("battery") >= 0 ? device.stateValue(deviceClass.stateTypes.findByName("batteryCritical").id) === true : false
readonly property bool disconnected: deviceClass && deviceClass.interfaces.indexOf("connectable") >= 0 ? device.stateValue(deviceClass.stateTypes.findByName("connected").id) === false : false
}