DelayButtonStyle.qml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 Extras 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 QtGraphicalEffects 1.0
  41. import QtQuick.Controls.Styles 1.4
  42. import QtQuick.Extras 1.4
  43. import QtQuick.Extras.Private.CppUtils 1.1
  44. /*!
  45. \qmltype DelayButtonStyle
  46. \inqmlmodule QtQuick.Controls.Styles
  47. \since 5.5
  48. \ingroup controlsstyling
  49. \brief Provides custom styling for DelayButton.
  50. You can create a custom DelayButton by replacing the following delegates:
  51. \list
  52. \li \l foreground
  53. \li \l {ButtonStyle::}{label}
  54. \endlist
  55. */
  56. CircularButtonStyle {
  57. id: delayButtonStyle
  58. /*!
  59. The \l DelayButton that this style is attached to.
  60. */
  61. readonly property DelayButton control: __control
  62. /*!
  63. The gradient of the progress bar around the button.
  64. */
  65. property Gradient progressBarGradient: Gradient {
  66. GradientStop {
  67. position: 0
  68. color: "#ff6666"
  69. }
  70. GradientStop {
  71. position: 1
  72. color: "#ff0000"
  73. }
  74. }
  75. /*!
  76. The color of the drop shadow under the progress bar.
  77. */
  78. property color progressBarDropShadowColor: "#ff6666"
  79. background: Item {
  80. implicitWidth: __buttonHelper.implicitWidth
  81. implicitHeight: __buttonHelper.implicitHeight
  82. Canvas {
  83. id: backgroundCanvas
  84. anchors.fill: parent
  85. Connections {
  86. target: control
  87. function onPressedChanged() { backgroundCanvas.requestPaint() }
  88. function onCheckedChanged() { backgroundCanvas.requestPaint() }
  89. }
  90. onPaint: {
  91. var ctx = getContext("2d");
  92. __buttonHelper.paintBackground(ctx);
  93. }
  94. }
  95. }
  96. /*!
  97. The foreground of the button.
  98. The progress bar is drawn here.
  99. */
  100. property Component foreground: Item {
  101. id: foregroundItem
  102. state: "normal"
  103. states: [
  104. State {
  105. name: "normal"
  106. PropertyChanges {
  107. target: foregroundItem
  108. opacity: 1
  109. }
  110. },
  111. State {
  112. name: "activated"
  113. }
  114. ]
  115. transitions: [
  116. Transition {
  117. from: "normal"
  118. to: "activated"
  119. SequentialAnimation {
  120. loops: Animation.Infinite
  121. NumberAnimation {
  122. target: foregroundItem
  123. property: "opacity"
  124. from: 0.8
  125. to: 0
  126. duration: 500
  127. easing.type: Easing.InOutSine
  128. }
  129. NumberAnimation {
  130. target: foregroundItem
  131. property: "opacity"
  132. from: 0
  133. to: 0.8
  134. duration: 500
  135. easing.type: Easing.InOutSine
  136. }
  137. }
  138. }
  139. ]
  140. Connections {
  141. target: control
  142. function onActivated() { state = "activated" }
  143. function onCheckedChanged() { if (!control.checked) state = "normal" }
  144. }
  145. CircularProgressBar {
  146. id: progressBar
  147. visible: false
  148. width: Math.min(parent.width, parent.height) + progressBarDropShadow.radius * 3 * 2
  149. height: width
  150. anchors.centerIn: parent
  151. antialiasing: true
  152. barWidth: __buttonHelper.outerArcLineWidth
  153. inset: progressBarDropShadow.radius * 3
  154. minimumValueAngle: -180
  155. maximumValueAngle: 180
  156. progress: control.progress
  157. // TODO: Add gradient property if/when we drop support for building with 5.1.
  158. function updateGradient() {
  159. clearStops();
  160. for (var i = 0; i < progressBarGradient.stops.length; ++i) {
  161. addStop(progressBarGradient.stops[i].position, progressBarGradient.stops[i].color);
  162. }
  163. }
  164. Component.onCompleted: updateGradient()
  165. Connections {
  166. target: delayButtonStyle
  167. function onProgressBarGradientChanged() { progressBar.updateGradient() }
  168. }
  169. }
  170. DropShadow {
  171. id: progressBarDropShadow
  172. anchors.fill: progressBar
  173. // QTBUG-33747
  174. // cached: !control.pressed
  175. color: progressBarDropShadowColor
  176. source: progressBar
  177. }
  178. }
  179. panel: Item {
  180. implicitWidth: backgroundLoader.implicitWidth
  181. implicitHeight: backgroundLoader.implicitHeight
  182. Loader {
  183. id: backgroundLoader
  184. anchors.fill: parent
  185. sourceComponent: background
  186. }
  187. Loader {
  188. id: foregroundLoader
  189. anchors.fill: parent
  190. sourceComponent: foreground
  191. }
  192. Loader {
  193. id: labelLoader
  194. sourceComponent: label
  195. anchors.fill: parent
  196. anchors.leftMargin: padding.left
  197. anchors.topMargin: padding.top
  198. anchors.rightMargin: padding.right
  199. anchors.bottomMargin: padding.bottom
  200. }
  201. }
  202. }