StatusPoint.qml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. 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. readonly 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.6
  48. }
  49. }
  50. Behavior on unscaledPwm {
  51. SpringAnimation {
  52. epsilon: 0.1
  53. spring: 1.0
  54. damping: 0.6
  55. }
  56. }
  57. Behavior on unscaledRpm {
  58. SpringAnimation {
  59. epsilon: 0.1
  60. spring: 1.0
  61. damping: 0.6
  62. }
  63. }
  64. MouseArea {
  65. id: pwmMouse
  66. anchors.fill: parent
  67. hoverEnabled: root.enabled ? true : false
  68. }
  69. Rectangle {
  70. id: tooltip
  71. parent: root.parent
  72. x: root.width + root.x
  73. y: root.y - height
  74. z: 2
  75. width: column.width
  76. height: column.height
  77. radius: Kirigami.Units.smallSpacing / 2
  78. color: Qt.rgba(root.color.r, root.color.g, root.color.b, 0.3)
  79. visible: root.enabled && pwmMouse.containsMouse
  80. Column {
  81. id: column
  82. padding: Kirigami.Units.smallSpacing
  83. Text {
  84. font.pixelSize: root.size * 1.5
  85. text: Number(Units.fromCelsius(root.unscaledTemp, unit)).toLocaleString(Qt.locale(), 'f', 1) + i18n(unit)
  86. color: Kirigami.Theme.textColor
  87. }
  88. Text {
  89. font.pixelSize: root.size * 1.5
  90. text: Number(unscaledPwm / 2.55).toLocaleString(Qt.locale(), 'f', 1) + Qt.locale().percent
  91. color: Kirigami.Theme.textColor
  92. }
  93. Text {
  94. font.pixelSize: root.size * 1.5
  95. text: Number(unscaledRpm).toLocaleString(Qt.locale(), 'f', 0) + i18n("rpm")
  96. color: Kirigami.Theme.textColor
  97. }
  98. }
  99. }
  100. }