Main.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. // ========== 全局融合进度弹窗 ==========
  223. property bool isGlobalFusing: false
  224. property string globalFusionMessage: ""
  225. property int globalFusionPercent: 0
  226. Connections {
  227. target: opencvFunc
  228. function onFusionProgress(message, percent) {
  229. console.log("[Main] 融合进度:", message, percent + "%")
  230. if (percent >= 100) {
  231. // 完成后延迟关闭弹窗,让用户看到完成状态
  232. globalFusionMessage = message
  233. globalFusionPercent = percent
  234. Qt.callLater(function() {
  235. isGlobalFusing = false
  236. })
  237. } else {
  238. isGlobalFusing = true
  239. globalFusionMessage = message
  240. globalFusionPercent = percent
  241. }
  242. }
  243. function onFuseFinished(resultPath) {
  244. isGlobalFusing = false
  245. console.log("[Main] 融合结束:", resultPath)
  246. }
  247. }
  248. Popup {
  249. id: globalFusionPopup
  250. anchors.centerIn: parent
  251. width: Math.min(parent.width * 0.8, 360)
  252. modal: true
  253. focus: true
  254. closePolicy: Popup.NoAutoClose
  255. visible: isGlobalFusing
  256. padding: 20
  257. z: 99999
  258. background: Rectangle {
  259. color: "white"
  260. radius: 8
  261. border.color: "#28a779"
  262. border.width: 2
  263. }
  264. contentItem: ColumnLayout {
  265. spacing: 16
  266. Text {
  267. Layout.fillWidth: true
  268. text: "图像融合中"
  269. font.pixelSize: 18
  270. font.bold: true
  271. color: "#28a779"
  272. horizontalAlignment: Text.AlignHCenter
  273. }
  274. BusyIndicator {
  275. Layout.alignment: Qt.AlignHCenter
  276. running: globalFusionPopup.visible
  277. width: 48
  278. height: 48
  279. }
  280. Text {
  281. Layout.fillWidth: true
  282. text: globalFusionMessage
  283. font.pixelSize: 14
  284. color: "#333"
  285. horizontalAlignment: Text.AlignHCenter
  286. wrapMode: Text.WordWrap
  287. }
  288. ProgressBar {
  289. id: globalFusionProgressBar
  290. Layout.fillWidth: true
  291. from: 0
  292. to: 100
  293. value: globalFusionPercent
  294. background: Rectangle {
  295. implicitHeight: 8
  296. color: "#eee"
  297. radius: 4
  298. }
  299. contentItem: Item {
  300. implicitHeight: 8
  301. Rectangle {
  302. width: globalFusionProgressBar.visualPosition * parent.width
  303. height: parent.height
  304. radius: 4
  305. color: "#28a779"
  306. }
  307. }
  308. }
  309. Text {
  310. Layout.fillWidth: true
  311. text: globalFusionPercent.toFixed(0) + "%"
  312. font.pixelSize: 12
  313. color: "#666"
  314. horizontalAlignment: Text.AlignHCenter
  315. }
  316. }
  317. }
  318. Component.onCompleted: {
  319. console.log("App Component.onCompleted, starting phased loading...")
  320. }
  321. LocalNotificationPage {
  322. id: notificationPage
  323. visible:false
  324. }
  325. // ========== 登录页(Phase2: 导航加载完成后才加载) ==========
  326. LoginPage {
  327. id: loginpage
  328. title: "植物病菌孢子捕捉分析系统"
  329. Connections{
  330. target: serial
  331. }
  332. visible: opacity > 0
  333. enabled: visible
  334. opacity: dataModel.userLoggedIn ? 0 : 1
  335. Behavior on opacity { NumberAnimation { duration: 250 } } // page fade in/out
  336. }
  337. Rectangle {
  338. id: rxFloatingWindow
  339. visible: floatPanel
  340. width: 400
  341. height: 300
  342. x: parent.width - 420
  343. y: 20
  344. color: "white"
  345. opacity: 0.8 // 50% 透明度
  346. radius: 10
  347. z: 9999
  348. Column {
  349. anchors.fill: parent
  350. anchors.margins: 10
  351. spacing: 5
  352. Row {
  353. width: parent.width
  354. spacing: 10
  355. AppText {
  356. text: floatPanel_title
  357. color: "#00ffff"
  358. fontSize: 16
  359. font.bold: true
  360. anchors.verticalCenter: appbutton_clear.verticalCenter
  361. }
  362. AppButton {
  363. id: appbutton_clear
  364. text: "清空"
  365. textColor: "white"
  366. backgroundColor: "#ff4444"
  367. flat: false
  368. onClicked: {
  369. rxDataLog = ""
  370. txDataLog = ""
  371. }
  372. }
  373. // AppButton {
  374. // text: "X"
  375. // textColor: "white"
  376. // backgroundColor: "#ff4444"
  377. // flat: false
  378. // onClicked: {
  379. // rxSwitch.checked = false
  380. // }
  381. // }
  382. }
  383. Flickable {
  384. width: parent.width
  385. height: parent.height - 40
  386. contentWidth: width
  387. contentHeight: txt_logdata.implicitHeight
  388. clip: true
  389. AppText {
  390. id: txt_logdata
  391. width: parent.width
  392. text: (showRxData ? rxDataLog : (showTxData ? txDataLog : "")) || (showSubData ? rxDataLog : (showPubData ? txDataLog : ""))
  393. color: "green"
  394. fontSize: 12
  395. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
  396. }
  397. }
  398. }
  399. // 拖拽功能
  400. MouseArea {
  401. anchors.fill: parent
  402. drag.target: rxFloatingWindow
  403. drag.axis: Drag.XAndYAxis
  404. }
  405. }
  406. }