Jelajahi Sumber

Split fan controls into own qml file

Malte Veerman 6 tahun lalu
induk
melakukan
bf6304e2c0
4 mengubah file dengan 160 tambahan dan 117 penghapusan
  1. 6 4
      import/CMakeLists.txt
  2. 141 0
      import/qml/FanControls.qml
  3. 12 113
      import/qml/FanItem.qml
  4. 1 0
      import/qml/qmldir

+ 6 - 4
import/CMakeLists.txt

@@ -12,6 +12,7 @@ set(LIB_SRCS src/hwmon.cpp
 
 set(QML_FILES qml/qmldir
               qml/ErrorDialog.qml
+              qml/FanControls.qml
               qml/FanHeader.qml
               qml/FanItem.qml
               qml/PwmPoint.qml
@@ -53,12 +54,13 @@ target_link_libraries(fancontrol_qml_plugin PRIVATE ${LIB_PRIVATE_LIBRARIES} PUB
 install(TARGETS fancontrol_qml_plugin DESTINATION "${KDE_INSTALL_QMLDIR}/Fancontrol/Qml/")
 install(FILES ${QML_FILES} DESTINATION "${KDE_INSTALL_QMLDIR}/Fancontrol/Qml/")
 
-if(${KF5_VERSION} VERSION_GREATER_EQUAL 5.33.0)
-    ecm_generate_qmltypes(Fancontrol.Qml 1.0 DESTINATION "${KDE_INSTALL_QMLDIR}/Fancontrol/Qml/")
-endif(${KF5_VERSION} VERSION_GREATER_EQUAL 5.33.0)
 
-#tests
+#install qmltypes file
+include(ECMGenerateQmlTypes)
+ecm_generate_qmltypes(Fancontrol.Qml 1.0 DESTINATION "${KDE_INSTALL_QMLDIR}/Fancontrol/Qml/")
+
 
+#tests
 if(BUILD_TESTING)
     add_subdirectory(tests)
 endif(BUILD_TESTING)

+ 141 - 0
import/qml/FanControls.qml

@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2019  Malte Veerman <malte.veerman@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+
+import QtQuick 2.6
+import QtQuick.Controls 2.1
+import QtQuick.Layouts 1.2
+import Fancontrol.Qml 1.0 as Fancontrol
+
+
+ColumnLayout {
+    id: root
+
+    property int padding
+    property QtObject fan
+    readonly property QtObject tempModel: Fancontrol.Base.tempModel
+
+    clip: true
+    spacing: 2
+
+    RowLayout {
+        CheckBox {
+            id: hasTempCheckBox
+            text: i18n("Controlled by:")
+            checked: !!fan ? fan.hasTemp : false
+            Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
+            onCheckedChanged: {
+                if (!!fan) {
+                    fan.hasTemp = checked;
+                    if (checked && !!tempModel.temp(tempBox.currentIndex)) {
+                        fan.temp = tempModel.temp(tempBox.currentIndex);
+                    }
+                }
+            }
+
+            Connections {
+                target: root
+                onFanChanged: hasTempCheckBox.checked = !!fan ? fan.hasTemp : false
+            }
+            Connections {
+                target: fan
+                onHasTempChanged: hasTempCheckBox.checked = fan.hasTemp
+            }
+        }
+        RowLayout {
+            ComboBox {
+                id: tempBox
+                Layout.fillWidth: true
+                model: tempModel
+                currentIndex: !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
+                textRole: "display"
+                enabled: hasTempCheckBox.checked
+                onCurrentIndexChanged: {
+                    if (hasTempCheckBox.checked)
+                        fan.temp = tempModel.temp(currentIndex);
+                }
+            }
+
+            Connections {
+                target: root
+                onFanChanged: tempBox.currentIndex = !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
+            }
+            Connections {
+                target: fan
+                onTempChanged: tempBox.currentIndex = !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
+            }
+        }
+    }
+
+    CheckBox {
+        id: fanOffCheckBox
+
+        text: i18n("Turn Fan off if temp < MINTEMP")
+        enabled: hasTempCheckBox.checked
+        checked: !!fan ? fan.minPwm == 0 : false
+        onCheckedChanged: {
+            if (!!fan) {
+                fan.minPwm = checked ? 0 : fan.minStop;
+            }
+        }
+
+        Connections {
+            target: root
+            onFanChanged: if (!!fan) fanOffCheckBox.checked = fan.minPwm == 0
+        }
+        Connections {
+            target: fan
+            onMinPwmChanged: fanOffCheckBox.checked = fan.minPwm == 0
+        }
+    }
+
+    RowLayout {
+        enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
+
+        Label {
+            text: i18n("Pwm value for fan to start:")
+            Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
+            renderType: Text.NativeRendering
+        }
+        SpinBox {
+            id: minStartInput
+
+            Layout.fillWidth: true
+            from: 0
+            to: 100
+            editable: true
+            value: !!fan ? Math.round(fan.minStart / 2.55) : 0
+            textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 1) + locale.percent }
+            onValueModified: {
+                if (!!fan) {
+                    fan.minStart = Math.round(value * 2.55)
+                }
+            }
+
+            Connections {
+                target: root
+                onFanChanged: if (!!fan) minStartInput.value = Math.round(fan.minStart / 2.55)
+            }
+            Connections {
+                target: fan
+                onMinStartChanged: minStartInput.value = Math.round(fan.minStart / 2.55)
+            }
+        }
+    }
+}

+ 12 - 113
import/qml/FanItem.qml

@@ -200,6 +200,12 @@ Item {
                     c.fillStyle = gradient;
                     c.fill();
                 }
+
+                Connections {
+                    target: fan
+                    onTempChanged: curveCanvas.requestPaint()
+                    onMinPwmChanged: curveCanvas.markDirty(Qt.rect(0, 0, stopPoint.x, stopPoint.y))
+                }
             }
             Canvas {
                 id: meshCanvas
@@ -262,11 +268,11 @@ Item {
                     if (!drag.active) {
                         fan.minStop = Math.round(graphBackground.scalePwm(centerY));
                         fan.minTemp = Math.round(graphBackground.scaleTemp(centerX));
-                        if (!fanOffCheckBox.checked) fan.minPwm = fan.minStop;
+                        if (fan.minPwm !== 0) fan.minPwm = fan.minStop;
                     }
                 }
                 onPositionChanged: {
-                    var left = fanOffCheckBox.checked ? x : 0;
+                    var left = fan.minPwm === 0 ? x : 0;
                     var width = maxPoint.x - left;
                     var height = y - maxPoint.y;
                     curveCanvas.markDirty(Qt.rect(left, maxPoint.y, width, height));
@@ -298,10 +304,11 @@ Item {
         }
     }
 
-    ColumnLayout {
-        property int padding: root.margin
-
+    FanControls {
         id: settingsArea
+
+        fan: root.fan
+        padding: root.margin
         anchors {
             left: parent.left
             leftMargin: padding
@@ -311,113 +318,5 @@ Item {
             bottomMargin: padding
         }
         visible: root.showControls && root.height >= height + 2*margin
-        clip: true
-        spacing: 2
-
-        RowLayout {
-            CheckBox {
-                id: hasTempCheckBox
-                text: i18n("Controlled by:")
-                checked: !!fan ? fan.hasTemp : false
-                Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
-                onCheckedChanged: {
-                    if (!!fan) {
-                        fan.hasTemp = checked;
-                        if (checked && !!tempModel.temp(tempBox.currentIndex)) {
-                            fan.temp = tempModel.temp(tempBox.currentIndex);
-                        }
-                        curveCanvas.requestPaint();
-                    }
-                }
-
-                Connections {
-                    target: root
-                    onFanChanged: hasTempCheckBox.checked = !!fan ? fan.hasTemp : false
-                }
-                Connections {
-                    target: fan
-                    onHasTempChanged: hasTempCheckBox.checked = fan.hasTemp
-                }
-            }
-            RowLayout {
-                ComboBox {
-                    id: tempBox
-                    Layout.fillWidth: true
-                    model: tempModel
-                    currentIndex: !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
-                    textRole: "display"
-                    enabled: hasTempCheckBox.checked
-                    onCurrentIndexChanged: {
-                        if (hasTempCheckBox.checked)
-                            fan.temp = tempModel.temp(currentIndex);
-                    }
-                }
-
-                Connections {
-                    target: root
-                    onFanChanged: tempBox.currentIndex = !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
-                }
-                Connections {
-                    target: fan
-                    onTempChanged: tempBox.currentIndex = !!fan && fan.hasTemp ? tempModel.indexOf(fan.temp) : -1
-                }
-            }
-        }
-
-        CheckBox {
-            id: fanOffCheckBox
-            text: i18n("Turn Fan off if temp < MINTEMP")
-            enabled: hasTempCheckBox.checked
-            checked: !!fan ? fan.minPwm == 0 : false
-            onCheckedChanged: {
-                if (!!fan) {
-                    fan.minPwm = checked ? 0 : fan.minStop;
-                    curveCanvas.markDirty(Qt.rect(0, 0, stopPoint.x, stopPoint.y));
-                }
-            }
-
-            Connections {
-                target: root
-                onFanChanged: if (!!fan) fanOffCheckBox.checked = fan.minPwm == 0
-            }
-            Connections {
-                target: fan
-                onMinPwmChanged: fanOffCheckBox.checked = fan.minPwm == 0
-            }
-        }
-
-        RowLayout {
-            enabled: fanOffCheckBox.checked && fanOffCheckBox.enabled
-
-            Label {
-                text: i18n("Pwm value for fan to start:")
-                Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
-                renderType: Text.NativeRendering
-            }
-            SpinBox {
-                id: minStartInput
-
-                Layout.fillWidth: true
-                from: 0
-                to: 100
-                editable: true
-                value: !!fan ? Math.round(fan.minStart / 2.55) : 0
-                textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 1) + locale.percent }
-                onValueModified: {
-                    if (!!fan) {
-                        fan.minStart = Math.round(value * 2.55)
-                    }
-                }
-
-                Connections {
-                    target: root
-                    onFanChanged: if (!!fan) minStartInput.value = Math.round(fan.minStart / 2.55)
-                }
-                Connections {
-                    target: fan
-                    onMinStartChanged: minStartInput.value = Math.round(fan.minStart / 2.55)
-                }
-            }
-        }
     }
 }

+ 1 - 0
import/qml/qmldir

@@ -2,6 +2,7 @@ module Fancontrol.Qml
 plugin fancontrol_qml_plugin
 internal StatusPoint StatusPoint.qml
 internal PwmPoint PwmPoint.qml
+FanControls 1.0 FanControls.qml
 FanHeader 1.0 FanHeader.qml
 FanItem 1.0 FanItem.qml
 ErrorDialog 1.0 ErrorDialog.qml