2
0

StatusPoint.qml 3.5 KB

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