Improve Space list
- Give it a context menu - Clean up code BUG: 460167
This commit is contained in:
119
src/qml/Menu/SpaceListContextMenu.qml
Normal file
119
src/qml/Menu/SpaceListContextMenu.qml
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
|
||||||
|
// SPDX-FileCopyrightText: 2022 Tobias Fella <fella@posteo.de>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
import QtQuick 2.15
|
||||||
|
import QtQuick.Controls 2.15
|
||||||
|
import QtQuick.Layouts 1.15
|
||||||
|
|
||||||
|
import org.kde.kirigami 2.19 as Kirigami
|
||||||
|
|
||||||
|
import org.kde.neochat 1.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context menu when clicking on a room in the room list
|
||||||
|
*/
|
||||||
|
Loader {
|
||||||
|
id: root
|
||||||
|
property var room
|
||||||
|
signal closed()
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: regularMenu
|
||||||
|
Menu {
|
||||||
|
MenuItem {
|
||||||
|
text: i18nc("@action:inmenu", "Copy Address to Clipboard")
|
||||||
|
onTriggered: if (room.canonicalAlias.length === 0) {
|
||||||
|
Clipboard.saveText(room.id)
|
||||||
|
} else {
|
||||||
|
Clipboard.saveText(room.canonicalAlias)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItem {
|
||||||
|
text: i18nc("'Space' is a matrix space", "Space Settings")
|
||||||
|
onTriggered: ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room})
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuSeparator {}
|
||||||
|
|
||||||
|
MenuItem {
|
||||||
|
text: i18nc("'Space' is a matrix space", "Leave Space")
|
||||||
|
onTriggered: RoomManager.leaveRoom(room)
|
||||||
|
}
|
||||||
|
|
||||||
|
onClosed: {
|
||||||
|
root.closed()
|
||||||
|
destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: mobileMenu
|
||||||
|
|
||||||
|
Kirigami.OverlayDrawer {
|
||||||
|
id: drawer
|
||||||
|
height: popupContent.implicitHeight
|
||||||
|
edge: Qt.BottomEdge
|
||||||
|
padding: 0
|
||||||
|
leftPadding: 0
|
||||||
|
rightPadding: 0
|
||||||
|
bottomPadding: 0
|
||||||
|
topPadding: 0
|
||||||
|
|
||||||
|
parent: applicationWindow().overlay
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
id: popupContent
|
||||||
|
width: parent.width
|
||||||
|
spacing: 0
|
||||||
|
RowLayout {
|
||||||
|
id: headerLayout
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.margins: Kirigami.Units.largeSpacing
|
||||||
|
spacing: Kirigami.Units.largeSpacing
|
||||||
|
Kirigami.Avatar {
|
||||||
|
id: avatar
|
||||||
|
source: room.avatarMediaId ? ("image://mxc/" + room.avatarMediaId) : ""
|
||||||
|
Layout.preferredWidth: Kirigami.Units.gridUnit * 3
|
||||||
|
Layout.preferredHeight: Kirigami.Units.gridUnit * 3
|
||||||
|
Layout.alignment: Qt.AlignTop
|
||||||
|
}
|
||||||
|
Kirigami.Heading {
|
||||||
|
level: 5
|
||||||
|
Layout.fillWidth: true
|
||||||
|
text: room.displayName
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolButton {
|
||||||
|
icon.name: 'settings-configure'
|
||||||
|
onClicked: ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Kirigami.BasicListItem {
|
||||||
|
text: i18nc("'Space' is a matrix space", "Leave Space")
|
||||||
|
onClicked: RoomManager.leaveRoom(room)
|
||||||
|
implicitHeight: visible ? Kirigami.Units.gridUnit * 3 : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onClosed: root.closed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
asynchronous: true
|
||||||
|
sourceComponent: Kirigami.Settings.isMobile ? mobileMenu : regularMenu
|
||||||
|
|
||||||
|
function open() {
|
||||||
|
active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
onStatusChanged: if (status == Loader.Ready) {
|
||||||
|
if (Kirigami.Settings.isMobile) {
|
||||||
|
item.open();
|
||||||
|
} else {
|
||||||
|
item.popup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,20 +13,19 @@ import org.kde.kitemmodels 1.0
|
|||||||
import org.kde.neochat 1.0
|
import org.kde.neochat 1.0
|
||||||
|
|
||||||
Kirigami.ScrollablePage {
|
Kirigami.ScrollablePage {
|
||||||
|
id: page
|
||||||
|
|
||||||
header: ColumnLayout {
|
header: ColumnLayout {
|
||||||
visible: !page.collapsedMode
|
visible: !page.collapsedMode
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.fillHeight: true
|
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: spaceList
|
id: spaceList
|
||||||
property string activeSpaceId: ''
|
property string activeSpaceId: ""
|
||||||
|
|
||||||
orientation: Qt.Horizontal
|
orientation: Qt.Horizontal
|
||||||
spacing: Kirigami.Units.largeSpacing
|
spacing: Kirigami.Units.smallSpacing
|
||||||
clip:true
|
clip: true
|
||||||
visible: spaceList.count > 0
|
visible: spaceList.count > 0
|
||||||
|
|
||||||
Layout.preferredHeight: Kirigami.Units.gridUnit * 3
|
Layout.preferredHeight: Kirigami.Units.gridUnit * 3
|
||||||
@@ -61,37 +60,55 @@ Kirigami.ScrollablePage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: QQC2.Control {
|
delegate: QQC2.ItemDelegate {
|
||||||
required property string avatar
|
required property string avatar
|
||||||
required property var currentRoom
|
required property var currentRoom
|
||||||
required property int index
|
required property int index
|
||||||
required property string id
|
required property string id
|
||||||
implicitWidth: ListView.view.headerItem.implicitWidth
|
|
||||||
implicitHeight: ListView.view.headerItem.implicitHeight
|
height: parent.height
|
||||||
|
width: height
|
||||||
|
leftPadding: topPadding
|
||||||
|
rightPadding: topPadding
|
||||||
|
|
||||||
contentItem: Kirigami.Avatar {
|
contentItem: Kirigami.Avatar {
|
||||||
actions.main: Kirigami.Action {
|
|
||||||
onTriggered: {
|
|
||||||
spaceList.activeSpaceId = id;
|
|
||||||
sortFilterRoomListModel.activeSpaceId = id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
name: currentRoom.displayName
|
name: currentRoom.displayName
|
||||||
|
|
||||||
QQC2.ToolTip {
|
|
||||||
text: currentRoom.displayName
|
|
||||||
}
|
|
||||||
|
|
||||||
source: avatar !== "" ? "image://mxc/" + avatar : ""
|
source: avatar !== "" ? "image://mxc/" + avatar : ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
spaceList.activeSpaceId = id;
|
||||||
|
sortFilterRoomListModel.activeSpaceId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
QQC2.ToolTip {
|
||||||
|
text: currentRoom.displayName
|
||||||
|
}
|
||||||
|
|
||||||
|
onPressAndHold: {
|
||||||
|
spaceList.createContextMenu(currentRoom)
|
||||||
|
}
|
||||||
|
TapHandler {
|
||||||
|
acceptedButtons: Qt.RightButton
|
||||||
|
acceptedDevices: PointerDevice.Mouse
|
||||||
|
onTapped: spaceList.createContextMenu(currentRoom)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function createContextMenu(room) {
|
||||||
|
const menu = spaceListContextMenu.createObject(page, {room: room})
|
||||||
|
menu.open()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Kirigami.Separator {
|
Kirigami.Separator {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: spaceListContextMenu
|
||||||
|
SpaceListContextMenu {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
id: page
|
|
||||||
|
|
||||||
title: i18n("Rooms")
|
title: i18n("Rooms")
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@
|
|||||||
<file alias="MessageSourceSheet.qml">qml/Menu/Timeline/MessageSourceSheet.qml</file>
|
<file alias="MessageSourceSheet.qml">qml/Menu/Timeline/MessageSourceSheet.qml</file>
|
||||||
<file alias="ReportSheet.qml">qml/Menu/Timeline/ReportSheet.qml</file>
|
<file alias="ReportSheet.qml">qml/Menu/Timeline/ReportSheet.qml</file>
|
||||||
<file alias="RoomListContextMenu.qml">qml/Menu/RoomListContextMenu.qml</file>
|
<file alias="RoomListContextMenu.qml">qml/Menu/RoomListContextMenu.qml</file>
|
||||||
|
<file alias="SpaceListContextMenu.qml">qml/Menu/SpaceListContextMenu.qml</file>
|
||||||
<file alias="glowdot.png">qml/Component/glowdot.png</file>
|
<file alias="glowdot.png">qml/Component/glowdot.png</file>
|
||||||
<file alias="confetti.png">qml/Component/confetti.png</file>
|
<file alias="confetti.png">qml/Component/confetti.png</file>
|
||||||
<file alias="SettingsPage.qml">qml/Settings/SettingsPage.qml</file>
|
<file alias="SettingsPage.qml">qml/Settings/SettingsPage.qml</file>
|
||||||
|
|||||||
Reference in New Issue
Block a user