SpinBox.qml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.Universal 2.12
  41. T.SpinBox {
  42. id: control
  43. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  44. contentItem.implicitWidth + 16 +
  45. up.implicitIndicatorWidth +
  46. down.implicitIndicatorWidth)
  47. implicitHeight: Math.max(implicitContentHeight + topPadding + bottomPadding,
  48. implicitBackgroundHeight,
  49. up.implicitIndicatorHeight,
  50. down.implicitIndicatorHeight)
  51. // TextControlThemePadding + 2 (border)
  52. padding: 12
  53. topPadding: padding - 7
  54. leftPadding: padding + (control.mirrored ? (up.indicator ? up.indicator.width : 0) : (down.indicator ? down.indicator.width : 0))
  55. rightPadding: padding - 4 + (control.mirrored ? (down.indicator ? down.indicator.width : 0) : (up.indicator ? up.indicator.width : 0))
  56. bottomPadding: padding - 5
  57. Universal.theme: activeFocus ? Universal.Light : undefined
  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. text: control.displayText
  65. font: control.font
  66. color: !enabled ? control.Universal.chromeDisabledLowColor :
  67. activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.foreground
  68. selectionColor: control.Universal.accent
  69. selectedTextColor: control.Universal.chromeWhiteColor
  70. horizontalAlignment: Qt.AlignHCenter
  71. verticalAlignment: TextInput.AlignVCenter
  72. readOnly: !control.editable
  73. validator: control.validator
  74. inputMethodHints: control.inputMethodHints
  75. }
  76. up.indicator: Item {
  77. implicitWidth: 28
  78. height: parent.height + 4
  79. y: -2
  80. x: control.mirrored ? 0 : parent.width - width
  81. Rectangle {
  82. x: 2; y: 4
  83. width: parent.width - 4
  84. height: parent.height - 8
  85. color: control.activeFocus ? control.Universal.accent :
  86. control.up.pressed ? control.Universal.baseMediumLowColor :
  87. control.up.hovered ? control.Universal.baseLowColor : "transparent"
  88. visible: control.up.pressed || control.up.hovered
  89. opacity: control.activeFocus && !control.up.pressed ? 0.4 : 1.0
  90. }
  91. ColorImage {
  92. x: (parent.width - width) / 2
  93. y: (parent.height - height) / 2
  94. color: !enabled ? control.Universal.chromeDisabledLowColor :
  95. control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.baseHighColor
  96. source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/" + (control.mirrored ? "left" : "right") + "arrow.png"
  97. }
  98. }
  99. down.indicator: Item {
  100. implicitWidth: 28
  101. height: parent.height + 4
  102. y: -2
  103. x: control.mirrored ? parent.width - width : 0
  104. Rectangle {
  105. x: 2; y: 4
  106. width: parent.width - 4
  107. height: parent.height - 8
  108. color: control.activeFocus ? control.Universal.accent :
  109. control.down.pressed ? control.Universal.baseMediumLowColor :
  110. control.down.hovered ? control.Universal.baseLowColor : "transparent"
  111. visible: control.down.pressed || control.down.hovered
  112. opacity: control.activeFocus && !control.down.pressed ? 0.4 : 1.0
  113. }
  114. ColorImage {
  115. x: (parent.width - width) / 2
  116. y: (parent.height - height) / 2
  117. color: !enabled ? control.Universal.chromeDisabledLowColor :
  118. control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.baseHighColor
  119. source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/" + (control.mirrored ? "right" : "left") + "arrow.png"
  120. }
  121. }
  122. background: Rectangle {
  123. implicitWidth: 60 + 28 // TextControlThemeMinWidth - 4 (border)
  124. implicitHeight: 28 // TextControlThemeMinHeight - 4 (border)
  125. border.width: 2 // TextControlBorderThemeThickness
  126. border.color: !control.enabled ? control.Universal.baseLowColor :
  127. control.activeFocus ? control.Universal.accent :
  128. control.hovered ? control.Universal.baseMediumColor : control.Universal.chromeDisabledLowColor
  129. color: control.enabled ? control.Universal.background : control.Universal.baseLowColor
  130. }
  131. }