AntiClipSettings/qml/Main.qml

258 lines
8.9 KiB
QML
Raw Permalink Normal View History

2024-08-24 22:35:35 +08:00
import QtQuick 2.15
import QtQuick.Controls 2.15
2024-08-26 16:46:41 +08:00
import QtQuick.Controls.Material 2.15
2024-08-24 22:35:35 +08:00
import QtQuick.Layouts 1.15
import AntiClipSettings 1.0
2024-08-13 09:54:41 +08:00
2024-08-13 20:06:10 +08:00
ApplicationWindow {
2024-08-21 09:26:06 +08:00
id: window
2024-08-16 16:24:15 +08:00
width: 1000
height: 640
2024-08-13 09:54:41 +08:00
visible: true
2024-08-26 14:55:15 +08:00
title: qsTr(Qt.application.name + " " + Qt.application.version)
2024-08-13 20:06:10 +08:00
2024-08-14 20:01:38 +08:00
header: ToolBar {
RowLayout {
anchors.fill: parent
2024-08-26 14:55:15 +08:00
Button {
2024-08-27 11:14:36 +08:00
Layout.leftMargin: 5
2024-08-26 14:55:15 +08:00
Material.background: Material.Blue
2024-08-14 20:01:38 +08:00
text: "搜索设备"
2024-08-16 16:24:15 +08:00
onClicked: {
deviceList.currentIndex = -1
2024-08-21 09:26:06 +08:00
App.startSearchDevice()
2024-08-30 14:47:03 +08:00
App.collector.stop() // 停止数据采集
App.collector.path = ""
2024-08-16 16:24:15 +08:00
}
2024-08-14 20:01:38 +08:00
}
2024-08-21 16:03:49 +08:00
Label {
2024-08-20 09:29:49 +08:00
text: `: ${deviceList.count}`
}
2024-08-21 16:03:49 +08:00
Label {
2024-08-14 20:01:38 +08:00
Layout.alignment: Qt.AlignRight
2024-08-21 16:03:49 +08:00
Layout.preferredWidth: 280
text: App.currentFirmware.length > 0 ? `: ${App.currentFirmware}` : ""
2024-08-14 20:01:38 +08:00
}
2024-08-13 20:06:10 +08:00
}
}
2024-08-16 16:24:15 +08:00
ListView {
2024-08-13 20:06:10 +08:00
id: deviceList
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
2024-08-16 16:24:15 +08:00
width: 420
clip: true
model: App.devices
2024-08-26 14:55:15 +08:00
Label {
id: emptyHint
visible: false
anchors.centerIn: parent
text: qsTr("未搜索到设备")
}
2024-08-16 16:24:15 +08:00
delegate: Rectangle {
width: deviceList.width
height: 40
color: ListView.isCurrentItem ? "#aaddff" : (index % 2 == 0 ? "#ffffff" : "#eeeeee")
Row {
anchors.fill: parent
spacing: 10
Text {
2024-08-20 09:29:49 +08:00
anchors.verticalCenter: parent.verticalCenter
2024-08-16 16:24:15 +08:00
text: deviceId
}
Item {}
Text {
2024-08-20 09:29:49 +08:00
anchors.verticalCenter: parent.verticalCenter
2024-08-16 16:24:15 +08:00
text: ip
}
2024-08-20 09:29:49 +08:00
Rectangle {
anchors.verticalCenter: parent.verticalCenter
2024-08-21 09:26:06 +08:00
color: onlineStatus ? "green" : "black"
2024-08-20 09:29:49 +08:00
width: 10
height: 10
radius: 5
}
2024-08-16 16:24:15 +08:00
}
MouseArea {
anchors.fill: parent
onClicked: {
deviceList.currentIndex = index
}
onDoubleClicked: {
if (softwareVersion.includes("T009") && !softwareVersion.includes("R003")) {
2024-08-30 14:47:03 +08:00
showMessageDialog(2, "网络设置", "当前设备不支持有线网络设置!")
} else if (onlineStatus) {
2024-08-26 14:55:15 +08:00
networkPopup.open()
} else {
showMessageDialog(2, "网络设置", "设备已离线!")
}
2024-08-16 16:24:15 +08:00
}
}
}
onCurrentIndexChanged: {
2024-08-20 09:29:49 +08:00
App.connectToDevice(deviceList.currentIndex)
2024-08-30 14:47:03 +08:00
App.collector.stop() // 停止数据采集
App.collector.path = ""
2024-08-16 16:24:15 +08:00
}
ProgressBar {
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
visible: App.devices.isSearching
from: 0
to: 100
value: App.devices.searchProgress
height: 25
}
2024-08-13 20:06:10 +08:00
}
DeviceView {
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: deviceList.right
anchors.right: parent.right
2024-08-26 14:55:15 +08:00
enabled: App.currentDeviceConnected && (deviceList.currentIndex >= 0)
2024-08-16 16:24:15 +08:00
openDoorAreaWay: App.currentOpenDoorAreaWay
2024-08-13 20:06:10 +08:00
openDoorAreaPoints: App.currentOpenDoorAreaPoints
2024-08-14 20:01:38 +08:00
shieldedAreaEnabled: App.currentShieldedAreaEnabled
shieldedAreaPoints: App.currentShieldedAreaPoints
antiClipAreaEnabled: App.currentAntiClipAreaEnabled
antiClipAreaPoints: App.currentAntiClipAreaPoints
flip: App.currentDeviceFlip
videoRotation: App.currentDeviceRotation
2024-08-14 20:01:38 +08:00
}
2024-08-16 16:24:15 +08:00
NetworkSettingPopup {
id: networkPopup
visible: false
width: 500
}
2024-08-19 09:33:04 +08:00
OtaPopup {
id: otaPopup
}
2024-08-14 20:01:38 +08:00
footer: RowLayout {
width: parent.width
Button {
2024-08-27 11:14:36 +08:00
Layout.leftMargin: 5
2024-08-21 09:26:06 +08:00
text: App.collector.enabled ? "停止采集" : "数据采集"
onClicked: {
if (App.collector.enabled) {
App.collector.stop()
} else {
if (deviceList.currentIndex < 0) {
showMessageDialog(2, "数据采集", "请先选择设备")
return
2024-08-26 14:55:15 +08:00
} else if (!App.currentDeviceConnected) {
2024-08-22 10:48:28 +08:00
showMessageDialog(2, "数据采集", "设备已离线,请重新连接设备!")
return
2024-08-21 09:26:06 +08:00
}
if (App.collector.path.length <= 0) {
2024-08-26 16:46:41 +08:00
showFolderDialog(folder => {
2024-08-26 14:55:15 +08:00
App.collector.path = folder
App.collector.start(App.devices.get(deviceList.currentIndex).ip)
})
2024-08-21 09:26:06 +08:00
} else {
App.collector.start(App.devices.get(
deviceList.currentIndex).ip)
}
}
}
2024-08-14 20:01:38 +08:00
}
Item {}
Button {
text: "升级"
2024-08-21 09:26:06 +08:00
onClicked: {
if (deviceList.currentIndex < 0) {
2024-08-22 10:48:28 +08:00
showMessageDialog(2, "OTA升级", "请先选择设备!")
return
2024-08-26 14:55:15 +08:00
} else if (!App.currentDeviceConnected) {
2024-08-22 10:48:28 +08:00
showMessageDialog(2, "OTA升级", "设备已离线,请重新连接设备!")
2024-08-21 09:26:06 +08:00
return
}
otaPopup.open()
}
2024-08-14 20:01:38 +08:00
}
Item {}
spacing: (parent.width - (2 * 100)) / 3
2024-08-13 20:06:10 +08:00
}
2024-08-21 09:26:06 +08:00
function showMessageDialog(type, title, message) {
let component = Qt.createComponent("MessageDialog.qml")
if (component.status === Component.Ready) {
let dialog = component.createObject(window, {
2024-08-30 14:47:03 +08:00
"type": type,
"titleText": title,
"text": message
})
2024-08-21 09:26:06 +08:00
dialog.open()
}
}
2024-08-26 14:55:15 +08:00
2024-08-30 14:47:03 +08:00
function showFileDialog(nameFilters, onSelected) {
2024-08-27 11:14:36 +08:00
let dialog = null
if (isQt5) {
dialog = Qt.createQmlObject("import QtQuick.Dialogs 1.3; FileDialog {}", window, "myDynamicSnippet")
} else {
dialog = Qt.createQmlObject("import QtQuick.Dialogs; FileDialog {}", window, "myDynamicSnippet")
}
if (dialog) {
dialog.nameFilters = nameFilters;
dialog.visible = true
dialog.accepted.connect(function () {
let fileUrl = isQt5 ? dialog.fileUrl.toString() : dialog.selectedFile.toString()
2024-08-30 14:47:03 +08:00
let localFilePath = fileUrl.startsWith("file:///") ? fileUrl.substring(8) : fileUrl
2024-08-27 11:14:36 +08:00
onSelected(localFilePath)
dialog.destroy()
})
dialog.rejected.connect(function () {
dialog.destroy()
})
} else {
console.error("Failed to create FolderDialog object")
}
}
2024-08-26 16:46:41 +08:00
function showFolderDialog(onSelected) {
let dialog = null
if (isQt5) {
dialog = Qt.createQmlObject("import QtQuick.Dialogs 1.3; FileDialog {}", window, "myDynamicSnippet")
dialog.selectExisting = true
dialog.selectFolder = true
2024-08-26 16:46:41 +08:00
} else {
dialog = Qt.createQmlObject("import QtQuick.Dialogs; FolderDialog {}", window, "myDynamicSnippet")
}
if (dialog) {
dialog.visible = true
dialog.accepted.connect(function () {
onSelected(isQt5 ? dialog.fileUrl : dialog.selectedFolder)
2024-08-26 16:46:41 +08:00
dialog.destroy()
})
dialog.rejected.connect(function () {
dialog.destroy()
})
} else {
console.error("Failed to create FolderDialog object")
}
2024-08-26 14:55:15 +08:00
}
2024-08-22 10:48:28 +08:00
Connections {
target: App
function onNewMessage(type, title, message) {
showMessageDialog(type, title, message)
}
}
2024-08-26 14:55:15 +08:00
Connections {
target: App.devices
function onIsSearchingChanged() {
if (App.devices.isSearching) {
emptyHint.visible = false
} else if (!App.devices.isSearching && (App.devices.rowCount() <= 0)) {
emptyHint.visible = true
}
}
}
2024-08-13 09:54:41 +08:00
}