LocalNotificationPage.qml 4.7 KB

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