Files
scheincommander/EditableListView.qml
T

91 lines
2.3 KiB
QML
Raw 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-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 {
text: qsTr("Add")
onClicked: addClicked(listView.currentIndex)
}
Item {
Layout.fillWidth: true
}
Button {
2023-02-18 15:53:44 +01:00
text: qsTr("Remove ")
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-15 22:27:57 +01:00
onCountChanged: if (count === 0 && currentIndex >= 0) currentIndex = -1
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-15 02:18:22 +01:00
Rectangle {
2023-02-15 01:12:19 +01:00
anchors.fill: parent
2023-02-15 02:18:22 +01:00
color: isCurrentItem ?
Material.color(Material.Purple) :
Material.background
radius: 0
Label {
anchors.fill: parent
//anchors.verticalCenter: parent.verticalCenter
id: text
text: model[textRole]
2023-02-15 02:18:22 +01:00
padding: 10
fontSizeMode: Text.VerticalFit
minimumPixelSize: 10;
font.pixelSize: 72
}
}
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
}
MouseArea {
anchors.fill: parent
onClicked: listView.currentIndex = index
}
}
focus: true
}
}