matrixion/resources/qml/CommunitiesList.qml

223 lines
8.5 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"
2021-06-11 14:12:43 +03:00
import "./dialogs"
import Qt.labs.platform 1.1 as Platform
2021-06-13 02:48:11 +03:00
import QtQml 2.12
import QtQuick 2.12
import QtQuick.Controls 2.5
2021-06-11 14:12:43 +03:00
import QtQuick.Layouts 1.3
import im.nheko 1.0
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()
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)
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 {
backgroundColor: palette.dark
bubbleBackground: palette.highlight
bubbleText: palette.highlightedText
2023-06-02 02:45:24 +03:00
importantText: palette.brightText
target: communityItem
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 {
backgroundColor: palette.highlight
bubbleBackground: palette.highlightedText
bubbleText: palette.highlight
2023-06-02 02:45:24 +03:00
importantText: palette.highlightedText
target: communityItem
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
height: fontMetrics.lineSpacing
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
width: fontMetrics.lineSpacing
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
2021-06-11 14:12:43 +03:00
height: avatarSize
2023-06-02 02:45:24 +03:00
roomid: model.id
2021-06-11 14:12:43 +03:00
url: {
if (model.avatarUrl.startsWith("mxc://"))
return model.avatarUrl.replace("mxc://", "image://MxcImage/");
2023-06-03 00:03:56 +03:00
else if (model.avatarUrl.length > 0)
return "image://colorimage/" + model.avatarUrl + "?" + communityItem.unimportantText;
2023-06-03 00:03:56 +03:00
else
return "";
2021-06-11 14:12:43 +03:00
}
2023-06-02 02:45:24 +03:00
width: 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
2023-06-02 02:45:24 +03:00
Platform.Menu {
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
}
2023-06-02 02:45:24 +03:00
Platform.MenuItem {
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)
}
Platform.MenuItem {
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
}
}