// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL import QtQuick import QtQuick.Layouts import QtQuick.Controls as QQC2 import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.delegates as Delegates import org.kde.kirigamiaddons.components as Components import koutnet.app // RoundedItemDelegate rather than a hand-written Rectangle: rounding, hover tint, // pressed state, selection fill and focus ring come with it and follow the scheme. // It binds its own width to its view, so elsewhere it must be handed one. Delegates.RoundedItemDelegate { id: root // The row paints itself out of the theme colours of whatever holds it: hover, // selection and focus all read from them, which is what puts the wallpaper and // the accent into the chosen row. inherit is left alone on purpose: it is what // stops a row taking colours from a sheet it happens to be drawn in. Kirigami.Theme.backgroundColor: ThemePalette.surfaceRaised Kirigami.Theme.textColor: ThemePalette.text Kirigami.Theme.hoverColor: ThemePalette.hover Kirigami.Theme.focusColor: ThemePalette.accent Kirigami.Theme.highlightColor: ThemePalette.accent Kirigami.Theme.highlightedTextColor: ThemePalette.accentText property string displayName: "" property string preview: "" property double stampSecs: 0 property double lastSeenSecs: 0 property int unreadCount: 0 property bool online: false property bool selected: false // A Breeze icon name for a pinned row: a blank Avatar name is what makes it // fall through to its icon instead of drawing initials. property string iconName: "" // A media URL for the avatar, empty when the row draws an initial. A LAN peer // pushes its picture over TLS and it arrives the same way as Matrix's. property string avatarSource: "" property bool showPresence: true // "lan", "matrix" or "reserved", straight off ChatListModel's transport role: // everything the row is told about where the conversation lives. property string transport: "lan" // DISABLE_FOR_NOW - hide element/behavior temporarily (code kept). // ALLOW_RIGHT_NOW - show/enable element/behavior now. readonly property bool kShowTransportBadge: false // DISABLE_FOR_NOW: hide transport symbol above avatar in chat list // in compact mode the preview and the stamp go, which is what takes the row // from two lines to one, and the avatar comes down a size. property bool compact: false // The column dragged down to a strip of avatars: name, preview, stamp and count // all go, leaving a face - the most a column this narrow can say. Not compact, // which is a smaller avatar with the name still on the row. property bool avatarOnly: false // Empty in compact mode, which makes SubtitleContentItem lay itself out on one // line. Empty in a strip of avatars too, where the item is hidden outright. readonly property string subtitleText: (root.compact || root.avatarOnly) ? "" : (root.preview.length > 0 ? root.preview : (root.showPresence ? RelativeTime.presenceLabel(root.online, root.lastSeenSecs, RelativeTime.now) : "")) // Twice the size it started at, and then some: forty is what it settled at, a // size Kirigami has no name for. A compact row keeps its three-quarter share, // so the dot and room mark follow, and the row takes its height from the slot. // A strip of avatars keeps the full size: the avatar is the entire row there. readonly property int listAvatarSize: 40 readonly property real avatarSize: (root.compact && !root.avatarOnly) ? Math.round(root.listAvatarSize * 0.75) : root.listAvatarSize // Centred in the column and taking all of it: a row this narrow has nothing // else, which is what makes the strip read as a column of faces. readonly property bool centred: root.avatarOnly signal avatarClicked(Item anchorItem) text: root.displayName // the base class ties this to the view's current item. Selection here means // which conversation is open, which the view knows nothing about. highlighted: root.selected // The accent is taken straight from the theme palette rather than from // Kirigami.Theme.highlightColor: a row created inside a folder's component // can inherit that attached property from somewhere else and end up with // the scheme's default blue while the pinned row keeps the picked accent. background: Rectangle { radius: Kirigami.Units.cornerRadius readonly property bool marked: root.highlighted || root.checked || (root.down && !root.checked) || root.visualFocus readonly property color accent: ThemePalette.accent color: { if (appSettings.chatOutlineSelection && marked) return "transparent" if (marked) { const highlight = Kirigami.ColorUtils.tintWithAlpha(AppPalette.background, accent, 0.3) if (root.hovered) return Kirigami.ColorUtils.tintWithAlpha(highlight, accent, 0.15) return highlight.valid ? highlight : "transparent" } if (root.hovered) return Kirigami.ColorUtils.tintWithAlpha(AppPalette.background, accent, 0.18) return "transparent" } border { color: accent width: (appSettings.chatOutlineSelection && marked) || root.visualFocus || root.activeFocus ? 1 : 0 } } // At one line the base class's padding is most of the row's height, so it comes // down through a Binding, keeping the roomy value instead of a stale copy. A // strip of avatars gets the same: the space keeps two faces from reading as one. Binding { target: root property: "verticalPadding" value: Kirigami.Units.smallSpacing when: root.compact || root.avatarOnly restoreMode: Binding.RestoreBindingOrValue } // The roomy padding is what Main.qml measures the column's minimum width // around, and it is too much here: the avatar is the whole row. Small here, // and the handle's stop is this padding twice over plus the avatar. Binding { target: root property: "leftPadding" value: Kirigami.Units.smallSpacing when: root.avatarOnly restoreMode: Binding.RestoreBindingOrValue } Binding { target: root property: "rightPadding" value: Kirigami.Units.smallSpacing when: root.avatarOnly restoreMode: Binding.RestoreBindingOrValue } contentItem: RowLayout { spacing: Kirigami.Units.smallSpacing Item { id: avatarSlot // Centred only when the avatar is the whole row. Layout.alignment // rather than anchors, so the layout still owns the position. Layout.alignment: root.centred ? Qt.AlignCenter : Qt.AlignVCenter implicitWidth: root.avatarSize implicitHeight: root.avatarSize // Taken before the delegate's own tap handling, so the card opens // instead of the conversation. TapHandler { acceptedButtons: Qt.LeftButton gesturePolicy: TapHandler.ReleaseWithinBounds onTapped: root.avatarClicked(avatarSlot) } HoverHandler { id: avatarHover cursorShape: Qt.PointingHandCursor } // The name is not drawn in a strip of avatars, so hovering is the only // way to be told which conversation a face belongs to. Only there: the // same string is the delegate's accessible text at every width. QQC2.ToolTip.visible: avatarHover.hovered && root.avatarOnly QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: root.displayName AnimatedAvatar { anchors.fill: parent // left on its generated per-name colour: every avatar used to be // the one accent colour, which made a column of identical circles. name: root.iconName.length > 0 ? "" : root.displayName // Pick the symbolic variant for dark themes. iconSource: root.iconName.length > 0 ? (AppPalette.dark ? root.iconName + "-symbolic" : root.iconName) : "" source: root.avatarSource.length > 0 ? root.avatarSource : "" } // Only for someone who is here: a grey circle on every peer says nothing. // The subtitle already says when a peer was last seen. Rectangle { // Off the avatar rather than off an icon size, so the dot keeps // its share of the circle when the circle changes size. width: Math.round(root.avatarSize * 0.2) height: width radius: width / 2 anchors.right: parent.right anchors.bottom: parent.bottom // Out of the dot's corner when the dot is there too: the count sits // in the corner and the dot immediately to its left. anchors.rightMargin: unreadBadgeOnAvatar.visible ? unreadBadgeOnAvatar.width + Kirigami.Units.smallSpacing : 0 visible: root.showPresence && root.online color: AppPalette.positiveText border.color: ThemePalette.surface border.width: 1 } // A conversation not on this network says so, since everything else is // deliberately identical to a LAN peer's. Top corner: presence owns the bottom. Kirigami.Icon { // As the dot: a share of the avatar, so the two marks over it // stay in proportion to whatever the circle is. width: Math.round(root.avatarSize * 0.24) height: width anchors.right: parent.right anchors.top: parent.top visible: root.kShowTransportBadge && root.transport === "matrix" // DISABLE_FOR_NOW (see kShowTransportBadge) source: "network-server" color: ThemePalette.accent QQC2.ToolTip.visible: hoverHandler.hovered QQC2.ToolTip.text: i18nc("@info:tooltip conversation list badge", "Matrix room") HoverHandler { id: hoverHandler } } // The unread count moves onto the circle when the name and stamp are // gone - the one thing that must be visible across a room. It may // overhang the corner rather than shrink, and the presence dot moves // aside for it (see the binding on the dot above). Rectangle { id: unreadBadgeOnAvatar anchors.right: parent.right anchors.bottom: parent.bottom anchors.rightMargin: -Math.round(root.avatarSize * 0.1) anchors.bottomMargin: -Math.round(root.avatarSize * 0.08) width: Math.max(height, unreadOnAvatar.implicitWidth + Kirigami.Units.smallSpacing) height: Math.round(root.avatarSize * 0.34) radius: height / 2 color: ThemePalette.accent // Against whatever the avatar happens to be, so a count stays // readable on a dark picture as well as a light one. border.color: ThemePalette.surface border.width: 2 visible: root.avatarOnly && root.unreadCount > 0 Accessible.role: Accessible.StaticText Accessible.name: i18ncp("@info:whatsthis unread messages in this conversation, %1 is a number", "%1 unread message", "%1 unread messages", root.unreadCount) QQC2.Label { id: unreadOnAvatar anchors.centerIn: parent text: root.unreadCount > 99 ? i18nc("@info unread count too large to show exactly", "99+") : String(root.unreadCount) font.pointSize: Math.max(6, Kirigami.Theme.smallFont.pointSize * 0.8) font.bold: true color: ThemePalette.accentText } } } // The name, preview and right-hand column are gone once the column is a // strip: at this width they elide to noise. The name still exists as the // accessible label and the avatar tooltip, so the row is still identified. Delegates.SubtitleContentItem { itemDelegate: root Layout.fillWidth: true visible: !root.avatarOnly subtitle: root.subtitleText bold: root.unreadCount > 0 } ColumnLayout { Layout.alignment: Qt.AlignVCenter // The unread count is drawn on the avatar in this width instead, so // this column is empty and is not laid out. visible: !root.avatarOnly spacing: 0 QQC2.Label { Layout.alignment: Qt.AlignRight visible: !root.compact && text.length > 0 text: root.stampSecs > 0 ? RelativeTime.chatStamp(root.stampSecs, RelativeTime.now) : "" font: Kirigami.Theme.smallFont color: AppPalette.disabledText } // Kirigami has no unread badge in the version this targets; sized to // its label rather than a fixed box a three-digit count spills out of. Rectangle { Layout.alignment: Qt.AlignRight visible: !root.avatarOnly && root.unreadCount > 0 implicitWidth: Math.max(height, unreadLabel.implicitWidth + Kirigami.Units.smallSpacing * 2) implicitHeight: Math.round(Kirigami.Units.gridUnit * 1.1) radius: height / 2 color: ThemePalette.accent Accessible.role: Accessible.StaticText Accessible.name: i18ncp("@info:whatsthis unread messages in this conversation, %1 is a number", "%1 unread message", "%1 unread messages", root.unreadCount) QQC2.Label { id: unreadLabel anchors.centerIn: parent // past two digits the count is a layout problem, not news. text: root.unreadCount > 99 ? i18nc("@info unread count too large to show exactly", "99+") : String(root.unreadCount) font.pointSize: Kirigami.Theme.smallFont.pointSize font.bold: true color: ThemePalette.accentText } } } } }