SpinBox.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2020 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.NativeStyle as NativeStyle
  39. T.SpinBox {
  40. id: control
  41. property bool __nativeBackground: background instanceof NativeStyle.StyleItem
  42. property bool nativeIndicators: up.indicator.hasOwnProperty("_qt_default")
  43. && down.indicator.hasOwnProperty("_qt_default")
  44. font.pixelSize: __nativeBackground ? background.styleFont(control).pixelSize : undefined
  45. implicitWidth: Math.max(contentItem.implicitWidth + leftInset + rightInset,
  46. 90 /* minimum */ )
  47. implicitHeight: Math.max(contentItem.implicitHeight, up.implicitIndicatorHeight + down.implicitIndicatorHeight)
  48. + topInset + bottomInset
  49. spacing: 2
  50. leftPadding: __nativeBackground ? background.contentPadding.left: 0
  51. topPadding: __nativeBackground ? background.contentPadding.top: 0
  52. rightPadding: (__nativeBackground ? background.contentPadding.right : 0) + rightInset
  53. bottomPadding: __nativeBackground ? background.contentPadding.bottom: 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: TextField {
  60. text: control.displayText
  61. font: control.font
  62. color: control.palette.text
  63. selectionColor: control.palette.highlight
  64. selectedTextColor: control.palette.highlightedText
  65. horizontalAlignment: Qt.AlignLeft
  66. verticalAlignment: Qt.AlignVCenter
  67. topPadding: 0
  68. bottomPadding: 0
  69. leftPadding: 10
  70. rightPadding: 10
  71. readOnly: !control.editable
  72. validator: control.validator
  73. inputMethodHints: control.inputMethodHints
  74. // Since the indicators are embedded inside the TextField we need to avoid that
  75. // the TextField consumes mouse events for that area.
  76. // We achieve that by setting a containmentMask
  77. containmentMask: Item { height: contentItem.height; width: contentItem.width - upAndDown.width }
  78. }
  79. NativeStyle.SpinBox {
  80. id: upAndDown
  81. control: control
  82. subControl: NativeStyle.SpinBox.Up
  83. visible: nativeIndicators
  84. x: up.indicator.x
  85. y: up.indicator.y
  86. //implicitHeight: contentItem.implicitHeight-2
  87. height: parent.height-2
  88. useNinePatchImage: false
  89. z:99
  90. }
  91. up.indicator: Item {
  92. x: parent.width - width - 2
  93. y: 1
  94. height: upAndDown.height >> 1
  95. implicitWidth: upAndDown.implicitWidth
  96. implicitHeight: (upAndDown.implicitHeight >> 1)
  97. property bool _qt_default
  98. }
  99. down.indicator: Item {
  100. x: parent.width - width - 2
  101. y: up.indicator.y + (upAndDown.height >> 1)
  102. height: upAndDown.height - up.indicator.height
  103. implicitWidth: upAndDown.implicitWidth
  104. implicitHeight: upAndDown.implicitHeight >> 1
  105. property bool _qt_default
  106. }
  107. background: Item {} // No background, the TextField will cover the whole control
  108. }