DoubleSpinBox.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.Imagine
  7. import QtQuick.Controls.Imagine.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. topPadding: background ? background.topPadding : 0
  17. leftPadding: (background ? background.leftPadding : 0) + (control.mirrored ? (up.indicator ? up.indicator.width : 0) : (down.indicator ? down.indicator.width : 0))
  18. rightPadding: (background ? background.rightPadding : 0) + (control.mirrored ? (down.indicator ? down.indicator.width : 0) : (up.indicator ? up.indicator.width : 0))
  19. bottomPadding: background ? background.bottomPadding : 0
  20. topInset: background ? -background.topInset || 0 : 0
  21. leftInset: background ? -background.leftInset || 0 : 0
  22. rightInset: background ? -background.rightInset || 0 : 0
  23. bottomInset: background ? -background.bottomInset || 0 : 0
  24. validator: DoubleValidator {
  25. locale: control.locale.name
  26. bottom: Math.min(control.from, control.to)
  27. top: Math.max(control.from, control.to)
  28. decimals: control.decimals
  29. }
  30. contentItem: TextInput {
  31. z: 2
  32. text: control.displayText
  33. opacity: control.enabled ? 1 : 0.3
  34. font: control.font
  35. color: control.palette.text
  36. selectionColor: control.palette.highlight
  37. selectedTextColor: control.palette.highlightedText
  38. horizontalAlignment: Qt.AlignHCenter
  39. verticalAlignment: Qt.AlignVCenter
  40. readOnly: !control.editable
  41. validator: control.validator
  42. inputMethodHints: control.inputMethodHints
  43. clip: width < implicitWidth
  44. ContextMenu.menu: TextEditingContextMenu {
  45. editor: parent
  46. }
  47. NinePatchImage {
  48. z: -1
  49. width: control.width
  50. height: control.height
  51. visible: control.editable
  52. source: Imagine.url + "spinbox-editor"
  53. NinePatchImageSelector on source {
  54. states: [
  55. {"disabled": !control.enabled},
  56. {"focused": control.activeFocus},
  57. {"mirrored": control.mirrored},
  58. {"hovered": control.enabled && control.hovered}
  59. ]
  60. }
  61. }
  62. }
  63. up.indicator: NinePatchImage {
  64. x: control.mirrored ? 0 : control.width - width
  65. height: control.height
  66. source: Imagine.url + "spinbox-indicator"
  67. NinePatchImageSelector on source {
  68. states: [
  69. {"up": true},
  70. {"disabled": !control.up.indicator.enabled},
  71. {"editable": control.editable},
  72. {"pressed": control.up.pressed},
  73. {"focused": control.activeFocus},
  74. {"mirrored": control.mirrored},
  75. {"hovered": control.up.hovered}
  76. ]
  77. }
  78. }
  79. down.indicator: NinePatchImage {
  80. x: control.mirrored ? control.width - width : 0
  81. height: control.height
  82. source: Imagine.url + "spinbox-indicator"
  83. NinePatchImageSelector on source {
  84. states: [
  85. {"down": true},
  86. {"disabled": !control.down.indicator.enabled},
  87. {"editable": control.editable},
  88. {"pressed": control.down.pressed},
  89. {"focused": control.activeFocus},
  90. {"mirrored": control.mirrored},
  91. {"hovered": control.down.hovered}
  92. ]
  93. }
  94. }
  95. background: NinePatchImage {
  96. source: Imagine.url + "spinbox-background"
  97. NinePatchImageSelector on source {
  98. states: [
  99. {"disabled": !control.enabled},
  100. {"editable": control.editable},
  101. {"focused": control.activeFocus},
  102. {"mirrored": control.mirrored},
  103. {"hovered": control.enabled && control.hovered}
  104. ]
  105. }
  106. }
  107. }