SpinBox.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright (C) 2017 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // Qt-Security score:significant reason:default
  4. import QtQuick
  5. import QtQuick.Templates as T
  6. import QtQuick.Controls.impl
  7. import QtQuick.Controls.Universal
  8. T.SpinBox {
  9. id: control
  10. // Note: the width of the indicators are calculated into the padding
  11. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  12. contentItem.implicitWidth + leftPadding + rightPadding)
  13. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  14. implicitContentHeight + topPadding + bottomPadding,
  15. up.implicitIndicatorHeight, down.implicitIndicatorHeight)
  16. // TextControlThemePadding + 2 (border)
  17. padding: 12
  18. topPadding: padding - 7
  19. leftPadding: padding + (control.mirrored ? (up.indicator ? up.indicator.width : 0) : (down.indicator ? down.indicator.width : 0))
  20. rightPadding: padding + (control.mirrored ? (down.indicator ? down.indicator.width : 0) : (up.indicator ? up.indicator.width : 0))
  21. bottomPadding: padding - 5
  22. Universal.theme: activeFocus ? Universal.Light : undefined
  23. validator: IntValidator {
  24. locale: control.locale.name
  25. bottom: Math.min(control.from, control.to)
  26. top: Math.max(control.from, control.to)
  27. }
  28. contentItem: TextInput {
  29. text: control.displayText
  30. font: control.font
  31. color: !enabled ? control.Universal.chromeDisabledLowColor :
  32. activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.foreground
  33. selectionColor: control.Universal.accent
  34. selectedTextColor: control.Universal.chromeWhiteColor
  35. horizontalAlignment: Qt.AlignHCenter
  36. verticalAlignment: TextInput.AlignVCenter
  37. readOnly: !control.editable
  38. validator: control.validator
  39. inputMethodHints: control.inputMethodHints
  40. clip: width < implicitWidth
  41. }
  42. up.indicator: Item {
  43. implicitWidth: 28
  44. height: control.height + 4
  45. y: -2
  46. x: control.mirrored ? 0 : control.width - width
  47. Rectangle {
  48. x: 2; y: 4
  49. width: parent.width - 4
  50. height: parent.height - 8
  51. color: control.activeFocus ? control.Universal.accent :
  52. control.up.pressed ? control.Universal.baseMediumLowColor :
  53. control.up.hovered ? control.Universal.baseLowColor : "transparent"
  54. visible: control.up.pressed || control.up.hovered
  55. opacity: control.activeFocus && !control.up.pressed ? 0.4 : 1.0
  56. }
  57. ColorImage {
  58. x: (parent.width - width) / 2
  59. y: (parent.height - height) / 2
  60. color: !enabled ? control.Universal.chromeDisabledLowColor :
  61. control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.baseHighColor
  62. source: "qrc:/qt-project.org/imports/QtQuick/Controls/Universal/images/" + (control.mirrored ? "left" : "right") + "arrow.png"
  63. }
  64. }
  65. down.indicator: Item {
  66. implicitWidth: 28
  67. height: control.height + 4
  68. y: -2
  69. x: control.mirrored ? control.width - width : 0
  70. Rectangle {
  71. x: 2; y: 4
  72. width: parent.width - 4
  73. height: parent.height - 8
  74. color: control.activeFocus ? control.Universal.accent :
  75. control.down.pressed ? control.Universal.baseMediumLowColor :
  76. control.down.hovered ? control.Universal.baseLowColor : "transparent"
  77. visible: control.down.pressed || control.down.hovered
  78. opacity: control.activeFocus && !control.down.pressed ? 0.4 : 1.0
  79. }
  80. ColorImage {
  81. x: (parent.width - width) / 2
  82. y: (parent.height - height) / 2
  83. color: !enabled ? control.Universal.chromeDisabledLowColor :
  84. control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.baseHighColor
  85. source: "qrc:/qt-project.org/imports/QtQuick/Controls/Universal/images/" + (control.mirrored ? "right" : "left") + "arrow.png"
  86. }
  87. }
  88. background: Rectangle {
  89. implicitWidth: 60 + 28 // TextControlThemeMinWidth - 4 (border)
  90. implicitHeight: 28 // TextControlThemeMinHeight - 4 (border)
  91. border.width: 2 // TextControlBorderThemeThickness
  92. border.color: !control.enabled ? control.Universal.baseLowColor :
  93. control.activeFocus ? control.Universal.accent :
  94. control.hovered ? control.Universal.baseMediumColor : control.Universal.chromeDisabledLowColor
  95. color: control.enabled ? control.Universal.background : control.Universal.baseLowColor
  96. }
  97. }