pragma ComponentBehavior: Bound import QtQuick import "../theme" // Pill-shaped single choice with a sliding accent indicator. Rectangle { id: root property var model: [] property int currentIndex: -1 signal activated(int index, string value) // Prettify config keywords ("top-left"); leave names such as "DP-4" untouched. function label(value) { const raw = String(value); if (!/^[a-z][a-z0-9_-]*$/.test(raw)) return raw; const text = raw.replace(/[-_]/g, " "); return text.charAt(0).toUpperCase() + text.slice(1); } implicitWidth: row.implicitWidth + 8 implicitHeight: 34 radius: height / 2 color: Theme.surfaceVariant border.width: 1 border.color: Theme.border Rectangle { readonly property Item target: root.currentIndex >= 0 && root.currentIndex < segments.count ? segments.itemAt(root.currentIndex) : null visible: target !== null x: target ? row.x + target.x : 4 y: 4 width: target ? target.width : 0 height: root.height - 8 radius: height / 2 color: Theme.accent Behavior on x { NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } Behavior on width { NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } } Row { id: row anchors.centerIn: parent Repeater { id: segments model: root.model Item { id: segment required property var modelData required property int index readonly property bool selected: root.currentIndex === index width: Math.max(52, caption.implicitWidth + 24) height: root.height - 8 Text { id: caption anchors.centerIn: parent text: root.label(segment.modelData) font.pixelSize: 12 font.weight: segment.selected ? Font.DemiBold : Font.Normal color: segment.selected ? Theme.accentText : area.containsMouse ? Theme.text : Theme.textSecondary Behavior on color { ColorAnimation { duration: Theme.duration / 2 } } } MouseArea { id: area anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: root.activated(segment.index, String(segment.modelData)) } } } } }