SpinBox.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. ContextMenu.menu: TextEditingContextMenu {
  39. editor: parent
  40. }
  41. }
  42. up.indicator: PaddedRectangle {
  43. x: control.mirrored ? 1 : control.width - width - 1
  44. y: 1
  45. height: control.height / 2 - 1
  46. implicitWidth: 16
  47. implicitHeight: 10
  48. radius: 1.7
  49. clip: true
  50. topPadding: -2
  51. leftPadding: -2
  52. color: control.up.pressed ? Fusion.buttonColor(control.palette, false, true, true) : "transparent"
  53. ColorImage {
  54. scale: -1
  55. width: parent.width
  56. height: parent.height
  57. opacity: enabled ? 1.0 : 0.5
  58. color: control.palette.buttonText
  59. source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/arrow.png"
  60. fillMode: Image.Pad
  61. }
  62. }
  63. down.indicator: PaddedRectangle {
  64. x: control.mirrored ? 1 : control.width - width - 1
  65. y: control.height - height - 1
  66. height: control.height / 2 - 1
  67. implicitWidth: 16
  68. implicitHeight: 10
  69. radius: 1.7
  70. clip: true
  71. topPadding: -2
  72. leftPadding: -2
  73. color: control.down.pressed ? Fusion.buttonColor(control.palette, false, true, true) : "transparent"
  74. ColorImage {
  75. width: parent.width
  76. height: parent.height
  77. opacity: enabled ? 1.0 : 0.5
  78. color: control.palette.buttonText
  79. source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/arrow.png"
  80. fillMode: Image.Pad
  81. }
  82. }
  83. background: Rectangle {
  84. implicitWidth: 120
  85. implicitHeight: 24
  86. radius: 2
  87. color: control.palette.base
  88. border.color: control.activeFocus ? Fusion.highlightedOutline(control.palette) : Fusion.outline(control.palette)
  89. Rectangle {
  90. x: 2
  91. y: 1
  92. width: parent.width - 4
  93. height: 1
  94. color: Fusion.topShadow
  95. }
  96. Rectangle {
  97. x: control.mirrored ? 1 : parent.width - width - 1
  98. y: 1
  99. width: Math.max(control.up.indicator ? control.up.indicator.width : 0,
  100. control.down.indicator ? control.down.indicator.width : 0) + 1
  101. height: parent.height - 2
  102. radius: 2
  103. gradient: Gradient {
  104. GradientStop {
  105. position: 0
  106. color: Fusion.gradientStart(Fusion.buttonColor(control.palette, control.visualFocus, false, control.up.hovered || control.down.hovered))
  107. }
  108. GradientStop {
  109. position: 1
  110. color: Fusion.gradientStop(Fusion.buttonColor(control.palette, control.visualFocus, false, control.up.hovered || control.down.hovered))
  111. }
  112. }
  113. Rectangle {
  114. x: control.mirrored ? parent.width - 1 : 0
  115. height: parent.height
  116. width: 1
  117. color: Fusion.outline(control.palette)
  118. }
  119. }
  120. Rectangle {
  121. x: 1; y: 1
  122. width: parent.width - 2
  123. height: parent.height - 2
  124. color: "transparent"
  125. border.color: Color.transparent(Fusion.highlightedOutline(control.palette), 40 / 255)
  126. visible: control.activeFocus
  127. radius: 1.7
  128. }
  129. }
  130. }