matrixion/resources/qml/CommunitiesList.qml

228 lines
8.6 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
2021-06-11 14:12:43 +03:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./components"
import QtQml
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import im.nheko
2021-06-11 14:12:43 +03:00
Page {
2021-12-01 02:02:41 +03:00
id: communitySidebar
2023-06-02 02:45:24 +03:00
2021-06-11 14:12:43 +03:00
//leftPadding: Nheko.paddingSmall
//rightPadding: Nheko.paddingSmall
property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 1.6)
property bool collapsed: false
2023-06-02 02:45:24 +03:00
background: Rectangle {
color: Nheko.theme.sidebarBackground
}
2023-01-31 21:34:26 +03:00
// HACK: https://bugreports.qt.io/browse/QTBUG-83972, qtwayland cannot auto hide menu
Connections {
function onHideMenu() {
2023-06-02 02:45:24 +03:00
communityContextMenu.close();
2023-01-31 21:34:26 +03:00
}
2023-06-02 02:45:24 +03:00
2023-01-31 21:34:26 +03:00
target: MainWindow
}
2021-06-11 14:12:43 +03:00
ListView {
id: communitiesList
anchors.left: parent.left
anchors.right: parent.right
height: parent.height
2021-12-01 02:02:41 +03:00
model: Communities.filtered()
boundsBehavior: Flickable.StopAtBounds
2021-06-11 14:12:43 +03:00
ScrollBar.vertical: ScrollBar {
id: scrollbar
2021-06-11 14:12:43 +03:00
2023-06-02 02:45:24 +03:00
parent: !collapsed && Settings.scrollbarsInRoomlist ? communitiesList : null
2021-06-11 14:12:43 +03:00
}
2021-11-04 01:20:28 +03:00
delegate: ItemDelegate {
2021-06-11 14:12:43 +03:00
id: communityItem
property color backgroundColor: palette.window
property color bubbleBackground: palette.highlight
property color bubbleText: palette.highlightedText
2023-06-02 02:45:24 +03:00
property color importantText: palette.text
required property var model
2023-06-02 02:45:24 +03:00
property color unimportantText: palette.buttonText
2021-06-11 14:12:43 +03:00
2023-06-02 02:45:24 +03:00
ToolTip.delay: Nheko.tooltipDelay
ToolTip.text: model.tooltip
ToolTip.visible: hovered && collapsed
2021-06-11 14:12:43 +03:00
height: avatarSize + 2 * Nheko.paddingMedium
state: "normal"
2023-06-02 02:45:24 +03:00
width: ListView.view.width - ((scrollbar.interactive && scrollbar.visible && scrollbar.parent) ? scrollbar.width : 0)
topInset: 0
bottomInset: 0
leftInset: 0
rightInset: 0
2023-06-02 02:45:24 +03:00
background: Rectangle {
color: communityItem.backgroundColor
}
2021-06-11 14:12:43 +03:00
states: [
State {
name: "highlight"
when: (communityItem.hovered || model.hidden) && !(Communities.currentTagId === model.id)
2021-06-11 14:12:43 +03:00
PropertyChanges {
2023-10-26 17:43:09 +03:00
communityItem {
backgroundColor: palette.dark
bubbleBackground: palette.highlight
bubbleText: palette.highlightedText
importantText: palette.brightText
unimportantText: palette.brightText
}
2021-06-11 14:12:43 +03:00
}
},
State {
name: "selected"
when: Communities.currentTagId == model.id
2021-06-11 14:12:43 +03:00
PropertyChanges {
2023-10-26 17:43:09 +03:00
communityItem {
backgroundColor: palette.highlight
bubbleBackground: palette.highlightedText
bubbleText: palette.highlight
importantText: palette.highlightedText
unimportantText: palette.highlightedText
}
2021-06-11 14:12:43 +03:00
}
}
]
2023-06-02 02:45:24 +03:00
onClicked: Communities.setCurrentTagId(model.id)
onPressAndHold: communityContextMenu.show(model.id, model.hidden, model.muted)
2021-11-04 01:20:28 +03:00
Item {
anchors.fill: parent
2021-06-11 14:12:43 +03:00
2021-11-04 01:20:28 +03:00
TapHandler {
acceptedButtons: Qt.RightButton
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
2023-06-02 02:45:24 +03:00
gesturePolicy: TapHandler.ReleaseWithinBounds
2021-06-11 14:12:43 +03:00
2023-06-02 02:45:24 +03:00
onSingleTapped: communityContextMenu.show(model.id, model.hidden, model.muted)
}
2021-06-11 14:12:43 +03:00
}
RowLayout {
2021-12-01 02:02:41 +03:00
id: r
2023-06-02 02:45:24 +03:00
2021-06-11 14:12:43 +03:00
anchors.fill: parent
anchors.leftMargin: Nheko.paddingMedium + (communitySidebar.collapsed ? 0 : (fontMetrics.lineSpacing * model.depth))
2023-06-02 02:45:24 +03:00
anchors.margins: Nheko.paddingMedium
spacing: Nheko.paddingMedium
2021-12-01 02:02:41 +03:00
ImageButton {
2023-06-02 02:45:24 +03:00
Layout.alignment: Qt.AlignVCenter
2021-12-01 02:02:41 +03:00
Layout.preferredHeight: fontMetrics.lineSpacing
Layout.preferredWidth: fontMetrics.lineSpacing
ToolTip.delay: Nheko.tooltipDelay
ToolTip.text: model.collapsed ? qsTr("Expand") : qsTr("Collapse")
2023-06-02 02:45:24 +03:00
ToolTip.visible: hovered
2021-12-01 02:02:41 +03:00
hoverEnabled: true
2023-06-02 02:45:24 +03:00
image: model.collapsed ? ":/icons/icons/ui/collapsed.svg" : ":/icons/icons/ui/expanded.svg"
visible: !communitySidebar.collapsed && model.collapsible
2021-12-01 02:02:41 +03:00
onClicked: model.collapsed = !model.collapsed
2021-12-01 02:02:41 +03:00
}
Item {
Layout.preferredWidth: fontMetrics.lineSpacing
visible: !communitySidebar.collapsed && !model.collapsible && Communities.containsSubspaces
2021-12-01 02:02:41 +03:00
}
2021-06-11 14:12:43 +03:00
Avatar {
id: avatar
Layout.alignment: Qt.AlignVCenter
2023-06-02 02:45:24 +03:00
color: communityItem.backgroundColor
displayName: model.displayName
enabled: false
2023-10-26 17:43:09 +03:00
Layout.preferredHeight: avatarSize
2023-06-02 02:45:24 +03:00
roomid: model.id
2023-10-18 23:43:45 +03:00
textColor: model.avatarUrl?.startsWith(":/") == true ? communityItem.unimportantText : communityItem.importantText
2021-06-11 14:12:43 +03:00
url: {
2023-10-18 23:43:45 +03:00
if (model.avatarUrl?.startsWith("mxc://") == true)
return model.avatarUrl.replace("mxc://", "image://MxcImage/");
2023-10-18 23:43:45 +03:00
else if ((model.avatarUrl?.length ?? 0) > 0)
2023-06-08 03:08:40 +03:00
return model.avatarUrl;
else
2023-06-03 00:03:56 +03:00
return "";
2021-06-11 14:12:43 +03:00
}
2023-10-26 17:43:09 +03:00
Layout.preferredWidth: avatarSize
NotificationBubble {
2023-06-02 02:45:24 +03:00
anchors.bottom: avatar.bottom
anchors.margins: -Nheko.paddingSmall
anchors.right: avatar.right
bubbleBackgroundColor: communityItem.bubbleBackground
bubbleTextColor: communityItem.bubbleText
font.pixelSize: fontMetrics.font.pixelSize * 0.6
2023-06-02 02:45:24 +03:00
hasLoudNotification: model.hasLoudNotification
mayBeVisible: communitySidebar.collapsed && !model.muted && Settings.spaceNotifications
2023-06-02 02:45:24 +03:00
notificationCount: model.unreadMessages
}
2021-06-11 15:51:29 +03:00
}
ElidedLabel {
Layout.alignment: Qt.AlignVCenter
2021-12-01 02:33:22 +03:00
Layout.fillWidth: true
2023-06-02 02:45:24 +03:00
color: communityItem.importantText
2021-12-01 02:33:22 +03:00
elideWidth: width
fullText: model.displayName
2021-06-11 15:51:29 +03:00
textFormat: Text.PlainText
2023-06-02 02:45:24 +03:00
visible: !communitySidebar.collapsed
2021-06-11 15:51:29 +03:00
}
Item {
Layout.fillWidth: true
2021-06-11 14:12:43 +03:00
}
NotificationBubble {
2023-06-02 02:45:24 +03:00
Layout.alignment: Qt.AlignRight
Layout.leftMargin: Nheko.paddingSmall
bubbleBackgroundColor: communityItem.bubbleBackground
bubbleTextColor: communityItem.bubbleText
2023-06-02 02:45:24 +03:00
hasLoudNotification: model.hasLoudNotification
mayBeVisible: !communitySidebar.collapsed && !model.muted && Settings.spaceNotifications
2023-06-02 02:45:24 +03:00
notificationCount: model.unreadMessages
}
2021-06-11 14:12:43 +03:00
}
2023-06-02 02:45:24 +03:00
}
2021-06-11 14:12:43 +03:00
Menu {
2023-06-02 02:45:24 +03:00
id: communityContextMenu
property bool hidden
property bool muted
property string tagId
function show(id_, hidden_, muted_) {
tagId = id_;
hidden = hidden_;
muted = muted_;
open();
2021-11-11 23:32:38 +03:00
}
MenuItem {
2023-06-02 02:45:24 +03:00
checkable: true
checked: communityContextMenu.muted
text: qsTr("Do not show notification counts for this community or tag.")
2021-06-11 14:12:43 +03:00
2023-06-02 02:45:24 +03:00
onTriggered: Communities.toggleTagMute(communityContextMenu.tagId)
}
MenuItem {
2023-06-02 02:45:24 +03:00
checkable: true
checked: communityContextMenu.hidden
text: qsTr("Hide rooms with this tag or from this community by default.")
2021-06-11 14:12:43 +03:00
2023-06-02 02:45:24 +03:00
onTriggered: Communities.toggleTagId(communityContextMenu.tagId)
}
}
2021-06-11 14:12:43 +03:00
}
}