styled list view

This commit is contained in:
Benjamin Palko 2025-08-01 23:21:29 -04:00
parent bac125abb0
commit 49ec4d8502
5 changed files with 94 additions and 82 deletions

View file

@ -10,7 +10,7 @@ import Quickshell.Widgets
StyledLabel {
id: root
property BluetoothDevice device
required property BluetoothDevice modelData
RowLayout {
id: row
@ -18,20 +18,20 @@ StyledLabel {
spacing: 8
Loader {
active: root.device?.icon != undefined
active: root.modelData?.icon != undefined
sourceComponent: IconImage {
implicitSize: 22
source: Quickshell.iconPath(root.device.icon, "device-support-unknown-symbolic")
source: Quickshell.iconPath(root.modelData.icon, "device-support-unknown-symbolic")
}
}
StyledText {
text: root.device.deviceName
text: root.modelData.deviceName
}
StyledButton {
Layout.alignment: Qt.AlignRight
hoverEnabled: !root.device.pairing
hoverEnabled: !root.modelData.pairing
color: containsMouse ? Theme.palette.primary : Theme.palette.base200
content: StyledText {
text: 'Pair'
@ -41,8 +41,8 @@ StyledLabel {
if (!hoverEnabled) {
return;
}
root.device.trusted = true;
root.device.pair();
root.modelData.trusted = true;
root.modelData.pair();
}
}
}

View file

@ -30,7 +30,8 @@ StyledPopupWindow {
}
Switch {
checked: Bluetooth.defaultAdapter.enabled
checkable: !!Bluetooth.defaultAdapter
checked: Bluetooth.defaultAdapter?.enabled ?? false
onClicked: Bluetooth.defaultAdapter.enabled = checked
}
}
@ -42,7 +43,8 @@ StyledPopupWindow {
}
Switch {
checked: Bluetooth.defaultAdapter.discovering
checkable: !!Bluetooth.defaultAdapter
checked: Bluetooth.defaultAdapter?.discovering ?? false
onClicked: Bluetooth.defaultAdapter.discovering = checked
}
}
@ -64,28 +66,28 @@ StyledPopupWindow {
text: "Connected Devices"
}
ColumnLayout {
Loader {
active: repeater1.count == 0
StyledListView {
id: list1
Layout.fillWidth: true
spacing: 8
implicitHeight: 20 + Math.min(40 * count, 160)
header: Loader {
active: list1.count == 0
sourceComponent: Loader {
active: list1.count == 0
sourceComponent: StyledText {
font.italic: true
text: "No devices connected..."
}
}
Repeater {
id: repeater1
}
clip: true
model: ScriptModel {
values: Bluetooth.devices.values.filter(device => device.state == BluetoothDeviceState.Connected)
}
delegate: Loader {
id: connectedDeviceLoader
required property var modelData
Layout.fillWidth: true
active: modelData != null
sourceComponent: ConnectedDevice {
device: connectedDeviceLoader.modelData
}
}
delegate: ConnectedDevice {
anchors.left: parent.left
anchors.right: parent.right
}
}
@ -96,28 +98,25 @@ StyledPopupWindow {
text: "Paired Devices"
}
ColumnLayout {
Loader {
active: repeater2.count == 0
StyledListView {
id: list2
Layout.fillWidth: true
spacing: 8
implicitHeight: 20 + Math.min(40 * count, 160)
header: Loader {
active: list2.count == 0
sourceComponent: StyledText {
font.italic: true
text: "No paired devices..."
}
}
Repeater {
id: repeater2
clip: true
model: ScriptModel {
values: Bluetooth.devices.values.filter(device => device.bonded && device.state == BluetoothDeviceState.Disconnected)
}
delegate: Loader {
id: pairedDeviceLoader
required property var modelData
Layout.fillWidth: true
active: modelData != null
sourceComponent: PairedDevice {
device: pairedDeviceLoader.modelData
}
values: Bluetooth.defaultAdapter.devices.values.filter(device => device.bonded && device.state == BluetoothDeviceState.Disconnected)
}
delegate: PairedDevice {
anchors.left: parent.left
anchors.right: parent.right
}
}
@ -128,28 +127,25 @@ StyledPopupWindow {
text: "Available Devices"
}
ColumnLayout {
Loader {
active: repeater3.count == 0
StyledListView {
id: list3
Layout.fillWidth: true
spacing: 8
clip: true
implicitHeight: 20 + Math.min(40 * count, 160)
header: Loader {
active: list3.count == 0
sourceComponent: StyledText {
font.italic: true
text: Bluetooth.defaultAdapter.discovering ? "No devices found..." : "Scan to find devices..."
}
}
Repeater {
id: repeater3
model: ScriptModel {
values: Bluetooth.devices.values.filter(device => !device.bonded && device.deviceName != "")
}
delegate: Loader {
id: availableDeviceLoader
required property var modelData
Layout.fillWidth: true
active: modelData != null
sourceComponent: AvailableDevice {
device: availableDeviceLoader.modelData
}
}
delegate: AvailableDevice {
anchors.left: parent.left
anchors.right: parent.right
}
}
}

View file

@ -11,7 +11,7 @@ import Quickshell.Widgets
StyledLabel {
id: root
required property BluetoothDevice device
required property BluetoothDevice modelData
RowLayout {
id: row
@ -19,19 +19,19 @@ StyledLabel {
spacing: 8
Loader {
active: root.device?.icon != undefined
active: root.modelData?.icon != undefined
sourceComponent: IconImage {
implicitSize: 22
source: Quickshell.iconPath(root.device.icon, "device-support-unknown-symbolic")
source: Quickshell.iconPath(root.modelData.icon, "device-support-unknown-symbolic")
}
}
StyledText {
text: root.device.deviceName
text: root.modelData.deviceName
}
Loader {
active: root.device.batteryAvailable
active: root.modelData.batteryAvailable
sourceComponent: RowLayout {
StyledText {
id: icon
@ -42,11 +42,11 @@ StyledLabel {
states: [
State {
name: "full"
when: root.device.battery > 0.66
when: root.modelData.battery > 0.66
},
State {
name: "medium"
when: root.device.battery > 0.33
when: root.modelData.battery > 0.33
PropertyChanges {
icon {
text: Icons.batteryFull
@ -55,7 +55,7 @@ StyledLabel {
},
State {
name: "low"
when: root.device.battery > 0.10
when: root.modelData.battery > 0.10
PropertyChanges {
icon {
text: Icons.batteryFull
@ -64,7 +64,7 @@ StyledLabel {
},
State {
name: "critical"
when: root.device.battery > 0.10
when: root.modelData.battery > 0.10
PropertyChanges {
icon {
text: Icons.batteryWarning
@ -85,10 +85,10 @@ StyledLabel {
font.pixelSize: 12
}
onClicked: {
if (root.device.state != BluetoothDeviceState.Connected) {
if (root.modelData.state != BluetoothDeviceState.Connected) {
return;
}
root.device.connected = false;
root.modelData.connected = false;
}
}
}

View file

@ -10,7 +10,7 @@ import Quickshell.Widgets
StyledLabel {
id: root
required property BluetoothDevice device
required property BluetoothDevice modelData
RowLayout {
id: row
@ -18,21 +18,21 @@ StyledLabel {
spacing: 8
Loader {
active: root.device?.icon != undefined
active: root.modelData?.icon != undefined
sourceComponent: IconImage {
implicitSize: 22
source: Quickshell.iconPath(root.device.icon, "device-support-unknown-symbolic")
source: Quickshell.iconPath(root.modelData.icon, "device-support-unknown-symbolic")
}
}
StyledText {
text: root.device.deviceName
text: root.modelData.deviceName
}
RowLayout {
Layout.alignment: Qt.AlignRight
StyledButton {
hoverEnabled: root.device.state == BluetoothDeviceState.Disconnected
hoverEnabled: root.modelData.state == BluetoothDeviceState.Disconnected
color: containsMouse ? Theme.palette.primary : Theme.palette.base200
content: StyledText {
text: 'Connect'
@ -42,12 +42,12 @@ StyledLabel {
if (!hoverEnabled) {
return;
}
root.device.connect();
root.modelData.connect();
}
}
StyledButton {
hoverEnabled: root.device.state == BluetoothDeviceState.Disconnected
hoverEnabled: root.modelData.state == BluetoothDeviceState.Disconnected
color: containsMouse ? Theme.palette.error : Theme.palette.base200
content: StyledText {
text: 'Unpair'
@ -57,7 +57,7 @@ StyledLabel {
if (!hoverEnabled) {
return;
}
root.device.forget();
root.modelData.forget();
}
}
}

View file

@ -0,0 +1,16 @@
import QtQuick
ListView {
id: root
maximumFlickVelocity: 3000
rebound: Transition {
NumberAnimation {
properties: "x,y"
duration: 400
easing.type: Easing.BezierSpline
easing.bezierCurve: [0.2, 0, 0, 1, 1, 1]
}
}
}