Files
scheincommander/EditableListView.qml

118 lines
3.3 KiB
QML
Raw Permalink Normal View History

2023-02-15 01:12:19 +01:00
import QtQuick
import QtQuick.Controls.Material
import QtQuick.Layouts
ColumnLayout {
property string textRole: "name"
2023-02-23 00:34:31 +01:00
property string iconSourceRole
2023-02-15 01:12:19 +01:00
property alias model: listView.model
property alias currentIndex: listView.currentIndex
property alias currentItem: listView.currentItem
2023-02-15 20:17:58 +01:00
property variant currentData: listView.currentItem ? listView.currentItem.myData : null
2023-02-15 01:12:19 +01:00
signal addClicked(index: int)
signal removeClicked(index: int)
RowLayout {
Layout.fillWidth: true
Button {
2023-02-20 00:44:44 +01:00
text: "\ue145"
font.family: materialIcons.font.family
font.pixelSize: 20
2023-02-15 01:12:19 +01:00
onClicked: addClicked(listView.currentIndex)
}
Item {
Layout.fillWidth: true
}
Button {
2023-02-20 00:44:44 +01:00
text: "\ue872"
font.family: materialIcons.font.family
font.pixelSize: 20
2023-02-15 01:12:19 +01:00
onClicked: removeClicked(listView.currentIndex)
enabled: listView.currentIndex >= 0
}
}
ListView {
id: listView
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
2023-02-22 12:13:09 +01:00
focus: true
// highlightRangeMode: ListView.ApplyRange
2023-02-15 01:12:19 +01:00
2023-02-15 22:27:57 +01:00
onCountChanged: if (count === 0 && currentIndex >= 0) currentIndex = -1
2023-02-22 12:13:09 +01:00
// displaced: Transition {
// NumberAnimation { properties: "x,y"; duration: 1000 }
// }
addDisplaced: Transition {
NumberAnimation { properties: "x,y"; duration: 1000 }
}
add: Transition {
ParallelAnimation {
NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 1000 }
NumberAnimation { properties: "x"; from: 100; duration: 1000 }
}
}
move: Transition {
NumberAnimation { properties: "x,y"; duration: 1000 }
}
moveDisplaced: Transition {
NumberAnimation { properties: "x,y"; duration: 1000 }
}
// populate: Transition {
// NumberAnimation { properties: "x,y"; duration: 100 }
// }
remove: Transition {
ParallelAnimation {
NumberAnimation { property: "opacity"; to: 0; duration: 1000 }
NumberAnimation { properties: "x"; to: 100; duration: 1000 }
}
}
removeDisplaced: Transition {
NumberAnimation { properties: "x,y"; duration: 1000 }
}
2023-02-15 02:18:22 +01:00
delegate: Item {
2023-02-15 01:12:19 +01:00
property variant myData: model
2023-02-15 02:18:22 +01:00
readonly property bool isCurrentItem: ListView.isCurrentItem
2023-02-15 01:12:19 +01:00
width: listView.width
2023-02-15 02:18:22 +01:00
height: 45
2023-02-15 01:12:19 +01:00
2023-02-19 04:37:03 +01:00
ItemDelegate {
2023-02-15 01:12:19 +01:00
anchors.fill: parent
2023-02-19 04:37:03 +01:00
contentItem: IconChooserDelegateLayout {
2023-02-15 02:18:22 +01:00
anchors.fill: parent
text: model[textRole]
2023-02-23 00:34:31 +01:00
iconSource: (model && model[iconSourceRole]) ? model[iconSourceRole] : null
2023-02-15 02:18:22 +01:00
}
2023-02-19 04:37:03 +01:00
onClicked: listView.currentIndex = index
down: listView.currentIndex === index
2023-02-15 02:18:22 +01:00
}
Rectangle {
color: Material.dividerColor
height: 1
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
visible: index !== (listView.count - 1)
2023-02-15 01:12:19 +01:00
}
}
}
}