TestPage.qml 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  1. import QtQuick
  2. import Felgo
  3. import QtMultimedia
  4. import QtQuick.Controls
  5. import Qt.labs.settings 1.0 as QtLabs
  6. import QtQuick.Controls.Material 2.0
  7. import QtLocation 5.5
  8. import QtPositioning 5.5
  9. import Qt5Compat.GraphicalEffects
  10. import "../controls"
  11. import "../common"
  12. import Frames 0.1
  13. AppPage {
  14. //【必须有 id】上传进度弹层里用了 page.uploadPercent / page.uploadFailed 等绑定,
  15. //根元素原来没有 id,page 是未定义标识符 -> 绑定报 ReferenceError,
  16. //Popup 的 visible 永远算不出来,表现为"上传进度不显示"。
  17. id: page
  18. objectName: "autoFocus_Page"
  19. navigationBarHidden: true
  20. backgroundColor: app.theme_backgroundColor
  21. property var videoFormats
  22. // 定义电机状态
  23. property int currentAxis: 0 // 当前选择的轴 (0: X, 1: Y, 2: Z)
  24. property var axisPositions: [0, 0, 0] // 各轴当前位置
  25. property int speed: 50 // 当前速度 (0-100)
  26. property int stepDistance: 20 // 步进脉冲数量
  27. property string fExposureTime: "0"
  28. property bool motorUnlocked: false
  29. // ===== 上传进度水印(单张) =====
  30. // 业务上一次只上传一张图片(串行队列 FIFO,见 CurlFtpUploader::runLoop),
  31. // 所以不需要按序号铺 32 格进度网格,直接在画面上叠加一个整体进度水印即可。
  32. // uploading : 是否处于上传中(含进度回调已到达但 finished 尚未回来的窗口)
  33. // percent : 0~100,来自 CurlFtpUploader::progressChanged
  34. // fileName : 当前上传文件名(取末段),仅用于水印上显示是哪一张
  35. // failed : 本次上传是否失败(决定水印配色与文案)
  36. property bool uploading: false
  37. property double uploadPercent: 0
  38. property string uploadFileName: ""
  39. property bool uploadFailed: false
  40. // 进度圆可见性:仅在触发上传时为 true,收到 finished 后立即置 false 关闭展示
  41. property bool uploadWatermarkVisible: false
  42. function resetUploadWatermark() {
  43. uploading = false
  44. uploadPercent = 0
  45. uploadFileName = ""
  46. uploadFailed = false
  47. uploadWatermarkVisible = false
  48. uploadHideTimer.stop()
  49. }
  50. function autotake(sw){
  51. if(sw)
  52. {
  53. console.log("autotakestart")
  54. frames.camera_sw = true
  55. //frames.auto_clicked = true //开始对焦
  56. auto_timer.start() //启动对焦定时器
  57. console.log("相机已打开")
  58. photoTimer.interval=180*1000
  59. photoTimer.start()
  60. }else{
  61. frames.camera_sw = true
  62. console.log("打开相机单次拍照!")
  63. }
  64. }
  65. Frames {
  66. objectName: "Frames"
  67. id: frames
  68. videoSink: output.videoSink
  69. onCameraOpenFailed:function(err){
  70. console.log("onCameraOpenFailed",err)
  71. nativeUtils.displayMessageBox("相机打开失败!",err,1)
  72. focus_switch.checked = false
  73. focus_switch.enabled = true
  74. takephoto_switch.checked = false
  75. takephoto_switch.enabled = true
  76. }
  77. onVideoSinkChanged: {
  78. console.log("onVideoSinkChanged")
  79. photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
  80. }
  81. onQulityStringChanged: {
  82. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  83. photoTimer.interval = 180*1000 //3分钟超时
  84. photoTimer.restart()
  85. }
  86. onRecordFileSaved: function(path){
  87. console.log("录制视频流已保存:", path)
  88. apptext_res.text = "录制已保存:" + path.split("/").pop()
  89. }
  90. onCameraStaChanged: function(sta_cam) {
  91. if(sta_cam){
  92. //camera.active = sta_cam
  93. //camera.start()
  94. //每次(重新)打开相机后清空上传进度水印(上一次采集的进度/结果不再保留)
  95. resetUploadWatermark()
  96. loginpage.logintimeout = 600; //拍照刷新熄屏计时
  97. output.visible = sta_cam
  98. photoTimer.interval = 180*1000 //3分钟超时
  99. photoTimer.start()
  100. //uvc_camera.visible = false
  101. }else{
  102. //camera.active = sta_cam
  103. //camera.stop()
  104. output.visible= sta_cam
  105. photoTimer.stop() //停止计时器
  106. focus_switch.checked = false
  107. focus_switch.enabled = true
  108. takephoto_switch.checked = false
  109. takephoto_switch.enabled = true
  110. //uvc_camera.visible = true
  111. }
  112. console.log("相机状态改变",sta_cam)
  113. }
  114. onStepCountChanged: function(step){
  115. console.log("坐标改变",step)
  116. step_apptextfield.text = step
  117. }
  118. onExposureTimeChanged: {
  119. fExposureTime = frames.cam_ExposureTime
  120. }
  121. }
  122. Timer {
  123. id: photoTimer
  124. interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  125. running: false // 初始状态下定时器停止
  126. repeat: false // 设置为false,以便只执行一次
  127. onTriggered: {
  128. // 定时器触发后,设置按钮可用
  129. // camera.active = false
  130. // camera.stop()
  131. output.visible = false
  132. frames.camera_sw = false
  133. }
  134. }
  135. Timer {
  136. id: auto_timer
  137. interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  138. running: false // 初始状态下定时器停止
  139. repeat: false // 设置为false,以便只执行一次
  140. onTriggered: {
  141. // 定时器触发后,开始对焦
  142. frames.auto_clicked = true
  143. }
  144. }
  145. Connections{
  146. target: mqtt
  147. function onMessagePub(message) {
  148. if(app.showPubData){
  149. var time = new Date().toLocaleTimeString()
  150. app.txDataLog = "[" + time + "] " + message + "\n" + app.txDataLog
  151. if(app.txDataLog.length > 5000) app.txDataLog = app.txDataLog.substring(0, 5000)
  152. }
  153. }
  154. function onMessageSub(message) {
  155. if(app.showSubData){
  156. var time = new Date().toLocaleTimeString()
  157. app.rxDataLog = "[" + time + "] " + message + "\n" + app.rxDataLog
  158. if(app.rxDataLog.length > 5000) app.rxDataLog = app.rxDataLog.substring(0, 5000)
  159. }
  160. }
  161. function onSignal_set_camera_exposure(exposureTime) {
  162. console.log("收到远程相机曝光设置指令,曝光时间:" + exposureTime)
  163. frames.cam_ExposureTime = exposureTime.toString()
  164. }
  165. // 远程校准指令: {"cmd":"slide","ext":{"calibrate":"y","speed":"50"}} → 打开相机
  166. function onSignal_open_camera() {
  167. console.log("收到远程相机开启指令,打开相机!")
  168. frames.camera_sw = true
  169. }
  170. }
  171. // 图片上传进度 → 画面上的单张上传水印
  172. Connections {
  173. target: curl_picture
  174. function onProgressChanged(uploadedPercent, filePath){
  175. // 一次只有一张图在传,直接更新整体进度即可,无需按序号分发
  176. uploading = true
  177. uploadWatermarkVisible = true
  178. uploadPercent = Math.max(0, Math.min(100, uploadedPercent))
  179. uploadFailed = false
  180. if(filePath && filePath !== uploadFileName){
  181. // 只取路径末段做显示,避免水印被长路径撑开
  182. uploadFileName = String(filePath).split(/[\\/]/).pop()
  183. }
  184. uploadHideTimer.stop()
  185. }
  186. function onFinished(success, filePath, error){
  187. uploading = false
  188. if(success){
  189. uploadPercent = 100
  190. uploadFailed = false
  191. console.log("上传完成:", filePath)
  192. }else{
  193. uploadFailed = true
  194. console.log("上传失败:", filePath, error)
  195. }
  196. // 进度条改为弹出式后不再遮挡画面,给它留一点停留时间:
  197. // 成功 1.5s 收起,失败 5s(也可点击弹层立即关闭)
  198. uploadHideTimer.interval = success ? 1500 : 5000
  199. uploadHideTimer.restart()
  200. }
  201. }
  202. // 保留:仅用于手动复位时的清理,正常流程由 onFinished 延时关闭展示
  203. Timer {
  204. id: uploadHideTimer
  205. interval: 1500
  206. running: false
  207. repeat: false
  208. onTriggered: uploadWatermarkVisible = false
  209. }
  210. // ===== 图片上传进度条(弹出式) =====
  211. // 需求:取消画面上叠加的上传进度圆/状态文字,改成居中弹出的进度条;
  212. // 上传中显示文件名与百分比,成功/失败保留一小段时间后自动收起(点击也可立即收起)。
  213. Popup {
  214. id: uploadPopup
  215. parent: Overlay.overlay
  216. modal: false
  217. focus: false
  218. closePolicy: Popup.NoAutoClose
  219. visible: page.uploadWatermarkVisible
  220. width: Math.min((parent ? parent.width : dp(600)) * 0.7, dp(520))
  221. height: dp(104)
  222. x: parent ? (parent.width - width) / 2 : 0
  223. y: parent ? parent.height * 0.10 : 0
  224. padding: dp(14)
  225. background: Rectangle {
  226. color: "#e6212121"
  227. radius: dp(8)
  228. border.width: 1
  229. border.color: page.uploadFailed ? "#ff8a80" : "#4f8cff"
  230. }
  231. // 点击立即收起(失败时现场可以先看清错误,再手动关掉)
  232. MouseArea {
  233. anchors.fill: parent
  234. onClicked: page.uploadWatermarkVisible = false
  235. }
  236. Column {
  237. id: uploadColumn
  238. width: parent.width
  239. spacing: dp(8)
  240. AppText {
  241. width: parent.width
  242. text: (page.uploading
  243. ? "图片上传中 "
  244. : (page.uploadFailed ? "图片上传失败 " : "图片上传完成 "))
  245. + page.uploadFileName
  246. color: page.uploadFailed ? "#ff8a80" : "#ffffff"
  247. font.pixelSize: sp(12)
  248. elide: Text.ElideMiddle
  249. }
  250. ProgressBar {
  251. width: parent.width
  252. from: 0
  253. to: 100
  254. value: page.uploadPercent
  255. }
  256. AppText {
  257. width: parent.width
  258. text: Math.round(page.uploadPercent) + " %"
  259. color: "#cfd8dc"
  260. font.pixelSize: sp(11)
  261. horizontalAlignment: Text.AlignRight
  262. }
  263. }
  264. }
  265. Connections{
  266. target: serial
  267. onTakephotodone:{
  268. console.log("立即拍照完成!")
  269. apptext_res.text = "立即拍照完成!"
  270. focus_switch.enabled = true
  271. focus_switch.checked = false
  272. }
  273. onAutotestdone: {
  274. console.log("自动对焦完成!")
  275. apptext_res.text = "自动对焦完成!"
  276. autotest_switch.enabled = true
  277. autotest_switch.checked = false
  278. }
  279. onTranslatedone: {
  280. console.log("胶带传送完成!")
  281. apptext_res.text = "胶带传送完成!"
  282. jiaodai_switch.enabled = true
  283. jiaodai_switch.checked = false
  284. }
  285. onDataReceived:function(data) {
  286. if(app.showRxData){
  287. var time = new Date().toLocaleTimeString()
  288. app.rxDataLog = "[" + time + "] " + data + "\n" + app.rxDataLog
  289. if(app.rxDataLog.length > 5000) app.rxDataLog = app.rxDataLog.substring(0, 5000)
  290. }
  291. // 同步坐标值到输入框
  292. try {
  293. var jsonData = JSON.parse(data)
  294. if(jsonData.ext && !textInput_x.focus && jsonData.ext.x_init_dis !== undefined) {
  295. textInput_x.text = jsonData.ext.x_init_dis.toString()
  296. }
  297. if(jsonData.ext && !textInput_y.focus && jsonData.ext.y_init_dis !== undefined) {
  298. textInput_y.text = jsonData.ext.y_init_dis.toString()
  299. }
  300. } catch(e) {
  301. console.log("解析坐标数据失败:", e)
  302. }
  303. }
  304. onNetMessage:function(data) {
  305. if(app.showTxData){
  306. var time = new Date().toLocaleTimeString()
  307. app.txDataLog = "[" + time + "] " + data + "\n" + app.txDataLog
  308. if(app.txDataLog.length > 5000) app.txDataLog = app.txDataLog.substring(0, 5000)
  309. }
  310. }
  311. }
  312. SplitView{
  313. anchors.fill: parent
  314. orientation: Qt.Horizontal
  315. Rectangle {
  316. SplitView.preferredWidth: parent.width * 0.7
  317. height: parent.height
  318. color: app.cardColor
  319. radius: 5
  320. AppButton {
  321. id: normButton
  322. //anchors.horizontalCenter: parent.horizontalCenter
  323. anchors.centerIn: parent
  324. anchors.fill: parent
  325. //text: "打开相机"
  326. flat: true //边框是否可视
  327. onClicked: {
  328. console.log("相机状态:",frames.camera_sw)
  329. //if(camera.active){
  330. if(frames.camera_sw){
  331. text = "相机已关闭"
  332. output.visible = false
  333. frames.camera_sw = false
  334. //uvc_camera.visible = false
  335. }else{
  336. text = "打开相机"
  337. output.visible = true
  338. frames.camera_sw = true
  339. //uvc_camera.visible = true
  340. }
  341. }
  342. Timer {
  343. id: longPressTimer
  344. interval: 1000 // 长按时间1000ms
  345. running: false // 初始状态下定时器停止
  346. repeat: false // 设置为false,以便只执行一次
  347. onTriggered: {
  348. console.log("长按触发")
  349. }
  350. }
  351. onPressed: {
  352. console.log("按钮按下,开始计时")
  353. longPressTimer.start()
  354. }
  355. onReleased: {
  356. console.log("按钮释放,停止计时")
  357. longPressTimer.stop()
  358. }
  359. AppImage{
  360. id: image_picdis
  361. anchors.centerIn: parent
  362. source: "../../assets/photoico.svg"
  363. }
  364. }
  365. VideoOutput
  366. {
  367. id: output
  368. anchors.fill: parent
  369. visible: false
  370. fillMode: VideoOutput.PreserveAspectFit //根据视频的纵横比例等比例缩放
  371. //fillMode: VideoOutput.Stretch
  372. Component.onCompleted: {
  373. console.log("output onCompleted")
  374. }
  375. }
  376. // 画面左上角信息:帧率 / 清晰度 / 已录制帧数
  377. // 统一用 Column 纵向排列(显式宽度 + spacing):
  378. // 原来 fps 放在 Row 里(width: parent.width),Row 的宽度又来自子项,
  379. // 形成循环依赖,Row 的高度解算不稳定,导致清晰度、帧数与 fps 叠在一起。
  380. // Column 的宽度是显式绑定的,子项 width: parent.width 不再回退到自身,
  381. // 纵向位置也由 Column 统一分配,不会再挤成一团。
  382. Column {
  383. id: infoColumn
  384. anchors.top: parent.top
  385. anchors.left: parent.left
  386. anchors.topMargin: dp(6)
  387. anchors.leftMargin: dp(8)
  388. width: parent.width - dp(44)
  389. spacing: dp(4)
  390. AppText {
  391. id: photoclarity_text
  392. width: parent.width
  393. text: frames.fpsString
  394. color: "red"
  395. elide: Text.ElideRight
  396. }
  397. AppText {
  398. id: photoclarity2_text
  399. width: parent.width
  400. text: frames.qulityString
  401. color: "green"
  402. elide: Text.ElideRight
  403. }
  404. // 已录制帧数:步进扫描时每步应只 +1,用来现场核对"移动 N 步是否只录了 N 帧"
  405. // (之前出现过移动 100 步写出 200 帧,原因是重复 movy 被重复落盘)
  406. AppText {
  407. id: recordFrames_text
  408. width: parent.width
  409. text: "已录制帧数: " + frames.recordedFrames + (frames.recording ? " (录制中)" : "")
  410. color: "#ffd54f"
  411. font.pixelSize: sp(13)
  412. elide: Text.ElideRight
  413. // 未开始录制时不占位(Column 会跳过不可见子项)
  414. visible: frames.recording || frames.recordedFrames > 0
  415. }
  416. }
  417. // ================= 清晰度折线图 =================
  418. // 什么时候画:C++ 每算出一个清晰度(Tenengrad)就往 frames.qualitySeries 追加一个点;
  419. // 步进对焦扫描时就是"每个位置一个点",连起来即标准对焦曲线,峰值位置=最清晰焦面。
  420. // 放左下角:左上角是帧率/清晰度/已录制帧数文字,右下角是抓图/录制按钮。
  421. // 宽度随 parent 收窄,窄屏上不会压到右下角按钮。
  422. // 曲线清空时机由 C++ 控制:新一次 startRecord、或步号回退(主板重新计数)时自动清零。
  423. Rectangle {
  424. id: qualityChartBox
  425. anchors.left: parent.left
  426. anchors.bottom: parent.bottom
  427. anchors.leftMargin: dp(8)
  428. anchors.bottomMargin: dp(8)
  429. width: Math.min(dp(260), parent.width - dp(140))
  430. height: dp(100)
  431. radius: dp(6)
  432. color: "#a6000000"
  433. border.color: "#4caf50"
  434. border.width: dp(1)
  435. // 只有真正算过清晰度才出现,纯预览时不遮挡画面
  436. visible: qualityCanvas.pointCount > 0
  437. Canvas {
  438. id: qualityCanvas
  439. anchors.fill: parent
  440. anchors.margins: dp(5)
  441. // 绑定 C++ 属性:qualitySeriesChanged 发出后重新取值 -> onSeriesChanged -> 重绘
  442. property var series: frames.qualitySeries
  443. property int pointCount: series ? series.length : 0
  444. // 已录制帧数:曲线点与该计数一一对应,帧数变化也要重绘(标题里要显示)
  445. property int frameCount: frames.recordedFrames
  446. onSeriesChanged: requestPaint()
  447. onFrameCountChanged: requestPaint()
  448. onPaint: {
  449. var ctx = getContext("2d")
  450. ctx.reset()
  451. var n = pointCount
  452. if (n <= 0) return
  453. var w = width, h = height
  454. var padL = 2, padR = 2, padT = 15, padB = 2
  455. var plotW = w - padL - padR
  456. var plotH = h - padT - padB
  457. if (plotW <= 1 || plotH <= 1) return
  458. // 纵向归一化:按本段数据的最小/最大值铺满高度;max==min 时撑开 1 防止除零
  459. var vmin = series[0], vmax = series[0], peakIdx = 0
  460. for (var i = 1; i < n; ++i) {
  461. var v = series[i]
  462. if (v < vmin) vmin = v
  463. if (v > vmax) { vmax = v; peakIdx = i }
  464. }
  465. if (vmax - vmin < 0.0001) vmax = vmin + 1
  466. // 水平网格(3 条):便于判断峰谷相对高低
  467. ctx.strokeStyle = "rgba(255,255,255,0.12)"
  468. ctx.lineWidth = 1
  469. for (var g = 0; g <= 3; ++g) {
  470. var gy = padT + plotH * g / 3
  471. ctx.beginPath()
  472. ctx.moveTo(padL, gy)
  473. ctx.lineTo(padL + plotW, gy)
  474. ctx.stroke()
  475. }
  476. var xAt = function(idx) {
  477. return n === 1 ? (padL + plotW / 2)
  478. : (padL + plotW * idx / (n - 1))
  479. }
  480. var yAt = function(val) {
  481. return padT + plotH * (1 - (val - vmin) / (vmax - vmin))
  482. }
  483. // 折线:点数远多于像素列时按列抽稀,趋势/峰值不变,重绘不卡
  484. var stride = Math.max(1, Math.floor(n / Math.max(1, plotW)))
  485. ctx.beginPath()
  486. ctx.moveTo(xAt(0), yAt(series[0]))
  487. for (var k = stride; k < n; k += stride)
  488. ctx.lineTo(xAt(k), yAt(series[k]))
  489. if (n > 1)
  490. ctx.lineTo(xAt(n - 1), yAt(series[n - 1]))
  491. ctx.strokeStyle = "#4caf50"
  492. ctx.lineWidth = 1.8
  493. ctx.lineJoin = "round"
  494. ctx.stroke()
  495. // 曲线下方面积填充:值越低越暗,视觉上更容易看出"峰在哪"
  496. ctx.lineTo(xAt(n - 1), padT + plotH)
  497. ctx.lineTo(xAt(0), padT + plotH)
  498. ctx.closePath()
  499. ctx.fillStyle = "rgba(76,175,80,0.18)"
  500. ctx.fill()
  501. // 峰值标记:红点 + 顶部一行文字(点数 / 峰值)
  502. ctx.beginPath()
  503. ctx.arc(xAt(peakIdx), yAt(vmax), 3, 0, Math.PI * 2)
  504. ctx.fillStyle = "#ff5252"
  505. ctx.fill()
  506. var fs = Math.max(9, Math.round(h * 0.12))
  507. ctx.font = fs + "px sans-serif"
  508. ctx.textBaseline = "top"
  509. ctx.fillStyle = "#a5d6a7"
  510. // 点数与已录制帧数并列显示,一眼看出"每个已录帧一个点"
  511. var framesTxt = frames.recordedFrames > 0
  512. ? (" / 帧 " + frames.recordedFrames) : ""
  513. ctx.fillText("清晰度 " + n + " 点" + framesTxt
  514. + " 峰值 " + Number(vmax).toFixed(2),
  515. padL + 1, 1)
  516. }
  517. }
  518. }
  519. // 抓图按钮:仅相机打开时显示,画面右下角透明背景,点击=模拟MCU拍照指令(按序号保存/锐化/上传)
  520. Rectangle {
  521. id: captureBtn
  522. visible: frames.camera_sw
  523. width: dp(56)
  524. height: dp(56)
  525. radius: width / 2
  526. color: "transparent"
  527. border.color: "#80ffffff"
  528. border.width: dp(2)
  529. anchors.right: parent.right
  530. anchors.bottom: parent.bottom
  531. anchors.rightMargin: dp(12)
  532. anchors.bottomMargin: dp(12)
  533. AppImage {
  534. anchors.centerIn: parent
  535. width: dp(34)
  536. height: dp(34)
  537. source: "../../assets/photoico.svg"
  538. }
  539. MouseArea {
  540. anchors.fill: parent
  541. onClicked: {
  542. console.log("抓图按钮点击!")
  543. frames.manualCapture()
  544. }
  545. }
  546. }
  547. // 录制按钮:仅相机打开时显示,画面右下角(抓图按钮左侧)
  548. // 点击开始录制原始(未压缩)视频流,再次点击停止并把视频流保存到相机打开时创建的文件夹
  549. Rectangle {
  550. id: recordBtn
  551. visible: frames.camera_sw
  552. width: dp(56)
  553. height: dp(56)
  554. radius: width / 2
  555. color: "transparent"
  556. border.color: frames.recording ? "#e74c3c" : "#80ffffff"
  557. border.width: dp(2)
  558. anchors.right: captureBtn.left
  559. anchors.bottom: parent.bottom
  560. anchors.rightMargin: dp(12)
  561. anchors.bottomMargin: dp(12)
  562. // 未录制:红色圆点(开始);录制中:红色方块(停止)
  563. Rectangle {
  564. anchors.centerIn: parent
  565. width: frames.recording ? dp(22) : dp(26)
  566. height: frames.recording ? dp(22) : dp(26)
  567. radius: frames.recording ? dp(3) : width / 2
  568. color: "#e74c3c"
  569. }
  570. MouseArea {
  571. anchors.fill: parent
  572. onClicked: {
  573. if(frames.recording){
  574. console.log("停止录制视频流")
  575. frames.stopRecord()
  576. }else{
  577. console.log("开始录制视频流")
  578. if(frames.startRecord()){
  579. apptext_res.text = "开始录制视频流"
  580. }else{
  581. nativeUtils.displayMessageBox("提示","录制失败,请先打开相机!",1)
  582. }
  583. }
  584. }
  585. }
  586. }
  587. // 分析/融合处理期间:挂起相机画面输出,用进度/过程替代画面
  588. Rectangle {
  589. id: processOverlay
  590. visible: frames.processing
  591. anchors.fill: parent
  592. color: "#E6000000"
  593. z: 20
  594. Column {
  595. anchors.centerIn: parent
  596. spacing: dp(12)
  597. BusyIndicator {
  598. anchors.horizontalCenter: parent.horizontalCenter
  599. running: frames.processing
  600. width: dp(56)
  601. height: dp(56)
  602. }
  603. AppText {
  604. anchors.horizontalCenter: parent.horizontalCenter
  605. text: frames.processMessage
  606. color: "white"
  607. fontSize: 16
  608. }
  609. AppText {
  610. anchors.horizontalCenter: parent.horizontalCenter
  611. text: "处理中 " + frames.processPercent + "%"
  612. color: "#28a779"
  613. fontSize: 15
  614. }
  615. // 进度条
  616. Rectangle {
  617. width: dp(280)
  618. height: dp(8)
  619. radius: dp(4)
  620. color: "#33ffffff"
  621. anchors.horizontalCenter: parent.horizontalCenter
  622. Rectangle {
  623. width: parent.width * frames.processPercent / 100
  624. height: parent.height
  625. radius: parent.radius
  626. color: "#28a779"
  627. }
  628. }
  629. }
  630. }
  631. }
  632. ScrollView
  633. {
  634. SplitView.preferredWidth: parent.width*0.29
  635. SplitView.minimumWidth: 200
  636. clip: true
  637. Column {
  638. spacing: dp(15)
  639. Row {
  640. spacing: 80
  641. AppText {
  642. id: text_title
  643. text: "测试调试"
  644. font.bold: true
  645. color: "#28a779"
  646. fontSize: 20
  647. }
  648. AppText {
  649. id: apptext_res
  650. text: "[测试结果]"
  651. fontSize:15
  652. color: "grey"
  653. anchors.verticalCenter: text_title.verticalCenter
  654. }
  655. }
  656. Row {
  657. spacing: dp(120)
  658. AppText{
  659. text: "一键测试"
  660. fontSize: 15
  661. color: app.fontColor
  662. anchors.verticalCenter: autotest_switch.verticalCenter
  663. }
  664. AppSwitch {
  665. id: autotest_switch
  666. onToggled: {
  667. if(autotest_switch.checked==true){
  668. autotest_switch.enabled = false
  669. serial.sendCmd("autotest",true,"","");
  670. t_autotest.start()
  671. }else{
  672. console.log("t_autotest 计数:",t_autotest.interval)
  673. }
  674. }
  675. }
  676. Timer {
  677. id: t_autotest
  678. interval: 1000*60
  679. running: false
  680. repeat: false
  681. onTriggered: {
  682. autotest_switch.enabled = true
  683. autotest_switch.checked = false
  684. }
  685. }
  686. }
  687. Row {
  688. spacing: dp(120)
  689. AppText{
  690. text: "风机测试"
  691. color: app.fontColor
  692. fontSize: 15
  693. anchors.verticalCenter: fantest_switch.verticalCenter
  694. }
  695. AppSwitch {
  696. id: fantest_switch
  697. onToggled: {
  698. if(fantest_switch.checked==true){
  699. serial.sendCmd("fan",true,"","");
  700. apptext_res.text = "打开风机"
  701. }else{
  702. serial.sendCmd("fan",false,"","");
  703. apptext_res.text = "关闭风机"
  704. }
  705. }
  706. }
  707. }
  708. Row {
  709. spacing: dp(120)
  710. AppText{
  711. text: "胶带测试"
  712. fontSize: 15
  713. color: app.fontColor
  714. //font.bold: true
  715. anchors.verticalCenter: jiaodai_switch.verticalCenter
  716. }
  717. AppSwitch {
  718. id: jiaodai_switch
  719. onToggled: {
  720. if(jiaodai_switch.checked==true){
  721. // 检查是否处于温度保护状态
  722. if(app.tempProtectionState === true){
  723. // 弹出提示对话框
  724. nativeUtils.displayMessageBox(
  725. "提示",
  726. "当前处于温控状态,请解除温控后再进行测试胶带传送",
  727. 1
  728. );
  729. // 恢复开关状态为未选中
  730. jiaodai_switch.checked = false;
  731. return;
  732. }
  733. // 正常执行胶带测试
  734. //jiaodai_switch.enabled = false
  735. apptext_res.text = "胶带测试开始"
  736. serial.sendCmd("jiaodai",true,"","");
  737. }
  738. }
  739. }
  740. }
  741. Row {
  742. spacing: dp(120)
  743. AppText {
  744. text: "补光测试"
  745. color: app.fontColor
  746. fontSize: 15
  747. anchors.verticalCenter: led_switch.verticalCenter
  748. }
  749. AppSwitch {
  750. id: led_switch
  751. onToggled: {
  752. if(led_switch.checked==true){
  753. serial.sendCmd("led",true,"","");
  754. apptext_res.text = "补光灯已打开"
  755. }else{
  756. serial.sendCmd("led",false,"","");
  757. apptext_res.text = "补光灯已关闭"
  758. }
  759. }
  760. }
  761. }
  762. Row {
  763. spacing: dp(120)
  764. AppText {
  765. text: "立即拍照"
  766. color: app.fontColor
  767. fontSize: 15
  768. anchors.verticalCenter: takephoto_switch.verticalCenter
  769. }
  770. AppSwitch {
  771. id: takephoto_switch
  772. onToggled: {
  773. if(takephoto_switch.checked==true){
  774. apptext_res.text = "立即拍照"
  775. frames.captureImage()
  776. }
  777. }
  778. }
  779. }
  780. Row {
  781. spacing: dp(120)
  782. AppText {
  783. text: "对焦拍照"
  784. color: app.fontColor
  785. fontSize: 15
  786. anchors.verticalCenter: focus_switch.verticalCenter
  787. }
  788. AppSwitch {
  789. id: focus_switch
  790. onToggled: {
  791. if(focus_switch.checked==true){
  792. apptext_res.text = "开始对焦"
  793. focus_switch.enabled = false
  794. serial.auto_takephoto(true)
  795. }
  796. }
  797. }
  798. }
  799. //【已移除】滤网更换(selfclean 自清洁测试)按钮: 该机型不再使用滤网
  800. // 分割线
  801. Rectangle {
  802. visible: !motorUnlocked
  803. width: parent.width
  804. height: dp(1)
  805. color: "#e0e0e0"
  806. }
  807. // 分割线
  808. Rectangle {
  809. width: parent.width
  810. height: dp(2)
  811. color: "#28a779"
  812. }
  813. // 密码输入区域(未解锁时显示)
  814. Rectangle {
  815. visible: !motorUnlocked
  816. width: parent.width
  817. height: passwordColumn.height + dp(16)
  818. color: app.cardColor
  819. radius: dp(8)
  820. border.color: "#28a779"
  821. border.width: dp(1)
  822. Column {
  823. id: passwordColumn
  824. anchors.centerIn: parent
  825. spacing: dp(10)
  826. AppText {
  827. anchors.horizontalCenter: parent.horizontalCenter
  828. text: "请输入密码解锁电机控制"
  829. color: app.fontColor
  830. font.bold: true
  831. fontSize: 14
  832. }
  833. Row {
  834. anchors.horizontalCenter: parent.horizontalCenter
  835. spacing: dp(8)
  836. AppTextField {
  837. id: motorPasswordInput
  838. width: dp(130)
  839. height: dp(38)
  840. echoMode: TextInput.Password
  841. placeholderText: "密码"
  842. inputMethodHints: Qt.ImhDigitsOnly
  843. anchors.verticalCenter: parent.verticalCenter
  844. onAccepted: {
  845. if(text === "666888"){
  846. motorUnlocked = true
  847. text = ""
  848. }else{
  849. apptext_res.text = "密码错误"
  850. text = ""
  851. }
  852. }
  853. }
  854. AppButton {
  855. text: "确认"
  856. textColor: "white"
  857. flat: false
  858. backgroundColor: "#28a779"
  859. minimumHeight: dp(38)
  860. minimumWidth: dp(55)
  861. anchors.verticalCenter: parent.verticalCenter
  862. onClicked: {
  863. if(motorPasswordInput.text === "666888"){
  864. motorUnlocked = true
  865. motorPasswordInput.text = ""
  866. }else{
  867. apptext_res.text = "密码错误"
  868. motorPasswordInput.text = ""
  869. }
  870. }
  871. }
  872. }
  873. }
  874. }
  875. // 电机控制及以下所有控件(解锁后显示)
  876. Item {
  877. id: motorSection
  878. visible: motorUnlocked
  879. width: parent.width
  880. height: motorContent.height + dp(20)
  881. property alias content: motorContent
  882. Column {
  883. id: motorContent
  884. spacing: dp(12)
  885. width: parent.width
  886. // 锁定按钮
  887. Row {
  888. spacing: dp(5)
  889. width: parent.width
  890. AppText {
  891. text: "高级控制"
  892. font.bold: true
  893. color: "#28a779"
  894. fontSize: 20
  895. anchors.verticalCenter: parent.verticalCenter
  896. }
  897. AppButton {
  898. text: "锁定"
  899. textColor: "white"
  900. flat: false
  901. backgroundColor: "#d9534f"
  902. minimumHeight: dp(25)
  903. minimumWidth: dp(50)
  904. anchors.verticalCenter: parent.verticalCenter
  905. onClicked: motorUnlocked = false
  906. }
  907. }
  908. AppText {
  909. id: text_title2
  910. text: "三轴步进电机控制"
  911. font.bold: true
  912. color: "#28a779"
  913. fontSize: 20
  914. }
  915. // ===== 图像处理开关(与电机控制一起锁在密码后面)=====
  916. // 1) 景深融合:关掉后录制结束只保留最清晰帧,不做融合
  917. // 状态唯一来源是 frames.fusionEnabled(= param::fusion_enable,
  918. // MQTT fusion_sw 也会改它,所以用 Connections 双向同步,不做单向绑定)
  919. Row {
  920. spacing: dp(12)
  921. width: parent.width
  922. AppText {
  923. text: "景深融合"
  924. width: dp(140)
  925. color: app.fontColor
  926. fontSize: 15
  927. anchors.verticalCenter: fusion_switch.verticalCenter
  928. }
  929. AppSwitch {
  930. id: fusion_switch
  931. // 不用 checked: frames.fusionEnabled 绑定:用户点开关时控件内部会
  932. // 直接给 checked 赋值、绑定被打断,之后 MQTT 改状态就同步不过来了。
  933. // 这里改成显式赋值 + Connections 回灌,始终以 frames 的值为准。
  934. Component.onCompleted: checked = frames.fusionEnabled
  935. onToggled: {
  936. frames.fusionEnabled = checked
  937. console.log("景深融合:", checked ? "开" : "关")
  938. }
  939. }
  940. AppText {
  941. text: frames.fusionEnabled ? "开" : "关"
  942. color: frames.fusionEnabled ? "#28a779" : "#d9534f"
  943. anchors.verticalCenter: fusion_switch.verticalCenter
  944. }
  945. }
  946. // 2) 临时调试:保留录制文件(rawv),便于复盘;不写库,重启复位
  947. Row {
  948. spacing: dp(12)
  949. width: parent.width
  950. AppText {
  951. text: "保留录像(调试)"
  952. width: dp(140)
  953. color: app.fontColor
  954. fontSize: 15
  955. anchors.verticalCenter: keep_record_switch.verticalCenter
  956. }
  957. AppSwitch {
  958. id: keep_record_switch
  959. Component.onCompleted: checked = frames.debugKeepRecord
  960. onToggled: {
  961. frames.debugKeepRecord = checked
  962. console.log("调试保留录像:", checked ? "开" : "关")
  963. }
  964. }
  965. AppText {
  966. text: frames.debugKeepRecord ? "开" : "关"
  967. color: frames.debugKeepRecord ? "#ffd54f" : "#9e9e9e"
  968. anchors.verticalCenter: keep_record_switch.verticalCenter
  969. }
  970. }
  971. // 融合开关状态回灌:MQTT fusion_sw、启动读库、按钮点击都会走这里,
  972. // 保证界面开关显示与 param::fusion_enable 始终一致
  973. Connections {
  974. target: frames
  975. function onFusionEnabledChanged() {
  976. if(fusion_switch.checked !== frames.fusionEnabled)
  977. fusion_switch.checked = frames.fusionEnabled
  978. }
  979. function onDebugKeepRecordChanged() {
  980. if(keep_record_switch.checked !== frames.debugKeepRecord)
  981. keep_record_switch.checked = frames.debugKeepRecord
  982. }
  983. }
  984. // 轴选择
  985. Row {
  986. spacing: dp(8)
  987. width: parent.width
  988. AppText {
  989. text: "选择轴:"
  990. width: dp(60)
  991. color: app.fontColor
  992. anchors.verticalCenter: parent.verticalCenter
  993. }
  994. ComboBox {
  995. width: parent.width - dp(100)
  996. height: dp(40)
  997. model: ["X轴", "Y轴", "Z轴"]
  998. onCurrentIndexChanged: currentAxis = currentIndex
  999. }
  1000. AppButton {
  1001. text: "校准"
  1002. textColor: "black"
  1003. flat: false
  1004. borderColor: "black"
  1005. borderWidth: dp(1)
  1006. backgroundColor: "white"
  1007. minimumHeight: dp(30)
  1008. minimumWidth: dp(50)
  1009. onClicked:
  1010. {
  1011. autotake(false)
  1012. if(currentAxis==0)
  1013. {
  1014. console.log("校准X")
  1015. serial.sendCmd("calibrate",false,"x",speed.toString())
  1016. }else if(currentAxis==1)
  1017. {
  1018. console.log("校准Y")
  1019. serial.sendCmd("calibrate",false,"y",speed.toString())
  1020. }else if(currentAxis==2)
  1021. {
  1022. console.log("校准Z")
  1023. serial.sendCmd("calibrate",false,"z",speed.toString())
  1024. }
  1025. }
  1026. }
  1027. }
  1028. // 速度调节
  1029. Row {
  1030. spacing: dp(10)
  1031. width: parent.width
  1032. AppText {
  1033. text: "速度:"
  1034. width: dp(40)
  1035. color: app.fontColor
  1036. anchors.verticalCenter: parent.verticalCenter
  1037. }
  1038. AppSlider {
  1039. width: parent.width - dp(60)
  1040. from: 0
  1041. to: 100
  1042. value: speed
  1043. stepSize: 1
  1044. onValueChanged: speed = value
  1045. anchors.verticalCenter: parent.verticalCenter
  1046. }
  1047. AppText {
  1048. text: speed
  1049. width: dp(40)
  1050. anchors.verticalCenter: parent.verticalCenter
  1051. }
  1052. }
  1053. // 步进距离设置
  1054. Row {
  1055. spacing: dp(10)
  1056. width: parent.width
  1057. AppText {
  1058. text: "步进脉冲次数:"
  1059. width: dp(120)
  1060. color: app.fontColor
  1061. anchors.verticalCenter: parent.verticalCenter
  1062. }
  1063. AppTextField {
  1064. id: step_apptextfield
  1065. width: parent.width - dp(120)
  1066. text: stepDistance
  1067. validator: IntValidator { bottom: 0; top: 2000 }
  1068. onTextChanged: stepDistance = parseInt(text)
  1069. }
  1070. }
  1071. // 运动控制按钮
  1072. Row {
  1073. spacing: dp(10)
  1074. width: parent.width
  1075. AppButton {
  1076. text: " 正转 "
  1077. textColor: "black"
  1078. flat: false
  1079. borderColor: "black"
  1080. borderWidth: dp(1)
  1081. backgroundColor: "grey"
  1082. minimumHeight: dp(30)
  1083. minimumWidth: dp(50)
  1084. width: (parent.width - dp(30))/4
  1085. onClicked:
  1086. {
  1087. if(currentAxis==0)
  1088. {
  1089. console.log("X轴正转:",stepDistance)
  1090. serial.sendCmd("movx",false,"f"+stepDistance,speed.toString())
  1091. }else if(currentAxis==1)
  1092. {
  1093. console.log("Y轴正转:",stepDistance)
  1094. serial.sendCmd("movy",false,"f"+stepDistance,speed.toString())
  1095. }else if(currentAxis==2)
  1096. {
  1097. console.log("Z轴正转:",stepDistance)
  1098. serial.sendCmd("movz",false,"f"+stepDistance,speed.toString())
  1099. }
  1100. }
  1101. }
  1102. AppButton {
  1103. text: " 停止 "
  1104. textColor: "black"
  1105. flat: false
  1106. borderColor: "black"
  1107. borderWidth: dp(1)
  1108. backgroundColor: "red"
  1109. minimumHeight: dp(30)
  1110. minimumWidth: dp(50)
  1111. width: (parent.width - dp(30))/4
  1112. onClicked:
  1113. {
  1114. console.log("停止")
  1115. serial.sendCmd("movx",false,"f0","")
  1116. }
  1117. }
  1118. AppButton {
  1119. text: " 反转 "
  1120. textColor: "black"
  1121. flat: false
  1122. borderColor: "black"
  1123. borderWidth: dp(1)
  1124. backgroundColor: "grey"
  1125. minimumHeight: dp(30)
  1126. minimumWidth: dp(50)
  1127. width: (parent.width - dp(30))/4
  1128. onClicked:
  1129. {
  1130. if(currentAxis==0)
  1131. {
  1132. console.log("X轴反转:",stepDistance)
  1133. serial.sendCmd("movx",false,"b"+stepDistance,speed.toString())
  1134. }else if(currentAxis==1)
  1135. {
  1136. console.log("Y轴反转:",stepDistance)
  1137. serial.sendCmd("movy",false,"b"+stepDistance,speed.toString())
  1138. }else if(currentAxis==2)
  1139. {
  1140. console.log("Z轴反转:",stepDistance)
  1141. serial.sendCmd("movz",false,"b"+stepDistance,speed.toString())
  1142. }
  1143. }
  1144. }
  1145. AppButton {
  1146. text: " 复位 "
  1147. textColor: "black"
  1148. flat: false
  1149. borderColor: "black"
  1150. borderWidth: dp(1)
  1151. backgroundColor: "grey"
  1152. minimumHeight: dp(30)
  1153. minimumWidth: dp(50)
  1154. width: (parent.width - dp(30))/4
  1155. onClicked: {
  1156. if(currentAxis==0)
  1157. {
  1158. console.log("X轴复位!")
  1159. serial.sendCmd("movx",true,"",speed.toString())
  1160. }else if(currentAxis==1)
  1161. {
  1162. console.log("Y轴复位!")
  1163. serial.sendCmd("movy",true,"",speed.toString())
  1164. }else if(currentAxis==2)
  1165. {
  1166. console.log("Z轴复位!")
  1167. serial.sendCmd("movz",true,"",speed.toString())
  1168. }
  1169. }
  1170. }
  1171. }
  1172. // ===== 坐标参数 =====
  1173. AppText {
  1174. text: "坐标参数"
  1175. font.bold: true
  1176. color: "#28a779"
  1177. fontSize: 20
  1178. }
  1179. // X 坐标输入行
  1180. Row {
  1181. spacing: dp(5)
  1182. width: parent.width
  1183. AppText {
  1184. text: "X坐标:"
  1185. width: dp(50)
  1186. color: app.fontColor
  1187. fontSize: 15
  1188. anchors.verticalCenter: textInput_x.verticalCenter
  1189. }
  1190. AppTextField {
  1191. id: textInput_x
  1192. width: parent.width - dp(80)
  1193. height: dp(40)
  1194. placeholderText: "0"
  1195. text: "0"
  1196. font.family: "Arial"
  1197. font.pixelSize: 15
  1198. validator: DoubleValidator { decimals: 2 }
  1199. EnterKey.type: Qt.EnterKeyDone
  1200. inputMethodHints: Qt.ImhFormattedNumbersOnly
  1201. property real numericValue_x: Number(text) || 0
  1202. Keys.onReturnPressed: {
  1203. serial.setHt_xy_dis(numericValue_x, textInput_y.numericValue_y)
  1204. Qt.inputMethod.hide()
  1205. }
  1206. onAccepted: {
  1207. serial.setHt_xy_dis(numericValue_x, textInput_y.numericValue_y)
  1208. }
  1209. }
  1210. }
  1211. // Y 坐标输入行
  1212. Row {
  1213. spacing: dp(5)
  1214. width: parent.width
  1215. AppText {
  1216. text: "Y坐标:"
  1217. width: dp(50)
  1218. color: app.fontColor
  1219. fontSize: 15
  1220. anchors.verticalCenter: textInput_y.verticalCenter
  1221. }
  1222. AppTextField {
  1223. id: textInput_y
  1224. width: parent.width - dp(80)
  1225. height: dp(40)
  1226. placeholderText: "0"
  1227. text: "0"
  1228. font.family: "Arial"
  1229. font.pixelSize: 15
  1230. validator: DoubleValidator { decimals: 2 }
  1231. EnterKey.type: Qt.EnterKeyDone
  1232. inputMethodHints: Qt.ImhFormattedNumbersOnly
  1233. property real numericValue_y: Number(text) || 0
  1234. Keys.onReturnPressed: {
  1235. serial.setHt_xy_dis(textInput_x.numericValue_x, numericValue_y)
  1236. Qt.inputMethod.hide()
  1237. }
  1238. onAccepted: {
  1239. serial.setHt_xy_dis(textInput_x.numericValue_x, numericValue_y)
  1240. }
  1241. }
  1242. }
  1243. // 分割线
  1244. Rectangle {
  1245. width: parent.width
  1246. height: dp(2)
  1247. color: "#e0e0e0"
  1248. }
  1249. // ===== 相机参数 =====
  1250. AppText {
  1251. id: text_camera
  1252. text: "相机参数"
  1253. font.bold: true
  1254. color: "#28a779"
  1255. fontSize: 20
  1256. }
  1257. Row {
  1258. spacing: dp(10)
  1259. width: parent.width
  1260. AppText {
  1261. id: txt_fExposureTime
  1262. text: "曝光值:"
  1263. color: app.fontColor
  1264. }
  1265. AppTextField {
  1266. anchors.verticalCenter: txt_fExposureTime.verticalCenter
  1267. placeholderText: fExposureTime
  1268. text: fExposureTime
  1269. width: parent.width - dp(10)
  1270. EnterKey.type: Qt.EnterKeyDone
  1271. wrapMode: Text.NoWrap
  1272. inputMethodHints: Qt.ImhFormattedNumbersOnly |
  1273. Qt.ImhPreferDone |
  1274. Qt.ImhNoPredictiveText
  1275. validator: DoubleValidator {
  1276. bottom: 100.00
  1277. top: 500000.00
  1278. decimals: 0
  1279. }
  1280. // 关键:兜底(IME 再作妖也不怕)
  1281. Keys.onReturnPressed: {
  1282. frames.cam_ExposureTime = text
  1283. console.log("设置曝光时间:",text)
  1284. Qt.inputMethod.hide()
  1285. }
  1286. onAccepted: {
  1287. frames.cam_ExposureTime = text
  1288. console.log("设置曝光时间",text)
  1289. }
  1290. }
  1291. }
  1292. // 相机型号(海康工业相机,打开相机后自动读取展示)
  1293. Row {
  1294. spacing: dp(10)
  1295. width: parent.width
  1296. AppText {
  1297. id: txt_camModel
  1298. text: "相机型号:"
  1299. color: app.fontColor
  1300. fontSize: 15
  1301. anchors.verticalCenter: parent.verticalCenter
  1302. }
  1303. AppText {
  1304. text: frames.cam_ModelName
  1305. color: "#28a779"
  1306. font.bold: true
  1307. fontSize: 15
  1308. elide: Text.ElideRight
  1309. width: parent.width - txt_camModel.width - dp(10)
  1310. anchors.verticalCenter: parent.verticalCenter
  1311. }
  1312. }
  1313. // 亮度(自动曝光目标灰度0-255,设置后切换为自动曝光,手动曝光值失效)
  1314. Row {
  1315. spacing: dp(10)
  1316. width: parent.width
  1317. AppText {
  1318. id: txt_fBrightness
  1319. text: "亮度:"
  1320. color: app.fontColor
  1321. fontSize: 15
  1322. anchors.verticalCenter: parent.verticalCenter
  1323. }
  1324. AppTextField {
  1325. anchors.verticalCenter: txt_fBrightness.verticalCenter
  1326. placeholderText: frames.cam_Brightness
  1327. text: frames.cam_Brightness
  1328. width: parent.width - dp(10)
  1329. EnterKey.type: Qt.EnterKeyDone
  1330. wrapMode: Text.NoWrap
  1331. inputMethodHints: Qt.ImhDigitsOnly |
  1332. Qt.ImhPreferDone |
  1333. Qt.ImhNoPredictiveText
  1334. validator: IntValidator {
  1335. bottom: 0
  1336. top: 255
  1337. }
  1338. Keys.onReturnPressed: {
  1339. frames.cam_Brightness = text
  1340. console.log("设置亮度:", text)
  1341. Qt.inputMethod.hide()
  1342. }
  1343. onAccepted: {
  1344. frames.cam_Brightness = text
  1345. console.log("设置亮度:", text)
  1346. }
  1347. }
  1348. }
  1349. // 白平衡自动模式(关闭后可手动调下方红/蓝比例)
  1350. Row {
  1351. spacing: dp(10)
  1352. width: parent.width
  1353. AppText {
  1354. text: "白平衡:"
  1355. color: app.fontColor
  1356. fontSize: 15
  1357. anchors.verticalCenter: wbModeBox.verticalCenter
  1358. }
  1359. ComboBox {
  1360. id: wbModeBox
  1361. width: parent.width - dp(80)
  1362. height: dp(40)
  1363. model: ["关闭", "自动一次", "连续自动"]
  1364. currentIndex: frames.cam_WhiteBalanceMode
  1365. onActivated: {
  1366. frames.cam_WhiteBalanceMode = currentIndex
  1367. apptext_res.text = "白平衡模式:" + model[currentIndex]
  1368. console.log("设置白平衡模式:", model[currentIndex])
  1369. //用户选择会打断currentIndex的属性绑定,重新建立以保持相机参数回显同步
  1370. wbModeBox.currentIndex = Qt.binding(function(){ return frames.cam_WhiteBalanceMode })
  1371. }
  1372. }
  1373. }
  1374. // 白平衡红/蓝比例(手动模式下生效,写入时自动切为关闭模式)
  1375. Row {
  1376. spacing: dp(8)
  1377. width: parent.width
  1378. AppText {
  1379. text: "红/蓝比例:"
  1380. color: app.fontColor
  1381. fontSize: 13
  1382. anchors.verticalCenter: parent.verticalCenter
  1383. }
  1384. AppTextField {
  1385. id: wbRatioRField
  1386. width: (parent.width - dp(80)) / 2
  1387. placeholderText: "红 " + frames.cam_BalanceRatioR
  1388. text: frames.cam_BalanceRatioR
  1389. EnterKey.type: Qt.EnterKeyDone
  1390. wrapMode: Text.NoWrap
  1391. inputMethodHints: Qt.ImhDigitsOnly |
  1392. Qt.ImhPreferDone |
  1393. Qt.ImhNoPredictiveText
  1394. validator: IntValidator {
  1395. bottom: 0
  1396. top: 16383
  1397. }
  1398. Keys.onReturnPressed: {
  1399. frames.cam_BalanceRatioR = text
  1400. console.log("设置白平衡红比例:", text)
  1401. Qt.inputMethod.hide()
  1402. }
  1403. onAccepted: {
  1404. frames.cam_BalanceRatioR = text
  1405. console.log("设置白平衡红比例:", text)
  1406. }
  1407. }
  1408. AppTextField {
  1409. id: wbRatioBField
  1410. width: (parent.width - dp(80)) / 2
  1411. placeholderText: "蓝 " + frames.cam_BalanceRatioB
  1412. text: frames.cam_BalanceRatioB
  1413. EnterKey.type: Qt.EnterKeyDone
  1414. wrapMode: Text.NoWrap
  1415. inputMethodHints: Qt.ImhDigitsOnly |
  1416. Qt.ImhPreferDone |
  1417. Qt.ImhNoPredictiveText
  1418. validator: IntValidator {
  1419. bottom: 0
  1420. top: 16383
  1421. }
  1422. Keys.onReturnPressed: {
  1423. frames.cam_BalanceRatioB = text
  1424. console.log("设置白平衡蓝比例:", text)
  1425. Qt.inputMethod.hide()
  1426. }
  1427. onAccepted: {
  1428. frames.cam_BalanceRatioB = text
  1429. console.log("设置白平衡蓝比例:", text)
  1430. }
  1431. }
  1432. }
  1433. AppText {
  1434. id: text_debug
  1435. text: "通信调试"
  1436. font.bold: true
  1437. color: "#28a779"
  1438. fontSize: 20
  1439. }
  1440. Row {
  1441. spacing: dp(12)
  1442. AppText {
  1443. text: "显示Serial发送数据"
  1444. color: app.fontColor
  1445. fontSize: 15
  1446. anchors.verticalCenter: txSwitch.verticalCenter
  1447. }
  1448. AppSwitch {
  1449. id: txSwitch
  1450. onToggled: {
  1451. app.floatPanel = checked
  1452. app.showTxData = checked
  1453. app.floatPanel_title = "Serial发送数据"
  1454. }
  1455. }
  1456. }
  1457. Row {
  1458. spacing: dp(12)
  1459. AppText {
  1460. text: "显示Serial接收数据"
  1461. color: app.fontColor
  1462. fontSize: 15
  1463. anchors.verticalCenter: rxSwitch.verticalCenter
  1464. }
  1465. AppSwitch {
  1466. id: rxSwitch
  1467. onToggled: {
  1468. app.floatPanel = checked
  1469. app.showRxData = checked
  1470. app.floatPanel_title = "Serial接收数据"
  1471. }
  1472. }
  1473. }
  1474. Row {
  1475. spacing: dp(12)
  1476. AppText {
  1477. text: "显示MQTT发送数据"
  1478. color: app.fontColor
  1479. fontSize: 15
  1480. anchors.verticalCenter: pubSwitch.verticalCenter
  1481. }
  1482. AppSwitch {
  1483. id: pubSwitch
  1484. onToggled: {
  1485. app.floatPanel = checked
  1486. app.showPubData = checked
  1487. app.showSubData = false
  1488. app.floatPanel_title = "MQTT发送数据"
  1489. }
  1490. }
  1491. }
  1492. Row {
  1493. spacing: dp(12)
  1494. AppText {
  1495. text: "显示MQTT接收数据"
  1496. color: app.fontColor
  1497. fontSize: 15
  1498. anchors.verticalCenter: subSwitch.verticalCenter
  1499. }
  1500. AppSwitch {
  1501. id: subSwitch
  1502. onToggled: {
  1503. app.floatPanel = checked
  1504. app.showSubData = checked
  1505. app.showPubData = false
  1506. app.floatPanel_title = "MQTT接收数据"
  1507. }
  1508. }
  1509. }
  1510. // ===== 运维App(com.rd.client) 运行状态 / 下载安装 =====
  1511. // 后台每 10 分钟巡检 FTP 取最高版本自动下载安装,
  1512. // 这里只做展示 + 手动触发,流程全部在 oaApp(C++) 里完成。
  1513. AppText {
  1514. id: text_oa_app
  1515. text: "运维App"
  1516. font.bold: true
  1517. color: "#28a779"
  1518. fontSize: 20
  1519. }
  1520. // 竖向排列:屏幕宽度不够时横向排列会被截断
  1521. Column {
  1522. spacing: dp(6)
  1523. width: parent.width
  1524. Row {
  1525. spacing: dp(6)
  1526. AppText {
  1527. text: "运行状态:"
  1528. color: app.fontColor
  1529. fontSize: 15
  1530. anchors.verticalCenter: parent.verticalCenter
  1531. }
  1532. AppText {
  1533. id: oa_state_text
  1534. text: oaApp.stateText
  1535. color: oaApp.running ? "#28a779" : "#d9534f"
  1536. font.bold: true
  1537. fontSize: 15
  1538. anchors.verticalCenter: parent.verticalCenter
  1539. }
  1540. }
  1541. Row {
  1542. spacing: dp(6)
  1543. AppText {
  1544. text: "已装版本:"
  1545. color: app.fontColor
  1546. fontSize: 15
  1547. anchors.verticalCenter: parent.verticalCenter
  1548. }
  1549. AppText {
  1550. text: oaApp.installedVersion.length > 0 ? oaApp.installedVersion : "--"
  1551. color: app.fontColor
  1552. fontSize: 15
  1553. anchors.verticalCenter: parent.verticalCenter
  1554. }
  1555. }
  1556. Row {
  1557. spacing: dp(6)
  1558. AppText {
  1559. text: "FTP最高版本:"
  1560. color: app.fontColor
  1561. fontSize: 15
  1562. anchors.verticalCenter: parent.verticalCenter
  1563. }
  1564. AppText {
  1565. text: oaApp.remoteVersion.length > 0 ? oaApp.remoteVersion : "--"
  1566. color: app.fontColor
  1567. fontSize: 15
  1568. anchors.verticalCenter: parent.verticalCenter
  1569. }
  1570. }
  1571. }
  1572. // 下载进度:仅在下载中显示
  1573. Rectangle {
  1574. visible: oaApp.downloading
  1575. width: parent.width
  1576. height: dp(10)
  1577. radius: dp(5)
  1578. color: "#33000000"
  1579. Rectangle {
  1580. width: parent.width * oaApp.progress / 100
  1581. height: parent.height
  1582. radius: parent.radius
  1583. color: "#28a779"
  1584. }
  1585. }
  1586. // 按钮同样竖排,避免三个按钮挤在一行被截断
  1587. Column {
  1588. spacing: dp(8)
  1589. // 下载/更新:立即巡检 FTP,有更高版本则下载并自动安装
  1590. AppButton {
  1591. id: oa_download_btn
  1592. text: oaApp.downloading ? "下载中 " + oaApp.progress + "%"
  1593. : (oaApp.installed ? "下载并更新" : "下载安装")
  1594. textColor: "white"
  1595. flat: false
  1596. backgroundColor: oaApp.downloading ? "grey" : "#28a779"
  1597. minimumHeight: dp(38)
  1598. minimumWidth: dp(140)
  1599. enabled: !oaApp.downloading
  1600. onClicked: {
  1601. oaApp.checkNow()
  1602. }
  1603. }
  1604. // 立即启动:不检查版本,直接把运维App拉起来
  1605. AppButton {
  1606. text: "立即启动"
  1607. textColor: "black"
  1608. flat: false
  1609. borderColor: "black"
  1610. borderWidth: dp(1)
  1611. backgroundColor: "white"
  1612. minimumHeight: dp(38)
  1613. minimumWidth: dp(140)
  1614. onClicked: {
  1615. oaApp.startApp()
  1616. }
  1617. }
  1618. // 刷新状态:立即查询已装版本/是否运行
  1619. AppButton {
  1620. text: "刷新状态"
  1621. textColor: "black"
  1622. flat: false
  1623. borderColor: "black"
  1624. borderWidth: dp(1)
  1625. backgroundColor: "white"
  1626. minimumHeight: dp(38)
  1627. minimumWidth: dp(140)
  1628. onClicked: {
  1629. oaApp.refreshStatus()
  1630. }
  1631. }
  1632. }
  1633. AppText {
  1634. id: oa_msg_text
  1635. // 无结果提示时显示"等待巡检 下次 mm:ss",剩余时间每秒刷新
  1636. text: (oaApp.message.length > 0 ? oaApp.message : "等待巡检")
  1637. + (oaApp.nextCheckText.length > 0 ? " 下次巡检 " + oaApp.nextCheckText : "")
  1638. + (oaApp.lastCheckTime.length > 0 ? " (" + oaApp.lastCheckTime + ")" : "")
  1639. color: app.fontColor
  1640. fontSize: 13
  1641. }
  1642. } // motorContent
  1643. } // motorSection
  1644. }
  1645. }
  1646. }
  1647. }