Use SwipeListItem instead of BasicListItem

This allows to have a second way to open the room options.
This commit is contained in:
Carl Schwan
2020-11-17 17:12:13 +00:00
parent 96bcb54806
commit fc0ed1d137

View File

@@ -79,11 +79,9 @@ Kirigami.ScrollablePage {
} }
} }
delegate: Kirigami.AbstractListItem { delegate: Kirigami.SwipeListItem {
id: roomListItem
visible: model.categoryVisible visible: model.categoryVisible
topPadding: Kirigami.Units.largeSpacing height: model.categoryVisible ? implicitHeight : 0
bottomPadding: Kirigami.Units.largeSpacing
focus: true focus: true
action: Kirigami.Action { action: Kirigami.Action {
id: enterRoomAction id: enterRoomAction
@@ -93,17 +91,43 @@ Kirigami.ScrollablePage {
roomItem.focus = true; roomItem.focus = true;
} }
} }
actions: [
Kirigami.Action {
id: makeAction
text: currentRoom.isFavourite ? i18n("Remove room from favorites") : i18n("Make room favorite")
icon.name: currentRoom.isFavourite ? "rating" : "rating-unrated"
checkable: true
checked: currentRoom.isFavourite
onTriggered: currentRoom.isFavourite ? currentRoom.removeTag("m.favourite") : currentRoom.addTag("m.favourite", 1.0)
},
Kirigami.Action {
id: optionAction
text: i18n("Configure room")
icon.name: "configure"
onTriggered: roomListContextMenu.createObject(roomLayout, {"room": currentRoom}).popup();
}
]
contentItem: Item { contentItem: Item {
id: listItem
focus: true
implicitHeight: roomLayout.implicitHeight implicitHeight: roomLayout.implicitHeight
RowLayout { RowLayout {
id: roomLayout id: roomLayout
spacing: Kirigami.Units.largeSpacing
anchors.fill: parent anchors.fill: parent
spacing: Kirigami.Units.largeSpacing
Kirigami.Avatar { Kirigami.Avatar {
Layout.preferredWidth: height id: roomAvatar
Layout.fillHeight: true property int size: Kirigami.Units.gridUnit * 3 - Kirigami.Units.smallSpacing * 2;
Layout.minimumHeight: size
Layout.maximumHeight: size
Layout.minimumWidth: size
Layout.maximumWidth: size
source: avatar ? "image://mxc/" + avatar : "" source: avatar ? "image://mxc/" + avatar : ""
name: model.name || i18n("No Name") name: model.name || i18n("No Name")
@@ -116,11 +140,11 @@ Kirigami.ScrollablePage {
spacing: Kirigami.Units.smallSpacing spacing: Kirigami.Units.smallSpacing
QQC2.Label { Kirigami.Heading {
level: 3
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
text: name ?? "" text: name ?? ""
font.pixelSize: 15
font.bold: unreadCount >= 0 font.bold: unreadCount >= 0
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
@@ -132,7 +156,7 @@ Kirigami.ScrollablePage {
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
text: (lastEvent == "" ? topic : lastEvent).replace(/(\r\n\t|\n|\r\t)/gm," ") text: (lastEvent == "" ? topic : lastEvent).replace(/(\r\n\t|\n|\r\t)/gm," ")
font.pixelSize: 12 visible: text.length > 0
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
} }
@@ -144,7 +168,7 @@ Kirigami.ScrollablePage {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
if (mouse.button == Qt.RightButton) { if (mouse.button == Qt.RightButton) {
roomListContextMenu.createObject(parent, {"room": currentRoom}).popup() roomListContextMenu.createObject(roomLayout, {"room": currentRoom}).popup()
} else { } else {
roomManager.enterRoom(currentRoom) roomManager.enterRoom(currentRoom)
} }