SpinBox.qml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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.SpinBox {
  10. id: control
  11. // Note: the width of the indicators are calculated into the padding
  12. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  13. contentItem.implicitWidth + leftPadding + rightPadding)
  14. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  15. implicitContentHeight + topPadding + bottomPadding,
  16. up.implicitIndicatorHeight + down.implicitIndicatorHeight)
  17. padding: 4
  18. leftPadding: padding + (control.mirrored ? (up.indicator ? up.indicator.width : 0) : 0)
  19. rightPadding: padding + (!control.mirrored ? (up.indicator ? up.indicator.width : 0) : 0)
  20. validator: IntValidator {
  21. locale: control.locale.name
  22. bottom: Math.min(control.from, control.to)
  23. top: Math.max(control.from, control.to)
  24. }
  25. contentItem: TextInput {
  26. z: 2
  27. text: control.displayText
  28. font: control.font
  29. color: control.palette.text
  30. selectionColor: control.palette.highlight
  31. selectedTextColor: control.palette.highlightedText
  32. horizontalAlignment: Qt.AlignHCenter
  33. verticalAlignment: Qt.AlignVCenter
  34. readOnly: !control.editable
  35. validator: control.validator
  36. inputMethodHints: control.inputMethodHints
  37. clip: width < implicitWidth
  38. }
  39. up.indicator: PaddedRectangle {
  40. x: control.mirrored ? 1 : control.width - width - 1
  41. y: 1
  42. height: control.height / 2 - 1
  43. implicitWidth: 16
  44. implicitHeight: 10
  45. radius: 1.7
  46. clip: true
  47. topPadding: -2
  48. leftPadding: -2
  49. color: control.up.pressed ? Fusion.buttonColor(control.palette, false, true, true) : "transparent"
  50. ColorImage {
  51. scale: -1
  52. width: parent.width
  53. height: parent.height
  54. opacity: enabled ? 1.0 : 0.5
  55. color: control.palette.buttonText
  56. source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/arrow.png"
  57. fillMode: Image.Pad
  58. }
  59. }
  60. down.indicator: PaddedRectangle {
  61. x: control.mirrored ? 1 : control.width - width - 1
  62. y: control.height - height - 1
  63. height: control.height / 2 - 1
  64. implicitWidth: 16
  65. implicitHeight: 10
  66. radius: 1.7
  67. clip: true
  68. topPadding: -2
  69. leftPadding: -2
  70. color: control.down.pressed ? Fusion.buttonColor(control.palette, false, true, true) : "transparent"
  71. ColorImage {
  72. width: parent.width
  73. height: parent.height
  74. opacity: enabled ? 1.0 : 0.5
  75. color: control.palette.buttonText
  76. source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/arrow.png"
  77. fillMode: Image.Pad
  78. }
  79. }
  80. background: Rectangle {
  81. implicitWidth: 120
  82. implicitHeight: 24
  83. radius: 2
  84. color: control.palette.base
  85. border.color: control.activeFocus ? Fusion.highlightedOutline(control.palette) : Fusion.outline(control.palette)
  86. Rectangle {
  87. x: 2
  88. y: 1
  89. width: parent.width - 4
  90. height: 1
  91. color: Fusion.topShadow
  92. }
  93. Rectangle {
  94. x: control.mirrored ? 1 : parent.width - width - 1
  95. y: 1
  96. width: Math.max(control.up.indicator ? control.up.indicator.width : 0,
  97. control.down.indicator ? control.down.indicator.width : 0) + 1
  98. height: parent.height - 2
  99. radius: 2
  100. gradient: Gradient {
  101. GradientStop {
  102. position: 0
  103. color: Fusion.gradientStart(Fusion.buttonColor(control.palette, control.visualFocus, false, control.up.hovered || control.down.hovered))
  104. }
  105. GradientStop {
  106. position: 1
  107. color: Fusion.gradientStop(Fusion.buttonColor(control.palette, control.visualFocus, false, control.up.hovered || control.down.hovered))
  108. }
  109. }
  110. Rectangle {
  111. x: control.mirrored ? parent.width - 1 : 0
  112. height: parent.height
  113. width: 1
  114. color: Fusion.outline(control.palette)
  115. }
  116. }
  117. Rectangle {
  118. x: 1; y: 1
  119. width: parent.width - 2
  120. height: parent.height - 2
  121. color: "transparent"
  122. border.color: Color.transparent(Fusion.highlightedOutline(control.palette), 40 / 255)
  123. visible: control.activeFocus
  124. radius: 1.7
  125. }
  126. }
  127. }