| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563 |
- import QtQuick
- 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样式:统一由 applyNavTabStyle() 设置(与 32 位工程 app_bzy_armhf_7 保持一致),
- // 避免主题切换时这里和 ProfilePage 各写一套、样式互相覆盖
- applyNavTabStyle()
- // 先按横排给个默认厚度,Navigation 起来后再用真实几何复算
- applyNavTabMetrics(0, 0)
- // 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
- }
- // ========== 导航项(tab)样式:唯一的样式出口 ==========
- // 目标:把 tab 从"小图标+小字"改成"明确的按钮/页面切换器":
- // ① 不显示图标(iconSize=0 与 showIcon=false 双保险),只留文字,字号加大;
- // ② 提高 tab 条高度/宽度,文字与边缘留出呼吸感,看起来像一排按钮;
- // ③ 三个状态给出不同颜色:选中(主题绿) / 未选中(弱化灰) / 按下·悬停(亮绿);
- // ④ 颜色全部跟随 app.theme_select,日间/夜间以及运行时切换主题都保持一致。
- function applyNavTabStyle() {
- Theme.navigationTabBar.textSize = Theme.isAndroid ? 18 : 17
- Theme.navigationTabBar.iconSize = 0 // 兜底:即使某处仍画图标也看不见
- // 【关键】Felgo 的 tab 栏从这里开始"隐身":底色和分隔线一律透明,
- // 只保留它的占位(内容区高度、tabPosition、页面切换机制都不变)。
- // 可见部分由下面的 navBarOverlay 自绘 —— 真机上验证:叠加在 tab 栏上的轮廓层不显示、
- // dividerColor 也不画竖线(Felgo 的 TabBar 根本不画分隔线),
- // 与其继续和 C++ 绘制的 tab 栏较劲,不如让它彻底透明、外观全部自己画。
- Theme.navigationTabBar.backgroundColor = "transparent"
- Theme.navigationTabBar.dividerColor = "transparent"
- // 文字颜色仍然保留(不设透明):这一层是"兜底"——
- // 万一 navBarOverlay 因任何原因没显示,导航项至少还有可读文字和选中状态,
- // 不会出现"底部一片空白、点了也不知道在哪一页"。
- // 叠加层正常显示时,它的不透明底色会把这里的文字完全盖住,不会重影。
- Theme.navigationTabBar.titleColor = app.theme_select === "day" ? "#2e7d32" : "#81c784"
- Theme.navigationTabBar.titleOffColor = app.theme_select === "day" ? "#757575" : "#9e9e9e"
- Theme.navigationTabBar.titlePressedColor = "#4caf50"
- Theme.navigationTabBar.titleDisabledColor = app.theme_select === "day" ? "#c0c0c0" : "#5a5a5a"
- Theme.navigationTabBar.showOnlySelectedLabel = false
- }
- // tab 条"厚度":这个字段在横排时是高度、竖排时是宽度,靠 tabPosition 判断不可靠
- // (两个工程都写 Navigation.Left,实际 Felgo 渲染在底部),所以用 tabBar 的真实几何:
- // width > height 即横排 → 给 52/56 的按钮高度;否则按竖排宽度给 96,保证四字标题不被截断。
- function applyNavTabMetrics(barW, barH) {
- var horizontal = (barW > 0 && barH > 0) ? (barW > barH) : true
- Theme.navigationTabBar.height = horizontal
- ? dp(Theme.isAndroid ? 56 : 52)
- : dp(96)
- }
- // 新增一个函数来接收 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 } }
- // ---- 导航项改为"纯文字按钮"----
- // showIcon: false 是 Felgo TabControl 的开关,关掉后 tab 只留文字(图标不再占位置);
- // textFont 让文字加粗、字号与 Theme.navigationTabBar.textSize 一致,按钮感更强。
- tabs.showIcon: false
- tabs.textFont: Qt.font({ pixelSize: Theme.isAndroid ? 18 : 17, bold: true })
- Component.onCompleted: {
- console.log("Navigation Component.onCompleted")
- // tabBar 已经建出来了,用它的真实宽高判断横排/竖排,再决定 tab 条厚度:
- // 靠 tabPosition 猜(写的是 Navigation.Left,实际渲染在底部)会把"宽度"当"高度"用,
- // 导致底部导航条被撑到 96px 高。
- var tb = tabs ? tabs.tabBar : null
- applyNavTabMetrics(tb ? tb.width : 0, tb ? tb.height : 0)
- applyNavTabStyle()
- 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: function(mode) { 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
- // 主题切换后重新套用导航项样式:以前这里只改 3 个颜色、
- // 还把分隔线设成绿色,会把上面的大小/三态/无图标样式覆盖掉。
- app.applyNavTabStyle()
- 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
- }
- // ================= 自绘底部导航条(取代 Felgo tab 栏的可见部分)=================
- // 为什么不用 Felgo 的 tab 栏画轮廓:
- // 多次实测在真机上叠加层始终不可见(tabBar alias 取不到 → 绑定失效;
- // Theme 读回 0 → 高度为 0;层级被 Felgo 压住),而 dividerColor 也不画竖线。
- // 与其继续和 C++ 绘制的 tab 栏较劲,不如让它"隐身占位",外观与点击全部自己画:
- // · Felgo tab 栏仍在(保证内容区高度、页面切换机制不变),但背景/文字/分隔线全部透明;
- // · 这一层叠在它正上方(同一位置、同一高度),画 4 个带边框的按钮 + 文字 + 点击。
- // 这样不依赖 mapToItem、不依赖 Theme 读回值,任何 Felgo 版本/设备上都一定看得见。
- Item {
- id: navBarOverlay
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.bottom: parent.bottom
- // 高度与 Felgo tab 栏一致;读不到就兜 dp(52)(横排默认厚度)
- height: (typeof Theme.navigationTabBar.height !== "undefined"
- && Theme.navigationTabBar.height > 0)
- ? Theme.navigationTabBar.height : dp(52)
- z: 1000
- // 未登录(锁屏/休眠)时导航条一并隐藏:
- // 锁屏页本身 z 更高已能盖住它,但隐藏后不会在锁屏淡出瞬间露出可点击的按钮,
- // 也省掉一层不必要的绘制。
- visible: navigation.count > 0 && dataModel.userLoggedIn
- // 标题必须与上面 NavigationItem 的 title 一一对应(改动时两处一起改)
- readonly property var titles: ["主界面", "测试维护", "图像查看", "系统设置"]
- readonly property int itemCount: Math.min(titles.length, navigation.count)
- readonly property int curIndex: Math.max(0, Math.min(navigation.currentIndex, itemCount - 1))
- readonly property bool isDay: app.theme_select === "day"
- readonly property color accent: isDay ? "#2e7d32" : "#81c784"
- readonly property color offText: isDay ? "#5f6368" : "#9e9e9e"
- readonly property color frameColor: isDay ? "#38000000" : "#38ffffff"
- // 底色:浅绿/深蓝灰,与页面内容拉开色相差(原来和页面同色,看不出导航条)
- Rectangle {
- anchors.fill: parent
- color: navBarOverlay.isDay ? "#e8f5e9" : "#263238"
- }
- // 与内容区的边界线
- Rectangle {
- width: parent.width
- height: dp(1)
- anchors.top: parent.top
- color: navBarOverlay.isDay ? "#40000000" : "#40ffffff"
- }
- Row {
- anchors.fill: parent
- Repeater {
- model: navBarOverlay.itemCount
- Item {
- id: navBtn
- readonly property bool active: index === navBarOverlay.curIndex
- width: navBarOverlay.width / Math.max(1, navBarOverlay.itemCount)
- height: navBarOverlay.height
- // 按钮轮廓:选中绿框+浅填充,未选中淡灰框 —— 每个 tab 都是独立按钮
- Rectangle {
- anchors.fill: parent
- anchors.margins: dp(5)
- radius: dp(6)
- color: navBtn.active
- ? (navBarOverlay.isDay ? "#1a2e7d32" : "#2e81c784")
- : "transparent"
- border.width: navBtn.active ? dp(1.5) : dp(1)
- border.color: navBtn.active ? navBarOverlay.accent
- : navBarOverlay.frameColor
- }
- Text {
- anchors.centerIn: parent
- text: navBarOverlay.titles[index]
- color: navBtn.active ? navBarOverlay.accent : navBarOverlay.offText
- font.pixelSize: Theme.isAndroid ? 18 : 17
- font.bold: navBtn.active
- }
- MouseArea {
- anchors.fill: parent
- // 直接切 currentIndex:Felgo 的页面切换、NavigationStack 行为都不变
- onClicked: navigation.currentIndex = index
- }
- }
- }
- }
- }
- // ========== 业务定时器 ==========
- 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)
- }
- }
- Component.onCompleted: {
- console.log("App Component.onCompleted, starting phased loading...")
- }
- LocalNotificationPage {
- id: notificationPage
- visible:false
- }
- // ========== 登录页(Phase2: 导航加载完成后才加载) ==========
- LoginPage {
- id: loginpage
- title: "植物病菌孢子捕捉分析系统"
- Connections{
- target: serial
- }
- // 锁屏必须盖住自绘导航条(navBarOverlay 是 z:1000 的兄弟节点)。
- // 这里给 2000:高于导航条、低于串口调试浮窗(rxFloatingWindow, z:9999)。
- z: 2000
- visible: opacity > 0
- enabled: visible
- opacity: dataModel.userLoggedIn ? 0 : 1
- Behavior on opacity { NumberAnimation { duration: 250 } } // page fade in/out
- }
- // ========== 启动过渡(纯色底 + "启动中...") ==========
- // 只在"Qt 已起来、锁屏页还没画完"的那一小段显示,提示文字为"启动中..."。
- // 退出条件收紧:只等 themeReady(onInitTheme 在 App 创建时同步执行完,通常几十毫秒),
- // 最短 500ms 防止一闪而过,1.5 秒硬兜底 —— 不会再像上一版那样顶到 6 秒把锁屏页挡住。
- // 用 100ms 轮询 + 一次性淡出动画,而不是给 opacity 绑 Behavior:
- // 后者淡出结束后绑定会重新算出 1,出现"淡出后又闪回"。
- property bool splashMinElapsed: false
- property bool splashForceDone: false
- property bool splashFinished: false
- Timer {
- interval: 500
- running: true
- onTriggered: app.splashMinElapsed = true
- }
- Timer {
- interval: 1500
- running: true
- onTriggered: app.splashForceDone = true
- }
- Timer {
- interval: 100
- running: !app.splashFinished
- repeat: true
- onTriggered: {
- var ready = app.splashForceDone || (app.splashMinElapsed && app.themeReady)
- if (ready) {
- running = false
- app.splashFinished = true
- splashFadeOut.start()
- }
- }
- }
- StartupSplash {
- id: splashScreen
- anchors.fill: parent
- z: 3000
- night: app.theme_select === "night"
- versionText: app.appversionText
- }
- NumberAnimation {
- id: splashFadeOut
- target: splashScreen
- property: "opacity"
- to: 0
- duration: 250
- easing.type: Easing.OutCubic
- onFinished: splashScreen.visible = false
- }
- 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
- }
- }
- }
|