CircularGauge.qml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. // Workaround for QTBUG-37751; we need this import for RangeModel, although we shouldn't.
  41. import QtQuick.Controls 1.4
  42. import QtQuick.Controls.Styles 1.4
  43. import QtQuick.Controls.Private 1.0
  44. import QtQuick.Extras.Private 1.0
  45. /*!
  46. \qmltype CircularGauge
  47. \inqmlmodule QtQuick.Extras
  48. \since 5.5
  49. \ingroup extras
  50. \ingroup extras-non-interactive
  51. \brief A gauge that displays a value within a range along an arc.
  52. \image circulargauge.png CircularGauge
  53. The CircularGauge is similar to traditional mechanical gauges that use a
  54. needle to display a value from some input, such as the speed of a vehicle or
  55. air pressure, for example.
  56. The minimum and maximum values displayable by the gauge can be set with the
  57. \l minimumValue and \l maximumValue properties. The angle at which these
  58. values are displayed can be set with the
  59. \l {CircularGaugeStyle::}{minimumValueAngle} and
  60. \l {CircularGaugeStyle::}{maximumValueAngle} properties of
  61. \l {CircularGaugeStyle}.
  62. Example:
  63. \code
  64. CircularGauge {
  65. value: accelerating ? maximumValue : 0
  66. anchors.centerIn: parent
  67. property bool accelerating: false
  68. Keys.onSpacePressed: accelerating = true
  69. Keys.onReleased: {
  70. if (event.key === Qt.Key_Space) {
  71. accelerating = false;
  72. event.accepted = true;
  73. }
  74. }
  75. Component.onCompleted: forceActiveFocus()
  76. Behavior on value {
  77. NumberAnimation {
  78. duration: 1000
  79. }
  80. }
  81. }
  82. \endcode
  83. You can create a custom appearance for a CircularGauge by assigning a
  84. \l {CircularGaugeStyle}.
  85. */
  86. Control {
  87. id: circularGauge
  88. style: Settings.styleComponent(Settings.style, "CircularGaugeStyle.qml", circularGauge)
  89. /*!
  90. \qmlproperty real CircularGauge::minimumValue
  91. This property holds the smallest value displayed by the gauge.
  92. */
  93. property alias minimumValue: range.minimumValue
  94. /*!
  95. \qmlproperty real CircularGauge::maximumValue
  96. This property holds the largest value displayed by the gauge.
  97. */
  98. property alias maximumValue: range.maximumValue
  99. /*!
  100. This property holds the current value displayed by the gauge, which will
  101. always be between \l minimumValue and \l maximumValue, inclusive.
  102. */
  103. property alias value: range.value
  104. /*!
  105. \qmlproperty real CircularGauge::stepSize
  106. This property holds the size of the value increments that the needle
  107. displays.
  108. For example, when stepSize is \c 10 and value is \c 0, adding \c 5 to
  109. \l value will have no visible effect on the needle, although \l value
  110. will still be incremented. Adding an extra \c 5 to \l value will then
  111. cause the needle to point to \c 10.
  112. */
  113. property alias stepSize: range.stepSize
  114. /*!
  115. This property determines whether or not the gauge displays tickmarks,
  116. minor tickmarks, and labels.
  117. For more fine-grained control over what is displayed, the following
  118. style components of
  119. \l CircularGaugeStyle can be
  120. used:
  121. \list
  122. \li \l {CircularGaugeStyle::}{tickmark}
  123. \li \l {CircularGaugeStyle::}{minorTickmark}
  124. \li \l {CircularGaugeStyle::}{tickmarkLabel}
  125. \endlist
  126. */
  127. property bool tickmarksVisible: true
  128. RangeModel {
  129. id: range
  130. minimumValue: 0
  131. maximumValue: 100
  132. stepSize: 0
  133. value: minimumValue
  134. }
  135. }