FanControls.qml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. spacing: 2
  29. RowLayout {
  30. CheckBox {
  31. id: hasTempCheckBox
  32. text: i18n("Controlled by:")
  33. checked: !!fan ? fan.hasTemp : false
  34. Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
  35. onCheckedChanged: {
  36. if (!!fan) {
  37. fan.hasTemp = checked;
  38. if (checked && !!tempModel.temp(tempBox.currentIndex)) {
  39. fan.temp = tempModel.temp(tempBox.currentIndex);
  40. }
  41. }
  42. }
  43. Connections {
  44. target: root
  45. onFanChanged: hasTempCheckBox.checked = !!fan ? fan.hasTemp : false
  46. }
  47. Connections {
  48. target: fan
  49. onHasTempChanged: hasTempCheckBox.checked = fan.hasTemp
  50. }
  51. }
  52. RowLayout {
  53. ComboBox {
  54. id: tempBox
  55. Layout.fillWidth: true
  56. model: tempModel
  57. currentIndex: !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
  58. textRole: "display"
  59. enabled: hasTempCheckBox.checked
  60. onCurrentIndexChanged: {
  61. if (hasTempCheckBox.checked)
  62. fan.temp = tempModel.temp(currentIndex);
  63. }
  64. }
  65. Connections {
  66. target: root
  67. onFanChanged: tempBox.currentIndex = !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
  68. }
  69. Connections {
  70. target: fan
  71. onTempChanged: tempBox.currentIndex = !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
  72. }
  73. }
  74. }
  75. RowLayout {
  76. Label {
  77. text: i18n("Number of cycles to average temperature")
  78. Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
  79. renderType: Text.NativeRendering
  80. }
  81. SpinBox {
  82. id: averageInput
  83. Layout.fillWidth: true
  84. from: 1
  85. to: 100
  86. editable: true
  87. value: !!fan ? fan.average : 1
  88. textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 1) }
  89. onValueModified: {
  90. if (!!fan) {
  91. fan.average = value
  92. }
  93. }
  94. Connections {
  95. target: root
  96. onFanChanged: if (!!fan) averageInput.value = fan.average
  97. }
  98. Connections {
  99. target: fan
  100. onAverageChanged: averageInput.value = fan.average
  101. }
  102. }
  103. }
  104. CheckBox {
  105. id: fanOffCheckBox
  106. text: i18n("Turn Fan off if temp < MINTEMP")
  107. enabled: hasTempCheckBox.checked
  108. checked: !!fan ? fan.minPwm == 0 : false
  109. onCheckedChanged: {
  110. if (!!fan) {
  111. fan.minPwm = checked ? 0 : fan.minStop;
  112. }
  113. }
  114. Connections {
  115. target: root
  116. onFanChanged: if (!!fan) fanOffCheckBox.checked = fan.minPwm == 0
  117. }
  118. Connections {
  119. target: fan
  120. onMinPwmChanged: fanOffCheckBox.checked = fan.minPwm == 0
  121. }
  122. }
  123. RowLayout {
  124. enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
  125. Label {
  126. text: i18n("Pwm value for fan to start:")
  127. Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
  128. renderType: Text.NativeRendering
  129. }
  130. SpinBox {
  131. id: minStartInput
  132. Layout.fillWidth: true
  133. from: 0
  134. to: 100
  135. editable: true
  136. value: !!fan ? Math.round(fan.minStart / 2.55) : 0
  137. textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 1) + locale.percent }
  138. onValueModified: {
  139. if (!!fan) {
  140. fan.minStart = Math.round(value * 2.55)
  141. }
  142. }
  143. Connections {
  144. target: root
  145. onFanChanged: if (!!fan) minStartInput.value = Math.round(fan.minStart / 2.55)
  146. }
  147. Connections {
  148. target: fan
  149. onMinStartChanged: minStartInput.value = Math.round(fan.minStart / 2.55)
  150. }
  151. }
  152. }
  153. }