Compare commits

...

9 Commits
v1.7 ... master

Author SHA1 Message Date
luocai
21df3a8ee3 修改参数保存方式。
All checks were successful
Release tag / build (push) Successful in 2m19s
2024-12-31 11:29:56 +08:00
luocai
d86a45680b 添加异常判断处理。 2024-12-27 18:10:34 +08:00
d3ccaba32f fix linux ota file error. 2024-12-16 19:01:28 +08:00
7c2a29740b linux not use gbk. 2024-12-16 16:59:23 +08:00
8f72fbded7 add log for create udp. 2024-12-16 15:59:29 +08:00
luocai
798962e8bb 适配Linux。 2024-12-16 15:34:40 +08:00
luocai
fd494f2a03 实现检测阈值设置。 2024-12-13 16:57:00 +08:00
luocai
dbe7c1a64e 实现安全帽阈值下发控制。 2024-12-12 18:49:42 +08:00
luocai
559867bd31 添加安全帽检测阈值设置。 2024-12-11 19:05:37 +08:00
12 changed files with 470 additions and 51 deletions

View File

@ -12,5 +12,7 @@
<file>resources/prompt_delete.svg</file>
<file>resources/successfull.svg</file>
<file>resources/warning.svg</file>
<file>qml/MessageBar.qml</file>
<file>qml/Object.qml</file>
</qresource>
</RCC>

View File

