nova-shell/shell/applets/BluetoothApplet.qml

129 lines
4.3 KiB
QML

import QtQuick
import "../services" as S
import NovaStats as NS
// NOT safe for lock screen - can toggle bluetooth power and connect/disconnect devices
Column {
id: root
required property color accentColor
property bool active: true
onActiveChanged: if (active)
S.BluetoothService.refresh()
AppletActionBar {
accentColor: root.accentColor
Item {
width: 20
height: 20
Text {
anchors.centerIn: parent
text: "\uF011"
color: S.BluetoothService.enabled ? root.accentColor : NS.ThemeService.base04
font.pixelSize: NS.ThemeService.fontSize
font.family: NS.ThemeService.iconFontFamily
Behavior on color {
ColorAnimation {
duration: 100
}
}
}
HoverHandler {
cursorShape: Qt.PointingHandCursor
}
TapHandler {
onTapped: S.BluetoothService.setPower(!S.BluetoothService.enabled)
}
}
}
Repeater {
model: S.BluetoothService.devices
delegate: HoverableListItem {
id: entry
required property var modelData
required property int index
readonly property bool _pending: S.BluetoothService.pendingMac === entry.modelData.mac
Text {
id: btIcon
anchors.left: parent.left
anchors.leftMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: "\uF294"
color: entry._pending || entry.modelData.connected ? root.accentColor : NS.ThemeService.base04
font.pixelSize: NS.ThemeService.fontSize + 1
font.family: NS.ThemeService.iconFontFamily
}
Text {
anchors.left: btIcon.right
anchors.leftMargin: 8
anchors.right: _statusLabel.left
anchors.rightMargin: 4
anchors.verticalCenter: parent.verticalCenter
text: entry.modelData.name
color: entry._pending || entry.modelData.connected ? root.accentColor : NS.ThemeService.base05
font.pixelSize: NS.ThemeService.fontSize
font.family: NS.ThemeService.fontFamily
font.bold: entry.modelData.connected || entry._pending
elide: Text.ElideRight
}
Text {
id: _statusLabel
anchors.right: parent.right
anchors.rightMargin: 12
anchors.verticalCenter: parent.verticalCenter
text: entry._pending ? (entry.modelData.connected ? "disconnecting..." : "connecting...") : (entry.modelData.battery >= 0 ? entry.modelData.battery + "%" : "")
color: NS.ThemeService.base04
font.pixelSize: NS.ThemeService.fontSize - 1
font.family: NS.ThemeService.fontFamily
font.italic: entry._pending
width: text ? implicitWidth : 0
}
// Pulse animation while pending
SequentialAnimation on opacity {
loops: Animation.Infinite
running: entry._pending && !S.ThemeUtil.reducedMotion
NumberAnimation {
to: 0.5
duration: 400
easing.type: Easing.InOutQuad
}
NumberAnimation {
to: 1
duration: 400
easing.type: Easing.InOutQuad
}
onRunningChanged: if (!running)
entry.opacity = 1
}
onTapped: {
if (!entry._pending)
S.BluetoothService.toggleDevice(entry.modelData.mac, !entry.modelData.connected);
}
}
}
Text {
visible: S.BluetoothService.devices.length === 0
width: root.width
height: 32
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: S.BluetoothService.enabled ? "No paired devices" : "Bluetooth is off"
color: NS.ThemeService.base04
font.pixelSize: NS.ThemeService.fontSize
font.family: NS.ThemeService.fontFamily
}
}