SpinBoxStyle.qml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the Qt Quick Controls module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  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 https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. import QtQuick 2.2
  40. import QtQuick.Controls 1.2
  41. import QtQuick.Controls.Private 1.0
  42. Style {
  43. readonly property SpinBox control: __control
  44. padding {
  45. top: control.__panel ? control.__panel.topPadding + (styleitem.style === "mac" ? 2 : 0) : 0
  46. left: control.__panel ? control.__panel.leftPadding : 0
  47. right: control.__panel ? control.__panel.rightPadding : 0
  48. bottom: control.__panel ? control.__panel.bottomPadding : 0
  49. }
  50. StyleItem {id: styleitem ; visible: false}
  51. property int renderType: Text.NativeRendering
  52. property Component panel: Item {
  53. id: style
  54. property rect upRect
  55. property rect downRect
  56. property int horizontalAlignment: Qt.platform.os === "osx" ? Qt.AlignRight : Qt.AlignLeft
  57. property int verticalAlignment: Qt.AlignVCenter
  58. property alias font: styleitem.font
  59. property color foregroundColor: SystemPaletteSingleton.text(control.enabled)
  60. property color backgroundColor: SystemPaletteSingleton.base(control.enabled)
  61. property color selectionColor: SystemPaletteSingleton.highlight(control.enabled)
  62. property color selectedTextColor: SystemPaletteSingleton.highlightedText(control.enabled)
  63. property int topPadding: edit.anchors.topMargin
  64. property int leftPadding: 3 + edit.anchors.leftMargin
  65. property int rightPadding: 3 + edit.anchors.rightMargin
  66. property int bottomPadding: edit.anchors.bottomMargin
  67. width: 100
  68. height: styleitem.implicitHeight
  69. implicitWidth: 2 + styleitem.implicitWidth
  70. implicitHeight: styleitem.implicitHeight
  71. baselineOffset: styleitem.baselineOffset
  72. Item {
  73. id: edit
  74. anchors.fill: parent
  75. FocusFrame {
  76. anchors.fill: parent
  77. focusMargin:-6
  78. visible: spinbox.activeFocus && styleitem.styleHint("focuswidget")
  79. }
  80. }
  81. function updateRect() {
  82. style.upRect = styleitem.subControlRect("up");
  83. style.downRect = styleitem.subControlRect("down");
  84. var inputRect = styleitem.subControlRect("edit");
  85. edit.anchors.topMargin = inputRect.y
  86. edit.anchors.leftMargin = inputRect.x
  87. edit.anchors.rightMargin = style.width - inputRect.width - edit.anchors.leftMargin
  88. edit.anchors.bottomMargin = style.height - inputRect.height - edit.anchors.topMargin
  89. }
  90. Component.onCompleted: updateRect()
  91. onWidthChanged: updateRect()
  92. onHeightChanged: updateRect()
  93. StyleItem {
  94. id: styleitem
  95. elementType: "spinbox"
  96. anchors.fill: parent
  97. sunken: (styleData.downEnabled && styleData.downPressed) || (styleData.upEnabled && styleData.upPressed)
  98. hover: control.hovered
  99. hints: control.styleHints
  100. hasFocus: control.activeFocus
  101. enabled: control.enabled
  102. value: (styleData.upPressed ? 1 : 0) |
  103. (styleData.downPressed ? 1<<1 : 0) |
  104. (styleData.upEnabled ? (1<<2) : 0) |
  105. (styleData.downEnabled ? (1<<3) : 0)
  106. contentWidth: styleData.contentWidth
  107. contentHeight: styleData.contentHeight
  108. textureHeight: implicitHeight
  109. border {top: 6 ; bottom: 6}
  110. }
  111. }
  112. }