ソースを参照

Added a KDE Plasma plasmoid

Malte Veerman 6 年 前
コミット
1ab8fab795

+ 10 - 1
CMakeLists.txt

@@ -7,6 +7,7 @@ project(fancontroller)
 option(NO_SYSTEMD "Compile without Systemd support. Reduces functionality significantly!" OFF)
 option(BUILD_GUI "Build the standalone application" ON)
 option(BUILD_KCM "Build the KCM" OFF)
+option(BUILD_PLASMOID "Build the plasmoid" OFF)
 option(BUILD_HELPER "Build the KHelper" ON)
 option(INSTALL_SHARED "Install the shared parts" ON)
 
@@ -42,7 +43,6 @@ include(KDECompilerSettings)
 include(FeatureSummary)
 include(FindPkgConfig)
 include(ECMQMLModules)
-include(ECMGenerateQmlTypes)
 
 #Find Qt5
 find_package(Qt5Core REQUIRED)
@@ -100,6 +100,15 @@ if(BUILD_KCM)
 endif(BUILD_KCM)
 
 
+#Build the plasmoid
+if(BUILD_PLASMOID)
+
+    message(STATUS "Build the plasmoid")
+    add_subdirectory(plasmoid)
+
+endif(BUILD_PLASMOID)
+
+
 #build and install the shared parts
 if(INSTALL_SHARED)
 

+ 2 - 0
README.md

@@ -13,6 +13,8 @@ If your distro looks for QML plugins in /usr/lib/qt/qml instead of /usr/lib/qml
 To compile the additional KCM set the cmake option -DBUILD_KCM=on.
 The KCM is only build, if the -DNO_SYSTEMD option is unset or set to false.
 
+To compile the additional KDE Plasma plasmoid set the cmake option -DBUILD_PLASMOID=on.
+
 # Build requirements
 * Qt5: Base/Core, Widgets, Gui, QML
 * KF5: I18n, Auth, Config, Package, Declarative, CoreAddons, DBusAddons, KCMUtils, Extra-Cmake-Modules, Notifications

+ 29 - 13
import/qml/FanHeader.qml

@@ -24,22 +24,43 @@ import QtQuick.Layouts 1.2
 import org.kde.kirigami 2.3 as Kirigami
 
 
