SpinBox.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.Material
  7. import QtQuick.Controls.Material.impl
  8. T.SpinBox {
  9. id: control
  10. // Note: the width of the indicators are calculated into the padding
  11. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  12. contentItem.implicitWidth + leftPadding + rightPadding)
  13. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  14. implicitContentHeight + topPadding + bottomPadding,
  15. up.implicitIndicatorHeight, down.implicitIndicatorHeight)
  16. spacing: 6
  17. topPadding: Material.textFieldVerticalPadding
  18. bottomPadding: Material.textFieldVerticalPadding
  19. leftPadding: control.mirrored ? (up.indicator ? up.indicator.width : 0) : (down.indicator ? down.indicator.width : 0)
  20. rightPadding: control.mirrored ? (down.indicator ? down.indicator.width : 0) : (up.indicator ? up.indicator.width : 0)
  21. validator: IntValidator {
  22. locale: control.locale.name
  23. bottom: Math.min(control.from, control.to)
  24. top: Math.max(control.from, control.to)
  25. }
  26. contentItem: TextInput {
  27. text: control.displayText
  28. font: control.font
  29. color: enabled ? control.Material.foreground : control.Material.hintTextColor
  30. selectionColor: control.Material.textSelectionColor
  31. selectedTextColor: control.Material.foreground
  32. horizontalAlignment: Qt.AlignHCenter
  33. verticalAlignment: Qt.AlignVCenter
  34. cursorDelegate: CursorDelegate { }
  35. readOnly: !control.editable
  36. validator: control.validator
  37. inputMethodHints: control.inputMethodHints
  38. clip: width < implicitWidth
  39. }
  40. up.indicator: Item {
  41. x: control.mirrored ? 0 : control.width - width
  42. implicitWidth: control.Material.touchTarget
  43. implicitHeight: control.Material.touchTarget
  44. height: control.height
  45. width: height
  46. Ripple {
  47. clipRadius: 2
  48. x: control.spacing
  49. y: control.spacing
  50. width: parent.width - 2 * control.spacing
  51. height: parent.height - 2 * control.spacing
  52. pressed: control.up.pressed
  53. active: control.up.pressed || control.up.hovered || control.visualFocus
  54. color: control.Material.rippleColor
  55. }
  56. Rectangle {
  57. x: (parent.width - width) / 2
  58. y: (parent.height - height) / 2
  59. width: Math.min(parent.width / 3, parent.height / 3)
  60. height: 2
  61. color: enabled ? control.Material.foreground : control.Material.spinBoxDisabledIconColor
  62. }
  63. Rectangle {
  64. x: (parent.width - width) / 2
  65. y: (parent.height - height) / 2
  66. width: 2
  67. height: Math.min(parent.width / 3, parent.height / 3)
  68. color: enabled ? control.Material.foreground : control.Material.spinBoxDisabledIconColor
  69. }
  70. }
  71. down.indicator: Item {
  72. x: control.mirrored ? control.width - width : 0
  73. implicitWidth: control.Material.touchTarget
  74. implicitHeight: control.Material.touchTarget
  75. height: control.height
  76. width: height
  77. Ripple {
  78. clipRadius: 2
  79. x: control.spacing
  80. y: control.spacing
  81. width: parent.width - 2 * control.spacing
  82. height: parent.height - 2 * control.spacing
  83. pressed: control.down.pressed
  84. active: control.down.pressed || control.down.hovered || control.visualFocus
  85. color: control.Material.rippleColor
  86. }
  87. Rectangle {
  88. x: (parent.width - width) / 2
  89. y: (parent.height - height) / 2
  90. width: parent.width / 3
  91. height: 2
  92. color: enabled ? control.Material.foreground : control.Material.spinBoxDisabledIconColor
  93. }
  94. }
  95. background: MaterialTextContainer {
  96. implicitWidth: 140
  97. implicitHeight: control.Material.textFieldHeight
  98. outlineColor: (enabled && control.hovered) ? control.Material.primaryTextColor : control.Material.hintTextColor
  99. focusedOutlineColor: control.Material.accentColor
  100. controlHasActiveFocus: control.activeFocus
  101. controlHasText: true
  102. horizontalPadding: control.Material.textFieldHorizontalPadding
  103. }
  104. }