LocalNotificationPage.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. Timer {
  12. id: autoCloseTimer
  13. interval: 5000
  14. onTriggered: notificationPage.visible = false
  15. }
  16. Connections{
  17. target: serial
  18. function onYmodemReady(mtype) {
  19. progressBar.value = 0.0
  20. notificationtext.text = mtype
  21. notificationPage.visible = true
  22. }
  23. function onYmodemProgress(val,tval) {
  24. //console.log("更新进度条:",val,tval)
  25. var percent = Number(val) / Number(tval) * 100.0
  26. percent = Math.min(percent,100)
  27. console.log("更新进度:",percent)
  28. progressBar.value = percent
  29. process_text.text = percent.toFixed(2) + "%"
  30. }
  31. function onYmodemFinished(r) {
  32. if(r===0){
  33. progressBar.value = 100.0
  34. notificationtext.text += "成功"
  35. autoCloseTimer.restart()
  36. }else{
  37. notificationtext.text += "失败:" + r.toString();
  38. }
  39. }
  40. }
  41. Connections{
  42. target: curl
  43. function onSglProgress(val,timeLeft,speed) {
  44. console.log("更新curl进度条:",val,timeLeft)
  45. progressBar.value = val
  46. process_text.text = val.toFixed(2) + "%";
  47. }
  48. function onDownloadStart(mtype) {
  49. notificationtext.text = mtype
  50. notificationPage.visible = true
  51. }
  52. function onDownloadFinished(result){
  53. //notificationPage.visible = false
  54. if(result){
  55. notificationtext.text += "成功"
  56. notificationtext.color = "green"
  57. }else{
  58. notificationtext.text += "失败"
  59. notificationtext.color = "red"
  60. }
  61. }
  62. }
  63. Connections{
  64. target:curl_picture
  65. function onProgressChanged(uploadedPercent){
  66. console.log("更新进度条:",uploadedPercent)
  67. progressBar.value = uploadedPercent
  68. process_text.text = uploadedPercent.toFixed(2) + "%";
  69. }
  70. function onDownloadStart(tips){
  71. notificationPage.visible = true
  72. notificationtext.text = tips
  73. }
  74. function onFinished(success,error){
  75. //notificationPage.visible = false
  76. if(success){
  77. notificationtext.color = "green"
  78. //延迟5S后关闭弹窗
  79. autoCloseTimer.restart()
  80. }else{
  81. notificationtext.text = error
  82. notificationtext.color = "red"
  83. }
  84. }
  85. }
  86. // login form background
  87. Rectangle {
  88. id: loginForm
  89. anchors.centerIn: parent
  90. color: "white"
  91. width: content.width + dp(48)
  92. height: content.height + dp(16)
  93. radius: dp(4)
  94. }
  95. // login form content
  96. GridLayout {
  97. id: content
  98. anchors.centerIn: loginForm
  99. columnSpacing: dp(20)
  100. rowSpacing: dp(10)
  101. columns: 2
  102. width: Math.min(parent.width * 0.9, dp(400)) // 限制最大宽度
  103. // headline
  104. AppText {
  105. id: notificationtext
  106. Layout.topMargin: dp(8)
  107. Layout.bottomMargin: dp(12)
  108. Layout.columnSpan: 2
  109. Layout.alignment: Qt.AlignHCenter
  110. text: "通知"
  111. Layout.preferredWidth: parent.width * 0.8 // 设置最大宽度
  112. Layout.maximumWidth: dp(300) // 限制最大宽度
  113. wrapMode: Text.Wrap // 关键换行属性
  114. horizontalAlignment: Text.AlignHCenter // 保持居中
  115. height: implicitHeight // 自动高度
  116. }
  117. AppText {
  118. id: process_text
  119. Layout.bottomMargin: dp(5)
  120. Layout.columnSpan: 2
  121. Layout.alignment: Qt.AlignHCenter
  122. text: ""
  123. }
  124. // 进度条行(占满第一列)
  125. ProgressBar {
  126. id: progressBar
  127. Layout.fillWidth: true // 关键属性:填充可用宽度
  128. Layout.columnSpan: 1 // 占第一列
  129. from: 0.0000
  130. to: 100.0000
  131. value: 0.0
  132. // 根据父布局动态计算宽度
  133. //implicitWidth: content.width - closeButton.width - content.columnSpacing
  134. }
  135. // 按钮行(第二列)
  136. AppButton {
  137. id: closeButton
  138. Layout.columnSpan: 1 // 占第二列
  139. Layout.alignment: Qt.AlignRight
  140. text: qsTr("关闭")
  141. flat: false
  142. // 固定按钮宽度
  143. implicitWidth: dp(80)
  144. onClicked: {
  145. progressBar.value = 0.0;
  146. notificationPage.visible = false;
  147. }
  148. }
  149. }
  150. }