StatusPoint.qml 3.2 KB

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