CircularTickmarkLabel.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.1
  42. import QtQuick.Controls.Private 1.0
  43. import QtQuick.Extras 1.4
  44. import QtQuick.Extras.Private 1.0
  45. Control {
  46. id: label
  47. style: Settings.styleComponent(Settings.style, "CircularTickmarkLabelStyle.qml", label)
  48. property alias minimumValue: range.minimumValue
  49. property alias maximumValue: range.maximumValue
  50. property alias stepSize: range.stepSize
  51. RangeModel {
  52. id: range
  53. minimumValue: 0
  54. maximumValue: 100
  55. stepSize: 0
  56. // Not used.
  57. value: minimumValue
  58. }
  59. /*!
  60. This property determines the angle at which the first tickmark is drawn.
  61. */
  62. property real minimumValueAngle: -145
  63. /*!
  64. This property determines the angle at which the last tickmark is drawn.
  65. */
  66. property real maximumValueAngle: 145
  67. /*!
  68. The range between \l minimumValueAngle and \l maximumValueAngle, in
  69. degrees.
  70. */
  71. readonly property real angleRange: maximumValueAngle - minimumValueAngle
  72. /*!
  73. The interval at which tickmarks are displayed.
  74. */
  75. property real tickmarkStepSize: 10
  76. /*!
  77. The distance in pixels from the outside of the control (outerRadius) at
  78. which the outermost point of the tickmark line is drawn.
  79. */
  80. property real tickmarkInset: 0.0
  81. /*!
  82. The amount of tickmarks displayed.
  83. */
  84. readonly property int tickmarkCount: __tickmarkCount
  85. /*!
  86. The amount of minor tickmarks between each tickmark.
  87. */
  88. property int minorTickmarkCount: 4
  89. /*!
  90. The distance in pixels from the outside of the control (outerRadius) at
  91. which the outermost point of the minor tickmark line is drawn.
  92. */
  93. property real minorTickmarkInset: 0.0
  94. /*!
  95. The distance in pixels from the outside of the control (outerRadius) at
  96. which the center of the value marker text is drawn.
  97. */
  98. property real labelInset: __style.__protectedScope.toPixels(0.19)
  99. /*!
  100. The interval at which tickmark labels are displayed.
  101. */
  102. property real labelStepSize: tickmarkStepSize
  103. /*!
  104. The amount of tickmark labels displayed.
  105. */
  106. readonly property int labelCount: (maximumValue - minimumValue) / labelStepSize + 1
  107. /*! \internal */
  108. readonly property real __tickmarkCount: tickmarkStepSize > 0 ? (maximumValue - minimumValue) / tickmarkStepSize + 1 : 0
  109. /*!
  110. This property determines whether or not the control displays tickmarks,
  111. minor tickmarks, and labels.
  112. */
  113. property bool tickmarksVisible: true
  114. /*!
  115. Returns \a value as an angle in degrees.
  116. For example, if minimumValueAngle is set to \c 270 and maximumValueAngle
  117. is set to \c 90, this function will return \c 270 when passed
  118. minimumValue and \c 90 when passed maximumValue.
  119. */
  120. function valueToAngle(value) {
  121. var normalised = (value - minimumValue) / (maximumValue - minimumValue);
  122. return (maximumValueAngle - minimumValueAngle) * normalised + minimumValueAngle;
  123. }
  124. }