PwmPoint.qml 2.5 KB

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