2
0

StatusPoint.qml 3.1 KB

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