@ -210,6 +210,51 @@ void Application::setCurrentDeviceRotation(int rotation) {
}
}
int Application::currentHelmetThreshold() const {
return m_currentHelmetThreshold;
}
void Application::setCurrentHelmetThreshold(int threshold) {
if (m_currentHelmetThreshold != threshold) {
m_currentHelmetThreshold = threshold;
emit currentHelmetThresholdChanged();
if (!m_device.expired()) {
auto device = m_device.lock();
device->updateDetectThreshold(m_currentHelmetThreshold, m_currentHeadThreshold, m_currentDetectFrameSize);
}
}
}
int Application::currentHeadThreshold() const {
return m_currentHeadThreshold;
}
void Application::setCurrentHeadThreshold(int threshold) {
if (m_currentHeadThreshold != threshold) {
m_currentHeadThreshold = threshold;
emit currentHeadThresholdChanged();
if (!m_device.expired()) {
auto device = m_device.lock();
device->updateDetectThreshold(m_currentHelmetThreshold, m_currentHeadThreshold, m_currentDetectFrameSize);
}
}
}
int Application::currentDetectFrameSize() const {
return m_currentDetectFrameSize;
}
void Application::setCurrentDetectFrameSize(int size) {
if (m_currentDetectFrameSize != size) {
m_currentDetectFrameSize = size;
emit currentDetectFrameSizeChanged();
if (!m_device.expired()) {
auto device = m_device.lock();
device->updateDetectThreshold(m_currentHelmetThreshold, m_currentHeadThreshold, m_currentDetectFrameSize);
}
}
}
void Application::updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway,
const QString &dns) {
if (!m_device.expired()) {
@ -231,6 +276,8 @@ void Application::connectToDevice(int index) {
disconnect(device.get(), &DeviceConnection::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea);
disconnect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea);
disconnect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea);
disconnect(device.get(), &DeviceConnection::detectThresholdChanged, this,
&Application::onDeviceDetectThresholdChanged);
disconnect(device.get(), &DeviceConnection::networkInfomationChanged, this,
&Application::onDeviceNetworkInfomation);
disconnect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware);
@ -255,6 +302,8 @@ void Application::connectToDevice(int index) {
connect(device.get(), &DeviceConnection::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea);
connect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea);
connect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea);
connect(device.get(), &DeviceConnection::detectThresholdChanged, this,
&Application::onDeviceDetectThresholdChanged);
connect(device.get(), &DeviceConnection::networkInfomationChanged, this,
&Application::onDeviceNetworkInfomation);
connect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware);
@ -283,6 +332,9 @@ void Application::connectToDevice(int index) {
m_currentDeviceConnected = device->isConnected();
m_currentDeviceFlip = info.flip;
m_currentDeviceRotation = info.rotation;
m_currentHelmetThreshold = info.helmetThreshold;
m_currentHeadThreshold = info.headThreshold;
m_currentDetectFrameSize = info.detectFrameSize;
emit currentDeviceRotationChanged();
emit currentDeviceFlipChanged();
emit currentOpenDoorAreaPointsChanged();
@ -292,6 +344,9 @@ void Application::connectToDevice(int index) {
emit currentShieldedAreaEnabledChanged();
emit currentAntiClipAreaEnabledChanged();
emit currentAntiClipSensitivityChanged();
emit currentHelmetThresholdChanged();
emit currentHeadThresholdChanged();
emit currentDetectFrameSizeChanged();
emit currentNetworkInfomationChanged();
}
emit currentFirmwareChanged();
@ -358,6 +413,12 @@ void Application::onDeviceAntiClipArea(bool enabled, const QList<QPointF> &point
setCurrentAntiClipSensitivity(sensitivity);
}
void Application::onDeviceDetectThresholdChanged(int helmetThreshold, int headThreshold, int detectFrameSize) {
setCurrentHelmetThreshold(helmetThreshold);
setCurrentHeadThreshold(headThreshold);
setCurrentDetectFrameSize(detectFrameSize);
}
void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) {
m_currentNetworkInfomation = info;
emit currentNetworkInfomationChanged();

View File

@ -35,6 +35,12 @@ class Application : public QObject {
Q_PROPERTY(bool currentAntiClipAreaEnabled READ currentAntiClipAreaEnabled WRITE setCurrentAntiClipAreaEnabled
NOTIFY currentAntiClipAreaEnabledChanged)
Q_PROPERTY(int currentAntiClipSensitivity READ currentAntiClipSensitivity WRITE setCurrentAntiClipSensitivity NOTIFY currentAntiClipSensitivityChanged)
Q_PROPERTY(int currentHelmetThreshold READ currentHelmetThreshold WRITE setCurrentHelmetThreshold NOTIFY
currentHelmetThresholdChanged)
Q_PROPERTY(int currentHeadThreshold READ currentHeadThreshold WRITE setCurrentHeadThreshold NOTIFY
currentHeadThresholdChanged)
Q_PROPERTY(int currentDetectFrameSize READ currentDetectFrameSize WRITE setCurrentDetectFrameSize NOTIFY
currentDetectFrameSizeChanged)
Q_PROPERTY(QList<QPointF> currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE
setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged)
Q_PROPERTY(
@ -77,6 +83,15 @@ public:
int currentDeviceRotation() const;
void setCurrentDeviceRotation(int rotation);
int currentHelmetThreshold() const;
void setCurrentHelmetThreshold(int threshold);
int currentHeadThreshold() const;
void setCurrentHeadThreshold(int threshold);
int currentDetectFrameSize() const;
void setCurrentDetectFrameSize(int size);
Q_INVOKABLE void updateOpenDoorAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateAntiClipAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateShieldedAreaPoints(const QList<QPointF> &points);
@ -99,6 +114,9 @@ signals:
void currentShieldedAreaEnabledChanged();
void currentAntiClipAreaEnabledChanged();
void currentAntiClipSensitivityChanged();
void currentHelmetThresholdChanged();
void currentDetectFrameSizeChanged();
void currentHeadThresholdChanged();
void currentNetworkInfomationChanged();
void currentFirmwareChanged();
void currentDeviceConnectedChanged();
@ -114,6 +132,7 @@ protected:
void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points);
void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points);
void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points, int sensitivity);
void onDeviceDetectThresholdChanged(int helmetThreshold, int headThreshold, int detectFrameSize);
void onDeviceNetworkInfomation(const NetworkInfomation &info);
void onDeviceFirmware(const QString &firmware);
void onDeviceConnected();
@ -140,6 +159,9 @@ private:
bool m_currentDeviceConnected = false;
bool m_currentDeviceFlip = false;
int m_currentDeviceRotation = 0;
int m_currentHelmetThreshold = 1;
int m_currentHeadThreshold = 2;
int m_currentDetectFrameSize = 3;
};
#endif // APPLICATION_H

View File

