DelayButton.qml 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.impl
  7. import QtQuick.Controls.Fusion
  8. import QtQuick.Controls.Fusion.impl
  9. T.DelayButton {
  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. padding: 6
  16. transition: Transition {
  17. NumberAnimation {
  18. duration: control.delay * (control.pressed ? 1.0 - control.progress : 0.3 * control.progress)
  19. }
  20. }
  21. contentItem: ItemGroup {
  22. ClippedText {
  23. clip: control.progress > 0
  24. clipX: -control.leftPadding + (control.mirrored ? 0 : control.progress * control.width)
  25. clipWidth: control.width
  26. visible: control.mirrored ? control.progress > 0 : control.progress < 1
  27. text: control.text
  28. font: control.font
  29. color: control.mirrored ? control.palette.brightText : control.palette.buttonText
  30. horizontalAlignment: Text.AlignHCenter
  31. verticalAlignment: Text.AlignVCenter
  32. elide: Text.ElideRight
  33. }
  34. ClippedText {
  35. clip: control.progress > 0
  36. clipX: -control.leftPadding
  37. clipWidth: (control.mirrored ? 1.0 - control.progress : control.progress) * control.width
  38. visible: control.mirrored ? control.progress < 1 : control.progress > 0
  39. text: control.text
  40. font: control.font
  41. color: control.mirrored ? control.palette.buttonText : control.palette.brightText
  42. horizontalAlignment: Text.AlignHCenter
  43. verticalAlignment: Text.AlignVCenter
  44. elide: Text.ElideRight
  45. }
  46. }
  47. background: ButtonPanel {
  48. implicitWidth: 80
  49. implicitHeight: 24
  50. control: control
  51. highlighted: false
  52. scale: control.mirrored ? -1 : 1
  53. Rectangle {
  54. width: control.progress * parent.width
  55. height: parent.height
  56. radius: 2
  57. border.color: Qt.darker(Fusion.highlight(control.palette), 1.4)
  58. gradient: Gradient {
  59. GradientStop {
  60. position: 0
  61. color: Qt.lighter(Fusion.highlight(control.palette), 1.2)
  62. }
  63. GradientStop {
  64. position: 1
  65. color: Fusion.highlight(control.palette)
  66. }
  67. }
  68. }
  69. }
  70. }