TestPage.qml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. objectName: "autoFocus_Page"
  15. navigationBarHidden: true
  16. backgroundColor: app.theme_backgroundColor
  17. property var videoFormats
  18. function autotake(sw){
  19. if(sw)
  20. {
  21. console.log("autotakestart")
  22. frames.camera_sw = true
  23. //frames.auto_clicked = true //开始对焦
  24. auto_timer.start() //启动对焦定时器
  25. console.log("相机已打开")
  26. photoTimer.interval=300*1000
  27. photoTimer.start()
  28. }else{
  29. frames.camera_sw = true
  30. console.log("打开相机单次拍照!")
  31. }
  32. }
  33. Frames {
  34. objectName: "Frames"
  35. id: frames
  36. videoSink: output.videoSink
  37. onVideoSinkChanged: {
  38. console.log("onVideoSinkChanged")
  39. photoTimer.start() //两秒后关闭相机,因为相机加载的慢,否则关不住
  40. }
  41. onCameraStaChanged: function(sta_cam) {
  42. if(sta_cam)
  43. {
  44. //camera.active = sta_cam
  45. //camera.start()
  46. output.visible= sta_cam
  47. photoTimer.interval=300*1000
  48. photoTimer.start()
  49. }else{
  50. //camera.active = sta_cam
  51. //camera.stop()
  52. output.visible= sta_cam
  53. photoTimer.stop() //停止计时器
  54. }
  55. console.log("相机状态改变",sta_cam)
  56. }
  57. }
  58. // MediaDevices {
  59. // id: mediaDevices
  60. // }
  61. /*//https://github.com/igormironchik/qt6_qcamera/blob/main/main.qml
  62. Camera {
  63. id: camera
  64. //cameraFormat:
  65. active: false
  66. whiteBalanceMode: Camera.WhiteBalanceAuto
  67. //colorTemperature: 5600
  68. //zoomFactor: maximumZoomFactor
  69. }
  70. CaptureSession {
  71. camera: camera
  72. videoOutput: output
  73. imageCapture : ImageCapture {
  74. id: imageCapture
  75. onImageSaved: {
  76. console.log("Image saved. Request ID:", requestId, "Path:", path);
  77. }
  78. onImageCaptured: {
  79. console.log("Image saved. Request ID:");
  80. imageCapture.captureToFile(appdir+"1.jpg")
  81. }
  82. }
  83. }
  84. */
  85. Timer {
  86. id: photoTimer
  87. interval: 2000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  88. running: false // 初始状态下定时器停止
  89. repeat: false // 设置为false,以便只执行一次
  90. onTriggered: {
  91. // 定时器触发后,设置按钮可用
  92. // camera.active = false
  93. // camera.stop()
  94. output.visible = false
  95. frames.camera_sw = false
  96. }
  97. }
  98. Timer {
  99. id: auto_timer
  100. interval: 1000 // 设置点击频率限制的时间间隔(以毫秒为单位)
  101. running: false // 初始状态下定时器停止
  102. repeat: false // 设置为false,以便只执行一次
  103. onTriggered: {
  104. // 定时器触发后,开始对焦
  105. frames.auto_clicked = true
  106. }
  107. }
  108. Connections{
  109. target: serial
  110. onTakephotodone:{
  111. console.log("立即拍照完成!")
  112. focus_switch.enabled = true
  113. focus_switch.checked = false
  114. }
  115. onAutotestdone: {
  116. console.log("自动对焦完成!")
  117. autotest_switch.enabled = true
  118. autotest_switch.checked = false
  119. }
  120. onTranslatedone: {
  121. console.log("胶带传送完成!")
  122. jiaodai_switch.enabled = true
  123. jiaodai_switch.checked = false
  124. }
  125. }
  126. // 接收并显示日志消息
  127. Connections {
  128. target: logger
  129. onLogMessage: {
  130. logTextArea.text += message + "\n"
  131. console.log("logTextArea:",logTextArea.contentHeight)
  132. if(logTextArea.contentHeight>5000){
  133. logTextArea.clear()
  134. }
  135. }
  136. }
  137. Row{
  138. anchors.fill: parent
  139. spacing: 5
  140. Rectangle {
  141. width: parent.width*0.7
  142. height: parent.height
  143. color: app.cardColor
  144. radius: 5
  145. AppButton {
  146. id: normButton
  147. //anchors.horizontalCenter: parent.horizontalCenter
  148. anchors.centerIn: parent
  149. anchors.fill: parent
  150. //text: "打开相机"
  151. flat: true //边框是否可视
  152. onClicked: {
  153. console.log("相机状态:",frames.camera_sw)
  154. //if(camera.active){
  155. if(frames.camera_sw){
  156. text = "相机已关闭"
  157. output.visible = false
  158. frames.camera_sw = false
  159. }else{
  160. text = "打开相机"
  161. output.visible = true
  162. frames.camera_sw = true
  163. }
  164. }
  165. AppImage{
  166. id: image_picdis
  167. anchors.centerIn: parent
  168. source: "../../assets/photoico.svg"
  169. }
  170. }
  171. VideoOutput
  172. {
  173. id: output
  174. anchors.centerIn: parent
  175. // width: parent.width
  176. anchors.fill: parent
  177. focus: visible
  178. fillMode: VideoOutput.PreserveAspectFit //根据视频的纵横比例等比例缩放
  179. // //fillMode: VideoOutput.Stretch
  180. Component.onCompleted: {
  181. console.log("output onCompleted")
  182. }
  183. }
  184. Row {
  185. AppText {
  186. id: photoclarity_text
  187. width: parent.width
  188. text: frames.fpsString
  189. color: "red"
  190. }
  191. AppText {
  192. id: photoclarity2_text
  193. anchors.top: photoclarity_text.bottom
  194. width: parent.width
  195. text: frames.qulityString
  196. color: "red"
  197. }
  198. }
  199. Row {
  200. anchors.bottom: parent.bottom
  201. anchors.bottomMargin: 10
  202. anchors.left: parent.left
  203. anchors.leftMargin: 10
  204. spacing: -5
  205. CustomRadioButton {
  206. id: x_rdb
  207. checked: true
  208. text: "X轴"
  209. }
  210. CustomRadioButton {
  211. id: y_rdb
  212. text: "Y轴"
  213. }
  214. CustomRadioButton {
  215. id: z_rdb
  216. text: "Z轴"
  217. }
  218. AppButton {
  219. text: "复位"
  220. flat: false
  221. minimumHeight: 20
  222. minimumWidth: 50
  223. textColor: "green"
  224. backgroundColor: "white"
  225. borderColor: "#f5f5f5"
  226. anchors.verticalCenter: x_rdb.verticalCenter
  227. onClicked: {
  228. if(x_rdb.checked){
  229. serial.sendCmd("movx",true,"");
  230. }else if(y_rdb.checked){
  231. serial.sendCmd("movy",true,"");
  232. }else if(z_rdb.checked){
  233. serial.sendCmd("movz",true,"");
  234. }
  235. }
  236. }
  237. AppButton {
  238. text: "前进"
  239. flat: false
  240. textColor: "green"
  241. backgroundColor: "white"
  242. borderColor: "#f5f5f5"
  243. minimumHeight: 20
  244. minimumWidth: 50
  245. anchors.verticalCenter: x_rdb.verticalCenter
  246. onClicked: {
  247. var dialog = InputDialog.inputTextSingleLine(app,
  248. "请输入距离:",
  249. "0um",
  250. function(ok,text){
  251. if(ok){
  252. if(text){
  253. if(x_rdb.checked===true){
  254. serial.sendCmd("movx",false,"f"+text);
  255. }else if(y_rdb.checked===true){
  256. serial.sendCmd("movy",false,"f"+text);
  257. }else if(z_rdb.checked===true){
  258. serial.sendCmd("movz",false,"f"+text);
  259. }
  260. }
  261. console.log("行进",text)
  262. }
  263. })
  264. }
  265. }
  266. AppButton {
  267. text: "后退"
  268. flat: false
  269. textColor: "green"
  270. backgroundColor: "white"
  271. borderColor: "#f5f5f5"
  272. minimumHeight: 30
  273. minimumWidth: 50
  274. anchors.verticalCenter: x_rdb.verticalCenter
  275. onClicked: {
  276. var dialog = InputDialog.inputTextSingleLine(app,
  277. "请输入距离:",
  278. "0um",
  279. function(ok,text){
  280. if(ok){
  281. if(text){
  282. if(x_rdb.checked===true){
  283. serial.sendCmd("movx",false,"b"+text);
  284. }else if(y_rdb.checked===true){
  285. serial.sendCmd("movy",false,"b"+text);
  286. }else if(z_rdb.checked===true){
  287. serial.sendCmd("movz",false,"b"+text);
  288. }
  289. }
  290. console.log("行进",text)
  291. }
  292. })
  293. }
  294. }
  295. AppButton{
  296. text: "+"
  297. flat: false
  298. textColor: "green"
  299. backgroundColor: "white"
  300. borderColor: "#f5f5f5"
  301. minimumHeight: 20
  302. minimumWidth: 20
  303. anchors.verticalCenter: x_rdb.verticalCenter
  304. onClicked:{
  305. if(x_rdb.checked===true){
  306. serial.sendCmd("movx",false,"f100");
  307. }else if(y_rdb.checked===true){
  308. serial.sendCmd("movy",false,"f100");
  309. }else if(z_rdb.checked===true){
  310. serial.sendCmd("movz",false,"f100");
  311. }
  312. }
  313. }
  314. AppButton{
  315. text: "-"
  316. flat: false
  317. textColor: "green"
  318. backgroundColor: "white"
  319. borderColor: "#f5f5f5"
  320. minimumHeight: 20
  321. minimumWidth: 20
  322. anchors.verticalCenter: x_rdb.verticalCenter
  323. onClicked: {
  324. if(x_rdb.checked===true){
  325. serial.sendCmd("movx",false,"b100");
  326. }else if(y_rdb.checked===true){
  327. serial.sendCmd("movy",false,"b100");
  328. }else if(z_rdb.checked===true){
  329. serial.sendCmd("movz",false,"b100");
  330. }
  331. }
  332. }
  333. }
  334. }
  335. Rectangle {
  336. width: parent.width*0.29
  337. height: parent.height
  338. color: app.cardColor
  339. radius: 5
  340. AppText {
  341. id: text_title
  342. anchors.left: parent.left
  343. anchors.leftMargin: 10
  344. anchors.top: parent.top
  345. anchors.topMargin: 10
  346. text: "测试设置"
  347. font.bold: true
  348. color: "#28a779"
  349. fontSize: 20
  350. }
  351. Rectangle{
  352. id: rec_test
  353. anchors.top: text_title.bottom
  354. anchors.topMargin: 5
  355. anchors.left: parent.left
  356. width: parent.width*0.97
  357. height: parent.height *0.5
  358. border.width: 1
  359. border.color: "white"
  360. radius: 5
  361. color: app.cardColor
  362. Column {
  363. anchors.top: text_title.bottom
  364. anchors.left: parent.left
  365. anchors.leftMargin: 10
  366. spacing: -15
  367. Row {
  368. spacing: 80
  369. AppText{
  370. text: "一键测试"
  371. fontSize: 15
  372. color: app.fontColor
  373. //font.bold: true
  374. anchors.verticalCenter: autotest_switch.verticalCenter
  375. }
  376. Switch {
  377. id: autotest_switch
  378. onToggled: {
  379. if(autotest_switch.checked==true){
  380. autotest_switch.enabled = false
  381. serial.sendCmd("autotest",true,"");
  382. }
  383. }
  384. }
  385. }
  386. Row {
  387. spacing: 80
  388. AppText{
  389. text: "风机测试"
  390. color: app.fontColor
  391. fontSize: 15
  392. //font.bold: true
  393. anchors.verticalCenter: fantest_switch.verticalCenter
  394. }
  395. Switch {
  396. id: fantest_switch
  397. onToggled: {
  398. if(fantest_switch.checked==true){
  399. serial.sendCmd("fan",true,"");
  400. }else{
  401. serial.sendCmd("fan",false,"");
  402. }
  403. }
  404. }
  405. }
  406. Row {
  407. spacing: 80
  408. AppText{
  409. text: "胶带测试"
  410. fontSize: 15
  411. color: app.fontColor
  412. //font.bold: true
  413. anchors.verticalCenter: jiaodai_switch.verticalCenter
  414. }
  415. Switch {
  416. id: jiaodai_switch
  417. onToggled: {
  418. if(jiaodai_switch.checked==true){
  419. jiaodai_switch.enabled = false
  420. serial.sendCmd("jiaodai",true,"");
  421. }
  422. }
  423. }
  424. }
  425. Row {
  426. spacing: 80
  427. AppText{
  428. text: "补光测试"
  429. color: app.fontColor
  430. fontSize: 15
  431. //font.bold: true
  432. anchors.verticalCenter: led_switch.verticalCenter
  433. }
  434. Switch {
  435. id: led_switch
  436. onToggled: {
  437. if(led_switch.checked==true){
  438. serial.sendCmd("led",true,"");
  439. }else{
  440. serial.sendCmd("led",false,"");
  441. }
  442. }
  443. }
  444. }
  445. Row {
  446. spacing: 80
  447. AppText{
  448. text: "立即拍照"
  449. color: app.fontColor
  450. fontSize: 15
  451. //font.bold: true
  452. anchors.verticalCenter: takephoto_switch.verticalCenter
  453. }
  454. Switch {
  455. id: takephoto_switch
  456. onToggled: {
  457. if(takephoto_switch.checked==true){
  458. frames.captureImage()
  459. }
  460. }
  461. }
  462. }
  463. Row {
  464. spacing: 80
  465. AppText{
  466. text: "对焦拍照"
  467. color: app.fontColor
  468. fontSize: 15
  469. //font.bold: true
  470. anchors.verticalCenter: focus_switch.verticalCenter
  471. }
  472. Switch {
  473. id: focus_switch
  474. onToggled: {
  475. if(focus_switch.checked==true){
  476. focus_switch.enabled = false
  477. serial.auto_takephoto(true)
  478. }
  479. }
  480. }
  481. }
  482. }
  483. Rectangle {
  484. anchors.top: rec_test.bottom
  485. anchors.left: parent.left
  486. width: parent.width
  487. height: parent.height * 0.85
  488. border.width: 1
  489. color: app.cardColor
  490. border.color: "white"
  491. radius: 5
  492. AppFlickable {
  493. id: scroll
  494. anchors.fill: parent
  495. contentHeight: content.height
  496. bottomMargin: nativeUtils.safeAreaInsets.bottom
  497. Column {
  498. id: content
  499. width: parent.width
  500. TextArea {
  501. id: logTextArea
  502. readOnly: true
  503. wrapMode: TextArea.WrapAtWordBoundaryOrAnywhere
  504. width: parent.width
  505. text: "日志"
  506. color: app.fontColor
  507. font.pixelSize: 8
  508. function scrollToLatestLine() {
  509. // 获取TextArea的内容高度
  510. var contentHeight = logTextArea.contentHeight;
  511. // 计算滚动位置,使视图滚动到最底部
  512. var scrollPosition = contentHeight - scroll.height;
  513. // 使用动画效果来平滑滚动
  514. scroll.contentY = scrollPosition;
  515. }
  516. onTextChanged: {
  517. // 当文本发生变化时,调用滚动函数以将视图滚动到最新行
  518. scrollToLatestLine();
  519. }
  520. }
  521. }
  522. }
  523. }
  524. }
  525. }
  526. }
  527. }