StatusPoint.qml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 background: 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. readonly property point center: Qt.point(centerX, centerY)
  31. property int size: 10
  32. property int unit: 0
  33. width: size
  34. height: size
  35. radius: size / 2
  36. x: background.scaleX(unscaledTemp) - width/2
  37. y: background.scaleY(unscaledPwm) - height/2
  38. color: "black"
  39. Behavior on unscaledTemp {
  40. SpringAnimation {
  41. epsilon: 0.1
  42. spring: 1.0
  43. damping: 0.4
  44. }
  45. }
  46. Behavior on unscaledPwm {
  47. SpringAnimation {
  48. epsilon: 0.1
  49. spring: 1.0
  50. damping: 0.4
  51. }
  52. }
  53. MouseArea {
  54. id: pwmMouse
  55. anchors.fill: parent
  56. hoverEnabled: root.enabled ? true : false
  57. }
  58. Rectangle {
  59. id: tooltip
  60. x: parent.width
  61. y: - height
  62. width: Math.max(pwm.width, rpm.width)
  63. height: temp.height + pwm.height + rpm.height
  64. radius: 4
  65. color: Qt.rgba(parent.color.r, parent.color.g, parent.color.b, 0.5)
  66. visible: root.enabled && pwmMouse.containsMouse
  67. Column {
  68. Label {
  69. property string suffix: (unit == 0) ? "°C" : (unit == 1) ? "K" : "°F"
  70. id: temp
  71. font.pixelSize: root.height * 1.5
  72. text: (fan.hasTemp ? fan.temp.value : "0") + suffix
  73. }
  74. Label {
  75. id: pwm
  76. font.pixelSize: root.height * 1.5
  77. text: Number(Math.round(background.scalePwm(root.centerY)) / 2.55).toLocaleString(locale, 'f', 1) + '%'
  78. }
  79. Label {
  80. id: rpm
  81. font.pixelSize: root.height * 1.5
  82. text: fan.rpm + i18n("rpm")
  83. }
  84. }
  85. }
  86. }