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 
0038     Delegates.RoundedItemDelegate {
0039         anchors.centerIn: root
0040         width: sizeHelper.currentWidth
0041 
0042         contentItem: RowLayout {
0043             spacing: Kirigami.Units.largeSpacing
0044 
0045             RowLayout {
0046                 spacing: 0
0047                 Item {
0048                     Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium * (root.depth + (root.isSpace ? 0 : 1))
0049                 }
0050                 Kirigami.Icon {
0051                     visible: root.isSpace
0052                     implicitWidth: Kirigami.Units.iconSizes.smallMedium
0053                     implicitHeight: Kirigami.Units.iconSizes.smallMedium
0054                     source: root.hasChildren ? (root.expanded ? "go-up" : "go-down") : "go-next"
0055                 }
0056             }
0057             Components.Avatar {
0058                 Layout.fillHeight: true
0059                 Layout.preferredWidth: height
0060                 implicitWidth: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
0061                 implicitHeight: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
0062                 source: root.avatarUrl
0063                 name: root.displayName
0064             }
0065             ColumnLayout {
0066                 spacing: 0
0067 
0068                 Layout.fillWidth: true
0069                 Layout.alignment: Qt.AlignVCenter
0070 
0071                 RowLayout {
0072                     Layout.fillWidth: true
0073                     Layout.alignment: Qt.AlignLeft | Qt.AlignBottom
0074                     spacing: Kirigami.Units.largeSpacing
0075                     QQC2.Label {
0076                         id: label
0077                         text: root.displayName
0078                         elide: Text.ElideRight
0079                         textFormat: Text.PlainText
0080                     }
0081                     QQC2.Label {
0082                         visible: root.isJoined || root.isSuggested
0083                         text: root.isJoined ? i18n("Joined") : i18n("Suggested")
0084                         color: root.isJoined ? Kirigami.Theme.linkColor : Kirigami.Theme.disabledTextColor
0085                     }
0086                 }
0087                 QQC2.Label {
0088                     id: subtitle
0089                     Layout.fillWidth: true
0090                     Layout.alignment: Qt.AlignLeft | Qt.AlignTop
0091 
0092                     text: root.memberCount + (root.topic !== "" ? i18nc("number of room members", " members - ") + root.topic : i18nc("number of room members", " members"))
0093                     elide: Text.ElideRight
0094                     font: Kirigami.Theme.smallFont
0095                     textFormat: Text.PlainText
0096                     maximumLineCount: 1
0097                 }
0098             }
0099             QQC2.ToolButton {
0100                 visible: root.isSpace && root.canAddChildren
0101                 text: i18nc("@button", "Add new child")
0102                 icon.name: "list-add"
0103                 display: QQC2.AbstractButton.IconOnly
0104                 onClicked: root.createRoom()
0105 
0106                 QQC2.ToolTip.text: text
0107                 QQC2.ToolTip.visible: hovered
0108                 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0109             }
0110             QQC2.ToolButton {
0111                 visible: root.canRemove
0112                 text: i18nc("@button", "Remove")
0113                 icon.name: "list-remove"
0114                 display: QQC2.AbstractButton.IconOnly
0115                 onClicked: {
0116                     removeChildDialog.createObject(QQC2.ApplicationWindow.overlay, {
0117                         parentRoom: root.parentRoom,
0118                         roomId: root.roomId,
0119                         displayName: root.displayName,
0120                         parentDisplayName: root.parentDisplayName,
0121                         canSetParent: root.canSetParent,
0122                         isDeclaredParent: root.isDeclaredParent
0123                     }).open();
0124                 }
0125 
0126                 QQC2.ToolTip.text: text
0127                 QQC2.ToolTip.visible: hovered
0128                 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0129             }
0130             QQC2.ToolButton {
0131                 visible: root.parentRoom?.canSendState("m.space.child") ?? false
0132                 text: root.isSuggested ? i18nc("@button", "Don't Make Suggested") : i18nc("@button", "Make Suggested")
0133                 icon.name: root.isSuggested ? "edit-delete-remove" : "checkmark"
0134                 display: QQC2.AbstractButton.IconOnly
0135                 onClicked: root.parentRoom.toggleChildSuggested(root.roomId)
0136 
0137                 QQC2.ToolTip.text: text
0138                 QQC2.ToolTip.visible: hovered
0139                 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0140             }
0141         }
0142 
0143         TapHandler {
0144             onTapped: {
0145                 if (root.isSpace) {
0146                     root.treeView.toggleExpanded(row);
0147                 } else {
0148                     RoomManager.resolveResource(root.roomId, root.isJoined ? "" : "join");
0149                 }
0150             }
0151         }
0152     }
0153 
0154     DelegateSizeHelper {
0155         id: sizeHelper
0156         startBreakpoint: Kirigami.Units.gridUnit * 46
0157         endBreakpoint: Kirigami.Units.gridUnit * 66
0158         startPercentWidth: 100
0159         endPercentWidth: 85
0160         maxWidth: Kirigami.Units.gridUnit * 60
0161 
0162         parentWidth: root.treeView ? root.treeView.width : 0
0163     }
0164 
0165     Component {
0166         id: removeChildDialog
0167         RemoveChildDialog {}
0168     }
0169 }