StatusPoint.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  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.2
  21. Rectangle {
  22. id: root
  23. property QtObject fan
  24. property Item canvas: parent
  25. property real unscaledTemp: fan.temp ? fan.temp.value : minTemp
  26. property real unscaledPwm: fan.pwm
  27. property var locale: Qt.locale()
  28. readonly property real centerX: x + width / 2
  29. readonly property real centerY: y + height / 2
  30. property int size: 10
  31. property int unit: 0
  32. width: size
  33. height: size
  34. radius: size / 2
  35. x: canvas.scaleX(unscaledTemp) - width/2
  36. y: canvas.scaleY(unscaledPwm) - height/2
  37. color: "black"
  38. Behavior on unscaledTemp {
  39. SpringAnimation {
  40. epsilon: 0.1
  41. spring: 1.0
  42. damping: 0.4
  43. }
  44. }
  45. Behavior on unscaledPwm {
  46. SpringAnimation {
  47. epsilon: 0.1
  48. spring: 1.0
  49. damping: 0.4
  50. }
  51. }
  52. MouseArea {
  53. id: pwmMouse
  54. anchors.fill: parent
  55. hoverEnabled: root.enabled ? true : false
  56. }
  57. Rectangle {
  58. id: tooltip
  59. x: parent.width
  60. y: - height
  61. width: Math.max(pwm.width, rpm.width)
  62. height: temp.height + pwm.height + rpm.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
  66. Column {
  67. Label {
  68. property string suffix: (unit == 0) ? "°C" : (unit == 1) ? "K" : "°F"
  69. id: temp
  70. font.pixelSize: root.height * 1.5
  71. text: (fan.hasTemp ? fan.temp.value : "0") + suffix
  72. }
  73. Label {
  74. id: pwm
  75. font.pixelSize: root.height * 1.5
  76. text: Number(Math.round(canvas.scalePwm(root.centerY)) / 2.55).toLocaleString(locale, 'f', 1) + '%'
  77. }
  78. Label {
  79. id: rpm
  80. font.pixelSize: root.height * 1.5
  81. text: fan.rpm + i18n("rpm")
  82. }
  83. }
  84. }
  85. }