PwmPoint.qml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. Rectangle {
  23. property Item canvas: parent
  24. property point center: Qt.point(x + width / 2, y + height / 2);
  25. readonly property real centerX: x + width / 2
  26. readonly property real centerY: y + height / 2
  27. property alias drag: pwmMouse.drag
  28. property alias size: root.width
  29. id: root
  30. width: 10
  31. height: width
  32. radius: width / 2
  33. border.width: pwmMouse.containsMouse || drag.active ? 1 : 0
  34. onXChanged: parent.requestPaint();
  35. onYChanged: parent.requestPaint();
  36. Drag.dragType: Drag.Automatic
  37. MouseArea {
  38. id: pwmMouse
  39. anchors.fill: parent
  40. hoverEnabled: canvas.minimized ? false : true
  41. drag.target: root
  42. drag.axis: Drag.XAndYAxis
  43. drag.smoothed: false
  44. drag.minimumX: canvas.scaleX(canvas.minTemp) - root.width/2
  45. drag.maximumX: canvas.scaleX(canvas.maxTemp) - root.width/2
  46. drag.minimumY: canvas.scaleY(255) - root.height/2
  47. drag.maximumY: canvas.scaleY(0) - root.height/2
  48. }
  49. Rectangle {
  50. id: tooltip
  51. x: parent.width
  52. y: - height
  53. width: Math.max(pwm.width, temp.width)
  54. height: pwm.height + temp.height
  55. radius: 4
  56. color: Qt.rgba(parent.color.r, parent.color.g, parent.color.b, 0.3)
  57. visible: pwmMouse.containsMouse || drag.active
  58. Column {
  59. Label {
  60. id: pwm
  61. font.pixelSize: root.size
  62. text: Math.round(canvas.scalePwm(root.centerY) / 2.55) + '%'
  63. }
  64. Label {
  65. id: temp
  66. font.pixelSize: root.size
  67. text: Math.round(canvas.scaleTemp(root.centerX)) + '°'
  68. }
  69. }
  70. }
  71. }