SpinBox.qml 6.5 KB

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