DelayButton.qml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.DelayButton {
  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. transition: Transition {
  23. NumberAnimation {
  24. duration: control.delay * (control.pressed ? 1.0 - control.progress : 0.3 * control.progress)
  25. }
  26. }
  27. contentItem: Text {
  28. text: control.text
  29. font: control.font
  30. color: control.palette.buttonText
  31. horizontalAlignment: Text.AlignHCenter
  32. verticalAlignment: Text.AlignVCenter
  33. elide: Text.ElideRight
  34. }
  35. background: NinePatchImage {
  36. source: control.Imagine.url + "delaybutton-background"
  37. NinePatchImageSelector on source {
  38. states: [
  39. {"disabled": !control.enabled},
  40. {"pressed": control.down},
  41. {"checked": control.checked},
  42. {"focused": control.visualFocus},
  43. {"mirrored": control.mirrored},
  44. {"hovered": control.enabled && control.hovered}
  45. ]
  46. }
  47. readonly property NinePatchImage progress: NinePatchImage {
  48. parent: control.background
  49. width: control.progress * parent.width
  50. height: parent.height
  51. visible: false
  52. source: control.Imagine.url + "delaybutton-progress"
  53. NinePatchImageSelector on source {
  54. states: [
  55. {"disabled": !control.enabled},
  56. {"pressed": control.down},
  57. {"checked": control.checked},
  58. {"focused": control.visualFocus},
  59. {"mirrored": control.mirrored},
  60. {"hovered": control.enabled && control.hovered}
  61. ]
  62. }
  63. }
  64. readonly property NinePatchImage mask: NinePatchImage {
  65. width: control.background.width
  66. height: control.background.height
  67. visible: false
  68. source: control.Imagine.url + "delaybutton-mask"
  69. NinePatchImageSelector on source {
  70. states: [
  71. {"disabled": !control.enabled},
  72. {"pressed": control.down},
  73. {"checked": control.checked},
  74. {"focused": control.visualFocus},
  75. {"mirrored": control.mirrored},
  76. {"hovered": control.enabled && control.hovered}
  77. ]
  78. }
  79. }
  80. readonly property OpacityMask effect: OpacityMask {
  81. parent: control.background
  82. width: source.width
  83. height: source.height
  84. source: control.background.progress
  85. maskSource: ShaderEffectSource {
  86. sourceItem: control.background.mask
  87. sourceRect: Qt.rect(0, 0, control.background.effect.width, control.background.effect.height)
  88. }
  89. }
  90. }
  91. }