diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-05-30 13:22:11 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2021-05-30 13:22:11 +0200 |
commit | 7f4656d3c3e90f5e0c3e22315e9c69df2ecdb532 (patch) | |
tree | 79a0384805a462b156f286431780a9afcedd046c /resources | |
parent | Port remaining sidebar actions to qml (diff) | |
download | nheko-7f4656d3c3e90f5e0c3e22315e9c69df2ecdb532.tar.xz |
Refactor to use Instantiator instead of doing it manually
Diffstat (limited to 'resources')
-rw-r--r-- | resources/qml/ChatPage.qml | 2 | ||||
-rw-r--r-- | resources/qml/RoomList.qml | 63 | ||||
-rw-r--r-- | resources/qml/Root.qml | 5 |
3 files changed, 26 insertions, 44 deletions
diff --git a/resources/qml/ChatPage.qml b/resources/qml/ChatPage.qml index 966f169b..0fe65afc 100644 --- a/resources/qml/ChatPage.qml +++ b/resources/qml/ChatPage.qml @@ -31,8 +31,8 @@ Rectangle { TimelineView { id: timeline - room: Rooms.currentRoom + room: Rooms.currentRoom SplitView.fillWidth: true SplitView.minimumWidth: 400 } diff --git a/resources/qml/RoomList.qml b/resources/qml/RoomList.qml index 3109b75c..ecfb3af9 100644 --- a/resources/qml/RoomList.qml +++ b/resources/qml/RoomList.qml @@ -4,6 +4,7 @@ import "./dialogs" import Qt.labs.platform 1.1 as Platform +import QtQml 2.13 import QtQuick 2.13 import QtQuick.Controls 2.13 import QtQuick.Layouts 1.3 @@ -37,19 +38,12 @@ Page { property string roomid property var tags + property var allTags function show(roomid_, tags_) { roomid = roomid_; tags = tags_; - roomContextMenu.clear(); - roomContextMenu.addItem(leaveOpt.createObject(roomContextMenu)); - roomContextMenu.addItem(separatorOpt.createObject(roomContextMenu)); - for (let tag of Rooms.tags()) { - roomContextMenu.addItem(tagDelegate.createObject(roomContextMenu, { - "t": tag - })); - } - roomContextMenu.addItem(newTagOpt.createObject(roomContextMenu)); + allTags = Rooms.tags(); open(); } @@ -63,30 +57,22 @@ Page { } } - Component { - id: leaveOpt - - Platform.MenuItem { - text: qsTr("Leave room") - onTriggered: Rooms.leave(roomContextMenu.roomid) - } - + Platform.MenuItem { + text: qsTr("Leave room") + onTriggered: Rooms.leave(roomContextMenu.roomid) } - Component { - id: separatorOpt - - Platform.MenuSeparator { - text: qsTr("Tag room as:") - } - + Platform.MenuSeparator { + text: qsTr("Tag room as:") } - Component { - id: tagDelegate + Instantiator { + model: roomContextMenu.allTags + onObjectAdded: roomContextMenu.insertItem(index + 2, object) + onObjectRemoved: roomContextMenu.removeItem(object) - Platform.MenuItem { - property string t + delegate: Platform.MenuItem { + property string t: modelData text: { switch (t) { @@ -107,14 +93,9 @@ Page { } - Component { - id: newTagOpt - - Platform.MenuItem { - text: qsTr("Create new tag...") - onTriggered: newTag.show() - } - + Platform.MenuItem { + text: qsTr("Create new tag...") + onTriggered: newTag.show() } } @@ -166,9 +147,9 @@ Page { TapHandler { acceptedButtons: Qt.RightButton onSingleTapped: { - if (!TimelineManager.isInvite) { + if (!TimelineManager.isInvite) roomContextMenu.show(model.roomId, model.tags); - } + } gesturePolicy: TapHandler.ReleaseWithinBounds } @@ -176,9 +157,9 @@ Page { TapHandler { onSingleTapped: Rooms.setCurrentRoom(model.roomId) onLongPressed: { - if (!TimelineManager.isInvite) { + if (!TimelineManager.isInvite) roomContextMenu.show(model.roomId, model.tags); - } + } } @@ -524,7 +505,6 @@ Page { ToolTip.visible: hovered ToolTip.text: qsTr("Start a new chat") Layout.margins: Nheko.paddingMedium - onClicked: roomJoinCreateMenu.open(parent) Platform.Menu { @@ -541,6 +521,7 @@ Page { } } + } ImageButton { diff --git a/resources/qml/Root.qml b/resources/qml/Root.qml index c23ab97d..078281d4 100644 --- a/resources/qml/Root.qml +++ b/resources/qml/Root.qml @@ -74,11 +74,12 @@ Page { Shortcut { sequence: "Ctrl+Down" - onActivated: Rooms.nextRoom(); + onActivated: Rooms.nextRoom() } + Shortcut { sequence: "Ctrl+Up" - onActivated: Rooms.previousRoom(); + onActivated: Rooms.previousRoom() } Component { |