2
0

PwmPoint.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <malte.veerman@gmail.com>
  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.6
  20. import QtQuick.Controls 2.1
  21. import org.kde.kirigami 2.3 as Kirigami
  22. import Fancontrol.Qml 1.0 as Fancontrol
  23. Rectangle {
  24. id: root
  25. property Item background: parent
  26. readonly property real centerX: x + width / 2
  27. readonly property real centerY: y + height / 2
  28. readonly property point center: Qt.point(centerX, centerY)
  29. property int temp: !!background ? background.scaleTemp(centerX) : 0
  30. property int pwm: !!background ? background.scalePwm(centerY) : 0
  31. property real minimumX: - width / 2
  32. property real maximumX: parent.width - width / 2
  33. property real minimumY: - height / 2
  34. property real maximumY: parent.height - height / 2
  35. property int size: Kirigami.Units.smallSpacing * 2
  36. property bool draggable: true
  37. signal positionChanged()
  38. signal dragFinished()
  39. width: size
  40. height: size
  41. radius: size / 2
  42. border.width: pwmMouse.containsMouse || pwmMouse.drag.active ? 1 : 0
  43. onXChanged: positionChanged()
  44. onYChanged: positionChanged()
  45. Drag.dragType: Drag.Automatic
  46. MouseArea {
  47. id: pwmMouse
  48. anchors.fill: parent
  49. hoverEnabled: root.enabled ? true : false
  50. cursorShape: draggable ? containsPress || drag.active ? Qt.DragMoveCursor : Qt.PointingHandCursor : Qt.ArrowCursor
  51. drag.target: draggable ? root : null
  52. drag.axis: Drag.XAndYAxis
  53. drag.smoothed: false
  54. drag.minimumX: root.minimumX
  55. drag.maximumX: root.maximumX
  56. drag.minimumY: root.minimumY
  57. drag.maximumY: root.maximumY
  58. drag.onActiveChanged: {
  59. if (!drag.active)
  60. root.dragFinished();
  61. }
  62. }
  63. Rectangle {
  64. id: tooltip
  65. parent: root.parent
  66. x: Math.min(root.width + root.x, background.width - width + background.anchors.rightMargin)
  67. y: Math.max(root.y - height, -background.anchors.topMargin)
  68. z: 2
  69. width: column.width
  70. height: column.height
  71. radius: Kirigami.Units.smallSpacing / 2
  72. color: Qt.rgba(root.color.r, root.color.g, root.color.b, 0.3)
  73. visible: root.enabled && (pwmMouse.containsMouse || pwmMouse.drag.active)
  74. Column {
  75. id: column
  76. padding: Kirigami.Units.smallSpacing
  77. Text {
  78. font.pixelSize: root.size * 1.5
  79. text: Number(root.temp).toLocaleString(Qt.locale(), 'f', 0) + i18n("°C")
  80. color: Kirigami.Theme.textColor
  81. }
  82. Text {
  83. font.pixelSize: root.size * 1.5
  84. text: Number(root.pwm / 2.55).toLocaleString(Qt.locale(), 'f', 1) + Qt.locale().percent
  85. color: Kirigami.Theme.textColor
  86. }
  87. }
  88. }
  89. }