SpinBox.qml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. ContextMenu.menu: TextEditingContextMenu {
  40. editor: parent
  41. }
  42. }
  43. up.indicator: Item {
  44. x: control.mirrored ? 0 : control.width - width
  45. implicitWidth: control.Material.touchTarget
  46. implicitHeight: control.Material.touchTarget
  47. height: control.height
  48. width: height
  49. Ripple {
  50. clipRadius: 2
  51. x: control.spacing
  52. y: control.spacing
  53. width: parent.width - 2 * control.spacing
  54. height: parent.height - 2 * control.spacing
  55. pressed: control.up.pressed
  56. active: control.up.pressed || control.up.hovered || control.visualFocus
  57. color: control.Material.rippleColor
  58. }
  59. Rectangle {
  60. x: (parent.width - width) / 2
  61. y: (parent.height - height) / 2
  62. width: Math.min(parent.width / 3, parent.height / 3)
  63. height: 2
  64. color: enabled ? control.Material.foreground : control.Material.spinBoxDisabledIconColor
  65. }
  66. Rectangle {
  67. x: (parent.width - width) / 2
  68. y: (parent.height - height) / 2
  69. width: 2
  70. height: Math.min(parent.width / 3, parent.height / 3)
  71. color: enabled ? control.Material.foreground : control.Material.spinBoxDisabledIconColor
  72. }
  73. }
  74. down.indicator: Item {
  75. x: control.mirrored ? control.width - width : 0
  76. implicitWidth: control.Material.touchTarget
  77. implicitHeight: control.Material.touchTarget
  78. height: control.height
  79. width: height
  80. Ripple {
  81. clipRadius: 2
  82. x: control.spacing
  83. y: control.spacing
  84. width: parent.width - 2 * control.spacing
  85. height: parent.height - 2 * control.spacing
  86. pressed: control.down.pressed
  87. active: control.down.pressed || control.down.hovered || control.visualFocus
  88. color: control.Material.rippleColor
  89. }
  90. Rectangle {
  91. x: (parent.width - width) / 2
  92. y: (parent.height - height) / 2
  93. width: parent.width / 3
  94. height: 2
  95. color: enabled ? control.Material.foreground : control.Material.spinBoxDisabledIconColor
  96. }
  97. }
  98. background: MaterialTextContainer {
  99. implicitWidth: 140
  100. implicitHeight: control.Material.textFieldHeight
  101. outlineColor: (enabled && control.hovered) ? control.Material.primaryTextColor : control.Material.hintTextColor
  102. focusedOutlineColor: control.Material.accentColor
  103. controlHasActiveFocus: control.activeFocus
  104. controlHasText: true
  105. horizontalPadding: control.Material.textFieldHorizontalPadding
  106. }
  107. }