import QtQuick import QtQuick.Layouts import Felgo import QtQuick.Controls import "pages" import "common" import "logic" import "model" App { id: app licenseKey: "6BBDF824AF729C33ECAA6DC917319EDB8A7F76A9EB5217C380F81C28203CF84078DBCEEC5DB44C7DB60373C0FFE65240DA17EAC1C8376F5939F26782D2A3110CFCDB938C557DDAC8C63F942AF917CD7BCD4235973E76002E69BE740BD2FE99BB7F22AD12408FB5EE3D3A538E604803F0947C372A8486E63B5CF101A18B6CEDF7AEDC615273B15ADBCF1DCC54F123FA093609F650378D2F2BC11C74421663CAB7C178C4123AF6C6B6E44EE45A5A790448F85D4039D7EB1C23C3CA97B42E0724B2987C185114E732662A4EFD507EDC0E5DC2DA7A9FF7754678F48BFC8AAFD40B21926B5A1FD427E279FDE44EC0315229371F4D77B918CC4663CB71572051E1E84DCBF8E183C44981C9D921DB7C5A02879E2D9352ECEC03FF21D99F941B9E31E10D6D625D2603135C101658FEA17FB7B397" property bool themeReady: false // ========== 主题相关 ========== property string theme_md: "day" property string theme_select: "day" property color theme_backgroundColor: theme_select === "day" ? "#d8d8d8" : "#1a1a1a" property color cardColor: theme_select == "day" ? "#f5f5f5" :(theme_select == "night" ? "#2b2b2b":"#f5f5f5") //背景色 //前景色 property color fontColor: theme_select == "day" ? "black" :(theme_select == "night" ? "white":"black") property bool floatPanel: false property bool showTxData: false property bool showRxData: false property bool showPubData: false property bool showSubData: false property string floatPanel_title: "串口数据" property string txDataLog: "" property string rxDataLog: "" // 初始为纯黑色,强制设置为不透明,防止花屏 color: "#000000" property string boardversionText: "" property string appversionText: "" property bool tempProtectionState: false // 温度保护状态,true表示处于保护状态 property int logoutcnt signal logoutClicked // ========== 主题初始化(最早执行) ========== onInitTheme: { console.log("onInitTheme") // 1. 先读取保存的主题,再设置任何颜色 var savedMode = "day" try { savedMode = settings.getValue("theme_mode") if (savedMode === undefined || savedMode === "" || savedMode === null) { savedMode = "day" settings.setValue("theme_mode", "day") } } catch(e) { savedMode = "day" } app.theme_md = savedMode if (savedMode !== "auto") { app.theme_select = savedMode } else { var h = new Date().getHours() app.theme_select = (h >= 6 && h <= 18) ? "day" : "night" } // 2. 根据主题设置颜色(此时颜色属性会自动更新) // 无需手动赋值,绑定表达式会自动计算 // 3. 设置Felgo主题 Theme.platform = "ios" // TabBar样式 Theme.navigationTabBar.titlePressedColor = "green" Theme.navigationTabBar.backgroundColor = app.cardColor Theme.navigationTabBar.titleColor = app.fontColor // NavigationBar样式 Theme.navigationBar.backgroundColor = app.cardColor Theme.navigationBar.titleColor = app.fontColor if (!Theme.navigationBar.height) { Theme.navigationBar.height = dp(56) } if (!Theme.statusBarHeight) { Theme.statusBarHeight = dp(24) } // 4. 标记主题就绪 themeReady = true } // 新增一个函数来接收 HomePage 发送的文本 function bvReceived(datbv){ boardversionText = datbv } function appReceived(datbv){ appversionText = datbv } onLogoutClicked: { logic.logout() // jump to main page after logout navigation.currentIndex = 0 //navigation.currentNavigationItem.navigationStack.popAllExceptFirst() } //business logic} Logic { id: logic } // model DataModel { id: dataModel dispatcher: logic // data model handles actions sent by logic } // view Navigation { objectName: "Navigation_main" id: navigation enabled: themeReady navigationMode: Theme.isAndroid ? navigationModeTabs : navigationModeDefault drawerLogoBackgroundColor: "red" opacity: themeReady ? 1.0 : 0.0 Behavior on opacity { NumberAnimation { duration: 200 } } Component.onCompleted: { console.log("Navigation Component.onCompleted") initializeNavigation() } function initializeNavigation() { console.log("Initializing navigation...") for(var i = 0;i < navigation.count; i++){ navigation.currentIndex = i } navigation.currentIndex = 0 } function setCurrentTab(index){ navigation.currentIndex = index } // only enable if user is logged in // login page below overlays navigation then // first tab NavigationItem { id: uiComponentsItem title: "主界面" iconType: IconType.home Loader{ asynchronous: true active: true source: "pages/HomePage.qml" } } NavigationItem { title: "测试维护" iconType: IconType.gears objectName: "autofocus_Item" TestPage { //id: autofocus_id } } // second tab NavigationItem { title: qsTr("图像查看") // use qsTr for strings you want to translate iconType: IconType.qrcode NavigationStack { PhotostitcherPage { onVisibleChanged: { if(visible){ console.log("进入图像查看界面,开始初始化加载...") loadRootDirectory() } } } } } // fourth tab NavigationItem { objectName: "systemset_Item" title: qsTr("系统设置") // use qsTr for strings you want to translate iconType: IconType.gears NavigationStack { initialPage: ProfilePage { id: page_sys onThemChange: { console.log("配置主题模式:",mode) app.theme_md = mode if (mode !== "auto") { app.theme_select = mode } else { var h = new Date().getHours() app.theme_select = (h >= 6 && h <= 18) ? "day" : "night" } app.theme_select = mode app.theme_md = mode Theme.navigationTabBar.backgroundColor= app.cardColor Theme.navigationTabBar.titleColor = app.fontColor Theme.navigationTabBar.dividerColor = "green" console.log("主题已更新:",app.theme_select) } // handle logout onLogoutClicked: { //loginpage.pushed() logic.logout() // jump to main page after logout navigation.currentIndex = 0 serial.setLightness(-255) //navigation.currentNavigationItem.navigationStack.popAllExceptFirst() } } } } tabPosition: Navigation.Left } // ========== 业务定时器 ========== Timer{ interval: 1000 running: true repeat: true onTriggered: { if(navigation.currentIndex === 0&&loginpage.logintimeout%5===0){ serial.readBoardData() } loginpage.logintimeout-- ProfilePage.boardversion = "123" console.log("休眠计数:",loginpage.logintimeout) if(loginpage.logintimeout===0){ //?秒后进入休眠 loginpage.logintimeout = 300 logoutClicked() //关闭屏幕(亮度设置为0) serial.setLightness(-255) } } } Connections{ target: curl function onDownloadFinished(result) { if(result){ navigation.setCurrentTab(1) } } } // 远程校准指令: {"cmd":"slide","ext":{"calibrate":"y","speed":"50"}} → 跳转相机界面(Tab 1 测试维护) Connections { target: mqtt function onSignal_open_camera() { console.log("[Main] 收到远程相机开启指令,跳转相机界面!") navigation.setCurrentTab(1) } } // ========== 全局融合进度弹窗 ========== property bool isGlobalFusing: false property string globalFusionMessage: "" property int globalFusionPercent: 0 Connections { target: opencvFunc function onFusionProgress(message, percent) { console.log("[Main] 融合进度:", message, percent + "%") if (percent >= 100) { // 完成后延迟关闭弹窗,让用户看到完成状态 globalFusionMessage = message globalFusionPercent = percent Qt.callLater(function() { isGlobalFusing = false }) } else { isGlobalFusing = true globalFusionMessage = message globalFusionPercent = percent } } function onFuseFinished(resultPath) { isGlobalFusing = false console.log("[Main] 融合结束:", resultPath) } } Popup { id: globalFusionPopup anchors.centerIn: parent width: Math.min(parent.width * 0.8, 360) modal: true focus: true closePolicy: Popup.NoAutoClose visible: isGlobalFusing padding: 20 z: 99999 background: Rectangle { color: "white" radius: 8 border.color: "#28a779" border.width: 2 } contentItem: ColumnLayout { spacing: 16 Text { Layout.fillWidth: true text: "图像融合中" font.pixelSize: 18 font.bold: true color: "#28a779" horizontalAlignment: Text.AlignHCenter } BusyIndicator { Layout.alignment: Qt.AlignHCenter running: globalFusionPopup.visible width: 48 height: 48 } Text { Layout.fillWidth: true text: globalFusionMessage font.pixelSize: 14 color: "#333" horizontalAlignment: Text.AlignHCenter wrapMode: Text.WordWrap } ProgressBar { id: globalFusionProgressBar Layout.fillWidth: true from: 0 to: 100 value: globalFusionPercent background: Rectangle { implicitHeight: 8 color: "#eee" radius: 4 } contentItem: Item { implicitHeight: 8 Rectangle { width: globalFusionProgressBar.visualPosition * parent.width height: parent.height radius: 4 color: "#28a779" } } } Text { Layout.fillWidth: true text: globalFusionPercent.toFixed(0) + "%" font.pixelSize: 12 color: "#666" horizontalAlignment: Text.AlignHCenter } } } Component.onCompleted: { console.log("App Component.onCompleted, starting phased loading...") } LocalNotificationPage { id: notificationPage visible:false } // ========== 登录页(Phase2: 导航加载完成后才加载) ========== LoginPage { id: loginpage title: "植物病菌孢子捕捉分析系统" Connections{ target: serial } visible: opacity > 0 enabled: visible opacity: dataModel.userLoggedIn ? 0 : 1 Behavior on opacity { NumberAnimation { duration: 250 } } // page fade in/out } Rectangle { id: rxFloatingWindow visible: floatPanel width: 400 height: 300 x: parent.width - 420 y: 20 color: "white" opacity: 0.8 // 50% 透明度 radius: 10 z: 9999 Column { anchors.fill: parent anchors.margins: 10 spacing: 5 Row { width: parent.width spacing: 10 AppText { text: floatPanel_title color: "#00ffff" fontSize: 16 font.bold: true anchors.verticalCenter: appbutton_clear.verticalCenter } AppButton { id: appbutton_clear text: "清空" textColor: "white" backgroundColor: "#ff4444" flat: false onClicked: { rxDataLog = "" txDataLog = "" } } // AppButton { // text: "X" // textColor: "white" // backgroundColor: "#ff4444" // flat: false // onClicked: { // rxSwitch.checked = false // } // } } Flickable { width: parent.width height: parent.height - 40 contentWidth: width contentHeight: txt_logdata.implicitHeight clip: true AppText { id: txt_logdata width: parent.width text: (showRxData ? rxDataLog : (showTxData ? txDataLog : "")) || (showSubData ? rxDataLog : (showPubData ? txDataLog : "")) color: "green" fontSize: 12 wrapMode: Text.WrapAtWordBoundaryOrAnywhere } } } // 拖拽功能 MouseArea { anchors.fill: parent drag.target: rxFloatingWindow drag.axis: Drag.XAndYAxis } } }