2
0

StatusPoint.qml 3.0 KB

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