| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499 |
- import QtQuick
- import QtQuick.Layouts
- 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 {
- 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
- // ===== 上传进度网格(32格), 蛇形编号, 1 在右上角 =====
- // 数组下标 = GridLayout 摆放顺序(左上→右下), 元素 = 该格显示/对应的图片序号
- property var uploadGridSerials: [
- 32,25,24,17,16, 9, 8, 1,
- 31,26,23,18,15,10, 7, 2,
- 30,27,22,19,14,11, 6, 3,
- 29,28,21,20,13,12, 5, 4
- ]
- ListModel { id: uploadGridModel }
- Component.onCompleted: {
- for(var i = 0; i < 32; i++){
- uploadGridModel.append({serial: uploadGridSerials[i], percent: 0, done: false})
- }
- }
- // 从上传文件路径解析图片序号
- // 归档命名有两种(都会上传):
- // 最清晰帧 <时间戳>z<z>x<x>_<序号>.jpg
- // 融合图 <时间戳>z<z>x<x>_sharp_<序号>.jpg
- // 故统一取"文件名末尾下划线后的数字",兼容两种命名及后续新增后缀
- function uploadSerialFromPath(filePath) {
- if(!filePath) return -1
- // 只处理图片(录制视频流 .rawv 不参与进度网格)
- if(!/\.(jpe?g|png)$/i.test(filePath.replace(/\?.*$/, ""))) return -1
- // 去掉扩展名(兼容查询串),再取末尾 _数字
- var base = filePath.replace(/\?.*$/, "").replace(/\.[^.\/\\]+$/, "")
- var m = base.match(/_(\d+)$/)
- if(m && m.length > 1) return parseInt(m[1])
- // 兜底:兼容历史上只认 _sharp_N 的命名
- m = filePath.match(/sharp_(\d+)/)
- if(m && m.length > 1) return parseInt(m[1])
- return -1
- }
- // 由图片序号(1..32)换算成网格摆放索引(0..31, 蛇形, 1 在右上角)
- function uploadSerialToIndex(serial){
- var n = serial - 1
- var q = Math.floor(n / 4) // 0..7 列组(自右向左)
- var pos = n % 4 // 组内 0..3
- var col = 7 - q
- var row = (q % 2 === 0) ? pos : (3 - pos)
- return row * 8 + col
- }
- // 更新某个网格格子的状态
- function setUploadCell(serial, percent, done) {
- var idx = uploadSerialToIndex(serial)
- if(idx < 0 || idx > 31) return
- var p = Math.max(0, Math.min(100, percent))
- uploadGridModel.setProperty(idx, "percent", p)
- uploadGridModel.setProperty(idx, "done", done)
- }
- // 清空网格全部状态(percent=0, done=false)
- function resetUploadGrid() {
- for(var i = 0; i < uploadGridModel.count; i++){
- uploadGridModel.setProperty(i, "percent", 0)
- uploadGridModel.setProperty(i, "done", false)
- }
- }
- 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()
- //每次(重新)打开相机后清空上传进度网格(上一次采集的进度/完成状态不再保留)
- resetUploadGrid()
- 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
- }
- }
- // 图片上传进度 → 右上角 32 格进度网格
- Connections {
- target: curl_picture
- function onProgressChanged(uploadedPercent, filePath){
- var serial = uploadSerialFromPath(filePath)
- if(serial < 1 || serial > 32){
- console.log("上传进度: 无法识别图片序号", filePath)
- return
- }
- setUploadCell(serial, uploadedPercent, uploadedPercent >= 100)
- }
- }
- 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")
- }
- }
- Row {
- AppText {
- id: photoclarity_text
- width: parent.width
- text: frames.fpsString
- color: "red"
- }
- AppText {
- visible: true//app.photoclarity
- id: photoclarity2_text
- anchors.top: photoclarity_text.bottom
- width: parent.width
- text: frames.qulityString
- color: "green"
- }
- }
- // 图片上传进度网格(8列 x 4行 = 32格), 蛇形编号 1 在右上角, 常显示; 可按住拖动位置
- Rectangle {
- id: uploadGridWrap
- visible: true
- width: uploadGrid.implicitWidth
- height: uploadGrid.implicitHeight
- color: "transparent"
- // 初始位置: 画面右上角
- Component.onCompleted: {
- uploadGridWrap.x = uploadGridWrap.parent.width - uploadGridWrap.width - dp(10)
- uploadGridWrap.y = dp(10)
- }
- GridLayout {
- id: uploadGrid
- columns: 8
- columnSpacing: dp(2)
- rowSpacing: dp(2)
- Repeater {
- id: uploadGridRepeater
- model: uploadGridModel
- Rectangle {
- width: dp(42)
- height: dp(34)
- radius: dp(3)
- color: model.done ? "#8C1f9e4d" : "transparent"
- border.color: model.done ? "#37a24b" : "#66ffffff"
- border.width: 1
- Column {
- anchors.fill: parent
- spacing: 0
- AppText {
- text: model.serial
- color: "white"
- font.bold: true
- font.pixelSize: 11
- anchors.horizontalCenter: parent.horizontalCenter
- }
- AppText {
- text: model.percent > 0 ? Math.round(model.percent) + "%" : ""
- color: model.done ? "white" : "#ffb020"
- font.pixelSize: 10
- anchors.horizontalCenter: parent.horizontalCenter
- }
- }
- }
- }
- }
- // 按住拖动整个网格(DragHandler原生手势,平滑不卡顿;支持鼠标与触摸)
- DragHandler {
- id: gridDragHandler
- target: null
- acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchScreen
- property real startX: 0
- property real startY: 0
- onActiveChanged: {
- if(active){
- // 记录按下瞬间网格位置
- startX = uploadGridWrap.x
- startY = uploadGridWrap.y
- }
- }
- onTranslationChanged: {
- if(!active) return
- var nx = startX + translation.x
- var ny = startY + translation.y
- // 限制在父容器范围内
- nx = Math.max(0, Math.min(uploadGridWrap.parent.width - uploadGridWrap.width, nx))
- ny = Math.max(0, Math.min(uploadGridWrap.parent.height - uploadGridWrap.height, ny))
- uploadGridWrap.x = nx
- uploadGridWrap.y = ny
- }
- }
- }
- // 抓图按钮:仅相机打开时显示,画面右下角透明背景,点击=模拟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
- }
- // 轴选择
- 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
- }
- }
- }
- }
|