TextFieldStyle.qml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 TextFieldStyle
  44. \inqmlmodule QtQuick.Controls.Styles
  45. \since 5.1
  46. \ingroup controlsstyling
  47. \brief Provides custom styling for TextField.
  48. Example:
  49. \qml
  50. TextField {
  51. style: TextFieldStyle {
  52. textColor: "black"
  53. background: Rectangle {
  54. radius: 2
  55. implicitWidth: 100
  56. implicitHeight: 24
  57. border.color: "#333"
  58. border.width: 1
  59. }
  60. }
  61. }
  62. \endqml
  63. */
  64. Style {
  65. id: style
  66. /*! The \l TextField this style is attached to. */
  67. readonly property TextField control: __control
  68. /*! The content margins of the text field. */
  69. padding { top: 4 ; left: Math.round(control.__contentHeight/3) ; right: control.__contentHeight/3 ; bottom: 4 }
  70. /*! The current font. */
  71. property font font
  72. /*! The text color. */
  73. property color textColor: SystemPaletteSingleton.text(control.enabled)
  74. /*! The text highlight color, used behind selections. */
  75. property color selectionColor: SystemPaletteSingleton.highlight(control.enabled)
  76. /*! The highlighted text color, used in selections. */
  77. property color selectedTextColor: SystemPaletteSingleton.highlightedText(control.enabled)
  78. /*!
  79. \qmlproperty string passwordCharacter
  80. \since QtQuick.Controls.Styles 1.4
  81. The password character that is displayed when echoMode
  82. on the TextField is set to TextInput.Password or
  83. TextInput.PasswordEchoOnEdit.
  84. */
  85. property string passwordCharacter: Qt.styleHints.passwordMaskCharacter
  86. /*!
  87. \qmlproperty enumeration renderType
  88. \since QtQuick.Controls.Styles 1.1
  89. Override the default rendering type for the control.
  90. Supported render types are:
  91. \list
  92. \li Text.QtRendering
  93. \li Text.NativeRendering
  94. \endlist
  95. The default value is platform dependent.
  96. \sa Text::renderType
  97. */
  98. property int renderType: Settings.isMobile ? Text.QtRendering : Text.NativeRendering
  99. /*! The placeholder text color, used when the text field is empty.
  100. \since QtQuick.Controls.Styles 1.1
  101. */
  102. property color placeholderTextColor: Qt.rgba(0, 0, 0, 0.5)
  103. /*! The background of the text field. */
  104. property Component background: Item {
  105. Rectangle {
  106. anchors.fill: parent
  107. anchors.bottomMargin: -1
  108. color: "#44ffffff"
  109. radius: baserect.radius
  110. }
  111. Rectangle {
  112. id: baserect
  113. gradient: Gradient {
  114. GradientStop {color: "#e0e0e0" ; position: 0}
  115. GradientStop {color: "#fff" ; position: 0.1}
  116. GradientStop {color: "#fff" ; position: 1}
  117. }
  118. radius: control.__contentHeight * 0.16
  119. anchors.fill: parent
  120. border.color: control.activeFocus ? "#47b" : "#999"
  121. }
  122. }
  123. /*! \internal */
  124. property Component panel: Item {
  125. anchors.fill: parent
  126. property int topMargin: padding.top
  127. property int leftMargin: padding.left
  128. property int rightMargin: padding.right
  129. property int bottomMargin: padding.bottom
  130. property color textColor: style.textColor
  131. property color selectionColor: style.selectionColor
  132. property color selectedTextColor: style.selectedTextColor
  133. implicitWidth: backgroundLoader.implicitWidth || Math.round(control.__contentHeight * 8)
  134. implicitHeight: backgroundLoader.implicitHeight || Math.max(25, Math.round(control.__contentHeight * 1.2))
  135. baselineOffset: padding.top + control.__baselineOffset
  136. property color placeholderTextColor: style.placeholderTextColor
  137. property font font: style.font
  138. Loader {
  139. id: backgroundLoader
  140. sourceComponent: background
  141. anchors.fill: parent
  142. }
  143. }
  144. /*! \internal
  145. The cursor handle.
  146. \since QtQuick.Controls.Styles 1.3
  147. The parent of the handle is positioned to the top left corner of
  148. the cursor position. The interactive area is determined by the
  149. geometry of the handle delegate.
  150. The following signals and read-only properties are available within the scope
  151. of the handle delegate:
  152. \table
  153. \row \li \b {styleData.activated()} [signal] \li Emitted when the handle is activated ie. the editor is clicked.
  154. \row \li \b {styleData.pressed} : bool \li Whether the handle is pressed.
  155. \row \li \b {styleData.position} : int \li The character position of the handle.
  156. \row \li \b {styleData.lineHeight} : real \li The height of the line the handle is on.
  157. \row \li \b {styleData.hasSelection} : bool \li Whether the editor has selected text.
  158. \endtable
  159. */
  160. property Component __cursorHandle
  161. /*! \internal
  162. The selection handle.
  163. \since QtQuick.Controls.Styles 1.3
  164. The parent of the handle is positioned to the top left corner of
  165. the first selected character. The interactive area is determined
  166. by the geometry of the handle delegate.
  167. The following signals and read-only properties are available within the scope
  168. of the handle delegate:
  169. \table
  170. \row \li \b {styleData.activated()} [signal] \li Emitted when the handle is activated ie. the editor is clicked.
  171. \row \li \b {styleData.pressed} : bool \li Whether the handle is pressed.
  172. \row \li \b {styleData.position} : int \li The character position of the handle.
  173. \row \li \b {styleData.lineHeight} : real \li The height of the line the handle is on.
  174. \row \li \b {styleData.hasSelection} : bool \li Whether the editor has selected text.
  175. \endtable
  176. */
  177. property Component __selectionHandle
  178. /*! \internal
  179. The cursor delegate.
  180. \since QtQuick.Controls.Styles 1.3
  181. */
  182. property Component __cursorDelegate
  183. /*! \internal
  184. The delegate for the cut/copy/paste menu.
  185. \since QtQuick.Controls.Styles 1.4
  186. */
  187. property Component __editMenu
  188. }