SpinBox.qml 6.3 KB

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