SpinBox.qml 4.4 KB

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