DoubleSpinBox.qml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright (C) 2025 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.DoubleSpinBox {
  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: DoubleValidator {
  22. locale: control.locale.name
  23. bottom: Math.min(control.from, control.to)
  24. top: Math.max(control.from, control.to)
  25. decimals: control.decimals
  26. }
  27. contentItem: TextInput {
  28. text: control.displayText
  29. font: control.font
  30. color: enabled ? control.Material.foreground : control.Material.hintTextColor
  31. selectionColor: control.Material.textSelectionColor
  32. selectedTextColor: control.Material.foreground
  33. horizontalAlignment: Qt.AlignHCenter
  34. verticalAlignment: Qt.AlignVCenter
  35. cursorDelegate: CursorDelegate { }
  36. readOnly: !control.editable
  37. validator: control.validator
  38. inputMethodHints: control.inputMethodHints
  39. clip: width < implicitWidth
  40. ContextMenu.menu: TextEditingContextMenu {
  41. editor: parent
  42. }
  43. }
  44. up.indicator: Item {
  45. x: control.mirrored ? 0 : control.width - width
  46. implicitWidth: control.Material.touchTarget
  47. implicitHeight: control.Material.touchTarget
  48. height: control.height
  49. width: height
  50. Ripple {
  51. clipRadius: 2
  52. x: control.spacing
  53. y: control.spacing
  54. width: parent.width - 2 * control.spacing
  55. height: parent.height - 2 * control.spacing
  56. pressed: control.up.pressed
  57. active: control.up.pressed || control.up.hovered || control.visualFocus
  58. color: control.Material.rippleColor
  59. }
  60. Rectangle {
  61. x: (parent.width - width) / 2
  62. y: (parent.height - height) / 2
  63. width: Math.min(parent.width / 3, parent.height / 3)
  64. height: 2
  65. color: enabled ? control.Material.foreground : control.Material.spinBoxDisabledIconColor
  66. }
  67. Rectangle {
  68. x: (parent.width - width) / 2
  69. y: (parent.height - height) / 2
  70. width: 2
  71. height: Math.min(parent.width / 3, parent.height / 3)
  72. color: enabled ? control.Material.foreground : control.Material.spinBoxDisabledIconColor
  73. }
  74. }
  75. down.indicator: Item {
  76. x: control.mirrored ? control.width - width : 0
  77. implicitWidth: control.Material.touchTarget
  78. implicitHeight: control.Material.touchTarget
  79. height: control.height
  80. width: height
  81. Ripple {
  82. clipRadius: 2
  83. x: control.spacing
  84. y: control.spacing
  85. width: parent.width - 2 * control.spacing
  86. height: parent.height - 2 * control.spacing
  87. pressed: control.down.pressed
  88. active: control.down.pressed || control.down.hovered || control.visualFocus
  89. color: control.Material.rippleColor
  90. }
  91. Rectangle {
  92. x: (parent.width - width) / 2
  93. y: (parent.height - height) / 2
  94. width: parent.width / 3
  95. height: 2
  96. color: enabled ? control.Material.foreground : control.Material.spinBoxDisabledIconColor
  97. }
  98. }
  99. background: MaterialTextContainer {
  100. implicitWidth: 140
  101. implicitHeight: control.Material.textFieldHeight
  102. outlineColor: (enabled && control.hovered) ? control.Material.primaryTextColor : control.Material.hintTextColor
  103. focusedOutlineColor: control.Material.accentColor
  104. controlHasActiveFocus: control.activeFocus
  105. controlHasText: true
  106. horizontalPadding: control.Material.textFieldHorizontalPadding
  107. }
  108. }