bluetooth menu: show connecting/disconnecting state with pulse feedback
This commit is contained in:
parent
b8789c67f4
commit
87952b543c
2 changed files with 41 additions and 12 deletions
|
|
@ -50,6 +50,8 @@ M.HoverPanel {
|
||||||
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
|
||||||
|
|
||||||
width: menuWindow.contentWidth
|
width: menuWindow.contentWidth
|
||||||
height: 32
|
height: 32
|
||||||
|
|
||||||
|
|
@ -67,7 +69,7 @@ M.HoverPanel {
|
||||||
anchors.leftMargin: 12
|
anchors.leftMargin: 12
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
text: "\uF294"
|
text: "\uF294"
|
||||||
color: entry.modelData.connected ? menuWindow.accentColor : S.Theme.base04
|
color: entry._pending ? menuWindow.accentColor : entry.modelData.connected ? menuWindow.accentColor : S.Theme.base04
|
||||||
font.pixelSize: S.Theme.fontSize + 1
|
font.pixelSize: S.Theme.fontSize + 1
|
||||||
font.family: S.Theme.iconFontFamily
|
font.family: S.Theme.iconFontFamily
|
||||||
}
|
}
|
||||||
|
|
@ -75,27 +77,46 @@ M.HoverPanel {
|
||||||
Text {
|
Text {
|
||||||
anchors.left: btIcon.right
|
anchors.left: btIcon.right
|
||||||
anchors.leftMargin: 8
|
anchors.leftMargin: 8
|
||||||
anchors.right: batLabel.left
|
anchors.right: _statusLabel.left
|
||||||
anchors.rightMargin: 4
|
anchors.rightMargin: 4
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
text: entry.modelData.name
|
text: entry.modelData.name
|
||||||
color: entry.modelData.connected ? menuWindow.accentColor : S.Theme.base05
|
color: entry._pending ? menuWindow.accentColor : entry.modelData.connected ? menuWindow.accentColor : S.Theme.base05
|
||||||
font.pixelSize: S.Theme.fontSize
|
font.pixelSize: S.Theme.fontSize
|
||||||
font.family: S.Theme.fontFamily
|
font.family: S.Theme.fontFamily
|
||||||
font.bold: entry.modelData.connected
|
font.bold: entry.modelData.connected || entry._pending
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: batLabel
|
id: _statusLabel
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.rightMargin: 12
|
anchors.rightMargin: 12
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
text: entry.modelData.battery >= 0 ? entry.modelData.battery + "%" : ""
|
text: entry._pending ? (entry.modelData.connected ? "disconnecting..." : "connecting...") : (entry.modelData.battery >= 0 ? entry.modelData.battery + "%" : "")
|
||||||
color: S.Theme.base04
|
color: entry._pending ? S.Theme.base04 : S.Theme.base04
|
||||||
font.pixelSize: S.Theme.fontSize - 1
|
font.pixelSize: S.Theme.fontSize - 1
|
||||||
font.family: S.Theme.fontFamily
|
font.family: S.Theme.fontFamily
|
||||||
width: entry.modelData.battery >= 0 ? implicitWidth : 0
|
font.italic: entry._pending
|
||||||
|
width: text ? implicitWidth : 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pulse animation while pending
|
||||||
|
SequentialAnimation on opacity {
|
||||||
|
loops: Animation.Infinite
|
||||||
|
running: entry._pending
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
HoverHandler {
|
HoverHandler {
|
||||||
|
|
@ -104,12 +125,14 @@ M.HoverPanel {
|
||||||
}
|
}
|
||||||
TapHandler {
|
TapHandler {
|
||||||
onTapped: {
|
onTapped: {
|
||||||
|
if (!entry._pending) {
|
||||||
S.BluetoothService.toggleDevice(entry.modelData.mac, !entry.modelData.connected);
|
S.BluetoothService.toggleDevice(entry.modelData.mac, !entry.modelData.connected);
|
||||||
menuWindow.keepOpen(500);
|
menuWindow.keepOpen(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
visible: S.BluetoothService.devices.length === 0
|
visible: S.BluetoothService.devices.length === 0
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,11 @@ QtObject {
|
||||||
_powerProc.running = true;
|
_powerProc.running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MAC address of device currently connecting/disconnecting
|
||||||
|
property string pendingMac: ""
|
||||||
|
|
||||||
function toggleDevice(mac, connect) {
|
function toggleDevice(mac, connect) {
|
||||||
|
pendingMac = mac;
|
||||||
_toggleProc._action = connect ? "connect" : "disconnect";
|
_toggleProc._action = connect ? "connect" : "disconnect";
|
||||||
_toggleProc._mac = mac;
|
_toggleProc._mac = mac;
|
||||||
_toggleProc.running = true;
|
_toggleProc.running = true;
|
||||||
|
|
@ -120,7 +124,9 @@ QtObject {
|
||||||
property string _action: ""
|
property string _action: ""
|
||||||
property string _mac: ""
|
property string _mac: ""
|
||||||
command: ["bluetoothctl", _action, _mac]
|
command: ["bluetoothctl", _action, _mac]
|
||||||
onRunningChanged: if (!running)
|
onRunningChanged: if (!running) {
|
||||||
root.refresh()
|
root.pendingMac = "";
|
||||||
|
root.refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue