Compare commits
2 commits
9873324823
...
49ec4d8502
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49ec4d8502 | ||
|
|
bac125abb0 |
6 changed files with 96 additions and 96 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
pragma ComponentBehavior: Bound
|
||||
|
||||
import qs.config
|
||||
import qs.services
|
||||
import qs.widgets
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Bluetooth
|
||||
import Quickshell.Widgets
|
||||
|
||||
StyledPopupWindow {
|
||||
|
|
@ -29,7 +30,8 @@ StyledPopupWindow {
|
|||
}
|
||||
|
||||
Switch {
|
||||
checked: Bluetooth.defaultAdapter.enabled
|
||||
checkable: !!Bluetooth.defaultAdapter
|
||||
checked: Bluetooth.defaultAdapter?.enabled ?? false
|
||||
onClicked: Bluetooth.defaultAdapter.enabled = checked
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +43,8 @@ StyledPopupWindow {
|
|||
}
|
||||
|
||||
Switch {
|
||||
checked: Bluetooth.defaultAdapter.discovering
|
||||
checkable: !!Bluetooth.defaultAdapter
|
||||
checked: Bluetooth.defaultAdapter?.discovering ?? false
|
||||
onClicked: Bluetooth.defaultAdapter.discovering = checked
|
||||
}
|
||||
}
|
||||
|
|
@ -63,26 +66,29 @@ StyledPopupWindow {
|
|||
text: "Connected Devices"
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Loader {
|
||||
active: Bluetooth.connectedDevices.length == 0
|
||||
sourceComponent: StyledText {
|
||||
font.italic: true
|
||||
text: "No devices connected..."
|
||||
}
|
||||
}
|
||||
Repeater {
|
||||
model: Bluetooth.connectedDevices
|
||||
delegate: Loader {
|
||||
id: connectedDeviceLoader
|
||||
required property var modelData
|
||||
Layout.fillWidth: true
|
||||
active: modelData != null
|
||||
sourceComponent: ConnectedDevice {
|
||||
device: connectedDeviceLoader.modelData
|
||||
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..."
|
||||
}
|
||||
}
|
||||
}
|
||||
clip: true
|
||||
model: ScriptModel {
|
||||
values: Bluetooth.devices.values.filter(device => device.state == BluetoothDeviceState.Connected)
|
||||
}
|
||||
delegate: ConnectedDevice {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
|
|
@ -92,25 +98,25 @@ StyledPopupWindow {
|
|||
text: "Paired Devices"
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Loader {
|
||||
active: Bluetooth.availableDevices.length == 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 {
|
||||
model: Bluetooth.pairedDevices
|
||||
delegate: Loader {
|
||||
id: pairedDeviceLoader
|
||||
required property var modelData
|
||||
Layout.fillWidth: true
|
||||
active: modelData != null
|
||||
sourceComponent: PairedDevice {
|
||||
device: pairedDeviceLoader.modelData
|
||||
}
|
||||
}
|
||||
clip: true
|
||||
model: ScriptModel {
|
||||
values: Bluetooth.defaultAdapter.devices.values.filter(device => device.bonded && device.state == BluetoothDeviceState.Disconnected)
|
||||
}
|
||||
delegate: PairedDevice {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -121,25 +127,25 @@ StyledPopupWindow {
|
|||
text: "Available Devices"
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Loader {
|
||||
active: Bluetooth.availableDevices.length == 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 {
|
||||
model: Bluetooth.availableDevices
|
||||
delegate: Loader {
|
||||
id: availableDeviceLoader
|
||||
required property var modelData
|
||||
Layout.fillWidth: true
|
||||
active: modelData != null
|
||||
sourceComponent: AvailableDevice {
|
||||
device: availableDeviceLoader.modelData
|
||||
}
|
||||
}
|
||||
model: ScriptModel {
|
||||
values: Bluetooth.devices.values.filter(device => !device.bonded && device.deviceName != "")
|
||||
}
|
||||
delegate: AvailableDevice {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Bluetooth
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property BluetoothAdapter defaultAdapter: Bluetooth.defaultAdapter
|
||||
property list<BluetoothDevice> connectedDevices: defaultAdapter?.devices.values.filter(device => device.state == BluetoothDeviceState.Connected)
|
||||
property list<BluetoothDevice> pairedDevices: defaultAdapter?.devices.values.filter(device => device.bonded && device.state == BluetoothDeviceState.Disconnected)
|
||||
property list<BluetoothDevice> availableDevices: defaultAdapter?.devices.values.filter(device => !device.bonded && device.deviceName != "")
|
||||
|
||||
function isConnected(BluetoothDevice: device) {
|
||||
return device.state == BluetoothDeviceState.Connected;
|
||||
}
|
||||
|
||||
function isConnecting(BluetoothDevice: device) {
|
||||
return device.state == BluetoothDeviceState.Connecting;
|
||||
}
|
||||
}
|
||||
16
widgets/StyledListView.qml
Normal file
16
widgets/StyledListView.qml
Normal 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]
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue