-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
117 lines (113 loc) · 3.84 KB
/
main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
ApplicationWindow {
visible: true
width: 460
height: 780
title: qsTr("Bluetooth Pairing Example")
Connections {
target: Bluetooth
onDevicesChanged: {
if (Bluetooth.devices && Bluetooth.devices[devicesList.currentIndex]) {
devicesList.itemAtIndex(devicesList.currentIndex).isDevicePaired =
Bluetooth.devices[devicesList.currentIndex].isPaired;
}
}
}
Item {
anchors.fill: parent
anchors.margins: 25
ToolButton {
id: refreshButton
implicitWidth: 35
implicitHeight: 35
anchors.right: parent.right
scale: pressed ? 1.1 : 1.0
Behavior on scale { NumberAnimation {} }
background: Image {
anchors.fill: parent
source: "qrc:/images/refresh.png"
}
onClicked: {
Bluetooth.refresh();
}
}
ScrollView {
implicitWidth: parent.width
anchors.top: refreshButton.bottom
anchors.topMargin: 40
anchors.horizontalCenter: parent.horizontalCenter
ListView {
id: devicesList
model: Bluetooth.devices
delegate: ItemDelegate {
id: deviceDelegate
property bool isDevicePaired: false
implicitWidth: parent.width
implicitHeight: 50
scale: pressed ? 1.1 : 1.0
Behavior on scale { NumberAnimation {} }
contentItem: RowLayout {
anchors.fill: parent
spacing: 20
Image {
Layout.preferredWidth: 20
Layout.preferredHeight: 35
fillMode: Image.PreserveAspectFit
source: "qrc:/images/bluetooth.png"
}
Label {
text: modelData.deviceName
}
Item {
Layout.fillWidth: true
Layout.fillHeight: true
}
Switch {
id: switchButton
checkable: false
checked: deviceDelegate.isDevicePaired
}
}
background: Rectangle {
width: parent.width
height: 1
anchors.bottom: parent.bottom
color: "lightgrey"
}
onClicked: {
devicesList.currentIndex = index;
Bluetooth.pairDevice(modelData.deviceAddress);
}
}
}
}
}
Label {
id: noDevicesLabel
anchors.centerIn: parent
font.pixelSize: 36
opacity: (devicesList.count > 0) ? 0.0 : 1.0
Behavior on opacity { NumberAnimation {}}
visible: (opacity > 0.0)
horizontalAlignment: Text.AlignHCenter
text: Bluetooth.scanning ? "Scanning..." : "No devices found \n Press refresh to try again"
SequentialAnimation {
running: Bluetooth.scanning
loops: Animation.Infinite
ScaleAnimator {
target: noDevicesLabel
from: 0.9
to: 1
duration: 1000
}
ScaleAnimator {
target: noDevicesLabel
from: 1
to: 0.9
duration: 1000
}
}
}
}