SettingsTab.qml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (C) 2015 Malte Veerman <maldela@halloarsch.de>
  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.4
  20. import QtQuick.Layouts 1.1
  21. import QtQuick.Controls 1.2
  22. import QtQml 2.2
  23. import "../scripts/arrayfunctions.js" as ArrayFunctions
  24. import "../scripts/units.js" as Units
  25. Item {
  26. property QtObject baseObject
  27. property QtObject loader: baseObject ? baseObject.loader : null
  28. property QtObject systemdCom: baseObject ? baseObject.hasSystemdCommunicator() ? baseObject.systemdCom : null : null
  29. property int interval: loader ? loader.interval : 1
  30. property int padding: 10
  31. property real textWidth: 0
  32. property var locale: Qt.locale()
  33. id: root
  34. anchors.fill: parent
  35. anchors.topMargin: 5
  36. Column {
  37. id: column
  38. anchors.fill: parent
  39. anchors.margins: padding
  40. spacing: 5
  41. RowLayout {
  42. width: parent.width
  43. Label {
  44. Layout.preferredWidth: root.textWidth
  45. clip: true
  46. text: i18n("Interval:")
  47. horizontalAlignment: Text.AlignRight
  48. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  49. }
  50. OptionInput {
  51. id: intervalValue
  52. Layout.minimumWidth: implicitWidth
  53. Layout.fillWidth: true
  54. inputMethodHints: Qt.ImhDigitsOnly
  55. text: Number(interval).toLocaleString(locale)
  56. onTextChanged: if (text && text != "0") loader.interval = parseInt(Number.fromLocaleString(locale, text))
  57. }
  58. }
  59. RowLayout {
  60. width: parent.width
  61. Label {
  62. Layout.preferredWidth: root.textWidth
  63. clip: true
  64. text: i18n("Minimum temperature for fan graphs:")
  65. horizontalAlignment: Text.AlignRight
  66. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  67. }
  68. OptionInput {
  69. id: minTempValue
  70. Layout.minimumWidth: implicitWidth
  71. Layout.fillWidth: true
  72. inputMethodHints: Qt.ImhDigitsOnly
  73. onTextChanged: if (activeFocus) baseObject.minTemp = Units.toCelsius(Number.fromLocaleString(locale, text), baseObject.unit)
  74. Component.onCompleted: text = Units.fromCelsius(baseObject.minTemp, baseObject.unit)
  75. Connections {
  76. target: baseObject
  77. onUnitChanged: minTempValue.text = Units.fromCelsius(baseObject.minTemp, baseObject.unit)
  78. }
  79. }
  80. }
  81. RowLayout {
  82. width: parent.width
  83. Label {
  84. Layout.preferredWidth: root.textWidth
  85. clip: true
  86. text: i18n("Maximum temperature for fan graphs:")
  87. horizontalAlignment: Text.AlignRight
  88. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  89. }
  90. OptionInput {
  91. id: maxTempValue
  92. Layout.minimumWidth: implicitWidth
  93. Layout.fillWidth: true
  94. inputMethodHints: Qt.ImhDigitsOnly
  95. onTextChanged: if (activeFocus) baseObject.maxTemp = Units.toCelsius(Number.fromLocaleString(locale, text), baseObject.unit)
  96. Component.onCompleted: text = Units.fromCelsius(baseObject.maxTemp, baseObject.unit)
  97. Connections {
  98. target: baseObject
  99. onUnitChanged: maxTempValue.text = Units.fromCelsius(baseObject.maxTemp, baseObject.unit)
  100. }
  101. }
  102. }
  103. RowLayout {
  104. width: parent.width
  105. Label {
  106. Layout.preferredWidth: root.textWidth
  107. clip: true
  108. text: i18n("Unit:")
  109. horizontalAlignment: Text.AlignRight
  110. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  111. }
  112. ComboBox {
  113. id: unitBox
  114. Layout.minimumWidth: implicitWidth
  115. Layout.fillWidth: true
  116. model: [i18n("Celsius"), i18n("Kelvin"), i18n("Fahrenheit")]
  117. currentIndex: baseObject.unit
  118. onCurrentIndexChanged: {
  119. baseObject.unit = currentIndex;
  120. }
  121. }
  122. }
  123. Loader {
  124. active: systemdCom
  125. sourceComponent: RowLayout {
  126. width: column.width
  127. Label {
  128. Layout.preferredWidth: root.textWidth
  129. clip: true
  130. text: i18n("Name of the fancontrol systemd service:")
  131. horizontalAlignment: Text.AlignRight
  132. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  133. }
  134. OptionInput {
  135. id: serviceName
  136. Layout.minimumWidth: implicitWidth
  137. Layout.fillWidth: true
  138. color: systemdCom.serviceExists ? "green" : "red"
  139. text: systemdCom.serviceName
  140. onTextChanged: systemdCom.serviceName = text
  141. }
  142. }
  143. }
  144. Loader {
  145. active: systemdCom
  146. sourceComponent: RowLayout {
  147. width: column.width
  148. Label {
  149. Layout.preferredWidth: root.textWidth
  150. clip: true
  151. text: i18n("Fancontrol systemd service autostart:")
  152. horizontalAlignment: Text.AlignRight
  153. Component.onCompleted: root.textWidth = Math.max(root.textWidth, contentWidth)
  154. }
  155. ComboBox {
  156. id: autostartBox
  157. Layout.minimumWidth: implicitWidth
  158. Layout.fillWidth: true
  159. model: [i18n("disabled") , i18n("enabled")]
  160. currentIndex: systemdCom.serviceEnabled ? 1 : 0
  161. onCurrentIndexChanged: systemdCom.serviceEnabled = (currentIndex == 1) ? true : false
  162. }
  163. }
  164. }
  165. }
  166. }