RadioButtonStyle.qml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 RadioButtonStyle
  44. \inqmlmodule QtQuick.Controls.Styles
  45. \since 5.1
  46. \ingroup controlsstyling
  47. \brief Provides custom styling for RadioButton.
  48. Example:
  49. \qml
  50. RadioButton {
  51. text: "Radio Button"
  52. style: RadioButtonStyle {
  53. indicator: Rectangle {
  54. implicitWidth: 16
  55. implicitHeight: 16
  56. radius: 9
  57. border.color: control.activeFocus ? "darkblue" : "gray"
  58. border.width: 1
  59. Rectangle {
  60. anchors.fill: parent
  61. visible: control.checked
  62. color: "#555"
  63. radius: 9
  64. anchors.margins: 4
  65. }
  66. }
  67. }
  68. }
  69. \endqml
  70. */
  71. Style {
  72. id: radiobuttonStyle
  73. /*! The \l RadioButton this style is attached to. */
  74. readonly property RadioButton control: __control
  75. /*! This defines the text label. */
  76. property Component label: Item {
  77. implicitWidth: text.implicitWidth + 2
  78. implicitHeight: text.implicitHeight
  79. baselineOffset: text.y + text.baselineOffset
  80. Rectangle {
  81. anchors.fill: text
  82. anchors.margins: -1
  83. anchors.leftMargin: -3
  84. anchors.rightMargin: -3
  85. visible: control.activeFocus
  86. height: 6
  87. radius: 3
  88. color: "#224f9fef"
  89. border.color: "#47b"
  90. opacity: 0.6
  91. }
  92. Text {
  93. id: text
  94. text: StyleHelpers.stylizeMnemonics(control.text)
  95. anchors.centerIn: parent
  96. color: SystemPaletteSingleton.text(control.enabled)
  97. renderType: Settings.isMobile ? Text.QtRendering : Text.NativeRendering
  98. }
  99. }
  100. /*! The background under indicator and label. */
  101. property Component background
  102. /*! The spacing between indicator and label. */
  103. property int spacing: Math.round(TextSingleton.implicitHeight/4)
  104. /*! This defines the indicator button. */
  105. property Component indicator: Rectangle {
  106. width: Math.round(TextSingleton.implicitHeight)
  107. height: width
  108. gradient: Gradient {
  109. GradientStop {color: "#eee" ; position: 0}
  110. GradientStop {color: control.pressed ? "#eee" : "#fff" ; position: 0.4}
  111. GradientStop {color: "#fff" ; position: 1}
  112. }
  113. border.color: control.activeFocus ? "#16c" : "gray"
  114. antialiasing: true
  115. radius: height/2
  116. Rectangle {
  117. anchors.centerIn: parent
  118. width: Math.round(parent.width * 0.5)
  119. height: width
  120. gradient: Gradient {
  121. GradientStop {color: "#999" ; position: 0}
  122. GradientStop {color: "#555" ; position: 1}
  123. }
  124. border.color: "#222"
  125. antialiasing: true
  126. radius: height/2
  127. Behavior on opacity {NumberAnimation {duration: 80}}
  128. opacity: control.checked ? control.enabled ? 1 : 0.5 : 0
  129. }
  130. }
  131. /*! \internal */
  132. property Component panel: Item {
  133. implicitWidth: Math.max(backgroundLoader.implicitWidth, row.implicitWidth + padding.left + padding.right)
  134. implicitHeight: Math.max(backgroundLoader.implicitHeight, labelLoader.implicitHeight + padding.top + padding.bottom,indicatorLoader.implicitHeight + padding.top + padding.bottom)
  135. baselineOffset: labelLoader.item ? padding.top + labelLoader.item.baselineOffset : 0
  136. Loader {
  137. id:backgroundLoader
  138. sourceComponent: background
  139. anchors.fill: parent
  140. }
  141. Row {
  142. id: row
  143. anchors.fill: parent
  144. anchors.leftMargin: padding.left
  145. anchors.rightMargin: padding.right
  146. anchors.topMargin: padding.top
  147. anchors.bottomMargin: padding.bottom
  148. spacing: radiobuttonStyle.spacing
  149. Loader {
  150. id: indicatorLoader
  151. sourceComponent: indicator
  152. }
  153. Loader {
  154. id: labelLoader
  155. sourceComponent: label
  156. }
  157. }
  158. }
  159. }