PwmPoint.qml 3.0 KB

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