ProgressBar.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright (C) 2017 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.Templates as T
  6. import QtQuick.Controls.Imagine
  7. import QtQuick.Controls.Imagine.impl
  8. T.ProgressBar {
  9. id: control
  10. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  11. implicitContentWidth + leftPadding + rightPadding)
  12. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  13. implicitContentHeight + topPadding + bottomPadding)
  14. topPadding: background ? background.topPadding : 0
  15. leftPadding: background ? background.leftPadding : 0
  16. rightPadding: background ? background.rightPadding : 0
  17. bottomPadding: background ? background.bottomPadding : 0
  18. topInset: background ? -background.topInset || 0 : 0
  19. leftInset: background ? -background.leftInset || 0 : 0
  20. rightInset: background ? -background.rightInset || 0 : 0
  21. bottomInset: background ? -background.bottomInset || 0 : 0
  22. contentItem: Item {
  23. implicitWidth: control.indeterminate ? animation.implicitWidth || progress.implicitWidth : progress.implicitWidth
  24. implicitHeight: control.indeterminate ? animation.implicitHeight || progress.implicitHeight : progress.implicitHeight
  25. scale: control.mirrored ? -1 : 1
  26. readonly property bool hasMask: mask.status !== Image.Null
  27. readonly property NinePatchImage progress: NinePatchImage {
  28. parent: control.contentItem
  29. width: control.position * parent.width
  30. height: parent.height
  31. visible: !control.indeterminate && !control.contentItem.hasMask
  32. source: Imagine.url + "progressbar-progress"
  33. NinePatchImageSelector on source {
  34. states: [
  35. {"disabled": !control.enabled},
  36. {"indeterminate": control.indeterminate},
  37. {"mirrored": control.mirrored},
  38. {"hovered": control.enabled && control.hovered}
  39. ]
  40. }
  41. }
  42. readonly property AnimatedImage animation: AnimatedImage {
  43. parent: control.contentItem
  44. width: parent.width
  45. height: parent.height
  46. playing: control.indeterminate
  47. visible: control.indeterminate && !control.contentItem.hasMask
  48. source: Imagine.url + "progressbar-animation"
  49. AnimatedImageSelector on source {
  50. states: [
  51. {"disabled": !control.enabled},
  52. {"mirrored": control.mirrored},
  53. {"hovered": control.enabled && control.hovered}
  54. ]
  55. }
  56. }
  57. readonly property NinePatchImage mask: NinePatchImage {
  58. width: control.availableWidth
  59. height: control.availableHeight
  60. visible: false
  61. source: Imagine.url + "progressbar-mask"
  62. NinePatchImageSelector on source {
  63. states: [
  64. {"disabled": !control.enabled},
  65. {"indeterminate": control.indeterminate},
  66. {"mirrored": control.mirrored},
  67. {"hovered": control.enabled && control.hovered}
  68. ]
  69. }
  70. }
  71. readonly property OpacityMask effect: OpacityMask {
  72. parent: control.contentItem
  73. width: source.width
  74. height: source.height
  75. source: control.indeterminate ? control.contentItem.animation : control.contentItem.progress
  76. maskSource: ShaderEffectSource {
  77. sourceItem: control.contentItem.mask
  78. sourceRect: Qt.rect(0, 0, control.contentItem.effect.width, control.contentItem.effect.height)
  79. }
  80. }
  81. }
  82. background: NinePatchImage {
  83. source: Imagine.url + "progressbar-background"
  84. NinePatchImageSelector on source {
  85. states: [
  86. {"disabled": !control.enabled},
  87. {"indeterminate": control.indeterminate},
  88. {"mirrored": control.mirrored},
  89. {"hovered": control.enabled && control.hovered}
  90. ]
  91. }
  92. }
  93. }