@ -1,12 +1,17 @@
cmake_minimum_required(VERSION 3.16)
project(AntiClipSettings VERSION 1.7 LANGUAGES C CXX)
project(AntiClipSettings VERSION 1.8 LANGUAGES C CXX)
set(APPLICATION_NAME "视觉防夹设备上位机工具")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(Libraries_ROOT E:/Projects/Libraries CACHE STRING "Libraries directory.")
if(LINUX)
set(Libraries_ROOT /opt/Libraries CACHE STRING "Libraries directory.")
else()
set(Libraries_ROOT E:/Projects/Libraries CACHE STRING "Libraries directory.")
endif()
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Qml Quick Network QuickControls2)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Qml Quick Network QuickControls2)
@ -24,7 +29,11 @@ else()
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
if(LINUX)
set(BOOST_ROOT ${Libraries_ROOT}/boost_1_83_0)
else()
set(BOOST_ROOT ${Libraries_ROOT}/boost_1_83_0_msvc2022_64bit)
endif()
set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include/boost-1_83)
set(FFmpeg_ROOT ${Libraries_ROOT}/ffmpeg-6.1.1-full_build-shared)
endif()
@ -39,8 +48,13 @@ set(FFmpeg_INCLUDE_DIR ${FFmpeg_ROOT}/include)
set(FFmpeg_LIB_DIR ${FFmpeg_ROOT}/lib)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(JPEGTURBO_ROOT ${Libraries_ROOT}/libjpeg-turbo-3.0.3_msvc2022_64bit_debug)
if(LINUX)
set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2)
set(JPEGTURBO_ROOT ${Libraries_ROOT}/libjpeg-turbo-3.1.0)
else()
set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2_msvc2022_64bit_debug)
set(JPEGTURBO_ROOT ${Libraries_ROOT}/libjpeg-turbo-3.0.3_msvc2022_64bit_debug)
endif()
else()
set(JPEGTURBO_ROOT ${Libraries_ROOT}/libjpeg-turbo-3.0.3_msvc2022_64bit_release)
set(MBEDTLS_ROOT ${Libraries_ROOT}/mbedtls-3.6.2_msvc2022_64bit_release)
@ -137,8 +151,9 @@ target_link_libraries(AntiClipSettings
PRIVATE avformat
PRIVATE Universal
PRIVATE Encrypt
PRIVATE turbojpeg-static
PRIVATE Ws2_32
$<$<PLATFORM_ID:Linux>:turbojpeg>
$<$<PLATFORM_ID:Windows>:turbojpeg-static>
$<$<PLATFORM_ID:Windows>:Ws2_32>
)
include(GNUInstallDirs)

View File

