PwmPoint.qml 3.5 KB

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