SpinBox.qml 4.0 KB

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