Gauge.qml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 QtQuick.Controls 1.4
  41. import QtQuick.Controls.Styles 1.4
  42. import QtQuick.Controls.Private 1.0
  43. import QtQuick.Extras 1.4
  44. import QtQuick.Extras.Private 1.0
  45. /*!
  46. \qmltype Gauge
  47. \inqmlmodule QtQuick.Extras
  48. \since 5.5
  49. \ingroup extras
  50. \ingroup extras-non-interactive
  51. \brief A straight gauge that displays a value within a range.
  52. \image gauge.png Gauge
  53. The Gauge control displays a value within some range along a horizontal or
  54. vertical axis. It can be thought of as an extension of ProgressBar,
  55. providing tickmarks and labels to provide a visual measurement of the
  56. progress.
  57. The minimum and maximum values displayable by the gauge can be set with the
  58. \l minimumValue and \l maximumValue properties.
  59. Example:
  60. \code
  61. Gauge {
  62. minimumValue: 0
  63. value: 50
  64. maximumValue: 100
  65. anchors.centerIn: parent
  66. }
  67. \endcode
  68. You can create a custom appearance for a Gauge by assigning a
  69. \l {GaugeStyle}.
  70. */
  71. Control {
  72. id: gauge
  73. style: Settings.styleComponent(Settings.style, "GaugeStyle.qml", gauge)
  74. /*!
  75. This property holds the smallest value displayed by the gauge.
  76. The default value is \c 0.
  77. */
  78. property alias minimumValue: range.minimumValue
  79. /*!
  80. This property holds the value displayed by the gauge.
  81. The default value is \c 0.
  82. */
  83. property alias value: range.value
  84. /*!
  85. This property holds the largest value displayed by the gauge.
  86. The default value is \c 100.
  87. */
  88. property alias maximumValue: range.maximumValue
  89. /*!
  90. This property determines the orientation of the gauge.
  91. The default value is \c Qt.Vertical.
  92. */
  93. property int orientation: Qt.Vertical
  94. /*!
  95. This property determines the alignment of each tickmark within the
  96. gauge. When \l orientation is \c Qt.Vertical, the valid values are:
  97. \list
  98. \li Qt.AlignLeft
  99. \li Qt.AlignRight
  100. \endlist
  101. Any other value will cause \c Qt.AlignLeft to be used, which is also the
  102. default value for this orientation.
  103. When \l orientation is \c Qt.Horizontal, the valid values are:
  104. \list
  105. \li Qt.AlignTop
  106. \li Qt.AlignBottom
  107. \endlist
  108. Any other value will cause \c Qt.AlignBottom to be used, which is also
  109. the default value for this orientation.
  110. */
  111. property int tickmarkAlignment: orientation == Qt.Vertical ? Qt.AlignLeft : Qt.AlignBottom
  112. property int __tickmarkAlignment: {
  113. if (orientation == Qt.Vertical) {
  114. return (tickmarkAlignment == Qt.AlignLeft || tickmarkAlignment == Qt.AlignRight) ? tickmarkAlignment : Qt.AlignLeft;
  115. }
  116. return (tickmarkAlignment == Qt.AlignTop || tickmarkAlignment == Qt.AlignBottom) ? tickmarkAlignment : Qt.AlignBottom;
  117. }
  118. /*!
  119. \internal
  120. TODO: finish this
  121. This property determines whether or not the tickmarks and their labels
  122. are drawn inside (over) the gauge. The value of this property affects
  123. \l tickmarkAlignment.
  124. */
  125. property bool __tickmarksInside: false
  126. /*!
  127. This property determines the rate at which tickmarks are drawn on the
  128. gauge. The lower the value, the more often tickmarks are drawn.
  129. The default value is \c 10.
  130. */
  131. property real tickmarkStepSize: 10
  132. /*!
  133. This property determines the amount of minor tickmarks drawn between
  134. each regular tickmark.
  135. The default value is \c 4.
  136. */
  137. property int minorTickmarkCount: 4
  138. /*!
  139. \qmlproperty font Gauge::font
  140. The font to use for the tickmark text.
  141. */
  142. property alias font: hiddenText.font
  143. /*!
  144. This property accepts a function that formats the given \a value for
  145. display in
  146. \l {GaugeStyle::}{tickmarkLabel}.
  147. For example, to provide a custom format that displays all values with 3
  148. decimal places:
  149. \code
  150. formatValue: function(value) {
  151. return value.toFixed(3);
  152. }
  153. \endcode
  154. The default function does no formatting.
  155. */
  156. property var formatValue: function(value) {
  157. return value;
  158. }
  159. property alias __hiddenText: hiddenText
  160. Text {
  161. id: hiddenText
  162. text: formatValue(maximumValue)
  163. visible: false
  164. }
  165. RangeModel {
  166. id: range
  167. minimumValue: 0
  168. value: 0
  169. maximumValue: 100
  170. }
  171. }