LocalNotificationPage.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import Felgo
  2. import QtQuick
  3. import QtQuick.Layouts
  4. import QtQuick.Controls
  5. import "../controls"
  6. import "../common"
  7. AppPage {
  8. id: notificationPage
  9. backgroundColor: Qt.rgba(0,0,0, 0.75) // page background is translucent, we can see other items beneath the page
  10. useSafeArea: false // do not consider safe area insets of screen
  11. Connections{
  12. target: serial
  13. function onYmodemReady(mtype) {
  14. progressBar.value = 0.0
  15. notificationtext.text = mtype
  16. notificationPage.visible = true
  17. }
  18. function onYmodemProgress(val,tval) {
  19. //console.log("更新进度条:",val,tval)
  20. var percent = Number(val) / Number(tval) * 100.0
  21. percent = Math.min(percent,100)
  22. console.log("更新进度:",percent)
  23. progressBar.value = percent
  24. process_text.text = percent.toFixed(2) + "%"
  25. }
  26. function onYmodemFinished(r) {
  27. if(r===0){
  28. progressBar.value = 100.0
  29. notificationtext.text += "成功"
  30. }else{
  31. notificationtext.text += "失败:" + r.toString();
  32. }
  33. }
  34. }
  35. Connections{
  36. target:curl
  37. function onSglProgress(val,timeLeft,speed) {
  38. console.log("更新curl进度条:",val,timeLeft)
  39. progressBar.value = val
  40. process_text.text = val.toFixed(2) + "%";
  41. }
  42. function onDownloadStart(mtype) {
  43. notificationtext.text = mtype
  44. notificationPage.visible = true
  45. }
  46. function onDownloadFinished(result){
  47. //notificationPage.visible = false
  48. if(result){
  49. notificationtext.text += "成功"
  50. notificationtext.color = "green"
  51. }else{
  52. notificationtext.text += "失败"
  53. notificationtext.color = "red"
  54. }
  55. }
  56. }
  57. // 图片上传进度已改为 TestPage 右上角 32 格进度网格展示, 不再弹出上传进度窗口
  58. Connections{
  59. target:curl_picture
  60. function onProgressChanged(uploadedPercent){ }
  61. function onDownloadStart(tips){ }
  62. function onFinished(success,error){ }
  63. }
  64. // login form background
  65. Rectangle {
  66. id: loginForm
  67. anchors.centerIn: parent
  68. color: "white"
  69. width: content.width + dp(48)
  70. height: content.height + dp(16)
  71. radius: dp(4)
  72. }
  73. // login form content
  74. GridLayout {
  75. id: content
  76. anchors.centerIn: loginForm
  77. columnSpacing: dp(20)
  78. rowSpacing: dp(10)
  79. columns: 2
  80. width: Math.min(parent.width * 0.9, dp(400)) // 限制最大宽度
  81. // headline
  82. AppText {
  83. id: notificationtext
  84. Layout.topMargin: dp(8)
  85. Layout.bottomMargin: dp(12)
  86. Layout.columnSpan: 2
  87. Layout.alignment: Qt.AlignHCenter
  88. text: "通知"
  89. Layout.preferredWidth: parent.width * 0.8 // 设置最大宽度
  90. Layout.maximumWidth: dp(300) // 限制最大宽度
  91. wrapMode: Text.Wrap // 关键换行属性
  92. horizontalAlignment: Text.AlignHCenter // 保持居中
  93. height: implicitHeight // 自动高度
  94. }
  95. AppText {
  96. id: process_text
  97. Layout.bottomMargin: dp(5)
  98. Layout.columnSpan: 2
  99. Layout.alignment: Qt.AlignHCenter
  100. text: ""
  101. }
  102. // 进度条行(占满第一列)
  103. ProgressBar {
  104. id: progressBar
  105. Layout.fillWidth: true // 关键属性:填充可用宽度
  106. Layout.columnSpan: 1 // 占第一列
  107. from: 0.0000
  108. to: 100.0000
  109. value: 0.0
  110. // 根据父布局动态计算宽度
  111. //implicitWidth: content.width - closeButton.width - content.columnSpacing
  112. }
  113. // 按钮行(第二列)
  114. AppButton {
  115. id: closeButton
  116. Layout.columnSpan: 1 // 占第二列
  117. Layout.alignment: Qt.AlignRight
  118. text: qsTr("关闭")
  119. flat: false
  120. // 固定按钮宽度
  121. implicitWidth: dp(80)
  122. onClicked: {
  123. progressBar.value = 0.0;
  124. notificationPage.visible = false;
  125. }
  126. }
  127. }
  128. }