PwmPoint.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 canvas: 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 alias size: root.width
  31. property int unit: 0
  32. id: root
  33. width: 10
  34. height: width
  35. radius: width / 2
  36. border.width: pwmMouse.containsMouse || drag.active ? 1 : 0
  37. onXChanged: parent.requestPaint();
  38. onYChanged: parent.requestPaint();
  39. Drag.dragType: Drag.Automatic
  40. MouseArea {
  41. id: pwmMouse
  42. anchors.fill: parent
  43. hoverEnabled: canvas.minimized ? false : true
  44. drag.target: root
  45. drag.axis: Drag.XAndYAxis
  46. drag.smoothed: false
  47. drag.minimumX: canvas.scaleX(canvas.minTemp) - root.width/2
  48. drag.maximumX: canvas.scaleX(canvas.maxTemp) - root.width/2
  49. drag.minimumY: canvas.scaleY(255) - root.height/2
  50. drag.maximumY: canvas.scaleY(0) - root.height/2
  51. }
  52. Rectangle {
  53. id: tooltip
  54. x: parent.width
  55. y: - height
  56. width: Math.max(pwm.width, temp.width)
  57. height: pwm.height + temp.height
  58. radius: 4
  59. color: Qt.rgba(parent.color.r, parent.color.g, parent.color.b, 0.3)
  60. visible: pwmMouse.containsMouse || drag.active
  61. Column {
  62. Label {
  63. id: pwm
  64. font.pixelSize: root.size * 1.5
  65. text: Number(Units.fromCelsius(canvas.scalePwm(root.centerY) / 2.55)).toLocaleString() + '%'
  66. }
  67. Label {
  68. property string suffix: (unit == 0) ? "°C" : (unit == 1) ? "K" : "°F"
  69. id: temp
  70. font.pixelSize: root.size * 1.5
  71. text: Number(Units.fromCelsius(canvas.scaleTemp(root.centerX), unit)).toLocaleString() + suffix
  72. }
  73. }
  74. }
  75. }