StatusPoint.qml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. console.log(root.unscaledTemp);
  46. }
  47. Behavior on unscaledTemp {
  48. SpringAnimation {
  49. epsilon: 0.1
  50. spring: 1.0
  51. damping: 0.4
  52. }
  53. }
  54. Behavior on unscaledPwm {
  55. SpringAnimation {
  56. epsilon: 0.1
  57. spring: 1.0
  58. damping: 0.4
  59. }
  60. }
  61. MouseArea {
  62. id: pwmMouse
  63. anchors.fill: parent
  64. hoverEnabled: root.enabled ? true : false
  65. }
  66. Rectangle {
  67. id: tooltip
  68. x: parent.width
  69. y: - height
  70. width: Math.max(pwm.width, rpm.width)
  71. height: temp.height + pwm.height + rpm.height
  72. radius: 4
  73. color: Qt.rgba(parent.color.r, parent.color.g, parent.color.b, 0.5)
  74. visible: root.enabled && pwmMouse.containsMouse
  75. Column {
  76. Label {
  77. property string suffix: (unit == 0) ? "°C" : (unit == 1) ? "K" : "°F"
  78. id: temp
  79. font.pixelSize: root.height * 1.5
  80. text: (fan.hasTemp ? Math.round(Units.fromCelsius(root.unscaledTemp, unit)) : "0") + suffix
  81. }
  82. Label {
  83. id: pwm
  84. font.pixelSize: root.height * 1.5
  85. text: Number(Math.round(unscaledPwm / 2.55)).toLocaleString(locale, 'f', 1) + '%'
  86. }
  87. Label {
  88. id: rpm
  89. font.pixelSize: root.height * 1.5
  90. text: fan.rpm + i18n("rpm")
  91. }
  92. }
  93. }
  94. }