@ -5,13 +5,17 @@
#include <QPointF>
#include <QTimer>
#include <QTimerEvent>
#include <WinSock2.h>
#include <boost/json/object.hpp>
#include <boost/json/parse.hpp>
#include <boost/json/serialize.hpp>
#include <filesystem>
#include <fstream>
#include <mbedtls/md5.h>
#ifdef Q_OS_LINUX
#include <arpa/inet.h>
#else
#include <WinSock2.h>
#endif
DeviceConnection::DeviceConnection(QObject *parent) : QObject{parent} {
}
@ -240,6 +244,56 @@ void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QList<QPoint
m_requests.push(task);
}
QFuture<bool> DeviceConnection::updateDetectThreshold(int helmetThreshold, int headThreshold, int detectFrameSize) {
constexpr auto command = "headdetectparam_setdata";
Task task;
task.command = command;
task.task = [this, helmetThreshold, headThreshold, detectFrameSize, command]() {
boost::json::object request;
request["func"] = command;
request["deviceid"] = "0";
boost::json::object data;
if (headThreshold >= 0) {
data["headthreshold"] = headThreshold;
}
if (helmetThreshold >= 0) {
data["hatthreshold"] = helmetThreshold;
}
if (detectFrameSize >= 0) {
data["detectframenum"] = detectFrameSize;
}
request["data"] = std::move(data);
auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size());
};
task.future = std::make_shared<QFutureInterface<bool>>();
if (m_requests.empty()) {
task.task();
}
auto ret = task.future->future();
m_requests.push(task);
return ret;
}
void DeviceConnection::requestHeadDetectThreshold() {
constexpr auto command = "headdetectparam_getdata";
Task task;
task.command = command;
task.task = [this, command]() {
boost::json::object request;
request["func"] = command;
request["deviceid"] = "0";
boost::json::object data;
request["data"] = std::move(data);
auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size());
};
if (m_requests.empty()) {
task.task();
}
m_requests.push(task);
}
void DeviceConnection::requestResolution(Resolution resolution) {
Task task;
task.command = "quality_setdata";
@ -399,7 +453,11 @@ void DeviceConnection::requestOta(const QString &firmware, const QString &file)
Task task;
task.command = "a22devicefirmware_setdata";
task.task = [this, file, firmware]() {
#ifdef Q_OS_LINUX
std::ifstream ifs(file.toStdString(), std::ifstream::binary);
#else
std::ifstream ifs(Amass::StringUtility::UTF8ToGBK(file.toStdString()), std::ifstream::binary);
#endif
m_uploadBuffer = std::vector<uint8_t>((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
m_sendedSize = 0;
@ -459,7 +517,11 @@ void DeviceConnection::requestReset() {
void DeviceConnection::transferBinContent() {
constexpr int SliceSize = 1024;
constexpr int WaitMd5CheckTime = 3000; // ms
if (m_sendedSize >= m_uploadBuffer.size()) return;
if (m_sendedSize >= m_uploadBuffer.size()) {
LOG(warning) << "file size is wrong, sended size: " << m_sendedSize
<< "ota file size: " << m_uploadBuffer.size();
return;
}
char buffer[1 + sizeof(int32_t) + 1024];
int sendSize = SliceSize;
@ -697,6 +759,29 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
requestVideoInformation();
} else if (function == "a12factory_setdata") {
LOG(info) << "device factory reset";
} else if (function == "headdetectparam_getdata") {
auto &data = reply.at("data").as_object();
if (data.contains("hatthreshold")) {
m_infomation.helmetThreshold = data.at("hatthreshold").as_int64();
}
if (data.contains("headthreshold")) {
m_infomation.headThreshold = data.at("headthreshold").as_int64();
}
if (data.contains("detectframenum")) {
m_infomation.detectFrameSize = data.at("detectframenum").as_int64();
}
emit detectThresholdChanged(m_infomation.helmetThreshold, m_infomation.headThreshold,
m_infomation.detectFrameSize);
} else if (function == "thresholdwithhat_setdata") {
if ((task != nullptr) && (task->command.toStdString() == function)) {
if (task->timeoutTimer) {
task->timeoutTimer->stop();
}
bool status = true;
if (task->future) {
task->future->reportFinished(&status);
}
}
} else {
LOG(warning) << "unknown reply: " << replyText;
}
@ -712,6 +797,7 @@ void DeviceConnection::onConnected() {
requestAntiClipArea();
requestNetworkInfomation();
requestVideoInformation();
requestHeadDetectThreshold();
emit connected();
m_heartbeatTimerId = startTimer(2500);
if (m_otaProgress == 99) {

View File

@ -9,8 +9,10 @@
#include <QTcpSocket>
#include <queue>
#include <string_view>
#include <QPointF>
class NetworkInfomation;
class QTimer;
class DeviceConnection : public QObject {
Q_OBJECT
@ -48,6 +50,9 @@ public:
QList<QPointF> antiClipArea;
bool antiClipAreaEnabled;
int antiClipSensitivity = 1;
int helmetThreshold = 1;
int headThreshold = 1;
int detectFrameSize = 1;
};
Q_ENUM(AreaWay)
@ -71,6 +76,8 @@ public:
void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points, int sensitivity);
void requestResolution(Resolution resolution);
void requestNetworkInfomation();
QFuture<bool> updateDetectThreshold(int helmetThreshold, int headThreshold, int detectFrameSize);
void requestHeadDetectThreshold();
QFuture<bool> updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway,
const QString &dns);
void requestVersion();
@ -98,6 +105,7 @@ signals:
void antiClipAreaChanged(bool enabled, const QList<QPointF> &points, int sensitivity);
void rotationChanged(int rotation);
void flipChanged(bool flip);
void detectThresholdChanged(int helmetThreshold, int headThreshold, int detectFrameSize);
void networkInfomationChanged(const NetworkInfomation &info);
void firmwareChanged(const QString &firmware);
void otaProgressChanged(bool status, int progress, const QString &message);

View File

@ -139,6 +139,8 @@ void DeviceListModel::startSearchDevice() {
emit searchProgressChanged();
m_timerId = startTimer(1000);
emit isSearchingChanged();
} else {
LOG(warning) << "cannot creat udp sockets.";
}
}

View File

@ -17,6 +17,9 @@ Item {
property var antiClipAreaPoints: []
property bool antiClipAreaEnabled: false
property int antiClipSensitivity: 1
property alias helmetThreshold: helmetInput.text
property alias headThreshold: headInput.text
property alias detectFrameSize: detectFrameInput.text
property alias flip: flipSwitch.checked
property alias videoRotation: rotateComboBox.currentIndex
@ -247,13 +250,12 @@ Item {
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
columns: 4
columns: 2
Label { text: qsTr("图像: ") }
Row {
enabled: root.enabled
Layout.columnSpan: 3
Label {
anchors.verticalCenter: parent.verticalCenter
text: qsTr("旋转")
@ -281,9 +283,9 @@ Item {
Label {
text: qsTr("开门区域: ")
}
Row {
enabled: root.enabled
Layout.columnSpan: 3
RadioButton {
text: "关闭"
checked: App.currentOpenDoorAreaWay ==DeviceConnection.Diabled
@ -307,11 +309,17 @@ Item {
}
}
Label {
Layout.alignment: Qt.AlignTop
Layout.topMargin: 14
text: qsTr("防夹区域: ")
}
Label {text: qsTr("防夹区域: ")}
Row {
Flow{
Layout.fillHeight: true
Layout.fillWidth: true
RowLayout {
enabled: root.enabled
Layout.columnSpan: 1
RadioButton {
text: "关闭"
checked: !App.currentAntiClipAreaEnabled
@ -326,22 +334,115 @@ Item {
onToggled: {
App.currentAntiClipAreaEnabled=true
}
Layout.rightMargin: 20
}
}
RowLayout {
Label { text: qsTr("灵敏度: ")
Layout.alignment: Qt.AlignRight
}
ComboBox {
id: antiClipSensitivityComboBox
enabled: root.enabled
implicitWidth: 60
Layout.alignment: Qt.AlignLeft
model: [1,2,3,4,5]
currentIndex: root.antiClipSensitivity-1
onCurrentIndexChanged: {
App.currentAntiClipSensitivity = antiClipSensitivityComboBox.currentIndex+1
}
Layout.rightMargin: 20
}
}
}
Label {
Layout.alignment: Qt.AlignTop
Layout.topMargin: 14
text: qsTr("阈值设置: ")
}
Flow {
Layout.fillHeight: true
Layout.fillWidth: true
RowLayout {
Label { text: qsTr("安全帽阈值: ")
Layout.alignment: Qt.AlignRight
}
TextField {
id: helmetInput
enabled: root.enabled
implicitWidth: 60
Layout.alignment: Qt.AlignLeft
selectByMouse: true
ToolTip.visible: helmetInput.hovered
ToolTip.text: "阈值范围 0-300"
validator: IntValidator {
bottom: 0
top: 300
}
Layout.rightMargin: 20
}
}
RowLayout {
Label { text: qsTr("头肩阈值: ")
Layout.alignment: Qt.AlignRight
}
TextField {
id: headInput
enabled: root.enabled
implicitWidth: 60
Layout.alignment: Qt.AlignLeft
selectByMouse: true
ToolTip.visible: headInput.hovered
ToolTip.text: "阈值范围 0-300"
validator: IntValidator {
bottom: 0
top: 300
}
Layout.rightMargin: 20
}
}
RowLayout {
Label { text: qsTr("识别帧数: ")
Layout.alignment: Qt.AlignRight
}
TextField {
id: detectFrameInput
enabled: root.enabled
implicitWidth: 60
Layout.alignment: Qt.AlignLeft
selectByMouse: true
ToolTip.visible: detectFrameInput.hovered
ToolTip.text: "帧数范围 0-30"
validator: IntValidator {
bottom: 0
top: 30
}
}
}
Button {
enabled: root.enabled
text: "保存"
onClicked: {
if(App.currentHelmetThreshold !== parseInt(helmetInput.text)){
App.currentHelmetThreshold= parseInt(helmetInput.text)
window.showSuccess("安全帽阈值设置成功",2500)
}
if(App.currentHeadThreshold !== parseInt(headInput.text)){
App.currentHeadThreshold= parseInt(headInput.text)
window.showSuccess("头肩阈值设置成功",2500)
}
if(App.currentDetectFrameSize !== parseInt(detectFrameInput.text)){
App.currentDetectFrameSize= parseInt(detectFrameInput.text)
window.showSuccess("识别帧数设置成功",2500)
}
}
}
}
Label {text: qsTr("屏蔽区域: ")}
Row {

View File

@ -48,7 +48,8 @@ ApplicationWindow {
id: emptyHint
visible: false
anchors.centerIn: parent
text: qsTr("未搜索到设备")
horizontalAlignment: Text.AlignHCenter
text: qsTr("未搜索到设备\n请尝试关闭Windows防火墙后再重试")
}
delegate: Rectangle {
width: deviceList.width
@ -120,6 +121,9 @@ ApplicationWindow {
antiClipAreaEnabled: App.currentAntiClipAreaEnabled
antiClipSensitivity: App.currentAntiClipSensitivity
antiClipAreaPoints: App.currentAntiClipAreaPoints
helmetThreshold: App.currentHelmetThreshold
headThreshold: App.currentHeadThreshold
detectFrameSize: App.currentDetectFrameSize
flip: App.currentDeviceFlip
videoRotation: App.currentDeviceRotation
}
@ -186,8 +190,8 @@ ApplicationWindow {
showMessageDialog(2, "恢复出厂设置", "请先选择设备")
return
} else {
showMessageDialog(2, "恢复出厂设置", "设备将会重启,重启后配置恢复默认",()=>{
App.resetDevice();
showMessageDialog(2, "恢复出厂设置", "设备将会重启,重启后配置恢复默认", () => {
App.resetDevice()
})
}
}
@ -195,6 +199,14 @@ ApplicationWindow {
spacing: (parent.width - (2 * 100)) / 3
}
MessageBar {
id: messageBar
root: window.contentItem
}
function showSuccess(text, duration) {
return messageBar.showSuccess(text, duration)
}
function showMessageDialog(type, title, message, callback) {
let component = Qt.createComponent("MessageDialog.qml")
if (component.status === Component.Ready) {
@ -216,11 +228,14 @@ ApplicationWindow {
dialog = Qt.createQmlObject("import QtQuick.Dialogs; FileDialog {}", window, "myDynamicSnippet")
}
if (dialog) {
dialog.nameFilters = nameFilters;
dialog.nameFilters = nameFilters
dialog.visible = true
dialog.accepted.connect(function () {
let fileUrl = isQt5 ? dialog.fileUrl.toString() : dialog.selectedFile.toString()
let localFilePath = fileUrl.startsWith("file:///") ? fileUrl.substring(8) : fileUrl
let localFilePath = fileUrl
if (fileUrl.startsWith("file:///")) {
localFilePath = fileUrl.substring(Qt.platform.os === "windows" ? 8 : 7)
}
onSelected(localFilePath)
dialog.destroy()
})

101
qml/MessageBar.qml Normal file
View File

@ -0,0 +1,101 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
Object {
id: control
property var root
property var screenLayout: null
property int layoutY: 75
function showSuccess(text,duration=1000){
return create("success",text,duration)
}
function create(type,text,duration){
if(screenLayout){
let last = screenLayout.getLastloader()
if(last.type === type && last.text === text){
last.duration = duration
if (duration > 0) last.restart()
return last
}
} else {
initScreenLayout()
}
return contentComponent.createObject(screenLayout,{type:type,text:text,duration:duration,})
}
function initScreenLayout() {
if(control.screenLayout == null) {
control.screenLayout = screenLayoutComponent.createObject(root)
screenLayout.y = control.layoutY
screenLayout.z = 100000
}
}
Component {
id:contentComponent
Rectangle {
id: content
property int duration: 1500
property string type
property alias text: message.text
color: "#EBF8ED"
radius: 3.2
border.width: 1
border.color: Qt.darker(content.color)
layer.enabled: true
x:(parent.width - width) / 2
width: 200
height: 32
Row {
anchors.fill: parent
Image {
width: 32
height: 32
fillMode: Image.Pad
source: "qrc:/qt/qml/AntiClipSettings/resources/successfull.svg"
anchors.verticalCenter: parent.verticalCenter
}
Label {
id: message
anchors.verticalCenter: parent.verticalCenter
}
}
Timer {
id:delayTimer
interval: duration
running: duration > 0
repeat: duration > 0
onTriggered: content.close()
}
function close(){
content.destroy()
}
}
}
Component {
id:screenLayoutComponent
Column{
parent: Overlay.overlay
z:999
spacing: 5
width: root.width
move: Transition {
NumberAnimation {
properties: "y"
easing.type: Easing.InOutQuad
duration: 167
}
}
onChildrenChanged: if(children.length === 0) destroy()
function getLastloader(){
if(children.length > 0){
return children[children.length - 1]
}
return null
}
}
}
}

5
qml/Object.qml Normal file
View File

@ -0,0 +1,5 @@
import QtQml 2.15
QtObject {
default property list<QtObject> children
}

View File

@ -41,6 +41,7 @@ Popup {
Layout.fillWidth: true
readOnly: true
placeholderText: "请选择升级bin文件"
selectByMouse: true
}
Button {
enabled: otaFinished