-Item {
+RowLayout {
     property QtObject fan
+    property bool editable: true
 
-    implicitHeight: layout.childrenRect.height
+    Loader {
+        active: !!fan
+        sourceComponent: editable ? editableNameComponent : nameComponent
+        Layout.alignment: Qt.AlignLeft
+        Layout.leftMargin: Kirigami.Units.smallSpacing
+    }
+    Item {
+        Layout.fillWidth: true
+    }
+    Label {
+        Layout.alignment: Qt.AlignRight
+        Layout.rightMargin: Kirigami.Units.smallSpacing
+        text: !!fan ? fan.path : ""
+        horizontalAlignment: Text.AlignRight
+    }
 
-    RowLayout {
-        id: layout
+    Component {
+        id: nameComponent
 
-        anchors.fill: parent
-        anchors.leftMargin: Kirigami.Units.smallSpacing
-        anchors.rightMargin: Kirigami.Units.smallSpacing
+        Label {
+            text: !!fan ? fan.name : ""
+            horizontalAlignment: TextEdit.AlignLeft
+            wrapMode: TextEdit.Wrap
+            font.bold: true
+            font.pointSize: Kirigami.Theme.defaultFont.pointSize + 2
+        }
+    }
+    Component {
+        id: editableNameComponent
 
         TextEdit {
             id: nameField
 
-            Layout.alignment: Qt.AlignLeft
             text: !!fan ? fan.name : ""
             color: Kirigami.Theme.textColor
             horizontalAlignment: TextEdit.AlignLeft
@@ -61,10 +82,5 @@ Item {
                 acceptedButtons: Qt.NoButton
             }
         }
-        Label {
-            Layout.alignment: Qt.AlignRight
-            text: !!fan ? fan.path : ""
-            horizontalAlignment: Text.AlignRight
-        }
     }
 }

+ 19 - 23
import/qml/FanItem.qml

@@ -29,9 +29,12 @@ import "colors.js" as Colors
 
 
 Item {
+    id: root
+
     property QtObject fan
     property int margin: Kirigami.Units.smallSpacing
     property bool showControls: true
+    property bool editable: true
     readonly property QtObject systemdCom: Fancontrol.Base.hasSystemdCommunicator ? Fancontrol.Base.systemdCom : null
     readonly property QtObject tempModel: Fancontrol.Base.tempModel
     readonly property real minTemp: Fancontrol.Base.minTemp
@@ -40,10 +43,6 @@ Item {
     readonly property real convertedMinTemp: Units.fromCelsius(minTemp, unit)
     readonly property real convertedMaxTemp: Units.fromCelsius(maxTemp, unit)
 
-    id: root
-
-    clip: false
-
     onConvertedMinTempChanged: {
         meshCanvas.requestPaint();
         curveCanvas.requestPaint();
@@ -249,27 +248,26 @@ Item {
             }
             StatusPoint {
                 id: currentPwm
+
                 size: graph.fontSize
                 visible: graphBackground.contains(center) && !!fan && fan.hasTemp
                 fan: root.fan
             }
             PwmPoint {
                 id: stopPoint
+
                 color: !!fan ? fan.hasTemp ? "blue" : Qt.tint(Kirigami.Theme.disabledTextColor, Qt.rgba(0, 0, 1, 0.5)) : "transparent"
                 size: graph.fontSize
                 visible: !!fan ? fan.hasTemp : false
-                drag.maximumX: Math.min(graphBackground.scaleX(graphBackground.scaleTemp(maxPoint.x)-1), maxPoint.x-1)
-                drag.minimumY: Math.max(graphBackground.scaleY(graphBackground.scalePwm(maxPoint.y)-1), maxPoint.y+1)
+                draggable: root.editable
+                maximumX: Math.min(graphBackground.scaleX(graphBackground.scaleTemp(maxPoint.x)-1), maxPoint.x-1)
+                minimumY: Math.max(graphBackground.scaleY(graphBackground.scalePwm(maxPoint.y)-1), maxPoint.y+1)
                 x: !!fan && fan.hasTemp ? graphBackground.scaleX(MoreMath.bound(root.minTemp, fan.minTemp, root.maxTemp)) - width/2 : -width/2
                 y: !!fan && fan.hasTemp ? graphBackground.scaleY(fan.minStop) - height/2 : -height/2
-                temp: !!fan && fan.hasTemp ? drag.active ? graphBackground.scaleTemp(centerX) : fan.minTemp : root.minTemp
-                pwm: !!fan && fan.hasTemp ? drag.active ? graphBackground.scalePwm(centerY) : fan.minStop : 255
-                drag.onActiveChanged: {
-                    if (!drag.active) {
-                        fan.minStop = Math.round(graphBackground.scalePwm(centerY));
-                        fan.minTemp = Math.round(graphBackground.scaleTemp(centerX));
-                        if (fan.minPwm !== 0) fan.minPwm = fan.minStop;
-                    }
+                onDragFinished: {
+                    fan.minStop = Math.round(graphBackground.scalePwm(centerY));
+                    fan.minTemp = Math.round(graphBackground.scaleTemp(centerX));
+                    if (fan.minPwm !== 0) fan.minPwm = fan.minStop;
                 }
                 onPositionChanged: {
                     var left = fan.minPwm === 0 ? x : 0;
@@ -280,20 +278,18 @@ Item {
             }
             PwmPoint {
                 id: maxPoint
+
                 color: !!fan ? fan.hasTemp ? "red" : Qt.tint(Kirigami.Theme.disabledTextColor, Qt.rgba(1, 0, 0, 0.5)) : "transparent"
                 size: graph.fontSize
                 visible: !!fan ? fan.hasTemp : false
-                drag.minimumX: Math.max(graphBackground.scaleX(graphBackground.scaleTemp(stopPoint.x)+1), stopPoint.x+1)
-                drag.maximumY: Math.min(graphBackground.scaleY(graphBackground.scalePwm(stopPoint.y)+1), stopPoint.y-1)
+                draggable: root.editable
+                minimumX: Math.max(graphBackground.scaleX(graphBackground.scaleTemp(stopPoint.x)+1), stopPoint.x+1)
+                maximumY: Math.min(graphBackground.scaleY(graphBackground.scalePwm(stopPoint.y)+1), stopPoint.y-1)
                 x: !!fan && fan.hasTemp ? graphBackground.scaleX(MoreMath.bound(root.minTemp, fan.maxTemp, root.maxTemp)) - width/2 : graphBackground.width - width/2
                 y: !!fan && fan.hasTemp ? graphBackground.scaleY(fan.maxPwm) - height/2 : -height/2
-                temp: !!fan && fan.hasTemp ? drag.active ? graphBackground.scaleTemp(centerX) : fan.maxTemp : root.maxTemp
-                pwm: !!fan && fan.hasTemp ? drag.active ? graphBackground.scalePwm(centerY) : fan.maxPwm : 255
-                drag.onActiveChanged: {
-                    if (!drag.active) {
-                        fan.maxPwm = Math.round(graphBackground.scalePwm(centerY));
-                        fan.maxTemp = Math.round(graphBackground.scaleTemp(centerX));
-                    }
+                onDragFinished: {
+                    fan.maxPwm = Math.round(graphBackground.scalePwm(centerY));
+                    fan.maxTemp = Math.round(graphBackground.scaleTemp(centerX));
                 }
                 onPositionChanged: {
                     var width = x - stopPoint.x;

+ 20 - 11
import/qml/PwmPoint.qml

@@ -32,18 +32,23 @@ Rectangle {
     readonly property real centerX: x + width / 2
     readonly property real centerY: y + height / 2
     readonly property point center: Qt.point(centerX, centerY)
-    property int temp: 0
-    property int pwm: 0
-    property alias drag: pwmMouse.drag
+    property int temp: !!background ? background.scaleTemp(centerX) : 0
+    property int pwm: !!background ? background.scalePwm(centerY) : 0
+    property real minimumX: - width / 2
+    property real maximumX: parent.width - width / 2
+    property real minimumY: - height / 2
+    property real maximumY: parent.height - height / 2
     property int size: Kirigami.Units.smallSpacing * 2
     readonly property string unit: Fancontrol.Base.unit
+    property bool draggable: true
 
     signal positionChanged()
+    signal dragFinished()
 
     width: size
     height: size
     radius: size / 2
-    border.width: pwmMouse.containsMouse || drag.active ? 1 : 0
+    border.width: pwmMouse.containsMouse || pwmMouse.drag.active ? 1 : 0
 
     onXChanged: positionChanged()
     onYChanged: positionChanged()
@@ -55,14 +60,18 @@ Rectangle {
 
         anchors.fill: parent
         hoverEnabled: root.enabled ? true : false
-        cursorShape: containsPress || drag.active ? Qt.DragMoveCursor : Qt.PointingHandCursor
-        drag.target: root
+        cursorShape: draggable ? containsPress || drag.active ? Qt.DragMoveCursor : Qt.PointingHandCursor : Qt.ArrowCursor
+        drag.target: draggable ? root : null
         drag.axis: Drag.XAndYAxis
         drag.smoothed: false
-        drag.minimumX: - root.width/2
-        drag.maximumX: background.width - root.width/2
-        drag.minimumY: - root.height/2
-        drag.maximumY: background.height - root.height/2
+        drag.minimumX: root.minimumX
+        drag.maximumX: root.maximumX
+        drag.minimumY: root.minimumY
+        drag.maximumY: root.maximumY
+        drag.onActiveChanged: {
+            if (!drag.active)
+                root.dragFinished();
+        }
     }
 
     Rectangle {
@@ -74,7 +83,7 @@ Rectangle {
         height: column.height
         radius: Kirigami.Units.smallSpacing / 2
         color: Qt.rgba(parent.color.r, parent.color.g, parent.color.b, 0.5)
-        visible: root.enabled && (pwmMouse.containsMouse || drag.active)
+        visible: root.enabled && (pwmMouse.containsMouse || pwmMouse.drag.active)
 
         Column {
             id: column

+ 6 - 0
plasmoid/CMakeLists.txt

@@ -0,0 +1,6 @@
+find_package(KF5Plasma REQUIRED)
+
+ecm_find_qmlmodule(org.kde.plasma.core 2.0)
+ecm_find_qmlmodule(org.kde.plasma.components 2.0)
+
+plasma_install_package(package org.kde.fancontrol.plasmoid)

+ 31 - 0
plasmoid/package/contents/config/config.qml

@@ -0,0 +1,31 @@
+/*
+ * 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 org.kde.plasma.configuration 2.0
+
+
+ConfigModel {
+    ConfigCategory {
+        name: i18n("General")
+        icon: "preferences-desktop-color"
+        source: "configGeneral.qml"
+    }
+}

+ 15 - 0
plasmoid/package/contents/config/main.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+      http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+    <kcfgfile name=""/>
+
+    <group name="General">
+        <entry name="Fan" type="Int">
+            <default>0</default>
+        </entry>
+    </group>
+
+</kcfg>
+

+ 42 - 0
plasmoid/package/contents/ui/configGeneral.qml

@@ -0,0 +1,42 @@
+/*
+ * 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.0
+import QtQuick.Controls 2.0
+import org.kde.kirigami 2.3 as Kirigami
+import Fancontrol.Qml 1.0 as Fancontrol
+
+
+Kirigami.FormLayout {
+    property alias cfg_Fan: fanComboBox.currentIndex
+
+    anchors {
+        left: parent.left
+        right: parent.right
+    }
+
+    ComboBox {
+        id: fanComboBox
+
+        model: Fancontrol.Base.pwmFanModel
+        textRole: "display"
+        Kirigami.FormData.label: i18n("Fan:")
+    }
+}

+ 60 - 0
plasmoid/package/contents/ui/main.qml

@@ -0,0 +1,60 @@
+/*
+ * 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.Layouts 1.2
+import org.kde.kirigami 2.3 as Kirigami
+import org.kde.plasma.plasmoid 2.0
+import org.kde.plasma.core 2.0 as PlasmaCore
+import Fancontrol.Qml 1.0 as Fancontrol
+
+
+ColumnLayout {
+    id: root
+
+    readonly property QtObject fan: Fancontrol.Base.pwmFanModel.fan(plasmoid.configuration.Fan)
+
+    Layout.minimumWidth: Plasmoid.formFactor == PlasmaCore.Types.Horizontal ? height : header.implicitWidth
+    Layout.minimumHeight: Plasmoid.formFactor == PlasmaCore.Types.Vertical ? width  : header.implicitHeight + Kirigami.Units.gridUnit * 5
+    Plasmoid.associatedApplication: "fancontrol_gui"
+    Plasmoid.icon: "org.kde.fancontrol.gui"
+    Kirigami.Theme.backgroundColor: PlasmaCore.ColorScope.backgroundColor
+    Kirigami.Theme.textColor: PlasmaCore.ColorScope.textColor
+
+    Component.onCompleted: {
+        Fancontrol.Base.load();
+    }
+
+    Fancontrol.FanHeader {
+        id: header
+
+        fan: root.fan
+        editable: false
+        Layout.fillWidth: true
+    }
+
+    Fancontrol.FanItem {
+        fan: root.fan
+        showControls: false
+        editable: false
+        Layout.fillWidth: true
+        Layout.fillHeight: true
+    }
+}

+ 16 - 0
plasmoid/package/metadata.desktop

@@ -0,0 +1,16 @@
+[Desktop Entry]
+Encoding=UTF-8
+Name=Fancontrol
+Comment=Plasmoid to observe and control fan speeds.
+Type=Service
+
+X-KDE-PluginInfo-Author=Malte Veerman
+X-KDE-PluginInfo-Email=malte.veerman@gmail.com
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-Name=org.kde.fancontrol.plasmoid
+X-KDE-PluginInfo-Version=0.1
+X-KDE-PluginInfo-Website=https://github.com/Maldela/fancontrol-gui
+X-KDE-ServiceTypes=Plasma/Applet
+X-Plasma-API=declarativeappletscript
+X-Plasma-MainScript=ui/main.qml
+X-KDE-PluginInfo-Category=Hardware