SpinBox.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. NinePatchImage {
  44. z: -1
  45. width: control.width
  46. height: control.height
  47. visible: control.editable
  48. source: Imagine.url + "spinbox-editor"
  49. NinePatchImageSelector on source {
  50. states: [
  51. {"disabled": !control.enabled},
  52. {"focused": control.activeFocus},
  53. {"mirrored": control.mirrored},
  54. {"hovered": control.enabled && control.hovered}
  55. ]
  56. }
  57. }
  58. }
  59. up.indicator: NinePatchImage {
  60. x: control.mirrored ? 0 : control.width - width
  61. height: control.height
  62. source: Imagine.url + "spinbox-indicator"
  63. NinePatchImageSelector on source {
  64. states: [
  65. {"up": true},
  66. {"disabled": !control.up.indicator.enabled},
  67. {"editable": control.editable},
  68. {"pressed": control.up.pressed},
  69. {"focused": control.activeFocus},
  70. {"mirrored": control.mirrored},
  71. {"hovered": control.up.hovered}
  72. ]
  73. }
  74. }
  75. down.indicator: NinePatchImage {
  76. x: control.mirrored ? control.width - width : 0
  77. height: control.height
  78. source: Imagine.url + "spinbox-indicator"
  79. NinePatchImageSelector on source {
  80. states: [
  81. {"down": true},
  82. {"disabled": !control.down.indicator.enabled},
  83. {"editable": control.editable},
  84. {"pressed": control.down.pressed},
  85. {"focused": control.activeFocus},
  86. {"mirrored": control.mirrored},
  87. {"hovered": control.down.hovered}
  88. ]
  89. }
  90. }
  91. background: NinePatchImage {
  92. source: Imagine.url + "spinbox-background"
  93. NinePatchImageSelector on source {
  94. states: [
  95. {"disabled": !control.enabled},
  96. {"editable": control.editable},
  97. {"focused": control.activeFocus},
  98. {"mirrored": control.mirrored},
  99. {"hovered": control.enabled && control.hovered}
  100. ]
  101. }
  102. }
  103. }