PwmPoint.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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: 0
  31. property int pwm: 0
  32. property alias drag: pwmMouse.drag
  33. property int size: Kirigami.Units.smallSpacing * 2
  34. readonly property string unit: Fancontrol.Base.unit
  35. signal positionChanged()
  36. width: size
  37. height: size
  38. radius: size / 2
  39. border.width: pwmMouse.containsMouse || drag.active ? 1 : 0
  40. onXChanged: positionChanged()
  41. onYChanged: positionChanged()
  42. Drag.dragType: Drag.Automatic
  43. MouseArea {
  44. id: pwmMouse
  45. anchors.fill: parent
  46. hoverEnabled: root.enabled ? true : false
  47. cursorShape: containsPress || drag.active ? Qt.DragMoveCursor : Qt.PointingHandCursor
  48. drag.target: root
  49. drag.axis: Drag.XAndYAxis
  50. drag.smoothed: false
  51. drag.minimumX: - root.width/2
  52. drag.maximumX: background.width - root.width/2
  53. drag.minimumY: - root.height/2
  54. drag.maximumY: background.height - root.height/2
  55. }
  56. Rectangle {
  57. id: tooltip
  58. x: parent.width
  59. y: - height
  60. width: column.width
  61. height: column.height
  62. radius: Kirigami.Units.smallSpacing / 2
  63. color: Qt.rgba(parent.color.r, parent.color.g, parent.color.b, 0.5)
  64. visible: root.enabled && (pwmMouse.containsMouse || drag.active)
  65. Column {
  66. id: column
  67. padding: Kirigami.Units.smallSpacing
  68. Text {
  69. font.pixelSize: root.size * 1.5
  70. text: Number(Units.fromCelsius(root.temp, unit)).toLocaleString(Qt.locale(), 'f', 0) + i18n(unit)
  71. color: Kirigami.Theme.textColor
  72. }
  73. Text {
  74. font.pixelSize: root.size * 1.5
  75. text: Number(root.pwm / 2.55).toLocaleString(Qt.locale(), 'f', 1) + Qt.locale().percent
  76. color: Kirigami.Theme.textColor
  77. }
  78. }
  79. }
  80. }