// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL import QtQuick import QtQuick.Controls as QQC2 import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.delegates as Delegates import koutnet.app // RoundedItemDelegate rather than a ToolButton so the selected state follows the // delegates around it - on a rail of identical circles the current mode is best // said by a ring, which leaves the button itself untinted. The user can ask for // the delegate's usual fill instead. Delegates.RoundedItemDelegate { id: root // NetworkManager.ConnectionMode, as an int - the enum is not registered in // QML and the persisted setting is an int either way. required property int mode required property string modeName property string unavailableReason: "" property bool current: false // unseen messages for this mode; the list hides other modes, the badge shows them property int unread: 0 signal picked() readonly property bool available: root.unavailableReason.length === 0 // the base class ties this to the view's current item; the rail is a column // and has no current item, so it is said here instead. checked: root.current enabled: root.available // an unreachable mode is greyed rather than hidden: a button that appears // later moves everything under it. opacity: root.available ? 1 : 0.45 activeFocusOnTab: true Accessible.name: root.modeName Accessible.description: root.unavailableReason Accessible.onPressAction: root.picked() Keys.onSpacePressed: root.picked() Keys.onEnterPressed: root.picked() Keys.onReturnPressed: root.picked() onClicked: root.picked() // The current mode is either a ring around the button or the delegate's // tinted fill, by the user's choice. Hover keeps a slight wash in both. background: Rectangle { radius: Kirigami.Units.cornerRadius readonly property bool outline: appSettings.railOutlineSelection readonly property bool selected: root.current || root.checked color: { if (outline) { return (root.hovered || root.dropAreaHovered) ? Kirigami.ColorUtils.tintWithAlpha(AppPalette.background, AppPalette.text, 0.10) : "transparent" } if (selected || (root.down && !root.checked) || root.visualFocus) { const highlight = Kirigami.ColorUtils.tintWithAlpha(AppPalette.background, AppPalette.highlight, 0.3) if (root.hovered || root.dropAreaHovered) return Kirigami.ColorUtils.tintWithAlpha(highlight, AppPalette.text, 0.10) return highlight.valid ? highlight : "transparent" } if (root.hovered || root.dropAreaHovered) return Kirigami.ColorUtils.tintWithAlpha(AppPalette.background, AppPalette.text, 0.10) return "transparent" } border { color: outline ? ThemePalette.accent : AppPalette.highlight width: outline ? (selected || root.visualFocus || root.activeFocus ? 1 : 0) : (root.visualFocus || root.activeFocus ? 1 : 0) } } QQC2.ToolTip.visible: root.hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: root.available ? (root.current ? i18nc("@info:tooltip the connection mode in use, %1 is its name", "%1 - in use", root.modeName) : root.modeName) : i18nc("@info:tooltip a connection mode that cannot be used, %1 is its name, %2 says why", "%1 - %2", root.modeName, root.unavailableReason) contentItem: Kirigami.Icon { source: root.icon.name implicitWidth: Kirigami.Units.iconSizes.smallMedium implicitHeight: Kirigami.Units.iconSizes.smallMedium color: root.current ? ThemePalette.accent : ThemePalette.text isMask: true } // drawn on top of the icon, not inside contentItem Item { anchors.fill: parent visible: root.unread > 0 z: 2 Rectangle { id: badge width: Math.max(Kirigami.Units.iconSizes.small, label.implicitWidth + Kirigami.Units.smallSpacing) height: width radius: width / 2 color: AppPalette.negativeText anchors.top: parent.top anchors.right: parent.right anchors.margins: -Kirigami.Units.smallSpacing Text { id: label anchors.centerIn: parent text: root.unread > 99 ? i18nc("@info a large unread count is capped", "99+") : String(root.unread) color: "white" font.pointSize: Kirigami.Theme.smallFont.pointSize font.family: Kirigami.Theme.smallFont.family } } } }