ProgressBar.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright (C) 2024 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // Qt-Security score:significant reason:default
  4. import QtQuick
  5. import QtQuick.Controls.impl
  6. import QtQuick.Controls.FluentWinUI3.impl as Impl
  7. import QtQuick.Templates as T
  8. import QtQuick.Effects
  9. T.ProgressBar {
  10. id: control
  11. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  12. implicitContentWidth + leftPadding + rightPadding)
  13. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  14. implicitContentHeight + topPadding + bottomPadding)
  15. topPadding: __config.topPadding || 0
  16. bottomPadding: __config.bottomPadding || 0
  17. leftPadding: __config.leftPadding || 0
  18. rightPadding: __config.rightPadding || 0
  19. topInset: (__isHighContrast ? -1 : 0) - (__config.topInset || 0)
  20. bottomInset: (__isHighContrast ? -1 : 0) - (__config.bottomInset || 0)
  21. leftInset: (__isHighContrast ? -1 : 0) - (__config.leftInset || 0)
  22. rightInset: (__isHighContrast ? -1 : 0) - (__config.rightInset || 0)
  23. readonly property string __currentState: [
  24. !control.enabled && "disabled",
  25. control.indeterminate && "indeterminate"
  26. ].filter(Boolean).join("_") || "normal"
  27. readonly property var __config: Config.controls.progressbar[__currentState] || {}
  28. readonly property bool __isHighContrast: Application.styleHints.accessibility.contrastPreference === Qt.HighContrast
  29. contentItem: Item {
  30. implicitWidth: control.indeterminate ? parent.availableWidth : progress.implicitWidth
  31. implicitHeight: control.indeterminate ? control.__config.track.height : progress.implicitHeight
  32. scale: control.mirrored ? -1 : 1
  33. clip: control.indeterminate
  34. readonly property Rectangle progress: Rectangle {
  35. x: control.background.groove?.x - (control.__isHighContrast ? 0 : 1)
  36. y: control.background.groove?.y - (control.__isHighContrast ? 0 : 1)
  37. parent: control.contentItem
  38. visible: !control.indeterminate && control.value
  39. implicitWidth: control.__config.track.width
  40. implicitHeight: control.__config.track.height
  41. width: control.position * parent.width
  42. height: control.__config.track.height
  43. radius: control.__config.track.height * 0.5
  44. color: control.palette.accent
  45. }
  46. readonly property Rectangle animatedProgress: Rectangle {
  47. parent: control.contentItem
  48. implicitWidth: parent.width
  49. implicitHeight: control.__config.track.height
  50. radius: control.__config.track.height * 0.5
  51. clip: true
  52. visible: false
  53. color: "transparent"
  54. Rectangle {
  55. width: 0.5 * parent.width
  56. height: control.__config.track.height
  57. radius: control.__config.track.height * 0.5
  58. color: control.palette.accent
  59. SequentialAnimation on x {
  60. loops: Animation.Infinite
  61. running: control.indeterminate && control.visible
  62. NumberAnimation {
  63. from: -control.contentItem.animatedProgress.width
  64. to: control.contentItem.width
  65. easing.type: Easing.InOutCubic
  66. duration: control.width * 8
  67. }
  68. NumberAnimation {
  69. from: -control.contentItem.animatedProgress.width * 0.5
  70. to: control.contentItem.width
  71. easing.type: Easing.InOutCubic
  72. duration: control.width * 5
  73. }
  74. }
  75. }
  76. }
  77. readonly property Rectangle mask: Rectangle {
  78. parent: control.contentItem
  79. width: control.availableWidth
  80. height: control.contentItem.animatedProgress.height
  81. radius: control.contentItem.animatedProgress.radius
  82. visible: false
  83. color: control.palette.accent
  84. layer.enabled: true
  85. antialiasing: false
  86. }
  87. MultiEffect {
  88. visible: control.indeterminate
  89. source: control.contentItem.animatedProgress
  90. width: control.contentItem.animatedProgress.width
  91. height: control.contentItem.animatedProgress.height
  92. maskEnabled: true
  93. maskSource: control.contentItem.mask
  94. }
  95. }
  96. background: Rectangle {
  97. implicitWidth: groove.width
  98. radius: height * 0.5
  99. color: control.__isHighContrast ? control.palette.window : "transparent"
  100. border.color: control.__isHighContrast ? control.palette.text : "transparent"
  101. property Item groove: Impl.StyleImage {
  102. imageConfig: control.__config.groove
  103. visible: !control.indeterminate && !control.__isHighContrast
  104. parent: control.background
  105. height: implicitHeight
  106. width: parent.width
  107. }
  108. }
  109. }