2020-10-11 15:50:13 +02:00
|
|
|
import QtQuick 2.0
|
|
|
|
import QtQuick.Controls 2.9
|
|
|
|
import QtQuick.Layouts 1.0
|
2020-10-18 15:08:12 +02:00
|
|
|
import de.itsblue.LedDisplayController 1.0
|
2020-10-11 15:50:13 +02:00
|
|
|
import de.itsblue.bluetoothleuart 1.0
|
|
|
|
import QtQuick.Controls.Material 2.0
|
2020-10-17 03:22:37 +02:00
|
|
|
import QtGraphicalEffects 1.0
|
2020-10-11 15:50:13 +02:00
|
|
|
|
|
|
|
Page {
|
|
|
|
id: root
|
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
property bool actionButtonVisible: false
|
|
|
|
property bool backButtonVisible: false
|
2020-10-11 15:50:13 +02:00
|
|
|
property string statusText
|
|
|
|
property bool working
|
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
title: qsTr("Available displays")
|
|
|
|
|
2020-10-18 01:39:59 +02:00
|
|
|
signal opened()
|
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
}
|
|
|
|
|
2020-10-11 15:50:13 +02:00
|
|
|
ColumnLayout {
|
2020-10-17 21:51:33 +02:00
|
|
|
id: mainLayout
|
2020-10-11 15:50:13 +02:00
|
|
|
anchors {
|
|
|
|
fill: parent
|
2020-10-17 21:51:33 +02:00
|
|
|
margins: Math.min(parent.height, parent.width) * 0.05
|
2020-10-11 15:50:13 +02:00
|
|
|
}
|
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
Chip {
|
|
|
|
Layout.fillWidth: true
|
2020-10-18 15:08:12 +02:00
|
|
|
Layout.preferredHeight: 35
|
2020-10-11 15:50:13 +02:00
|
|
|
Layout.alignment: Layout.Center
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
verticalPadding: height * 0.25
|
|
|
|
horizontalPadding: width * 0.05
|
|
|
|
|
|
|
|
color: "#ffffff"
|
|
|
|
text: root.statusText
|
2020-10-17 21:51:33 +02:00
|
|
|
|
|
|
|
onClicked: {
|
2020-10-18 15:08:12 +02:00
|
|
|
if(parseInt(root.state) === LedDisplayBackend.LocationPermissionDenied && !backend.bleClient.isLocationPermissionGranted())
|
|
|
|
backend.bleClient.requestLocationPermission()
|
|
|
|
else
|
|
|
|
backend.bleClient.startScanningForDevices()
|
2020-10-17 21:51:33 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
BusyIndicator {
|
|
|
|
id: busyIndicator
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
anchors {
|
|
|
|
right: parent.right
|
|
|
|
}
|
2020-10-17 21:51:33 +02:00
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
height: parent.height
|
|
|
|
width: height
|
2020-10-17 21:51:33 +02:00
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
scale: 0.8
|
2020-10-17 21:51:33 +02:00
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
opacity: root.working ? 1:0
|
2020-10-17 21:51:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: mainLayout.height * 0.025
|
2020-10-11 15:50:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ListView {
|
2020-10-17 21:51:33 +02:00
|
|
|
id: availableDisplaysListView
|
2020-10-11 15:50:13 +02:00
|
|
|
|
|
|
|
Layout.preferredWidth: parent.width
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.alignment: Layout.Center
|
|
|
|
|
|
|
|
clip: true
|
2020-10-15 12:52:19 +02:00
|
|
|
boundsBehavior: Flickable.OvershootBounds
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
model: backend.bleClient.availableDevicesModel
|
2020-10-11 15:50:13 +02:00
|
|
|
|
|
|
|
add: Transition {
|
|
|
|
NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 200 }
|
|
|
|
NumberAnimation { property: "scale"; from: 0.9; to: 1; duration: 200 }
|
|
|
|
}
|
|
|
|
|
|
|
|
remove: Transition {
|
|
|
|
NumberAnimation { property: "opacity"; from: 1; to: 0; duration: 200 }
|
|
|
|
NumberAnimation { property: "scale"; from: 1; to: 0.9; duration: 200 }
|
|
|
|
}
|
|
|
|
|
|
|
|
spacing: 5
|
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
delegate: ItemDelegate {
|
|
|
|
width: parent.width
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
text: name
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
onClicked: backend.bleClient.connectToDevice(device)
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
Rectangle {
|
|
|
|
anchors {
|
|
|
|
top: parent.top
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
topMargin: - availableDisplaysListView.spacing * 0.5
|
2020-10-11 15:50:13 +02:00
|
|
|
}
|
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
color: "lightgrey"
|
|
|
|
height: 1
|
|
|
|
visible: index !== 0
|
|
|
|
}
|
|
|
|
}
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
Item {
|
2020-10-18 01:39:59 +02:00
|
|
|
id: noDisplaysItem
|
2020-10-17 21:51:33 +02:00
|
|
|
anchors.centerIn: parent
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
width: Math.min(parent.height, parent.width)
|
|
|
|
height: Math.min(parent.height, parent.width)
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
opacity: availableDisplaysListView.model.rowCount === 0 ? 1:0
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
Behavior on opacity {
|
|
|
|
NumberAnimation {}
|
|
|
|
}
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
Rectangle {
|
|
|
|
id: noDisplaysRect
|
|
|
|
|
|
|
|
anchors {
|
|
|
|
top: parent.top
|
|
|
|
topMargin: parent.height * 0.2
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
2020-10-11 15:50:13 +02:00
|
|
|
}
|
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
width: parent.width * 0.7
|
|
|
|
height: width * 0.3
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
color: "transparent"
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
border.width: height * 0.15
|
|
|
|
border.color: "lightgrey"
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
Text {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
anchors.verticalCenterOffset: text === "..." ? -height * 0.25:0
|
|
|
|
color: "lightgrey"
|
|
|
|
font.pixelSize: parent.height * 0.6
|
|
|
|
font.bold: true
|
2020-10-18 15:08:12 +02:00
|
|
|
text: parseInt(root.state) === LedDisplayBackend.Scanning ? "...":"?"
|
2020-10-17 21:51:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: noDisplaysText
|
2020-10-13 01:58:14 +02:00
|
|
|
anchors {
|
2020-10-17 21:51:33 +02:00
|
|
|
top: noDisplaysRect.bottom
|
|
|
|
topMargin: noDisplaysRect.height * 0.15
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
2020-10-13 01:58:14 +02:00
|
|
|
}
|
2020-10-11 15:50:13 +02:00
|
|
|
|
2020-10-17 21:51:33 +02:00
|
|
|
font.bold: true
|
|
|
|
font.pixelSize: noDisplaysRect.height * 0.3
|
|
|
|
|
|
|
|
color: Qt.darker("lightgrey", 1.1)
|
2020-10-18 15:08:12 +02:00
|
|
|
text: parseInt(root.state) === LedDisplayBackend.Scanning ? qsTr("Still scanning"):qsTr("No displays found")
|
2020-10-13 01:58:14 +02:00
|
|
|
}
|
2020-10-11 15:50:13 +02:00
|
|
|
}
|
2020-10-18 03:26:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: bluetoothOffItem
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
|
|
|
width: Math.min(parent.height, parent.width)
|
|
|
|
height: Math.min(parent.height, parent.width)
|
|
|
|
|
|
|
|
opacity: 0
|
|
|
|
|
|
|
|
Behavior on opacity {
|
|
|
|
NumberAnimation {}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: bluetoothOffIcon
|
|
|
|
anchors {
|
|
|
|
top: parent.top
|
|
|
|
topMargin: parent.height * 0.1
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
anchors.verticalCenterOffset: text === "..." ? -height * 0.25:0
|
|
|
|
color: "lightgrey"
|
|
|
|
font.pixelSize: parent.height * 0.4
|
|
|
|
font.family: fontAwesomeBrands.name
|
|
|
|
text: "\uf294"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: bluetoothOffText
|
|
|
|
anchors {
|
|
|
|
top: bluetoothOffIcon.bottom
|
|
|
|
topMargin: bluetoothOffIcon.height * 0.15
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
font.bold: true
|
|
|
|
font.pixelSize: bluetoothOffIcon.height * 0.15
|
|
|
|
|
|
|
|
color: Qt.darker("lightgrey", 1.1)
|
|
|
|
text: qsTr("Bluetooth is turned off")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: noPermissionItem
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
|
|
|
width: Math.min(parent.height, parent.width)
|
|
|
|
height: Math.min(parent.height, parent.width)
|
|
|
|
|
|
|
|
opacity: 0
|
|
|
|
|
|
|
|
Behavior on opacity {
|
|
|
|
NumberAnimation {}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: noPermissionIcon
|
|
|
|
anchors {
|
|
|
|
top: parent.top
|
|
|
|
topMargin: parent.height * 0
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
anchors.verticalCenterOffset: text === "..." ? -height * 0.25:0
|
|
|
|
color: "lightgrey"
|
|
|
|
font.pixelSize: parent.height * 0.4
|
|
|
|
font.family: fontAwesome.name
|
|
|
|
text: "\uf3ed"
|
|
|
|
}
|
|
|
|
Text {
|
|
|
|
id: noPermissionText
|
|
|
|
anchors {
|
|
|
|
top: noPermissionIcon.bottom
|
|
|
|
topMargin: noPermissionIcon.height * 0.15
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
width: parent.width * 0.9
|
|
|
|
|
|
|
|
font.bold: true
|
|
|
|
font.pixelSize: noPermissionIcon.height * 0.15
|
|
|
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
|
|
|
|
color: Qt.darker("lightgrey", 1.1)
|
|
|
|
text: qsTr("Error:\nLocation permission denied!")
|
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: noPermissionDetailText
|
|
|
|
anchors {
|
|
|
|
top: noPermissionText.bottom
|
|
|
|
topMargin: noPermissionText.height * 0.15
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
width: parent.width * 0.9
|
|
|
|
|
|
|
|
font.bold: true
|
|
|
|
font.pixelSize: noPermissionText.font.pixelSize * 0.7
|
|
|
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
|
|
|
|
color: Qt.darker("lightgrey", 1.1)
|
|
|
|
text: qsTr("This app requires location permission in order for Bluetooth to work, it will not actually access your location.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-11 15:50:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 01:08:23 +02:00
|
|
|
Dialog {
|
|
|
|
id: authenticationDialog
|
|
|
|
|
|
|
|
property bool shouldBeOpened: false
|
|
|
|
|
|
|
|
parent: Overlay.overlay
|
|
|
|
x: (parent.width - width) / 2
|
|
|
|
y: (parent.height - height) / 2
|
|
|
|
|
|
|
|
width: parent.width * 0.9
|
|
|
|
|
|
|
|
modal: true
|
|
|
|
closePolicy: Popup.NoAutoClose
|
|
|
|
standardButtons: Dialog.Ok | Dialog.Cancel
|
|
|
|
|
|
|
|
title: qsTr("Input code")
|
|
|
|
|
|
|
|
onShouldBeOpenedChanged: {
|
|
|
|
if(shouldBeOpened)
|
|
|
|
open()
|
|
|
|
else
|
|
|
|
close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onAccepted: {
|
|
|
|
backend.authenticate(secretTextInput.text)
|
|
|
|
}
|
|
|
|
|
|
|
|
onRejected: {
|
2020-10-17 21:51:33 +02:00
|
|
|
backend.bleClient.disconnectFromDevice()
|
2020-10-17 01:08:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: TextField {
|
|
|
|
id: secretTextInput
|
|
|
|
placeholderText: qsTr("code")
|
|
|
|
Keys.onReturnPressed: authenticationDialog.accept()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-11 15:50:13 +02:00
|
|
|
states: [
|
|
|
|
State {
|
2020-10-18 15:08:12 +02:00
|
|
|
name: LedDisplayBackend.Idle
|
2020-10-11 15:50:13 +02:00
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
2020-10-17 21:51:33 +02:00
|
|
|
statusText: qsTr("Tap here to scan")
|
2020-10-11 15:50:13 +02:00
|
|
|
working: false
|
|
|
|
}
|
2020-10-18 03:26:02 +02:00
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: noPermissionItem
|
|
|
|
opacity: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
2020-10-18 15:08:12 +02:00
|
|
|
name: LedDisplayBackend.BluetoothOff
|
2020-10-18 03:26:02 +02:00
|
|
|
PropertyChanges {
|
|
|
|
target: bluetoothOffItem
|
|
|
|
opacity: 1
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
|
|
|
statusText: qsTr("Bluetooth is turned off")
|
|
|
|
working: false
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: noDisplaysItem
|
|
|
|
opacity: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
2020-10-18 15:08:12 +02:00
|
|
|
name: LedDisplayBackend.LocationPermissionDenied
|
2020-10-18 03:26:02 +02:00
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: noPermissionItem
|
|
|
|
opacity: 1
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
|
|
|
statusText: qsTr("Tap here to continue")
|
|
|
|
working: false
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: noDisplaysItem
|
|
|
|
opacity: 0
|
|
|
|
}
|
2020-10-11 15:50:13 +02:00
|
|
|
},
|
|
|
|
State {
|
2020-10-18 15:08:12 +02:00
|
|
|
name: LedDisplayBackend.Scanning
|
2020-10-11 15:50:13 +02:00
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
2020-10-17 21:51:33 +02:00
|
|
|
statusText: qsTr("Scanning...")
|
2020-10-11 15:50:13 +02:00
|
|
|
working: true
|
|
|
|
}
|
2020-10-18 03:26:02 +02:00
|
|
|
PropertyChanges {
|
|
|
|
target: bluetoothOffItem
|
|
|
|
opacity: 0
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
target: noPermissionItem
|
|
|
|
opacity: 0
|
|
|
|
}
|
2020-10-11 15:50:13 +02:00
|
|
|
},
|
|
|
|
State {
|
2020-10-18 15:08:12 +02:00
|
|
|
name: LedDisplayBackend.ReadyToConnect
|
2020-10-11 15:50:13 +02:00
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
2020-10-17 21:51:33 +02:00
|
|
|
statusText: availableDisplaysListView.model.rowCount > 0 ? qsTr("Please select a device or tap to scan again"):qsTr("No displays found. Tap to scan again")
|
2020-10-11 15:50:13 +02:00
|
|
|
working: false
|
|
|
|
}
|
|
|
|
},
|
2020-10-17 01:08:23 +02:00
|
|
|
|
|
|
|
State {
|
2020-10-18 15:08:12 +02:00
|
|
|
name: LedDisplayBackend.AuthenticationRequired
|
2020-10-17 01:08:23 +02:00
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: authenticationDialog
|
|
|
|
shouldBeOpened: true
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanges {
|
2020-10-17 21:51:33 +02:00
|
|
|
target: availableDisplaysListView
|
2020-10-17 01:08:23 +02:00
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
2020-10-17 21:51:33 +02:00
|
|
|
statusText: qsTr("trying to authenticate...")
|
2020-10-17 01:08:23 +02:00
|
|
|
working: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
2020-10-18 15:08:12 +02:00
|
|
|
name: LedDisplayBackend.Authenticating
|
2020-10-17 01:08:23 +02:00
|
|
|
|
|
|
|
PropertyChanges {
|
2020-10-17 21:51:33 +02:00
|
|
|
target: availableDisplaysListView
|
2020-10-17 01:08:23 +02:00
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
2020-10-17 21:51:33 +02:00
|
|
|
statusText: qsTr("trying to authenticate...")
|
2020-10-17 01:08:23 +02:00
|
|
|
working: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-11 15:50:13 +02:00
|
|
|
State {
|
2020-10-18 15:08:12 +02:00
|
|
|
name: LedDisplayBackend.Connecting
|
2020-10-11 15:50:13 +02:00
|
|
|
|
|
|
|
PropertyChanges {
|
2020-10-17 21:51:33 +02:00
|
|
|
target: availableDisplaysListView
|
2020-10-11 15:50:13 +02:00
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
2020-10-17 21:51:33 +02:00
|
|
|
statusText: qsTr("trying to connect...")
|
2020-10-11 15:50:13 +02:00
|
|
|
working: true
|
|
|
|
}
|
2020-10-14 23:54:12 +02:00
|
|
|
},
|
|
|
|
State {
|
2020-10-18 15:08:12 +02:00
|
|
|
name: LedDisplayBackend.Initing
|
2020-10-14 23:54:12 +02:00
|
|
|
|
|
|
|
PropertyChanges {
|
2020-10-17 21:51:33 +02:00
|
|
|
target: availableDisplaysListView
|
2020-10-14 23:54:12 +02:00
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
target: root
|
2020-10-17 21:51:33 +02:00
|
|
|
statusText: qsTr("loading data...")
|
2020-10-14 23:54:12 +02:00
|
|
|
working: true
|
|
|
|
}
|
2020-10-11 15:50:13 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|