Main.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. import QtQuick
  2. import QtQuick.Layouts
  3. import Felgo
  4. import QtQuick.Controls
  5. import "pages"
  6. import "common"
  7. import "logic"
  8. import "model"
  9. App {
  10. id: app
  11. licenseKey: "6BBDF824AF729C33ECAA6DC917319EDB8A7F76A9EB5217C380F81C28203CF84078DBCEEC5DB44C7DB60373C0FFE65240DA17EAC1C8376F5939F26782D2A3110CFCDB938C557DDAC8C63F942AF917CD7BCD4235973E76002E69BE740BD2FE99BB7F22AD12408FB5EE3D3A538E604803F0947C372A8486E63B5CF101A18B6CEDF7AEDC615273B15ADBCF1DCC54F123FA093609F650378D2F2BC11C74421663CAB7C178C4123AF6C6B6E44EE45A5A790448F85D4039D7EB1C23C3CA97B42E0724B2987C185114E732662A4EFD507EDC0E5DC2DA7A9FF7754678F48BFC8AAFD40B21926B5A1FD427E279FDE44EC0315229371F4D77B918CC4663CB71572051E1E84DCBF8E183C44981C9D921DB7C5A02879E2D9352ECEC03FF21D99F941B9E31E10D6D625D2603135C101658FEA17FB7B397"
  12. property bool themeReady: false
  13. // ========== 主题相关 ==========
  14. property string theme_md: "day"
  15. property string theme_select: "day"
  16. property color theme_backgroundColor: theme_select === "day" ? "#d8d8d8" : "#1a1a1a"
  17. property color cardColor: theme_select == "day" ? "#f5f5f5" :(theme_select == "night" ? "#2b2b2b":"#f5f5f5") //背景色 //前景色
  18. property color fontColor: theme_select == "day" ? "black" :(theme_select == "night" ? "white":"black")
  19. property bool floatPanel: false
  20. property bool showTxData: false
  21. property bool showRxData: false
  22. property bool showPubData: false
  23. property bool showSubData: false
  24. property string floatPanel_title: "串口数据"
  25. property string txDataLog: ""
  26. property string rxDataLog: ""
  27. // 初始为纯黑色,强制设置为不透明,防止花屏
  28. color: "#000000"
  29. property string boardversionText: ""
  30. property string appversionText: ""
  31. property bool tempProtectionState: false // 温度保护状态,true表示处于保护状态
  32. property int logoutcnt
  33. signal logoutClicked
  34. // ========== 主题初始化(最早执行) ==========
  35. onInitTheme: {
  36. console.log("onInitTheme")
  37. // 1. 先读取保存的主题,再设置任何颜色
  38. var savedMode = "day"
  39. try {
  40. savedMode = settings.getValue("theme_mode")
  41. if (savedMode === undefined || savedMode === "" || savedMode === null) {
  42. savedMode = "day"
  43. settings.setValue("theme_mode", "day")
  44. }
  45. } catch(e) {
  46. savedMode = "day"
  47. }
  48. app.theme_md = savedMode
  49. if (savedMode !== "auto") {
  50. app.theme_select = savedMode
  51. } else {
  52. var h = new Date().getHours()
  53. app.theme_select = (h >= 6 && h <= 18) ? "day" : "night"
  54. }
  55. // 2. 根据主题设置颜色(此时颜色属性会自动更新)
  56. // 无需手动赋值,绑定表达式会自动计算
  57. // 3. 设置Felgo主题
  58. Theme.platform = "ios"
  59. // TabBar样式
  60. Theme.navigationTabBar.titlePressedColor = "green"
  61. Theme.navigationTabBar.backgroundColor = app.cardColor
  62. Theme.navigationTabBar.titleColor = app.fontColor
  63. // NavigationBar样式
  64. Theme.navigationBar.backgroundColor = app.cardColor
  65. Theme.navigationBar.titleColor = app.fontColor
  66. if (!Theme.navigationBar.height) {
  67. Theme.navigationBar.height = dp(56)
  68. }
  69. if (!Theme.statusBarHeight) {
  70. Theme.statusBarHeight = dp(24)
  71. }
  72. // 4. 标记主题就绪
  73. themeReady = true
  74. }
  75. // 新增一个函数来接收 HomePage 发送的文本
  76. function bvReceived(datbv){
  77. boardversionText = datbv
  78. }
  79. function appReceived(datbv){
  80. appversionText = datbv
  81. }
  82. onLogoutClicked: {
  83. logic.logout()
  84. // jump to main page after logout
  85. navigation.currentIndex = 0
  86. //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
  87. }
  88. //business logic}
  89. Logic {
  90. id: logic
  91. }
  92. // model
  93. DataModel {
  94. id: dataModel
  95. dispatcher: logic // data model handles actions sent by logic
  96. }
  97. // view
  98. Navigation {
  99. objectName: "Navigation_main"
  100. id: navigation
  101. enabled: themeReady
  102. navigationMode: Theme.isAndroid ? navigationModeTabs : navigationModeDefault
  103. drawerLogoBackgroundColor: "red"
  104. opacity: themeReady ? 1.0 : 0.0
  105. Behavior on opacity { NumberAnimation { duration: 200 } }
  106. Component.onCompleted: {
  107. console.log("Navigation Component.onCompleted")
  108. initializeNavigation()
  109. }
  110. function initializeNavigation() {
  111. console.log("Initializing navigation...")
  112. for(var i = 0;i < navigation.count; i++){
  113. navigation.currentIndex = i
  114. }
  115. navigation.currentIndex = 0
  116. }
  117. function setCurrentTab(index){
  118. navigation.currentIndex = index
  119. }
  120. // only enable if user is logged in
  121. // login page below overlays navigation then
  122. // first tab
  123. NavigationItem {
  124. id: uiComponentsItem
  125. title: "主界面"
  126. iconType: IconType.home
  127. Loader{
  128. asynchronous: true
  129. active: true
  130. source: "pages/HomePage.qml"
  131. }
  132. }
  133. NavigationItem {
  134. title: "测试维护"
  135. iconType: IconType.gears
  136. objectName: "autofocus_Item"
  137. TestPage {
  138. //id: autofocus_id
  139. }
  140. }
  141. // second tab
  142. NavigationItem {
  143. title: qsTr("图像查看") // use qsTr for strings you want to translate
  144. iconType: IconType.qrcode
  145. NavigationStack {
  146. PhotostitcherPage {
  147. onVisibleChanged: {
  148. if(visible){
  149. console.log("进入图像查看界面,开始初始化加载...")
  150. loadRootDirectory()
  151. }
  152. }
  153. }
  154. }
  155. }
  156. // fourth tab
  157. NavigationItem {
  158. objectName: "systemset_Item"
  159. title: qsTr("系统设置") // use qsTr for strings you want to translate
  160. iconType: IconType.gears
  161. NavigationStack {
  162. initialPage: ProfilePage {
  163. id: page_sys
  164. onThemChange: {
  165. console.log("配置主题模式:",mode)
  166. app.theme_md = mode
  167. if (mode !== "auto") {
  168. app.theme_select = mode
  169. } else {
  170. var h = new Date().getHours()
  171. app.theme_select = (h >= 6 && h <= 18) ? "day" : "night"
  172. }
  173. app.theme_select = mode
  174. app.theme_md = mode
  175. Theme.navigationTabBar.backgroundColor= app.cardColor
  176. Theme.navigationTabBar.titleColor = app.fontColor
  177. Theme.navigationTabBar.dividerColor = "green"
  178. console.log("主题已更新:",app.theme_select)
  179. }
  180. // handle logout
  181. onLogoutClicked: {
  182. //loginpage.pushed()
  183. logic.logout()
  184. // jump to main page after logout
  185. navigation.currentIndex = 0
  186. serial.setLightness(-255)
  187. //navigation.currentNavigationItem.navigationStack.popAllExceptFirst()
  188. }
  189. }
  190. }
  191. }
  192. tabPosition: Navigation.Left
  193. }
  194. // ========== 业务定时器 ==========
  195. Timer{
  196. interval: 1000
  197. running: true
  198. repeat: true
  199. onTriggered: {
  200. if(navigation.currentIndex === 0&&loginpage.logintimeout%5===0){
  201. serial.readBoardData()
  202. }
  203. loginpage.logintimeout--
  204. ProfilePage.boardversion = "123"
  205. console.log("休眠计数:",loginpage.logintimeout)
  206. if(loginpage.logintimeout===0){ //?秒后进入休眠
  207. loginpage.logintimeout = 300
  208. logoutClicked()
  209. //关闭屏幕(亮度设置为0)
  210. serial.setLightness(-255)
  211. }
  212. }
  213. }
  214. Connections{
  215. target: curl
  216. function onDownloadFinished(result) {
  217. if(result){
  218. navigation.setCurrentTab(1)
  219. }
  220. }
  221. }
  222. // 远程校准指令: {"cmd":"slide","ext":{"calibrate":"y","speed":"50"}} → 跳转相机界面(Tab 1 测试维护)
  223. Connections {
  224. target: mqtt
  225. function onSignal_open_camera() {
  226. console.log("[Main] 收到远程相机开启指令,跳转相机界面!")
  227. navigation.setCurrentTab(1)
  228. }
  229. }
  230. // ========== 全局融合进度弹窗 ==========
  231. property bool isGlobalFusing: false
  232. property string globalFusionMessage: ""
  233. property int globalFusionPercent: 0
  234. Connections {
  235. target: opencvFunc
  236. function onFusionProgress(message, percent) {
  237. console.log("[Main] 融合进度:", message, percent + "%")
  238. if (percent >= 100) {
  239. // 完成后延迟关闭弹窗,让用户看到完成状态
  240. globalFusionMessage = message
  241. globalFusionPercent = percent
  242. Qt.callLater(function() {
  243. isGlobalFusing = false
  244. })
  245. } else {
  246. isGlobalFusing = true
  247. globalFusionMessage = message
  248. globalFusionPercent = percent
  249. }
  250. }
  251. function onFuseFinished(resultPath) {
  252. isGlobalFusing = false
  253. console.log("[Main] 融合结束:", resultPath)
  254. }
  255. }
  256. Popup {
  257. id: globalFusionPopup
  258. anchors.centerIn: parent
  259. width: Math.min(parent.width * 0.8, 360)
  260. modal: true
  261. focus: true
  262. closePolicy: Popup.NoAutoClose
  263. visible: isGlobalFusing
  264. padding: 20
  265. z: 99999
  266. background: Rectangle {
  267. color: "white"
  268. radius: 8
  269. border.color: "#28a779"
  270. border.width: 2
  271. }
  272. contentItem: ColumnLayout {
  273. spacing: 16
  274. Text {
  275. Layout.fillWidth: true
  276. text: "图像融合中"
  277. font.pixelSize: 18
  278. font.bold: true
  279. color: "#28a779"
  280. horizontalAlignment: Text.AlignHCenter
  281. }
  282. BusyIndicator {
  283. Layout.alignment: Qt.AlignHCenter
  284. running: globalFusionPopup.visible
  285. width: 48
  286. height: 48
  287. }
  288. Text {
  289. Layout.fillWidth: true
  290. text: globalFusionMessage
  291. font.pixelSize: 14
  292. color: "#333"
  293. horizontalAlignment: Text.AlignHCenter
  294. wrapMode: Text.WordWrap
  295. }
  296. ProgressBar {
  297. id: globalFusionProgressBar
  298. Layout.fillWidth: true
  299. from: 0
  300. to: 100
  301. value: globalFusionPercent
  302. background: Rectangle {
  303. implicitHeight: 8
  304. color: "#eee"
  305. radius: 4
  306. }
  307. contentItem: Item {
  308. implicitHeight: 8
  309. Rectangle {
  310. width: globalFusionProgressBar.visualPosition * parent.width
  311. height: parent.height
  312. radius: 4
  313. color: "#28a779"
  314. }
  315. }
  316. }
  317. Text {
  318. Layout.fillWidth: true
  319. text: globalFusionPercent.toFixed(0) + "%"
  320. font.pixelSize: 12
  321. color: "#666"
  322. horizontalAlignment: Text.AlignHCenter
  323. }
  324. }
  325. }
  326. Component.onCompleted: {
  327. console.log("App Component.onCompleted, starting phased loading...")
  328. }
  329. LocalNotificationPage {
  330. id: notificationPage
  331. visible:false
  332. }
  333. // ========== 登录页(Phase2: 导航加载完成后才加载) ==========
  334. LoginPage {
  335. id: loginpage
  336. title: "植物病菌孢子捕捉分析系统"
  337. Connections{
  338. target: serial
  339. }
  340. visible: opacity > 0
  341. enabled: visible
  342. opacity: dataModel.userLoggedIn ? 0 : 1
  343. Behavior on opacity { NumberAnimation { duration: 250 } } // page fade in/out
  344. }
  345. Rectangle {
  346. id: rxFloatingWindow
  347. visible: floatPanel
  348. width: 400
  349. height: 300
  350. x: parent.width - 420
  351. y: 20
  352. color: "white"
  353. opacity: 0.8 // 50% 透明度
  354. radius: 10
  355. z: 9999
  356. Column {
  357. anchors.fill: parent
  358. anchors.margins: 10
  359. spacing: 5
  360. Row {
  361. width: parent.width
  362. spacing: 10
  363. AppText {
  364. text: floatPanel_title
  365. color: "#00ffff"
  366. fontSize: 16
  367. font.bold: true
  368. anchors.verticalCenter: appbutton_clear.verticalCenter
  369. }
  370. AppButton {
  371. id: appbutton_clear
  372. text: "清空"
  373. textColor: "white"
  374. backgroundColor: "#ff4444"
  375. flat: false
  376. onClicked: {
  377. rxDataLog = ""
  378. txDataLog = ""
  379. }
  380. }
  381. // AppButton {
  382. // text: "X"
  383. // textColor: "white"
  384. // backgroundColor: "#ff4444"
  385. // flat: false
  386. // onClicked: {
  387. // rxSwitch.checked = false
  388. // }
  389. // }
  390. }
  391. Flickable {
  392. width: parent.width
  393. height: parent.height - 40
  394. contentWidth: width
  395. contentHeight: txt_logdata.implicitHeight
  396. clip: true
  397. AppText {
  398. id: txt_logdata
  399. width: parent.width
  400. text: (showRxData ? rxDataLog : (showTxData ? txDataLog : "")) || (showSubData ? rxDataLog : (showPubData ? txDataLog : ""))
  401. color: "green"
  402. fontSize: 12
  403. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
  404. }
  405. }
  406. }
  407. // 拖拽功能
  408. MouseArea {
  409. anchors.fill: parent
  410. drag.target: rxFloatingWindow
  411. drag.axis: Drag.XAndYAxis
  412. }
  413. }
  414. }