FanControls.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. CheckBox {
  76. id: fanOffCheckBox
  77. text: i18n("Turn Fan off if temp < MINTEMP")
  78. enabled: hasTempCheckBox.checked
  79. checked: !!fan ? fan.minPwm == 0 : false
  80. onCheckedChanged: {
  81. if (!!fan) {
  82. fan.minPwm = checked ? 0 : fan.minStop;
  83. }
  84. }
  85. Connections {
  86. target: root
  87. onFanChanged: if (!!fan) fanOffCheckBox.checked = fan.minPwm == 0
  88. }
  89. Connections {
  90. target: fan
  91. onMinPwmChanged: fanOffCheckBox.checked = fan.minPwm == 0
  92. }
  93. }
  94. RowLayout {
  95. enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
  96. Label {
  97. text: i18n("Pwm value for fan to start:")
  98. Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
  99. renderType: Text.NativeRendering
  100. }
  101. SpinBox {
  102. id: minStartInput
  103. Layout.fillWidth: true
  104. from: 0
  105. to: 100
  106. editable: true
  107. value: !!fan ? Math.round(fan.minStart / 2.55) : 0
  108. textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 1) + locale.percent }
  109. onValueModified: {
  110. if (!!fan) {
  111. fan.minStart = Math.round(value * 2.55)
  112. }
  113. }
  114. Connections {
  115. target: root
  116. onFanChanged: if (!!fan) minStartInput.value = Math.round(fan.minStart / 2.55)
  117. }
  118. Connections {
  119. target: fan
  120. onMinStartChanged: minStartInput.value = Math.round(fan.minStart / 2.55)
  121. }
  122. }
  123. }
  124. }