SpinBox.qml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2017 The Qt Company Ltd.
  4. ** Contact: http://www.qt.io/licensing/
  5. **
  6. ** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL3$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see http://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at http://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPLv3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or later as published by the Free
  28. ** Software Foundation and appearing in the file LICENSE.GPL included in
  29. ** the packaging of this file. Please review the following information to
  30. ** ensure the GNU General Public License version 2.0 requirements will be
  31. ** met: http://www.gnu.org/licenses/gpl-2.0.html.
  32. **
  33. ** $QT_END_LICENSE$
  34. **
  35. ****************************************************************************/
  36. import QtQuick
  37. import QtQuick.Templates as T
  38. import QtQuick.Controls.Imagine
  39. import QtQuick.Controls.Imagine.impl
  40. T.SpinBox {
  41. id: control
  42. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  43. contentItem.implicitWidth + 2 * padding +
  44. up.implicitIndicatorWidth +
  45. down.implicitIndicatorWidth)
  46. implicitHeight: Math.max(implicitContentHeight + topPadding + bottomPadding,
  47. implicitBackgroundHeight,
  48. up.implicitIndicatorHeight,
  49. down.implicitIndicatorHeight)
  50. topPadding: background ? background.topPadding : 0
  51. leftPadding: (background ? background.leftPadding : 0) + (control.mirrored ? (up.indicator ? up.indicator.width : 0) : (down.indicator ? down.indicator.width : 0))
  52. rightPadding: (background ? background.rightPadding : 0) + (control.mirrored ? (down.indicator ? down.indicator.width : 0) : (up.indicator ? up.indicator.width : 0))
  53. bottomPadding: background ? background.bottomPadding : 0
  54. topInset: background ? -background.topInset || 0 : 0
  55. leftInset: background ? -background.leftInset || 0 : 0
  56. rightInset: background ? -background.rightInset || 0 : 0
  57. bottomInset: background ? -background.bottomInset || 0 : 0
  58. validator: IntValidator {
  59. locale: control.locale.name
  60. bottom: Math.min(control.from, control.to)
  61. top: Math.max(control.from, control.to)
  62. }
  63. contentItem: TextInput {
  64. z: 2
  65. text: control.displayText
  66. opacity: control.enabled ? 1 : 0.3
  67. font: control.font
  68. color: control.palette.text
  69. selectionColor: control.palette.highlight
  70. selectedTextColor: control.palette.highlightedText
  71. horizontalAlignment: Qt.AlignHCenter
  72. verticalAlignment: Qt.AlignVCenter
  73. readOnly: !control.editable
  74. validator: control.validator
  75. inputMethodHints: control.inputMethodHints
  76. NinePatchImage {
  77. z: -1
  78. width: control.width
  79. height: control.height
  80. visible: control.editable
  81. source: Imagine.url + "spinbox-editor"
  82. NinePatchImageSelector on source {
  83. states: [
  84. {"disabled": !control.enabled},
  85. {"focused": control.activeFocus},
  86. {"mirrored": control.mirrored},
  87. {"hovered": control.hovered}
  88. ]
  89. }
  90. }
  91. }
  92. up.indicator: NinePatchImage {
  93. x: control.mirrored ? 0 : control.width - width
  94. height: control.height
  95. source: Imagine.url + "spinbox-indicator"
  96. NinePatchImageSelector on source {
  97. states: [
  98. {"up": true},
  99. {"disabled": !control.up.indicator.enabled},
  100. {"editable": control.editable},
  101. {"pressed": control.up.pressed},
  102. {"focused": control.activeFocus},
  103. {"mirrored": control.mirrored},
  104. {"hovered": control.up.hovered}
  105. ]
  106. }
  107. }
  108. down.indicator: NinePatchImage {
  109. x: control.mirrored ? control.width - width : 0
  110. height: control.height
  111. source: Imagine.url + "spinbox-indicator"
  112. NinePatchImageSelector on source {
  113. states: [
  114. {"down": true},
  115. {"disabled": !control.down.indicator.enabled},
  116. {"editable": control.editable},
  117. {"pressed": control.down.pressed},
  118. {"focused": control.activeFocus},
  119. {"mirrored": control.mirrored},
  120. {"hovered": control.down.hovered}
  121. ]
  122. }
  123. }
  124. background: NinePatchImage {
  125. source: Imagine.url + "spinbox-background"
  126. NinePatchImageSelector on source {
  127. states: [
  128. {"disabled": !control.enabled},
  129. {"editable": control.editable},
  130. {"focused": control.activeFocus},
  131. {"mirrored": control.mirrored},
  132. {"hovered": control.hovered}
  133. ]
  134. }
  135. }
  136. }