SpinBoxStyle.qml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. /*!
  43. \qmltype SpinBoxStyle
  44. \inqmlmodule QtQuick.Controls.Styles
  45. \since 5.2
  46. \ingroup controlsstyling
  47. \brief Provides custom styling for SpinBox.
  48. Example:
  49. \qml
  50. SpinBox {
  51. style: SpinBoxStyle{
  52. background: Rectangle {
  53. implicitWidth: 100
  54. implicitHeight: 20
  55. border.color: "gray"
  56. radius: 2
  57. }
  58. }
  59. }
  60. \endqml
  61. */
  62. Style {
  63. id: spinboxStyle
  64. /*! The \l SpinBox this style is attached to. */
  65. readonly property SpinBox control: __control
  66. /*! The content margins of the text field. */
  67. padding { top: 1 ; left: Math.round(styleData.contentHeight/2) ; right: Math.max(22, Math.round(styleData.contentHeight)) ; bottom: 0 }
  68. /*! \qmlproperty enumeration horizontalAlignment
  69. This property defines the default text aligment.
  70. The supported values are:
  71. \list
  72. \li Qt.AlignLeft
  73. \li Qt.AlignHCenter
  74. \li Qt.AlignRight
  75. \endlist
  76. The default value is Qt.AlignRight
  77. */
  78. property int horizontalAlignment: Qt.AlignRight
  79. /*! The text color. */
  80. property color textColor: SystemPaletteSingleton.text(control.enabled)
  81. /*! The text highlight color, used behind selections. */
  82. property color selectionColor: SystemPaletteSingleton.highlight(control.enabled)
  83. /*! The highlighted text color, used in selections. */
  84. property color selectedTextColor: SystemPaletteSingleton.highlightedText(control.enabled)
  85. /*!
  86. \qmlproperty enumeration renderType
  87. Override the default rendering type for the control.
  88. Supported render types are:
  89. \list
  90. \li Text.QtRendering
  91. \li Text.NativeRendering
  92. \endlist
  93. The default value is platform dependent.
  94. \sa Text::renderType
  95. */
  96. property int renderType: Settings.isMobile ? Text.QtRendering : Text.NativeRendering
  97. /*!
  98. \since QtQuick.Controls.Styles 1.3
  99. The font of the control.
  100. */
  101. property font font
  102. /*! The button used to increment the value. */
  103. property Component incrementControl: Item {
  104. implicitWidth: padding.right
  105. Image {
  106. source: "images/arrow-up.png"
  107. anchors.centerIn: parent
  108. anchors.verticalCenterOffset: 1
  109. opacity: control.enabled ? (styleData.upPressed ? 1 : 0.6) : 0.5
  110. }
  111. }
  112. /*! The button used to decrement the value. */
  113. property Component decrementControl: Item {
  114. implicitWidth: padding.right
  115. Image {
  116. source: "images/arrow-down.png"
  117. anchors.centerIn: parent
  118. anchors.verticalCenterOffset: -2
  119. opacity: control.enabled ? (styleData.downPressed ? 1 : 0.6) : 0.5
  120. }
  121. }
  122. /*! The background of the SpinBox. */
  123. property Component background: Item {
  124. implicitHeight: Math.max(25, Math.round(styleData.contentHeight * 1.2))
  125. implicitWidth: styleData.contentWidth + padding.left + padding.right
  126. baselineOffset: control.__baselineOffset
  127. Rectangle {
  128. anchors.fill: parent
  129. anchors.bottomMargin: -1
  130. color: "#44ffffff"
  131. radius: baserect.radius
  132. }
  133. Rectangle {
  134. id: baserect
  135. gradient: Gradient {
  136. GradientStop {color: "#eee" ; position: 0}
  137. GradientStop {color: "#fff" ; position: 0.1}
  138. GradientStop {color: "#fff" ; position: 1}
  139. }
  140. radius: control.font.pixelSize * 0.16
  141. anchors.fill: parent
  142. border.color: control.activeFocus ? "#47b" : "#999"
  143. }
  144. }
  145. /*! \internal */
  146. property Component panel: Item {
  147. id: styleitem
  148. implicitWidth: backgroundLoader.implicitWidth
  149. implicitHeight: backgroundLoader.implicitHeight
  150. baselineOffset: backgroundLoader.item ? backgroundLoader.item.baselineOffset : 0
  151. property font font: spinboxStyle.font
  152. property color foregroundColor: spinboxStyle.textColor
  153. property color selectionColor: spinboxStyle.selectionColor
  154. property color selectedTextColor: spinboxStyle.selectedTextColor
  155. property var margins: spinboxStyle.padding
  156. property rect upRect: Qt.rect(width - incrementControlLoader.implicitWidth, 0, incrementControlLoader.implicitWidth, height / 2 + 1)
  157. property rect downRect: Qt.rect(width - decrementControlLoader.implicitWidth, height / 2, decrementControlLoader.implicitWidth, height / 2)
  158. property int horizontalAlignment: spinboxStyle.horizontalAlignment
  159. property int verticalAlignment: Qt.AlignVCenter
  160. Loader {
  161. id: backgroundLoader
  162. anchors.fill: parent
  163. sourceComponent: background
  164. }
  165. Loader {
  166. id: incrementControlLoader
  167. x: upRect.x
  168. y: upRect.y
  169. width: upRect.width
  170. height: upRect.height
  171. sourceComponent: incrementControl
  172. }
  173. Loader {
  174. id: decrementControlLoader
  175. x: downRect.x
  176. y: downRect.y
  177. width: downRect.width
  178. height: downRect.height
  179. sourceComponent: decrementControl
  180. }
  181. }
  182. /*! \internal
  183. The cursor handle.
  184. \since QtQuick.Controls.Styles 1.3
  185. The parent of the handle is positioned to the top left corner of
  186. the cursor position. The interactive area is determined by the
  187. geometry of the handle delegate.
  188. The following signals and read-only properties are available within the scope
  189. of the handle delegate:
  190. \table
  191. \row \li \b {styleData.activated()} [signal] \li Emitted when the handle is activated ie. the editor is clicked.
  192. \row \li \b {styleData.pressed} : bool \li Whether the handle is pressed.
  193. \row \li \b {styleData.position} : int \li The character position of the handle.
  194. \row \li \b {styleData.lineHeight} : real \li The height of the line the handle is on.
  195. \row \li \b {styleData.hasSelection} : bool \li Whether the editor has selected text.
  196. \endtable
  197. */
  198. property Component __cursorHandle
  199. /*! \internal
  200. The selection handle.
  201. \since QtQuick.Controls.Styles 1.3
  202. The parent of the handle is positioned to the top left corner of
  203. the first selected character. The interactive area is determined
  204. by the geometry of the handle delegate.
  205. The following signals and read-only properties are available within the scope
  206. of the handle delegate:
  207. \table
  208. \row \li \b {styleData.activated()} [signal] \li Emitted when the handle is activated ie. the editor is clicked.
  209. \row \li \b {styleData.pressed} : bool \li Whether the handle is pressed.
  210. \row \li \b {styleData.position} : int \li The character position of the handle.
  211. \row \li \b {styleData.lineHeight} : real \li The height of the line the handle is on.
  212. \row \li \b {styleData.hasSelection} : bool \li Whether the editor has selected text.
  213. \endtable
  214. */
  215. property Component __selectionHandle
  216. /*! \internal
  217. The cursor delegate.
  218. \since QtQuick.Controls.Styles 1.3
  219. */
  220. property Component __cursorDelegate
  221. }