PwmPoint.qml 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.4
  20. import QtQuick.Controls 1.4
  21. import org.kde.kirigami 2.4 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: Math.max(pwm.width, temp.width)
  62. height: pwm.height + temp.height
  63. radius: 4
  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. Label {
  68. id: pwm
  69. font.pixelSize: root.size * 1.5
  70. text: Number(Math.round(root.pwm / 2.55)).toLocaleString(locale, 'f', 1) + i18n('%')
  71. }
  72. Label {
  73. id: temp
  74. font.pixelSize: root.size * 1.5
  75. text: Math.round(Units.fromCelsius(root.temp, unit)) + i18n(unit)
  76. }
  77. }
  78. }
  79. }