PwmPoint.qml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.Controls 1.4
  21. import "units.js" as Units
  22. Rectangle {
  23. id: root
  24. property Item background: parent
  25. readonly property real centerX: x + width / 2
  26. readonly property real centerY: y + height / 2
  27. readonly property point center: Qt.point(centerX, centerY)
  28. property alias drag: pwmMouse.drag
  29. property int size: 10
  30. property string unit: "°C"
  31. property var locale: Qt.locale()
  32. signal positionChanged()
  33. width: size
  34. height: size
  35. radius: size / 2
  36. border.width: pwmMouse.containsMouse || drag.active ? 1 : 0
  37. onXChanged: positionChanged()
  38. onYChanged: positionChanged()
  39. Drag.dragType: Drag.Automatic
  40. MouseArea {
  41. id: pwmMouse
  42. anchors.fill: parent
  43. hoverEnabled: root.enabled ? true : false
  44. cursorShape: containsPress || drag.active ? Qt.DragMoveCursor : Qt.PointingHandCursor
  45. drag.target: root
  46. drag.axis: Drag.XAndYAxis
  47. drag.smoothed: false
  48. drag.minimumX: - root.width/2
  49. drag.maximumX: background.width - root.width/2
  50. drag.minimumY: - root.height/2
  51. drag.maximumY: background.height - root.height/2
  52. }
  53. Rectangle {
  54. id: tooltip
  55. x: parent.width
  56. y: - height
  57. width: Math.max(pwm.width, temp.width)
  58. height: pwm.height + temp.height
  59. radius: 4
  60. color: Qt.rgba(parent.color.r, parent.color.g, parent.color.b, 0.5)
  61. visible: root.enabled && (pwmMouse.containsMouse || drag.active)
  62. Column {
  63. Label {
  64. id: pwm
  65. font.pixelSize: root.size * 1.5
  66. text: Number(Math.round(background.scalePwm(root.centerY)) / 2.55).toLocaleString(locale, 'f', 1) + i18n('%')
  67. }
  68. Label {
  69. id: temp
  70. font.pixelSize: root.size * 1.5
  71. text: Math.round(Units.fromCelsius(background.scaleTemp(root.centerX)), unit) + i18n(unit)
  72. }
  73. }
  74. }
  75. }