SmartLockerTools/Analyser/qml/OperationItem.qml
2024-09-05 16:36:54 +08:00

276 lines
10 KiB
QML

import QtCore
import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs
import QtQuick.Layouts
import Analyser
Item {
id: root
ColumnLayout {
anchors.fill: parent
ConnectionItem {}
Column {
Text{
width: 50
text: "烧录版本: "+ (App.module!==null? App.module.verison:"")
}
Text{
width: 50
text: "OTA版本: "+(App.module!==null?App.module.otaVerison:"")
}
}
GroupBox {
id: commandBox
title: "命令"
Layout.columnSpan: 2
enabled: App.connected
GridLayout {
columns: 2
GroupBox {
title: "注册用户"
GridLayout {
columns: 2
Label {
text: qsTr("用户姓名")
}
TextField {
id: enrollName
implicitWidth: 100
}
Label {
text: qsTr("严格模式")
}
Switch {
id: strictMode
}
Label {
text: qsTr("超时时间")
}
TextField {
id: enrollTimeout
implicitWidth: 100
text: "30"
}
Label {
text: qsTr("持久化")
}
Switch {
id: persistence
checked: true
}
Label {
text: qsTr("保存图片")
}
Switch {
id: extendedMode
}
Button {
property bool enrolling: App.module ? (App.module.currentMessageId === ModuleCommunication.EnrollSingle) || (App.module.currentMessageId === ModuleCommunication.EnrollExtended) : false
text: enrolling ? "取消" : "注册"
onClicked: {
if (enrolling) {
App.module.reset()
} else if (extendedMode.checked) {
App.enrollExtended(enrollName.text, strictMode.checked, persistence.checked, parseInt(enrollTimeout.text))
} else {
App.enroll(enrollName.text, strictMode.checked, persistence.checked, parseInt(enrollTimeout.text))
}
}
}
}
}
GroupBox {
title: "识别用户"
GridLayout {
columns: 2
Label {
text: qsTr("超时时间(s)")
}
TextField {
id: verifyTimeout
implicitWidth: 80
text: "10"
}
Label {
text: qsTr("持续识别")
}
Switch {
checked: App.persistenceMode
onToggled: App.persistenceMode = !App.persistenceMode
}
Label {
text: qsTr("保存图片")
}
Switch {
id: extendedVerifyMode
}
Label {
text: qsTr("识别间隔(s)")
}
TextField {
id: verifyIntetval
implicitWidth: 80
text: App.persistenceVerifyInterval
}
Item {}
Button {
text: App.isVerifying ? "停止" : "识别"
onClicked: {
if (App.isVerifying) {
App.module.reset()
} else {
App.persistenceVerifyInterval = parseInt(
verifyIntetval.text)
App.verify(extendedVerifyMode.checked,
parseInt(verifyTimeout.text))
}
}
}
}
}
Column {
GroupBox {
title: "删除用户"
GridLayout {
columns: 2
Label {
text: qsTr("用户ID")
}
TextField {
id: deleteUserId
implicitWidth: 100
}
Button {
text: "删除"
onClicked: App.deleteUser(parseInt(
deleteUserId.text))
}
Button {
text: "删除所有"
onClicked: App.deleteAll()
}
}
}
GroupBox {
GridLayout {
columns: 2
Button {
text: "复位"
onClicked: App.module.reset()
}
Button {
text: "状态查询"
onClicked: App.module.requestCurrentStatus()
}
Button {
text: "ID查询"
onClicked: App.module.requestUniqueId()
}
Button {
id: otaButton
text: "OTA升级"
onClicked: loader.active = true
}
Row {
Label {
text: qsTr("日志")
}
Switch {
id: debugMode
onToggled: App.module.setDebugEnabled(debugMode.checked)
}
}
}
}
}
GroupBox {
title: "图片注册"
visible: true
GridLayout {
columns: 2
TextField {
id: imagePath
Layout.columnSpan: 2
implicitWidth: 200
placeholderText: "请选择图片"
onPressed: {
fileDialog.open()
}
}
Label {
text: qsTr("用户姓名")
}
TextField {
id: imageEnrollName
implicitWidth: 100
text: "测试下发"
}
Label {
text: qsTr("循环")
}
Switch {
checked: App.imageUploadPersistenceMode
onToggled: {
App.imageUploadPersistenceMode = checked
}
}
Button {
text: "注册"
onClicked: App.uploadImage(imagePath.text,imageEnrollName.text, 0)
}
Button {
text: "识别"
onClicked: App.uploadImage(imagePath.text,imageEnrollName.text, 1)
}
}
}
}
}
}
FileDialog {
id: fileDialog
nameFilters: ["图片 (*.jpg *.yuv)"]
currentFolder: StandardPaths.standardLocations(
StandardPaths.DesktopLocation)[0]
onAccepted: {
var fileUrl = fileDialog.selectedFile.toString()
var localFilePath = fileUrl.startsWith(
"file:///") ? fileUrl.substring(8) : fileUrl
imagePath.text = localFilePath
}
}
MouseArea {
width: otaButton.width
height: otaButton.height
enabled: !commandBox.enabled
onClicked: {
loader.active = true
}
Component.onCompleted: {
x = Qt.binding(() => otaButton.mapToItem(root, 0, 0).x)
y = Qt.binding(() => otaButton.mapToItem(root, 0, 0).y)
}
}
Loader {
id: loader
source: "OtaPage.qml"
active: false
onLoaded: {
if (loader.item && loader.item.open) {
loader.item.open()
loader.item.onClose = () => {
loader.active = false
}
}
}
}
}