SpinBox.qml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 2.12
  37. import QtQuick.Templates 2.12 as T
  38. import QtQuick.Controls 2.12
  39. import QtQuick.Controls.impl 2.12
  40. import QtQuick.Controls.Fusion 2.12
  41. import QtQuick.Controls.Fusion.impl 2.12
  42. T.SpinBox {
  43. id: control
  44. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  45. contentItem.implicitWidth + 2 * padding +
  46. Math.max(up.implicitIndicatorWidth,
  47. down.implicitIndicatorWidth))
  48. implicitHeight: Math.max(implicitContentHeight + topPadding + bottomPadding,
  49. implicitBackgroundHeight,
  50. up.implicitIndicatorHeight +
  51. down.implicitIndicatorHeight)
  52. padding: 4
  53. leftPadding: padding + (control.mirrored ? (up.indicator ? up.indicator.width : 0) : (down.indicator ? down.indicator.width : 0))
  54. rightPadding: padding + (control.mirrored ? (down.indicator ? down.indicator.width : 0) : (up.indicator ? up.indicator.width : 0))
  55. validator: IntValidator {
  56. locale: control.locale.name
  57. bottom: Math.min(control.from, control.to)
  58. top: Math.max(control.from, control.to)
  59. }
  60. contentItem: TextInput {
  61. z: 2
  62. text: control.displayText
  63. font: control.font
  64. color: control.palette.text
  65. selectionColor: control.palette.highlight
  66. selectedTextColor: control.palette.highlightedText
  67. horizontalAlignment: Qt.AlignHCenter
  68. verticalAlignment: Qt.AlignVCenter
  69. readOnly: !control.editable
  70. validator: control.validator
  71. inputMethodHints: control.inputMethodHints
  72. }
  73. up.indicator: PaddedRectangle {
  74. x: control.mirrored ? 1 : parent.width - width - 1
  75. y: 1
  76. height: parent.height / 2 - 1
  77. implicitWidth: 16
  78. implicitHeight: 10
  79. radius: 1.7
  80. clip: true
  81. topPadding: -2
  82. leftPadding: -2
  83. color: control.up.pressed ? Fusion.buttonColor(control.palette, false, true, true) : "transparent"
  84. ColorImage {
  85. scale: -1
  86. width: parent.width
  87. height: parent.height
  88. opacity: enabled ? 1.0 : 0.5
  89. color: control.palette.buttonText
  90. source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Fusion/images/arrow.png"
  91. fillMode: Image.Pad
  92. }
  93. }
  94. down.indicator: PaddedRectangle {
  95. x: control.mirrored ? 1 : parent.width - width - 1
  96. y: parent.height - height - 1
  97. height: parent.height / 2 - 1
  98. implicitWidth: 16
  99. implicitHeight: 10
  100. radius: 1.7
  101. clip: true
  102. topPadding: -2
  103. leftPadding: -2
  104. color: control.down.pressed ? Fusion.buttonColor(control.palette, false, true, true) : "transparent"
  105. ColorImage {
  106. width: parent.width
  107. height: parent.height
  108. opacity: enabled ? 1.0 : 0.5
  109. color: control.palette.buttonText
  110. source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Fusion/images/arrow.png"
  111. fillMode: Image.Pad
  112. }
  113. }
  114. background: Rectangle {
  115. implicitWidth: 120
  116. implicitHeight: 24
  117. radius: 2
  118. color: control.palette.base
  119. border.color: control.activeFocus ? Fusion.highlightedOutline(control.palette) : Fusion.outline(control.palette)
  120. Rectangle {
  121. x: 2
  122. y: 1
  123. width: parent.width - 4
  124. height: 1
  125. color: Fusion.topShadow
  126. }
  127. Rectangle {
  128. x: control.mirrored ? 1 : parent.width - width - 1
  129. y: 1
  130. width: Math.max(control.up.indicator ? control.up.indicator.width : 0,
  131. control.down.indicator ? control.down.indicator.width : 0) + 1
  132. height: parent.height - 2
  133. radius: 2
  134. gradient: Gradient {
  135. GradientStop {
  136. position: 0
  137. color: Fusion.gradientStart(Fusion.buttonColor(control.palette, control.visualFocus, false, control.up.hovered || control.down.hovered))
  138. }
  139. GradientStop {
  140. position: 1
  141. color: Fusion.gradientStop(Fusion.buttonColor(control.palette, control.visualFocus, false, control.up.hovered || control.down.hovered))
  142. }
  143. }
  144. Rectangle {
  145. x: control.mirrored ? parent.width - 1 : 0
  146. height: parent.height
  147. width: 1
  148. color: Fusion.outline(control.palette)
  149. }
  150. }
  151. Rectangle {
  152. x: 1; y: 1
  153. width: parent.width - 2
  154. height: parent.height - 2
  155. color: "transparent"
  156. border.color: Color.transparent(Fusion.highlightedOutline(control.palette), 40 / 255)
  157. visible: control.activeFocus
  158. radius: 1.7
  159. }
  160. }
  161. }