| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585 |
- import QtQuick
- import Felgo
- import QtMultimedia
- import QtQuick.Controls
- import Qt.labs.settings 1.0 as QtLabs
- import QtQuick.Controls.Material 2.0
- import QtLocation 5.5
- import QtPositioning 5.5
- import Qt5Compat.GraphicalEffects
- import "../controls"
- import "../common"
- import Frames 0.1
- AppPage {
- //【必须有 id】上传进度弹层里用了 page.uploadPercent / page.uploadFailed 等绑定,
- //根元素原来没有 id,page 是未定义标识符 -> 绑定报 ReferenceError,
- //Popup 的 visible 永远算不出来,表现为"上传进度不显示"。
- id: page
- objectName: "autoFocus_Page"
- navigationBarHidden: true
- backgroundColor: app.theme_backgroundColor
- property var videoFormats
- // 定义电机状态
- property int currentAxis: 0 // 当前选择的轴 (0: X, 1: Y, 2: Z)
- property var axisPositions: [0, 0, 0] // 各轴当前位置
- property int speed: 50 // 当前速度 (0-100)
- property int stepDistance: 20 // 步进脉冲数量
- property string fExposureTime: "0"
- property bool motorUnlocked: false
- // ===== 上传进度水印(单张) =====
- // 业务上一次只上传一张图片(串行队列 FIFO,见 CurlFtpUploader::runLoop),
- // 所以不需要按序号铺 32 格进度网格,直接在画面上叠加一个整体进度水印即可。
- // uploading : 是否处于上传中(含进度回调已到达但 finished 尚未回来的窗口)
- // percent : 0~100,来自 CurlFtpUploader::progressChanged
- // fileName : 当前上传文件名(取末段),仅用于水印上显示是哪一张
- // failed : 本次上传是否失败(决定水印配色与文案)
- property bool uploading: false
- property double uploadPercent: 0
- property string uploadFileName: ""
- property bool uploadFailed: false
- // 进度圆可见性:仅在触发上传时为 true,收到 finished 后立即置 false 关闭展示
- property bool uploadWatermarkVisible: false
- function resetUploadWatermark() {
- uploading = false
- uploadPercent = 0
- uploadFileName = ""
- uploadFailed = false
- uploadWatermarkVisible = false
- uploadHideTimer.stop()
- }
- function autotake(sw){
- if(sw)
- {
- console.log("autotakestart")
- frames.camera_sw = true
- //frames.auto_clicked = true //开始对焦
- auto_timer.start() //启动对焦定时器
- console.log("相机已打开")
- photoTimer.interval=180*1000
- photoTimer.start()
- }else{
- frames.camera_sw = true
- console.log("打开相机单次拍照!")
- }
- }
- Frames {
- objectName: "Frames"
- id: frames
- videoSink: output.videoSink
- onCameraOpenFailed:function(err){
- console.log("onCameraOpenFailed",err)
- nativeUtils.displayMessageBox("相机打开失败!",err,1)
- focus_switch.checked = false
- focus_switch.enabled = true
- takephoto_switch.checked = false
- takephoto_switch.enabled = true
- }
- onVideoSinkChanged: {
- console.log("onVideoSinkChanged")
- photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
- }
- onQulityStringChanged: {
- loginpage.logintimeout = 600; //拍照刷新熄屏计时
- photoTimer.interval = 180*1000 //3分钟超时
- photoTimer.restart()
- }
- onRecordFileSaved: function(path){
- console.log("录制视频流已保存:", path)
- apptext_res.text = "录制已保存:" + path.split("/").pop()
- }
- onCameraStaChanged: function(sta_cam) {
- if(sta_cam){
- //camera.active = sta_cam
- //camera.start()
- //每次(重新)打开相机后清空上传进度水印(上一次采集的进度/结果不再保留)
- resetUploadWatermark()
- loginpage.logintimeout = 600; //拍照刷新熄屏计时
- output.visible = sta_cam
- photoTimer.interval = 180*1000 //3分钟超时
- photoTimer.start()
- //uvc_camera.visible = false
- }else{
- //camera.active = sta_cam
- //camera.stop()
- output.visible= sta_cam
- photoTimer.stop() //停止计时器
- focus_switch.checked = false
- focus_switch.enabled = true
- takephoto_switch.checked = false
- takephoto_switch.enabled = true
- //uvc_camera.visible = true
- }
- console.log("相机状态改变",sta_cam)
- }
- onStepCountChanged: function(step){
- console.log("坐标改变",step)
- step_apptextfield.text = step
- }
- onExposureTimeChanged: {
- fExposureTime = frames.cam_ExposureTime
- }
- }
- Timer {
- id: photoTimer
- interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位)
- running: false // 初始状态下定时器停止
- repeat: false // 设置为false,以便只执行一次
- onTriggered: {
- // 定时器触发后,设置按钮可用
- // camera.active = false
- // camera.stop()
- output.visible = false
- frames.camera_sw = false
- }
- }
- Timer {
- id: auto_timer
- interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位)
- running: false // 初始状态下定时器停止
- repeat: false // 设置为false,以便只执行一次
- onTriggered: {
- // 定时器触发后,开始对焦
- frames.auto_clicked = true
- }
- }
- Connections{
- target: mqtt
- function onMessagePub(message) {
- if(app.showPubData){
- var time = new Date().toLocaleTimeString()
- app.txDataLog = "[" + time + "] " + message + "\n" + app.txDataLog
- if(app.txDataLog.length > 5000) app.txDataLog = app.txDataLog.substring(0, 5000)
- }
- }
- function onMessageSub(message) {
- if(app.showSubData){
- var time = new Date().toLocaleTimeString()
- app.rxDataLog = "[" + time + "] " + message + "\n" + app.rxDataLog
- if(app.rxDataLog.length > 5000) app.rxDataLog = app.rxDataLog.substring(0, 5000)
- }
- }
- function onSignal_set_camera_exposure(exposureTime) {
- console.log("收到远程相机曝光设置指令,曝光时间:" + exposureTime)
- frames.cam_ExposureTime = exposureTime.toString()
- }
- // 远程校准指令: {"cmd":"slide","ext":{"calibrate":"y","speed":"50"}} → 打开相机
- function onSignal_open_camera() {
- console.log("收到远程相机开启指令,打开相机!")
- frames.camera_sw = true
- }
- }
- // 图片上传进度 → 画面上的单张上传水印
- Connections {
- target: curl_picture
- function onProgressChanged(uploadedPercent, filePath){
- // 一次只有一张图在传,直接更新整体进度即可,无需按序号分发
- uploading = true
- uploadWatermarkVisible = true
- uploadPercent = Math.max(0, Math.min(100, uploadedPercent))
- uploadFailed = false
- if(filePath && filePath !== uploadFileName){
- // 只取路径末段做显示,避免水印被长路径撑开
- uploadFileName = String(filePath).split(/[\\/]/).pop()
- }
- uploadHideTimer.stop()
- }
- function onFinished(success, filePath, error){
- uploading = false
- if(success){
- uploadPercent = 100
- uploadFailed = false
- console.log("上传完成:", filePath)
- }else{
- uploadFailed = true
- console.log("上传失败:", filePath, error)
- }
- // 进度条改为弹出式后不再遮挡画面,给它留一点停留时间:
- // 成功 1.5s 收起,失败 5s(也可点击弹层立即关闭)
- uploadHideTimer.interval = success ? 1500 : 5000
- uploadHideTimer.restart()
- }
- }
- // 保留:仅用于手动复位时的清理,正常流程由 onFinished 延时关闭展示
- Timer {
- id: uploadHideTimer
- interval: 1500
- running: false
- repeat: false
- onTriggered: uploadWatermarkVisible = false
- }
- // ===== 图片上传进度条(弹出式) =====
- // 需求:取消画面上叠加的上传进度圆/状态文字,改成居中弹出的进度条;
- // 上传中显示文件名与百分比,成功/失败保留一小段时间后自动收起(点击也可立即收起)。
- Popup {
- id: uploadPopup
- parent: Overlay.overlay
- modal: false
- focus: false
- closePolicy: Popup.NoAutoClose
- visible: page.uploadWatermarkVisible
- width: Math.min((parent ? parent.width : dp(600)) * 0.7, dp(520))
- height: dp(104)
- x: parent ? (parent.width - width) / 2 : 0
- y: parent ? parent.height * 0.10 : 0
- padding: dp(14)
- background: Rectangle {
- color: "#e6212121"
- radius: dp(8)
- border.width: 1
- border.color: page.uploadFailed ? "#ff8a80" : "#4f8cff"
- }
- // 点击立即收起(失败时现场可以先看清错误,再手动关掉)
- MouseArea {
- anchors.fill: parent
- onClicked: page.uploadWatermarkVisible = false
- }
- Column {
- id: uploadColumn
- width: parent.width
- spacing: dp(8)
- AppText {
- width: parent.width
- text: (page.uploading
- ? "图片上传中 "
- : (page.uploadFailed ? "图片上传失败 " : "图片上传完成 "))
- + page.uploadFileName
- color: page.uploadFailed ? "#ff8a80" : "#ffffff"
- font.pixelSize: sp(12)
- elide: Text.ElideMiddle
- }
- ProgressBar {
- width: parent.width
- from: 0
- to: 100
- value: page.uploadPercent
- }
- AppText {
- width: parent.width
- text: Math.round(page.uploadPercent) + " %"
- color: "#cfd8dc"
- font.pixelSize: sp(11)
- horizontalAlignment: Text.AlignRight
- }
- }
- }
- Connections{
- target: serial
- onTakephotodone:{
- console.log("立即拍照完成!")
- apptext_res.text = "立即拍照完成!"
- focus_switch.enabled = true
- focus_switch.checked = false
- }
- onAutotestdone: {
- console.log("自动对焦完成!")
- apptext_res.text = "自动对焦完成!"
- autotest_switch.enabled = true
- autotest_switch.checked = false
- }
- onTranslatedone: {
- console.log("胶带传送完成!")
- apptext_res.text = "胶带传送完成!"
- jiaodai_switch.enabled = true
- jiaodai_switch.checked = false
- }
- onDataReceived:function(data) {
- if(app.showRxData){
- var time = new Date().toLocaleTimeString()
- app.rxDataLog = "[" + time + "] " + data + "\n" + app.rxDataLog
- if(app.rxDataLog.length > 5000) app.rxDataLog = app.rxDataLog.substring(0, 5000)
- }
- // 同步坐标值到输入框
- try {
- var jsonData = JSON.parse(data)
- if(jsonData.ext && !textInput_x.focus && jsonData.ext.x_init_dis !== undefined) {
- textInput_x.text = jsonData.ext.x_init_dis.toString()
- }
- if(jsonData.ext && !textInput_y.focus && jsonData.ext.y_init_dis !== undefined) {
- textInput_y.text = jsonData.ext.y_init_dis.toString()
- }
- } catch(e) {
- console.log("解析坐标数据失败:", e)
- }
- }
- onNetMessage:function(data) {
- if(app.showTxData){
- var time = new Date().toLocaleTimeString()
- app.txDataLog = "[" + time + "] " + data + "\n" + app.txDataLog
- if(app.txDataLog.length > 5000) app.txDataLog = app.txDataLog.substring(0, 5000)
- }
- }
- }
- SplitView{
- anchors.fill: parent
- orientation: Qt.Horizontal
- Rectangle {
- SplitView.preferredWidth: parent.width * 0.7
- height: parent.height
- color: app.cardColor
- radius: 5
- AppButton {
- id: normButton
- //anchors.horizontalCenter: parent.horizontalCenter
- anchors.centerIn: parent
- anchors.fill: parent
- //text: "打开相机"
- flat: true //边框是否可视
- onClicked: {
- console.log("相机状态:",frames.camera_sw)
- //if(camera.active){
- if(frames.camera_sw){
- text = "相机已关闭"
- output.visible = false
- frames.camera_sw = false
- //uvc_camera.visible = false
- }else{
- text = "打开相机"
- output.visible = true
- frames.camera_sw = true
- //uvc_camera.visible = true
- }
- }
- Timer {
- id: longPressTimer
- interval: 1000 // 长按时间1000ms
- running: false // 初始状态下定时器停止
- repeat: false // 设置为false,以便只执行一次
- onTriggered: {
- console.log("长按触发")
- }
- }
- onPressed: {
- console.log("按钮按下,开始计时")
- longPressTimer.start()
- }
- onReleased: {
- console.log("按钮释放,停止计时")
- longPressTimer.stop()
- }
- AppImage{
- id: image_picdis
- anchors.centerIn: parent
- source: "../../assets/photoico.svg"
- }
- }
- VideoOutput
- {
- id: output
- anchors.fill: parent
- visible: false
- fillMode: VideoOutput.PreserveAspectFit //根据视频的纵横比例等比例缩放
- //fillMode: VideoOutput.Stretch
- Component.onCompleted: {
- console.log("output onCompleted")
- }
- }
- // 画面左上角信息:帧率 / 清晰度 / 已录制帧数
- // 统一用 Column 纵向排列(显式宽度 + spacing):
- // 原来 fps 放在 Row 里(width: parent.width),Row 的宽度又来自子项,
- // 形成循环依赖,Row 的高度解算不稳定,导致清晰度、帧数与 fps 叠在一起。
- // Column 的宽度是显式绑定的,子项 width: parent.width 不再回退到自身,
- // 纵向位置也由 Column 统一分配,不会再挤成一团。
- Column {
- id: infoColumn
- anchors.top: parent.top
- anchors.left: parent.left
- anchors.topMargin: dp(6)
- anchors.leftMargin: dp(8)
- width: parent.width - dp(44)
- spacing: dp(4)
- AppText {
- id: photoclarity_text
- width: parent.width
- text: frames.fpsString
- color: "red"
- elide: Text.ElideRight
- }
- AppText {
- id: photoclarity2_text
- width: parent.width
- text: frames.qulityString
- color: "green"
- elide: Text.ElideRight
- }
- // 已录制帧数:步进扫描时每步应只 +1,用来现场核对"移动 N 步是否只录了 N 帧"
- // (之前出现过移动 100 步写出 200 帧,原因是重复 movy 被重复落盘)
- AppText {
- id: recordFrames_text
- width: parent.width
- text: "已录制帧数: " + frames.recordedFrames + (frames.recording ? " (录制中)" : "")
- color: "#ffd54f"
- font.pixelSize: sp(13)
- elide: Text.ElideRight
- // 未开始录制时不占位(Column 会跳过不可见子项)
- visible: frames.recording || frames.recordedFrames > 0
- }
- }
- // 抓图按钮:仅相机打开时显示,画面右下角透明背景,点击=模拟MCU拍照指令(按序号保存/锐化/上传)
- Rectangle {
- id: captureBtn
- visible: frames.camera_sw
- width: dp(56)
- height: dp(56)
- radius: width / 2
- color: "transparent"
- border.color: "#80ffffff"
- border.width: dp(2)
- anchors.right: parent.right
- anchors.bottom: parent.bottom
- anchors.rightMargin: dp(12)
- anchors.bottomMargin: dp(12)
- AppImage {
- anchors.centerIn: parent
- width: dp(34)
- height: dp(34)
- source: "../../assets/photoico.svg"
- }
- MouseArea {
- anchors.fill: parent
- onClicked: {
- console.log("抓图按钮点击!")
- frames.manualCapture()
- }
- }
- }
- // 录制按钮:仅相机打开时显示,画面右下角(抓图按钮左侧)
- // 点击开始录制原始(未压缩)视频流,再次点击停止并把视频流保存到相机打开时创建的文件夹
- Rectangle {
- id: recordBtn
- visible: frames.camera_sw
- width: dp(56)
- height: dp(56)
- radius: width / 2
- color: "transparent"
- border.color: frames.recording ? "#e74c3c" : "#80ffffff"
- border.width: dp(2)
- anchors.right: captureBtn.left
- anchors.bottom: parent.bottom
- anchors.rightMargin: dp(12)
- anchors.bottomMargin: dp(12)
- // 未录制:红色圆点(开始);录制中:红色方块(停止)
- Rectangle {
- anchors.centerIn: parent
- width: frames.recording ? dp(22) : dp(26)
- height: frames.recording ? dp(22) : dp(26)
- radius: frames.recording ? dp(3) : width / 2
- color: "#e74c3c"
- }
- MouseArea {
- anchors.fill: parent
- onClicked: {
- if(frames.recording){
- console.log("停止录制视频流")
- frames.stopRecord()
- }else{
- console.log("开始录制视频流")
- if(frames.startRecord()){
- apptext_res.text = "开始录制视频流"
- }else{
- nativeUtils.displayMessageBox("提示","录制失败,请先打开相机!",1)
- }
- }
- }
- }
- }
- // 分析/融合处理期间:挂起相机画面输出,用进度/过程替代画面
- Rectangle {
- id: processOverlay
- visible: frames.processing
- anchors.fill: parent
- color: "#E6000000"
- z: 20
- Column {
- anchors.centerIn: parent
- spacing: dp(12)
- BusyIndicator {
- anchors.horizontalCenter: parent.horizontalCenter
- running: frames.processing
- width: dp(56)
- height: dp(56)
- }
- AppText {
- anchors.horizontalCenter: parent.horizontalCenter
- text: frames.processMessage
- color: "white"
- fontSize: 16
- }
- AppText {
- anchors.horizontalCenter: parent.horizontalCenter
- text: "处理中 " + frames.processPercent + "%"
- color: "#28a779"
- fontSize: 15
- }
- // 进度条
- Rectangle {
- width: dp(280)
- height: dp(8)
- radius: dp(4)
- color: "#33ffffff"
- anchors.horizontalCenter: parent.horizontalCenter
- Rectangle {
- width: parent.width * frames.processPercent / 100
- height: parent.height
- radius: parent.radius
- color: "#28a779"
- }
- }
- }
- }
- }
- ScrollView
- {
- SplitView.preferredWidth: parent.width*0.29
- SplitView.minimumWidth: 200
- clip: true
- Column {
- spacing: dp(15)
- Row {
- spacing: 80
- AppText {
- id: text_title
- text: "测试调试"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- AppText {
- id: apptext_res
- text: "[测试结果]"
- fontSize:15
- color: "grey"
- anchors.verticalCenter: text_title.verticalCenter
- }
- }
- Row {
- spacing: dp(120)
- AppText{
- text: "一键测试"
- fontSize: 15
- color: app.fontColor
- anchors.verticalCenter: autotest_switch.verticalCenter
- }
- AppSwitch {
- id: autotest_switch
- onToggled: {
- if(autotest_switch.checked==true){
- autotest_switch.enabled = false
- serial.sendCmd("autotest",true,"","");
- t_autotest.start()
- }else{
- console.log("t_autotest 计数:",t_autotest.interval)
- }
- }
- }
- Timer {
- id: t_autotest
- interval: 1000*60
- running: false
- repeat: false
- onTriggered: {
- autotest_switch.enabled = true
- autotest_switch.checked = false
- }
- }
- }
- Row {
- spacing: dp(120)
- AppText{
- text: "风机测试"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: fantest_switch.verticalCenter
- }
- AppSwitch {
- id: fantest_switch
- onToggled: {
- if(fantest_switch.checked==true){
- serial.sendCmd("fan",true,"","");
- apptext_res.text = "打开风机"
- }else{
- serial.sendCmd("fan",false,"","");
- apptext_res.text = "关闭风机"
- }
- }
- }
- }
- Row {
- spacing: dp(120)
- AppText{
- text: "胶带测试"
- fontSize: 15
- color: app.fontColor
- //font.bold: true
- anchors.verticalCenter: jiaodai_switch.verticalCenter
- }
- AppSwitch {
- id: jiaodai_switch
- onToggled: {
- if(jiaodai_switch.checked==true){
- // 检查是否处于温度保护状态
- if(app.tempProtectionState === true){
- // 弹出提示对话框
- nativeUtils.displayMessageBox(
- "提示",
- "当前处于温控状态,请解除温控后再进行测试胶带传送",
- 1
- );
- // 恢复开关状态为未选中
- jiaodai_switch.checked = false;
- return;
- }
- // 正常执行胶带测试
- //jiaodai_switch.enabled = false
- apptext_res.text = "胶带测试开始"
- serial.sendCmd("jiaodai",true,"","");
- }
- }
- }
- }
- Row {
- spacing: dp(120)
- AppText {
- text: "补光测试"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: led_switch.verticalCenter
- }
- AppSwitch {
- id: led_switch
- onToggled: {
- if(led_switch.checked==true){
- serial.sendCmd("led",true,"","");
- apptext_res.text = "补光灯已打开"
- }else{
- serial.sendCmd("led",false,"","");
- apptext_res.text = "补光灯已关闭"
- }
- }
- }
- }
- Row {
- spacing: dp(120)
- AppText {
- text: "立即拍照"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: takephoto_switch.verticalCenter
- }
- AppSwitch {
- id: takephoto_switch
- onToggled: {
- if(takephoto_switch.checked==true){
- apptext_res.text = "立即拍照"
- frames.captureImage()
- }
- }
- }
- }
- Row {
- spacing: dp(120)
- AppText {
- text: "对焦拍照"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: focus_switch.verticalCenter
- }
- AppSwitch {
- id: focus_switch
- onToggled: {
- if(focus_switch.checked==true){
- apptext_res.text = "开始对焦"
- focus_switch.enabled = false
- serial.auto_takephoto(true)
- }
- }
- }
- }
- // 滤网更换测试按钮(始终可见)
- Row {
- spacing: dp(120)
- AppText {
- text: "滤网更换"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: selfclean_switch.verticalCenter
- }
- AppSwitch {
- id: selfclean_switch
- onToggled: {
- if(selfclean_switch.checked==true){
- apptext_res.text = "自清洁测试中..."
- serial.sendCmd("selfclean",true,"","");
- }
- }
- }
- }
- // 分割线
- Rectangle {
- visible: !motorUnlocked
- width: parent.width
- height: dp(1)
- color: "#e0e0e0"
- }
- // 分割线
- Rectangle {
- width: parent.width
- height: dp(2)
- color: "#28a779"
- }
- // 密码输入区域(未解锁时显示)
- Rectangle {
- visible: !motorUnlocked
- width: parent.width
- height: passwordColumn.height + dp(16)
- color: app.cardColor
- radius: dp(8)
- border.color: "#28a779"
- border.width: dp(1)
- Column {
- id: passwordColumn
- anchors.centerIn: parent
- spacing: dp(10)
- AppText {
- anchors.horizontalCenter: parent.horizontalCenter
- text: "请输入密码解锁电机控制"
- color: app.fontColor
- font.bold: true
- fontSize: 14
- }
- Row {
- anchors.horizontalCenter: parent.horizontalCenter
- spacing: dp(8)
- AppTextField {
- id: motorPasswordInput
- width: dp(130)
- height: dp(38)
- echoMode: TextInput.Password
- placeholderText: "密码"
- inputMethodHints: Qt.ImhDigitsOnly
- anchors.verticalCenter: parent.verticalCenter
- onAccepted: {
- if(text === "666888"){
- motorUnlocked = true
- text = ""
- }else{
- apptext_res.text = "密码错误"
- text = ""
- }
- }
- }
- AppButton {
- text: "确认"
- textColor: "white"
- flat: false
- backgroundColor: "#28a779"
- minimumHeight: dp(38)
- minimumWidth: dp(55)
- anchors.verticalCenter: parent.verticalCenter
- onClicked: {
- if(motorPasswordInput.text === "666888"){
- motorUnlocked = true
- motorPasswordInput.text = ""
- }else{
- apptext_res.text = "密码错误"
- motorPasswordInput.text = ""
- }
- }
- }
- }
- }
- }
- // 电机控制及以下所有控件(解锁后显示)
- Item {
- id: motorSection
- visible: motorUnlocked
- width: parent.width
- height: motorContent.height + dp(20)
- property alias content: motorContent
- Column {
- id: motorContent
- spacing: dp(12)
- width: parent.width
- // 锁定按钮
- Row {
- spacing: dp(5)
- width: parent.width
- AppText {
- text: "高级控制"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- anchors.verticalCenter: parent.verticalCenter
- }
- AppButton {
- text: "锁定"
- textColor: "white"
- flat: false
- backgroundColor: "#d9534f"
- minimumHeight: dp(25)
- minimumWidth: dp(50)
- anchors.verticalCenter: parent.verticalCenter
- onClicked: motorUnlocked = false
- }
- }
- AppText {
- id: text_title2
- text: "三轴步进电机控制"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- // ===== 图像处理开关(与电机控制一起锁在密码后面)=====
- // 1) 景深融合:关掉后录制结束只保留最清晰帧,不做融合
- // 状态唯一来源是 frames.fusionEnabled(= param::fusion_enable,
- // MQTT fusion_sw 也会改它,所以用 Connections 双向同步,不做单向绑定)
- Row {
- spacing: dp(12)
- width: parent.width
- AppText {
- text: "景深融合"
- width: dp(140)
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: fusion_switch.verticalCenter
- }
- AppSwitch {
- id: fusion_switch
- // 不用 checked: frames.fusionEnabled 绑定:用户点开关时控件内部会
- // 直接给 checked 赋值、绑定被打断,之后 MQTT 改状态就同步不过来了。
- // 这里改成显式赋值 + Connections 回灌,始终以 frames 的值为准。
- Component.onCompleted: checked = frames.fusionEnabled
- onToggled: {
- frames.fusionEnabled = checked
- console.log("景深融合:", checked ? "开" : "关")
- }
- }
- AppText {
- text: frames.fusionEnabled ? "开" : "关"
- color: frames.fusionEnabled ? "#28a779" : "#d9534f"
- anchors.verticalCenter: fusion_switch.verticalCenter
- }
- }
- // 2) 临时调试:保留录制文件(rawv),便于复盘;不写库,重启复位
- Row {
- spacing: dp(12)
- width: parent.width
- AppText {
- text: "保留录像(调试)"
- width: dp(140)
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: keep_record_switch.verticalCenter
- }
- AppSwitch {
- id: keep_record_switch
- Component.onCompleted: checked = frames.debugKeepRecord
- onToggled: {
- frames.debugKeepRecord = checked
- console.log("调试保留录像:", checked ? "开" : "关")
- }
- }
- AppText {
- text: frames.debugKeepRecord ? "开" : "关"
- color: frames.debugKeepRecord ? "#ffd54f" : "#9e9e9e"
- anchors.verticalCenter: keep_record_switch.verticalCenter
- }
- }
- // 融合开关状态回灌:MQTT fusion_sw、启动读库、按钮点击都会走这里,
- // 保证界面开关显示与 param::fusion_enable 始终一致
- Connections {
- target: frames
- function onFusionEnabledChanged() {
- if(fusion_switch.checked !== frames.fusionEnabled)
- fusion_switch.checked = frames.fusionEnabled
- }
- function onDebugKeepRecordChanged() {
- if(keep_record_switch.checked !== frames.debugKeepRecord)
- keep_record_switch.checked = frames.debugKeepRecord
- }
- }
- // 轴选择
- Row {
- spacing: dp(8)
- width: parent.width
- AppText {
- text: "选择轴:"
- width: dp(60)
- color: app.fontColor
- anchors.verticalCenter: parent.verticalCenter
- }
- ComboBox {
- width: parent.width - dp(100)
- height: dp(40)
- model: ["X轴", "Y轴", "Z轴"]
- onCurrentIndexChanged: currentAxis = currentIndex
- }
- AppButton {
- text: "校准"
- textColor: "black"
- flat: false
- borderColor: "black"
- borderWidth: dp(1)
- backgroundColor: "white"
- minimumHeight: dp(30)
- minimumWidth: dp(50)
- onClicked:
- {
- autotake(false)
- if(currentAxis==0)
- {
- console.log("校准X")
- serial.sendCmd("calibrate",false,"x",speed.toString())
- }else if(currentAxis==1)
- {
- console.log("校准Y")
- serial.sendCmd("calibrate",false,"y",speed.toString())
- }else if(currentAxis==2)
- {
- console.log("校准Z")
- serial.sendCmd("calibrate",false,"z",speed.toString())
- }
- }
- }
- }
- // 速度调节
- Row {
- spacing: dp(10)
- width: parent.width
- AppText {
- text: "速度:"
- width: dp(40)
- color: app.fontColor
- anchors.verticalCenter: parent.verticalCenter
- }
- AppSlider {
- width: parent.width - dp(60)
- from: 0
- to: 100
- value: speed
- stepSize: 1
- onValueChanged: speed = value
- anchors.verticalCenter: parent.verticalCenter
- }
- AppText {
- text: speed
- width: dp(40)
- anchors.verticalCenter: parent.verticalCenter
- }
- }
- // 步进距离设置
- Row {
- spacing: dp(10)
- width: parent.width
- AppText {
- text: "步进脉冲次数:"
- width: dp(120)
- color: app.fontColor
- anchors.verticalCenter: parent.verticalCenter
- }
- AppTextField {
- id: step_apptextfield
- width: parent.width - dp(120)
- text: stepDistance
- validator: IntValidator { bottom: 0; top: 2000 }
- onTextChanged: stepDistance = parseInt(text)
- }
- }
- // 运动控制按钮
- Row {
- spacing: dp(10)
- width: parent.width
- AppButton {
- text: " 正转 "
- textColor: "black"
- flat: false
- borderColor: "black"
- borderWidth: dp(1)
- backgroundColor: "grey"
- minimumHeight: dp(30)
- minimumWidth: dp(50)
- width: (parent.width - dp(30))/4
- onClicked:
- {
- if(currentAxis==0)
- {
- console.log("X轴正转:",stepDistance)
- serial.sendCmd("movx",false,"f"+stepDistance,speed.toString())
- }else if(currentAxis==1)
- {
- console.log("Y轴正转:",stepDistance)
- serial.sendCmd("movy",false,"f"+stepDistance,speed.toString())
- }else if(currentAxis==2)
- {
- console.log("Z轴正转:",stepDistance)
- serial.sendCmd("movz",false,"f"+stepDistance,speed.toString())
- }
- }
- }
- AppButton {
- text: " 停止 "
- textColor: "black"
- flat: false
- borderColor: "black"
- borderWidth: dp(1)
- backgroundColor: "red"
- minimumHeight: dp(30)
- minimumWidth: dp(50)
- width: (parent.width - dp(30))/4
- onClicked:
- {
- console.log("停止")
- serial.sendCmd("movx",false,"f0","")
- }
- }
- AppButton {
- text: " 反转 "
- textColor: "black"
- flat: false
- borderColor: "black"
- borderWidth: dp(1)
- backgroundColor: "grey"
- minimumHeight: dp(30)
- minimumWidth: dp(50)
- width: (parent.width - dp(30))/4
- onClicked:
- {
- if(currentAxis==0)
- {
- console.log("X轴反转:",stepDistance)
- serial.sendCmd("movx",false,"b"+stepDistance,speed.toString())
- }else if(currentAxis==1)
- {
- console.log("Y轴反转:",stepDistance)
- serial.sendCmd("movy",false,"b"+stepDistance,speed.toString())
- }else if(currentAxis==2)
- {
- console.log("Z轴反转:",stepDistance)
- serial.sendCmd("movz",false,"b"+stepDistance,speed.toString())
- }
- }
- }
- AppButton {
- text: " 复位 "
- textColor: "black"
- flat: false
- borderColor: "black"
- borderWidth: dp(1)
- backgroundColor: "grey"
- minimumHeight: dp(30)
- minimumWidth: dp(50)
- width: (parent.width - dp(30))/4
- onClicked: {
- if(currentAxis==0)
- {
- console.log("X轴复位!")
- serial.sendCmd("movx",true,"",speed.toString())
- }else if(currentAxis==1)
- {
- console.log("Y轴复位!")
- serial.sendCmd("movy",true,"",speed.toString())
- }else if(currentAxis==2)
- {
- console.log("Z轴复位!")
- serial.sendCmd("movz",true,"",speed.toString())
- }
- }
- }
- }
- // ===== 坐标参数 =====
- AppText {
- text: "坐标参数"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- // X 坐标输入行
- Row {
- spacing: dp(5)
- width: parent.width
- AppText {
- text: "X坐标:"
- width: dp(50)
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: textInput_x.verticalCenter
- }
- AppTextField {
- id: textInput_x
- width: parent.width - dp(80)
- height: dp(40)
- placeholderText: "0"
- text: "0"
- font.family: "Arial"
- font.pixelSize: 15
- validator: DoubleValidator { decimals: 2 }
- EnterKey.type: Qt.EnterKeyDone
- inputMethodHints: Qt.ImhFormattedNumbersOnly
- property real numericValue_x: Number(text) || 0
- Keys.onReturnPressed: {
- serial.setHt_xy_dis(numericValue_x, textInput_y.numericValue_y)
- Qt.inputMethod.hide()
- }
- onAccepted: {
- serial.setHt_xy_dis(numericValue_x, textInput_y.numericValue_y)
- }
- }
- }
- // Y 坐标输入行
- Row {
- spacing: dp(5)
- width: parent.width
- AppText {
- text: "Y坐标:"
- width: dp(50)
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: textInput_y.verticalCenter
- }
- AppTextField {
- id: textInput_y
- width: parent.width - dp(80)
- height: dp(40)
- placeholderText: "0"
- text: "0"
- font.family: "Arial"
- font.pixelSize: 15
- validator: DoubleValidator { decimals: 2 }
- EnterKey.type: Qt.EnterKeyDone
- inputMethodHints: Qt.ImhFormattedNumbersOnly
- property real numericValue_y: Number(text) || 0
- Keys.onReturnPressed: {
- serial.setHt_xy_dis(textInput_x.numericValue_x, numericValue_y)
- Qt.inputMethod.hide()
- }
- onAccepted: {
- serial.setHt_xy_dis(textInput_x.numericValue_x, numericValue_y)
- }
- }
- }
- // 分割线
- Rectangle {
- width: parent.width
- height: dp(2)
- color: "#e0e0e0"
- }
- // ===== 相机参数 =====
- AppText {
- id: text_camera
- text: "相机参数"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- Row {
- spacing: dp(10)
- width: parent.width
- AppText {
- id: txt_fExposureTime
- text: "曝光值:"
- color: app.fontColor
- }
- AppTextField {
- anchors.verticalCenter: txt_fExposureTime.verticalCenter
- placeholderText: fExposureTime
- text: fExposureTime
- width: parent.width - dp(10)
- EnterKey.type: Qt.EnterKeyDone
- wrapMode: Text.NoWrap
- inputMethodHints: Qt.ImhFormattedNumbersOnly |
- Qt.ImhPreferDone |
- Qt.ImhNoPredictiveText
- validator: DoubleValidator {
- bottom: 100.00
- top: 500000.00
- decimals: 0
- }
- // 关键:兜底(IME 再作妖也不怕)
- Keys.onReturnPressed: {
- frames.cam_ExposureTime = text
- console.log("设置曝光时间:",text)
- Qt.inputMethod.hide()
- }
- onAccepted: {
- frames.cam_ExposureTime = text
- console.log("设置曝光时间",text)
- }
- }
- }
- // 相机型号(海康工业相机,打开相机后自动读取展示)
- Row {
- spacing: dp(10)
- width: parent.width
- AppText {
- id: txt_camModel
- text: "相机型号:"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: parent.verticalCenter
- }
- AppText {
- text: frames.cam_ModelName
- color: "#28a779"
- font.bold: true
- fontSize: 15
- elide: Text.ElideRight
- width: parent.width - txt_camModel.width - dp(10)
- anchors.verticalCenter: parent.verticalCenter
- }
- }
- // 亮度(自动曝光目标灰度0-255,设置后切换为自动曝光,手动曝光值失效)
- Row {
- spacing: dp(10)
- width: parent.width
- AppText {
- id: txt_fBrightness
- text: "亮度:"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: parent.verticalCenter
- }
- AppTextField {
- anchors.verticalCenter: txt_fBrightness.verticalCenter
- placeholderText: frames.cam_Brightness
- text: frames.cam_Brightness
- width: parent.width - dp(10)
- EnterKey.type: Qt.EnterKeyDone
- wrapMode: Text.NoWrap
- inputMethodHints: Qt.ImhDigitsOnly |
- Qt.ImhPreferDone |
- Qt.ImhNoPredictiveText
- validator: IntValidator {
- bottom: 0
- top: 255
- }
- Keys.onReturnPressed: {
- frames.cam_Brightness = text
- console.log("设置亮度:", text)
- Qt.inputMethod.hide()
- }
- onAccepted: {
- frames.cam_Brightness = text
- console.log("设置亮度:", text)
- }
- }
- }
- // 白平衡自动模式(关闭后可手动调下方红/蓝比例)
- Row {
- spacing: dp(10)
- width: parent.width
- AppText {
- text: "白平衡:"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: wbModeBox.verticalCenter
- }
- ComboBox {
- id: wbModeBox
- width: parent.width - dp(80)
- height: dp(40)
- model: ["关闭", "自动一次", "连续自动"]
- currentIndex: frames.cam_WhiteBalanceMode
- onActivated: {
- frames.cam_WhiteBalanceMode = currentIndex
- apptext_res.text = "白平衡模式:" + model[currentIndex]
- console.log("设置白平衡模式:", model[currentIndex])
- //用户选择会打断currentIndex的属性绑定,重新建立以保持相机参数回显同步
- wbModeBox.currentIndex = Qt.binding(function(){ return frames.cam_WhiteBalanceMode })
- }
- }
- }
- // 白平衡红/蓝比例(手动模式下生效,写入时自动切为关闭模式)
- Row {
- spacing: dp(8)
- width: parent.width
- AppText {
- text: "红/蓝比例:"
- color: app.fontColor
- fontSize: 13
- anchors.verticalCenter: parent.verticalCenter
- }
- AppTextField {
- id: wbRatioRField
- width: (parent.width - dp(80)) / 2
- placeholderText: "红 " + frames.cam_BalanceRatioR
- text: frames.cam_BalanceRatioR
- EnterKey.type: Qt.EnterKeyDone
- wrapMode: Text.NoWrap
- inputMethodHints: Qt.ImhDigitsOnly |
- Qt.ImhPreferDone |
- Qt.ImhNoPredictiveText
- validator: IntValidator {
- bottom: 0
- top: 16383
- }
- Keys.onReturnPressed: {
- frames.cam_BalanceRatioR = text
- console.log("设置白平衡红比例:", text)
- Qt.inputMethod.hide()
- }
- onAccepted: {
- frames.cam_BalanceRatioR = text
- console.log("设置白平衡红比例:", text)
- }
- }
- AppTextField {
- id: wbRatioBField
- width: (parent.width - dp(80)) / 2
- placeholderText: "蓝 " + frames.cam_BalanceRatioB
- text: frames.cam_BalanceRatioB
- EnterKey.type: Qt.EnterKeyDone
- wrapMode: Text.NoWrap
- inputMethodHints: Qt.ImhDigitsOnly |
- Qt.ImhPreferDone |
- Qt.ImhNoPredictiveText
- validator: IntValidator {
- bottom: 0
- top: 16383
- }
- Keys.onReturnPressed: {
- frames.cam_BalanceRatioB = text
- console.log("设置白平衡蓝比例:", text)
- Qt.inputMethod.hide()
- }
- onAccepted: {
- frames.cam_BalanceRatioB = text
- console.log("设置白平衡蓝比例:", text)
- }
- }
- }
- AppText {
- id: text_debug
- text: "通信调试"
- font.bold: true
- color: "#28a779"
- fontSize: 20
- }
- Row {
- spacing: dp(12)
- AppText {
- text: "显示Serial发送数据"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: txSwitch.verticalCenter
- }
- AppSwitch {
- id: txSwitch
- onToggled: {
- app.floatPanel = checked
- app.showTxData = checked
- app.floatPanel_title = "Serial发送数据"
- }
- }
- }
- Row {
- spacing: dp(12)
- AppText {
- text: "显示Serial接收数据"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: rxSwitch.verticalCenter
- }
- AppSwitch {
- id: rxSwitch
- onToggled: {
- app.floatPanel = checked
- app.showRxData = checked
- app.floatPanel_title = "Serial接收数据"
- }
- }
- }
- Row {
- spacing: dp(12)
- AppText {
- text: "显示MQTT发送数据"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: pubSwitch.verticalCenter
- }
- AppSwitch {
- id: pubSwitch
- onToggled: {
- app.floatPanel = checked
- app.showPubData = checked
- app.showSubData = false
- app.floatPanel_title = "MQTT发送数据"
- }
- }
- }
- Row {
- spacing: dp(12)
- AppText {
- text: "显示MQTT接收数据"
- color: app.fontColor
- fontSize: 15
- anchors.verticalCenter: subSwitch.verticalCenter
- }
- AppSwitch {
- id: subSwitch
- onToggled: {
- app.floatPanel = checked
- app.showSubData = checked
- app.showPubData = false
- app.floatPanel_title = "MQTT接收数据"
- }
- }
- }
- } // motorContent
- } // motorSection
- }
- }
- }
- }
|