DoubleSpinBox.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.Controls.impl
  6. import QtQuick.Controls.Basic.impl
  7. import QtQuick.Templates as T
  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. leftPadding: padding + (control.mirrored ? (up.indicator ? up.indicator.width : 0) : (down.indicator ? down.indicator.width : 0))
  17. rightPadding: padding + (control.mirrored ? (down.indicator ? down.indicator.width : 0) : (up.indicator ? up.indicator.width : 0))
  18. validator: DoubleValidator {
  19. locale: control.locale.name
  20. bottom: Math.min(control.from, control.to)
  21. top: Math.max(control.from, control.to)
  22. decimals: control.decimals
  23. }
  24. contentItem: TextInput {
  25. z: 2
  26. text: control.displayText
  27. clip: width < implicitWidth
  28. padding: 6
  29. font: control.font
  30. color: control.palette.text
  31. selectionColor: control.palette.highlight
  32. selectedTextColor: control.palette.highlightedText
  33. horizontalAlignment: Qt.AlignHCenter
  34. verticalAlignment: Qt.AlignVCenter
  35. readOnly: !control.editable
  36. validator: control.validator
  37. inputMethodHints: control.inputMethodHints
  38. ContextMenu.menu: TextEditingContextMenu {
  39. editor: parent
  40. }
  41. Rectangle {
  42. width: parent.width
  43. height: parent.height
  44. visible: control.activeFocus
  45. color: "transparent"
  46. border.color: control.palette.highlight
  47. border.width: 2
  48. }
  49. }
  50. up.indicator: Rectangle {
  51. x: control.mirrored ? 0 : control.width - width
  52. height: control.height
  53. implicitWidth: 40
  54. implicitHeight: 40
  55. color: control.up.pressed ? control.palette.mid : control.palette.button
  56. border.color: enabled ? control.palette.text : control.palette.mid
  57. border.width: Qt.styleHints.accessibility.contrastPreference === Qt.HighContrast ? 1 : 0
  58. Rectangle {
  59. x: (parent.width - width) / 2
  60. y: (parent.height - height) / 2
  61. width: parent.width / 3
  62. height: 2
  63. color: enabled ? control.palette.buttonText : control.palette.mid
  64. }
  65. Rectangle {
  66. x: (parent.width - width) / 2
  67. y: (parent.height - height) / 2
  68. width: 2
  69. height: parent.width / 3
  70. color: enabled ? control.palette.buttonText : control.palette.mid
  71. }
  72. }
  73. down.indicator: Rectangle {
  74. x: control.mirrored ? parent.width - width : 0
  75. height: control.height
  76. implicitWidth: 40
  77. implicitHeight: 40
  78. color: control.down.pressed ? control.palette.mid : control.palette.button
  79. border.color: enabled ? control.palette.text : control.palette.mid
  80. border.width: Qt.styleHints.accessibility.contrastPreference === Qt.HighContrast ? 1 : 0
  81. Rectangle {
  82. x: (parent.width - width) / 2
  83. y: (parent.height - height) / 2
  84. width: parent.width / 3
  85. height: 2
  86. color: enabled ? control.palette.buttonText : control.palette.mid
  87. }
  88. }
  89. background: Rectangle {
  90. implicitWidth: 140
  91. color: enabled ? control.palette.base : control.palette.button
  92. border.color: {
  93. if (Qt.styleHints.accessibility.contrastPreference !== Qt.HighContrast)
  94. return control.palette.button
  95. return enabled ? control.palette.text : control.palette.mid
  96. }
  97. }
  98. }