You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nheko/resources/qml/CommunitiesList.qml

223 lines
8.5 KiB

// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./components"
import "./dialogs"
import Qt.labs.platform 1.1 as Platform
import QtQml 2.12
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import im.nheko 1.0
Page {
id: communitySidebar
2 years ago
//leftPadding: Nheko.paddingSmall
//rightPadding: Nheko.paddingSmall
property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 1.6)
property bool collapsed: false
2 years ago
background: Rectangle {
color: Nheko.theme.sidebarBackground
}
// HACK: https://bugreports.qt.io/browse/QTBUG-83972, qtwayland cannot auto hide menu
Connections {
function onHideMenu() {
2 years ago
communityContextMenu.close();
}
2 years ago
target: MainWindow
}
ListView {
id: communitiesList
anchors.left: parent.left
anchors.right: parent.right
height: parent.height
model: Communities.filtered()
ScrollBar.vertical: ScrollBar {
id: scrollbar
2 years ago
parent: !collapsed && Settings.scrollbarsInRoomlist ? communitiesList : null
}
delegate: ItemDelegate {
id: communityItem
property color backgroundColor: palette.window
property color bubbleBackground: palette.highlight
property color bubbleText: palette.highlightedText
2 years ago
property color importantText: palette.text
required property var model
2 years ago
property color unimportantText: palette.buttonText
2 years ago
ToolTip.delay: Nheko.tooltipDelay
ToolTip.text: model.tooltip
ToolTip.visible: hovered && collapsed
height: avatarSize + 2 * Nheko.paddingMedium
state: "normal"
2 years ago
width: ListView.view.width - ((scrollbar.interactive && scrollbar.visible && scrollbar.parent) ? scrollbar.width : 0)
background: Rectangle {
color: communityItem.backgroundColor
}
states: [
State {
name: "highlight"
when: (communityItem.hovered || model.hidden) && !(Communities.currentTagId === model.id)
PropertyChanges {
backgroundColor: palette.dark
bubbleBackground: palette.highlight
bubbleText: palette.highlightedText
2 years ago
importantText: palette.brightText
target: communityItem
unimportantText: palette.brightText
}
},
State {
name: "selected"
when: Communities.currentTagId == model.id
PropertyChanges {
backgroundColor: palette.highlight
bubbleBackground: palette.highlightedText
bubbleText: palette.highlight
2 years ago
importantText: palette.highlightedText
target: communityItem
unimportantText: palette.highlightedText
}
}
]
2 years ago
onClicked: Communities.setCurrentTagId(model.id)
onPressAndHold: communityContextMenu.show(model.id, model.hidden, model.muted)
Item {
anchors.fill: parent
TapHandler {
acceptedButtons: Qt.RightButton
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
2 years ago
gesturePolicy: TapHandler.ReleaseWithinBounds
2 years ago
onSingleTapped: communityContextMenu.show(model.id, model.hidden, model.muted)
}
}
RowLayout {
id: r
2 years ago
anchors.fill: parent
anchors.leftMargin: Nheko.paddingMedium + (communitySidebar.collapsed ? 0 : (fontMetrics.lineSpacing * model.depth))
2 years ago
anchors.margins: Nheko.paddingMedium
spacing: Nheko.paddingMedium
ImageButton {
2 years ago
Layout.alignment: Qt.AlignVCenter
Layout.preferredHeight: fontMetrics.lineSpacing
Layout.preferredWidth: fontMetrics.lineSpacing
ToolTip.delay: Nheko.tooltipDelay
ToolTip.text: model.collapsed ? qsTr("Expand") : qsTr("Collapse")
2 years ago
ToolTip.visible: hovered
height: fontMetrics.lineSpacing
hoverEnabled: true
2 years ago
image: model.collapsed ? ":/icons/icons/ui/collapsed.svg" : ":/icons/icons/ui/expanded.svg"
visible: !communitySidebar.collapsed && model.collapsible
width: fontMetrics.lineSpacing
onClicked: model.collapsed = !model.collapsed
}
Item {
Layout.preferredWidth: fontMetrics.lineSpacing
visible: !communitySidebar.collapsed && !model.collapsible && Communities.containsSubspaces
}
Avatar {
id: avatar
Layout.alignment: Qt.AlignVCenter
2 years ago
color: communityItem.backgroundColor
displayName: model.displayName
enabled: false
height: avatarSize
2 years ago
roomid: model.id
url: {
if (model.avatarUrl.startsWith("mxc://"))
return model.avatarUrl.replace("mxc://", "image://MxcImage/");
else if (model.avatarUrl.length > 0)
return "image://colorimage/" + model.avatarUrl + "?" + communityItem.unimportantText;
else
return "";
}
2 years ago
width: avatarSize
NotificationBubble {
2 years ago
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
2 years ago
hasLoudNotification: model.hasLoudNotification
mayBeVisible: communitySidebar.collapsed && !model.muted && Settings.spaceNotifications
2 years ago
notificationCount: model.unreadMessages
}
}
ElidedLabel {
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
2 years ago
color: communityItem.importantText
elideWidth: width
fullText: model.displayName
textFormat: Text.PlainText
2 years ago
visible: !communitySidebar.collapsed
}
Item {
Layout.fillWidth: true
}
NotificationBubble {
2 years ago
Layout.alignment: Qt.AlignRight
Layout.leftMargin: Nheko.paddingSmall
bubbleBackgroundColor: communityItem.bubbleBackground
bubbleTextColor: communityItem.bubbleText
2 years ago
hasLoudNotification: model.hasLoudNotification
mayBeVisible: !communitySidebar.collapsed && !model.muted && Settings.spaceNotifications
2 years ago
notificationCount: model.unreadMessages
}
}
2 years ago
}
2 years ago
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();
3 years ago
}
2 years ago
Platform.MenuItem {
checkable: true
checked: communityContextMenu.muted
text: qsTr("Do not show notification counts for this community or tag.")
2 years ago
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.")
2 years ago
onTriggered: Communities.toggleTagId(communityContextMenu.tagId)
}
}
}
}