LocalNotificationPage.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. Connections{
  58. target:curl_picture
  59. function onProgressChanged(uploadedPercent){
  60. console.log("更新进度条:",uploadedPercent)
  61. progressBar.value = uploadedPercent
  62. process_text.text = uploadedPercent.toFixed(2) + "%";
  63. }
  64. function onDownloadStart(tips){
  65. notificationPage.visible = true
  66. notificationtext.text = tips
  67. }
  68. function onFinished(success,error){
  69. //notificationPage.visible = false
  70. if(success){
  71. notificationtext.color = "green"
  72. }else{
  73. notificationtext.text = error
  74. notificationtext.color = "red"
  75. }
  76. }
  77. }
  78. // login form background
  79. Rectangle {
  80. id: loginForm
  81. anchors.centerIn: parent
  82. color: "white"
  83. width: content.width + dp(48)
  84. height: content.height + dp(16)
  85. radius: dp(4)
  86. }
  87. // login form content
  88. GridLayout {
  89. id: content
  90. anchors.centerIn: loginForm
  91. columnSpacing: dp(20)
  92. rowSpacing: dp(10)
  93. columns: 2
  94. width: Math.min(parent.width * 0.9, dp(400)) // 限制最大宽度
  95. // headline
  96. AppText {
  97. id: notificationtext
  98. Layout.topMargin: dp(8)
  99. Layout.bottomMargin: dp(12)
  100. Layout.columnSpan: 2
  101. Layout.alignment: Qt.AlignHCenter
  102. text: "通知"
  103. Layout.preferredWidth: parent.width * 0.8 // 设置最大宽度
  104. Layout.maximumWidth: dp(300) // 限制最大宽度
  105. wrapMode: Text.Wrap // 关键换行属性
  106. horizontalAlignment: Text.AlignHCenter // 保持居中
  107. height: implicitHeight // 自动高度
  108. }
  109. AppText {
  110. id: process_text
  111. Layout.bottomMargin: dp(5)
  112. Layout.columnSpan: 2
  113. Layout.alignment: Qt.AlignHCenter
  114. text: ""
  115. }
  116. // 进度条行(占满第一列)
  117. ProgressBar {
  118. id: progressBar
  119. Layout.fillWidth: true // 关键属性:填充可用宽度
  120. Layout.columnSpan: 1 // 占第一列
  121. from: 0.0000
  122. to: 100.0000
  123. value: 0.0
  124. // 根据父布局动态计算宽度
  125. //implicitWidth: content.width - closeButton.width - content.columnSpacing
  126. }
  127. // 按钮行(第二列)
  128. AppButton {
  129. id: closeButton
  130. Layout.columnSpan: 1 // 占第二列
  131. Layout.alignment: Qt.AlignRight
  132. text: qsTr("关闭")
  133. flat: false
  134. // 固定按钮宽度
  135. implicitWidth: dp(80)
  136. onClicked: {
  137. progressBar.value = 0.0;
  138. notificationPage.visible = false;
  139. }
  140. }
  141. }
  142. }