extract HoverableListItem component from list delegates

This commit is contained in:
Damocles 2026-04-23 23:36:03 +02:00
parent 85e32dcd8c
commit e712842424
5 changed files with 29 additions and 47 deletions

View file

@ -9,24 +9,13 @@ Column {
Repeater { Repeater {
model: S.BluetoothService.devices model: S.BluetoothService.devices
delegate: Item { delegate: HoverableListItem {
id: entry id: entry
required property var modelData required property var modelData
required property int index required property int index
readonly property bool _pending: S.BluetoothService.pendingMac === entry.modelData.mac readonly property bool _pending: S.BluetoothService.pendingMac === entry.modelData.mac
width: root.width
height: 32
Rectangle {
anchors.fill: parent
anchors.leftMargin: 4
anchors.rightMargin: 4
color: entryHover.hovered ? S.Theme.base02 : "transparent"
radius: S.Theme.radius
}
Text { Text {
id: btIcon id: btIcon
anchors.left: parent.left anchors.left: parent.left
@ -83,10 +72,6 @@ Column {
entry.opacity = 1 entry.opacity = 1
} }
HoverHandler {
id: entryHover
cursorShape: Qt.PointingHandCursor
}
TapHandler { TapHandler {
onTapped: { onTapped: {
if (!entry._pending) if (!entry._pending)

View file

@ -0,0 +1,25 @@
import QtQuick
import "../services" as S
Item {
id: root
readonly property bool hovered: _hover.hovered
width: parent?.width ?? 0
height: 32
Rectangle {
anchors.fill: parent
anchors.leftMargin: 4
anchors.rightMargin: 4
color: root.hovered ? S.Theme.base02 : "transparent"
radius: S.Theme.radius
z: -1
}
HoverHandler {
id: _hover
cursorShape: Qt.PointingHandCursor
}
}

View file

@ -9,22 +9,11 @@ Column {
Repeater { Repeater {
model: S.NetworkService.networks model: S.NetworkService.networks
delegate: Item { delegate: HoverableListItem {
id: entry id: entry
required property var modelData required property var modelData
required property int index required property int index
width: root.width
height: 32
Rectangle {
anchors.fill: parent
anchors.leftMargin: 4
anchors.rightMargin: 4
color: entryHover.hovered ? S.Theme.base02 : "transparent"
radius: S.Theme.radius
}
Text { Text {
id: netIcon id: netIcon
anchors.left: parent.left anchors.left: parent.left
@ -62,10 +51,6 @@ Column {
width: entry.modelData.signal >= 0 ? implicitWidth : 0 width: entry.modelData.signal >= 0 ? implicitWidth : 0
} }
HoverHandler {
id: entryHover
cursorShape: Qt.PointingHandCursor
}
TapHandler { TapHandler {
onTapped: { onTapped: {
if (entry.modelData.active) if (entry.modelData.active)

View file

@ -121,22 +121,13 @@ Column {
Repeater { Repeater {
model: root.sinkList model: root.sinkList
delegate: Item { delegate: HoverableListItem {
required property var modelData required property var modelData
width: root.width
height: 28 height: 28
readonly property bool _active: modelData === root.sink readonly property bool _active: modelData === root.sink
Rectangle {
anchors.fill: parent
anchors.leftMargin: 4
anchors.rightMargin: 4
color: deviceHover.hovered ? S.Theme.base02 : "transparent"
radius: S.Theme.radius
}
Text { Text {
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 12 anchors.leftMargin: 12
@ -151,11 +142,6 @@ Column {
elide: Text.ElideRight elide: Text.ElideRight
} }
HoverHandler {
id: deviceHover
cursorShape: Qt.PointingHandCursor
}
TapHandler { TapHandler {
onTapped: Pipewire.preferredDefaultAudioSink = modelData onTapped: Pipewire.preferredDefaultAudioSink = modelData
} }

View file

@ -7,6 +7,7 @@ CpuApplet 1.0 CpuApplet.qml
DiskApplet 1.0 DiskApplet.qml DiskApplet 1.0 DiskApplet.qml
GpuApplet 1.0 GpuApplet.qml GpuApplet 1.0 GpuApplet.qml
HexWaveBackground 1.0 HexWaveBackground.qml HexWaveBackground 1.0 HexWaveBackground.qml
HoverableListItem 1.0 HoverableListItem.qml
InfoRow 1.0 InfoRow.qml InfoRow 1.0 InfoRow.qml
MemoryApplet 1.0 MemoryApplet.qml MemoryApplet 1.0 MemoryApplet.qml
MprisApplet 1.0 MprisApplet.qml MprisApplet 1.0 MprisApplet.qml