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

0001 // SPDX-FileCopyrightText: 2020-2023 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-FileCopyrightText: 2021-2022 Bart De Vries <bart@mogwai.be>
0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 import QtQuick
0006 import QtQuick.Controls as QQC2
0007 import QtQuick.Layouts
0008 
0009 import org.kde.kirigami as Kirigami
0010 
0011 import org.kde.neochat
0012 
0013 QQC2.Control {
0014     id: root
0015 
0016     readonly property real pinnedWidth: Kirigami.Units.gridUnit * 6
0017     property bool drawerEnabled: true
0018 
0019     required property NeoChatConnection connection
0020 
0021     leftPadding: 0
0022     rightPadding: 0
0023     topPadding: 0
0024     bottomPadding: 0
0025 
0026     property string selectedSpaceId
0027 
0028     contentItem: Loader {
0029         id: sidebarColumn
0030         active: root.drawerEnabled
0031         z: 0
0032 
0033         sourceComponent: ColumnLayout {
0034             spacing: 0
0035 
0036             QQC2.ScrollView {
0037                 id: scrollView
0038                 Layout.fillWidth: true
0039                 Layout.fillHeight: true
0040 
0041                 QQC2.ScrollBar.vertical.policy: QQC2.ScrollBar.AlwaysOff
0042                 QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff
0043                 contentWidth: -1 // disable horizontal scroll
0044 
0045                 background: Rectangle {
0046                     color: Kirigami.Theme.backgroundColor
0047                     Kirigami.Theme.colorSet: Kirigami.Theme.View
0048                 }
0049 
0050                 ColumnLayout {
0051                     id: column
0052                     width: scrollView.width
0053                     spacing: 0
0054 
0055                     AvatarTabButton {
0056                         id: allRoomButton
0057 
0058                         Layout.fillWidth: true
0059                         Layout.preferredHeight: width - Kirigami.Units.smallSpacing
0060                         Layout.maximumHeight: width - Kirigami.Units.smallSpacing
0061                         Layout.topMargin: Kirigami.Units.smallSpacing / 2
0062 
0063                         text: i18n("All Rooms")
0064                         source: "globe"
0065 
0066                         contentItem: Kirigami.Icon {
0067                             source: "globe"
0068                         }
0069 
0070                         checked: root.selectedSpaceId === ""
0071                         onClicked: root.selectedSpaceId = ""
0072                     }
0073 
0074                     Repeater {
0075                         model: SortFilterSpaceListModel {
0076                             sourceModel: RoomListModel {
0077                                 connection: root.connection
0078                             }
0079                         }
0080                         onCountChanged: {
0081                             root.enabled = count > 0
0082                             if (!root.connection.room(root.selectedSpaceId)) {
0083                                 root.selectedSpaceId = ""
0084                             }
0085                         }
0086                         Component.onCompleted: root.enabled = count > 0
0087 
0088                         delegate: AvatarTabButton {
0089                             id: spaceDelegate
0090 
0091                             required property string displayName
0092                             required property string avatar
0093                             required property string roomId
0094                             required property var currentRoom
0095 
0096                             Layout.fillWidth: true
0097                             Layout.preferredHeight: width - Kirigami.Units.smallSpacing
0098                             Layout.maximumHeight: width - Kirigami.Units.smallSpacing
0099 
0100                             text: displayName
0101                             source: avatar ? ("image://mxc/" + avatar) : ""
0102 
0103                             onSelected: root.selectedSpaceId = roomId
0104                             checked: root.selectedSpaceId === roomId
0105                             onContextMenuRequested: root.createContextMenu(currentRoom)
0106                         }
0107                     }
0108                 }
0109             }
0110         }
0111     }
0112 
0113     function createContextMenu(room) {
0114         let context = spaceListContextMenu.createObject(root, {
0115             room: room,
0116             connection: root.connection
0117         });
0118         context.open()
0119     }
0120     Component {
0121         id: spaceListContextMenu
0122         SpaceListContextMenu {}
0123     }
0124 }