2
0

StatusPoint.qml 3.0 KB

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