SpinBox.qml 4.9 KB

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