2
0

PwmPoint.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. import QtQuick 2.4
  20. import QtQuick.Layouts 1.2
  21. import QtQuick.Controls 1.4
  22. import QtQml 2.2
  23. import "../scripts/units.js" as Units
  24. Rectangle {
  25. property Item background: parent
  26. property point center: Qt.point(x + width / 2, y + height / 2);
  27. readonly property real centerX: x + width / 2
  28. readonly property real centerY: y + height / 2
  29. property alias drag: pwmMouse.drag
  30. property int size: 10
  31. property int unit: 0
  32. property var locale: Qt.locale()
  33. signal positionChanged()
  34. id: root
  35. width: size
  36. height: size
  37. radius: size / 2
  38. border.width: pwmMouse.containsMouse || drag.active ? 1 : 0
  39. onXChanged: positionChanged()
  40. onYChanged: positionChanged()
  41. Drag.dragType: Drag.Automatic
  42. MouseArea {
  43. id: pwmMouse
  44. anchors.fill: parent
  45. hoverEnabled: root.enabled ? true : false
  46. drag.target: root
  47. drag.axis: Drag.XAndYAxis
  48. drag.smoothed: false
  49. drag.minimumX: - root.width/2
  50. drag.maximumX: background.width - root.width/2
  51. drag.minimumY: - root.height/2
  52. drag.maximumY: background.height - root.height/2
  53. }
  54. Rectangle {
  55. id: tooltip
  56. x: parent.width
  57. y: - height
  58. width: Math.max(pwm.width, temp.width)
  59. height: pwm.height + temp.height
  60. radius: 4
  61. color: Qt.rgba(parent.color.r, parent.color.g, parent.color.b, 0.5)
  62. visible: root.enabled && (pwmMouse.containsMouse || drag.active)
  63. Column {
  64. Label {
  65. id: pwm
  66. font.pixelSize: root.size * 1.5
  67. text: Number(Math.round(background.scalePwm(root.centerY)) / 2.55).toLocaleString(locale, 'f', 1) + '%'
  68. }
  69. Label {
  70. property string suffix: (unit == 0) ? "°C" : (unit == 1) ? "K" : "°F"
  71. id: temp
  72. font.pixelSize: root.size * 1.5
  73. text: Units.fromCelsius(Math.round(background.scaleTemp(root.centerX)), unit) + suffix
  74. }
  75. }
  76. }
  77. }