FanControls.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (C) 2019 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 QtQuick.Layouts 1.2
  22. import Fancontrol.Qml 1.0 as Fancontrol
  23. ColumnLayout {
  24. id: root
  25. property int padding
  26. property QtObject fan
  27. readonly property QtObject tempModel: Fancontrol.Base.tempModel
  28. clip: true
  29. spacing: 2
  30. RowLayout {
  31. CheckBox {
  32. id: hasTempCheckBox
  33. text: i18n("Controlled by:")
  34. checked: !!fan ? fan.hasTemp : false
  35. Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
  36. onCheckedChanged: {
  37. if (!!fan) {
  38. fan.hasTemp = checked;
  39. if (checked && !!tempModel.temp(tempBox.currentIndex)) {
  40. fan.temp = tempModel.temp(tempBox.currentIndex);
  41. }
  42. }
  43. }
  44. Connections {
  45. target: root
  46. onFanChanged: hasTempCheckBox.checked = !!fan ? fan.hasTemp : false
  47. }
  48. Connections {
  49. target: fan
  50. onHasTempChanged: hasTempCheckBox.checked = fan.hasTemp
  51. }
  52. }
  53. RowLayout {
  54. ComboBox {
  55. id: tempBox
  56. Layout.fillWidth: true
  57. model: tempModel
  58. currentIndex: !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
  59. textRole: "display"
  60. enabled: hasTempCheckBox.checked
  61. onCurrentIndexChanged: {
  62. if (hasTempCheckBox.checked)
  63. fan.temp = tempModel.temp(currentIndex);
  64. }
  65. }
  66. Connections {
  67. target: root
  68. onFanChanged: tempBox.currentIndex = !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
  69. }
  70. Connections {
  71. target: fan
  72. onTempChanged: tempBox.currentIndex = !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
  73. }
  74. }
  75. }
  76. CheckBox {
  77. id: fanOffCheckBox
  78. text: i18n("Turn Fan off if temp < MINTEMP")
  79. enabled: hasTempCheckBox.checked
  80. checked: !!fan ? fan.minPwm == 0 : false
  81. onCheckedChanged: {
  82. if (!!fan) {
  83. fan.minPwm = checked ? 0 : fan.minStop;
  84. }
  85. }
  86. Connections {
  87. target: root
  88. onFanChanged: if (!!fan) fanOffCheckBox.checked = fan.minPwm == 0
  89. }
  90. Connections {
  91. target: fan
  92. onMinPwmChanged: fanOffCheckBox.checked = fan.minPwm == 0
  93. }
  94. }
  95. RowLayout {
  96. enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
  97. Label {
  98. text: i18n("Pwm value for fan to start:")
  99. Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
  100. renderType: Text.NativeRendering
  101. }
  102. SpinBox {
  103. id: minStartInput
  104. Layout.fillWidth: true
  105. from: 0
  106. to: 100
  107. editable: true
  108. value: !!fan ? Math.round(fan.minStart / 2.55) : 0
  109. textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 1) + locale.percent }
  110. onValueModified: {
  111. if (!!fan) {
  112. fan.minStart = Math.round(value * 2.55)
  113. }
  114. }
  115. Connections {
  116. target: root
  117. onFanChanged: if (!!fan) minStartInput.value = Math.round(fan.minStart / 2.55)
  118. }
  119. Connections {
  120. target: fan
  121. onMinStartChanged: minStartInput.value = Math.round(fan.minStart / 2.55)
  122. }
  123. }
  124. }
  125. }