StatusPoint.qml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.6
  20. import QtQuick.Controls 2.1
  21. import org.kde.kirigami 2.3 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 real unscaledRpm: !!fan ? fan.rpm : 0
  32. property var locale: Qt.locale()
  33. readonly property real centerX: x + width / 2
  34. readonly property real centerY: y + height / 2
  35. readonly property point center: Qt.point(centerX, centerY)
  36. property int size: Kirigami.Units.smallSpacing * 2
  37. property string unit: Fancontrol.Base.unit
  38. width: size
  39. height: size
  40. radius: size / 2
  41. x: MoreMath.bound(-width/2, background.scaleX(unscaledTemp) - width/2, background.width-width/2)
  42. y: background.scaleY(unscaledPwm) - height/2
  43. color: "black"
  44. Behavior on unscaledTemp {
  45. SpringAnimation {
  46. epsilon: 0.1
  47. spring: 1.0
  48. damping: 0.6
  49. }
  50. }
  51. Behavior on unscaledPwm {
  52. SpringAnimation {
  53. epsilon: 0.1
  54. spring: 1.0
  55. damping: 0.6
  56. }
  57. }
  58. Behavior on unscaledRpm {
  59. SpringAnimation {
  60. epsilon: 0.1
  61. spring: 1.0
  62. damping: 0.6
  63. }
  64. }
  65. MouseArea {
  66. id: pwmMouse
  67. anchors.fill: parent
  68. hoverEnabled: root.enabled ? true : false
  69. }
  70. Rectangle {
  71. id: tooltip
  72. x: parent.width
  73. y: - height
  74. width: column.width
  75. height: column.height
  76. radius: Kirigami.Units.smallSpacing / 2
  77. color: Qt.rgba(parent.color.r, parent.color.g, parent.color.b, 0.5)
  78. visible: root.enabled && pwmMouse.containsMouse
  79. Column {
  80. id: column
  81. padding: Kirigami.Units.smallSpacing
  82. Text {
  83. font.pixelSize: root.size * 1.5
  84. text: Number(Units.fromCelsius(root.unscaledTemp, unit)).toLocaleString(locale, 'f', 1) + i18n(unit)
  85. color: Kirigami.Theme.textColor
  86. }
  87. Text {
  88. font.pixelSize: root.size * 1.5
  89. text: Number(unscaledPwm / 2.55).toLocaleString(locale, 'f', 1) + locale.percent
  90. color: Kirigami.Theme.textColor
  91. }
  92. Text {
  93. font.pixelSize: root.size * 1.5
  94. text: Number(unscaledRpm).toLocaleString(locale, 'f', 0) + i18n("rpm")
  95. color: Kirigami.Theme.textColor
  96. }
  97. }
  98. }
  99. }