Warning, /network/neochat/src/qml/SpaceHierarchyDelegate.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 
0008 import org.kde.kirigami as Kirigami
0009 import org.kde.kirigamiaddons.delegates as Delegates
0010 import org.kde.kirigamiaddons.labs.components as Components
0011 
0012 import org.kde.neochat
0013 
0014 Item {
0015     id: root
0016     required property TreeView treeView
0017     required property bool isTreeNode
0018     required property bool expanded
0019     required property int hasChildren
0020     required property int depth
0021     required property string roomId
0022     required property string displayName
0023     required property url avatarUrl
0024     required property bool isSpace
0025     required property bool isSuggested
0026     required property int memberCount
0027     required property string topic
0028     required property bool isJoined
0029     required property bool canAddChildren
0030     required property string parentDisplayName
0031     required property bool canSetParent
0032     required property bool isDeclaredParent
0033     required property bool canRemove
0034     required property NeoChatRoom parentRoom
0035 
0036     signal createRoom()
0037     signal enterRoom()
0038 
0039     Delegates.RoundedItemDelegate {
0040         anchors.centerIn: root
0041         width: sizeHelper.currentWidth
0042 
0043         contentItem: RowLayout {
0044             spacing: Kirigami.Units.largeSpacing
0045 
0046             RowLayout {
0047                 spacing: 0
0048                 Item {
0049                     Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium * (root.depth + (root.isSpace ? 0 : 1))
0050                 }
0051                 Kirigami.Icon {
0052                     visible: root.isSpace
0053                     implicitWidth: Kirigami.Units.iconSizes.smallMedium
0054                     implicitHeight: Kirigami.Units.iconSizes.smallMedium
0055                     source: root.hasChildren ? (root.expanded ? "go-up" : "go-down") : "go-next"
0056                 }
0057             }
0058             Components.Avatar {
0059                 Layout.fillHeight: true
0060                 Layout.preferredWidth: height
0061                 implicitWidth: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
0062                 implicitHeight: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
0063                 source: root.avatarUrl
0064                 name: root.displayName
0065             }
0066             ColumnLayout {
0067                 spacing: 0
0068 
0069                 Layout.fillWidth: true
0070                 Layout.alignment: Qt.AlignVCenter
0071 
0072                 RowLayout {
0073                     Layout.fillWidth: true
0074                     Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
0075                     spacing: Kirigami.Units.largeSpacing
0076                     QQC2.Label {
0077                         id: label
0078                         text: root.displayName
0079                         elide: Text.ElideRight
0080                         textFormat: Text.PlainText
0081                     }
0082                     QQC2.Label {
0083                         visible: root.isJoined || root.isSuggested
0084                         text: root.isJoined ? i18n("Joined") : i18n("Suggested")
0085                         color: root.isJoined ? Kirigami.Theme.linkColor : Kirigami.Theme.disabledTextColor
0086                     }
0087                 }
0088                 QQC2.Label {
0089                     id: subtitle
0090                     Layout.fillWidth: true
0091                     Layout.alignment: Qt.AlignLeft | Qt.AlignTop
0092 
0093                     text: root.memberCount + (root.topic !== "" ? i18nc("number of room members", " members - ") + root.topic : i18nc("number of room members", " members"))
0094                     elide: Text.ElideRight
0095                     font: Kirigami.Theme.smallFont
0096                     textFormat: Text.PlainText
0097                     maximumLineCount: 1
0098                 }
0099             }
0100             QQC2.ToolButton {
0101                 visible: root.isSpace && root.canAddChildren
0102                 text: i18nc("@button", "Add new child")
0103                 icon.name: "list-add"
0104                 display: QQC2.AbstractButton.IconOnly
0105                 onClicked: root.createRoom()
0106 
0107                 QQC2.ToolTip.text: text
0108                 QQC2.ToolTip.visible: hovered
0109                 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0110             }
0111             QQC2.ToolButton {
0112                 visible: root.canRemove
0113                 text: i18nc("@button", "Remove")
0114                 icon.name: "list-remove"
0115                 display: QQC2.AbstractButton.IconOnly
0116                 onClicked: {
0117                     removeChildDialog.createObject(QQC2.ApplicationWindow.overlay, {
0118                         parentRoom: root.parentRoom,
0119                         roomId: root.roomId,
0120                         displayName: root.displayName,
0121                         parentDisplayName: root.parentDisplayName,
0122                         canSetParent: root.canSetParent,
0123                         isDeclaredParent: root.isDeclaredParent
0124                     }).open();
0125                 }
0126 
0127                 QQC2.ToolTip.text: text
0128                 QQC2.ToolTip.visible: hovered
0129                 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0130             }
0131             QQC2.ToolButton {
0132                 visible: root.parentRoom?.canSendState("m.space.child") ?? false
0133                 text: root.isSuggested ? i18nc("@button", "Don't Make Suggested") : i18nc("@button", "Make Suggested")
0134                 icon.name: root.isSuggested ? "edit-delete-remove" : "checkmark"
0135                 display: QQC2.AbstractButton.IconOnly
0136                 onClicked: root.parentRoom.toggleChildSuggested(root.roomId)
0137 
0138                 QQC2.ToolTip.text: text
0139                 QQC2.ToolTip.visible: hovered
0140                 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0141             }
0142         }
0143 
0144         TapHandler {
0145             onTapped: {
0146                 if (root.isSpace) {
0147                     root.treeView.toggleExpanded(row)
0148                 } else {
0149                     if (root.isJoined) {
0150                         root.enterRoom()
0151                     } else {
0152                         RoomManager.resolveResource(root.roomId, "join")
0153                     }
0154                 }
0155             }
0156         }
0157     }
0158 
0159     DelegateSizeHelper {
0160         id: sizeHelper
0161         startBreakpoint: Kirigami.Units.gridUnit * 46
0162         endBreakpoint: Kirigami.Units.gridUnit * 66
0163         startPercentWidth: 100
0164         endPercentWidth: 85
0165         maxWidth: Kirigami.Units.gridUnit * 60
0166 
0167         parentWidth: root.treeView ? root.treeView.width : 0
0168     }
0169 
0170     Component {
0171         id: removeChildDialog
0172         RemoveChildDialog {}
0173     }
0174 }