浏览代码

some fan graph improvements

Malte Veerman 10 年之前
父节点
当前提交
6feb38aa5e

+ 23 - 0
package/contents/scripts/colors.js

@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2015  Malte Veerman <maldela@halloarsch.de>
+ *
+ * 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.
+ *
+ */
+
+
+function setAlpha(color, alpha) {
+    return Qt.rgba(color.r, color.g, color.b, alpha);
+}

+ 0 - 1
package/contents/ui/KCM.qml

@@ -102,7 +102,6 @@ Item {
             Layout.fillHeight: true
             active: !!kcm.loader.allPwmFans[fanCombobox.currentIndex]
             sourceComponent: PwmFan {
-                minimizable: false
                 unit: kcm.base.unit
                 fan: kcm.loader.allPwmFans[fanCombobox.currentIndex]
                 loader: kcm.loader

+ 106 - 135
package/contents/ui/PwmFan.qml

@@ -24,6 +24,7 @@ import "../scripts/arrayfunctions.js" as ArrayFunctions
 import "../scripts/math.js" as MoreMath
 import "../scripts/units.js" as Units
 import "../scripts/coordinates.js" as Coordinates
+import "../scripts/colors.js" as Colors
 
 Rectangle {
     property QtObject fan
@@ -34,7 +35,6 @@ Rectangle {
     property int margin: 5
     property int minimizeDuration: 400
     property int unit: 0
-    property bool minimizable: true
 
     id: root
     color: "transparent"
@@ -42,7 +42,6 @@ Rectangle {
     border.width: 2
     radius: 10
     clip: false
-    state: fan.active ? "" : minimizable ? "minimized" : ""
 
     function update() {
         if (fan) {
@@ -68,10 +67,15 @@ Rectangle {
 
     SystemPalette {
         id: palette
+        colorGroup: SystemPalette.Active
+    }
+    SystemPalette {
+        id: disabledPalette
+        colorGroup: SystemPalette.Disabled
     }
 
-    RowLayout {
-        id: header
+    TextEdit {
+        id: nameField
         anchors {
             left: parent.left
             leftMargin: margin
@@ -80,55 +84,20 @@ Rectangle {
             top: parent.top
             topMargin: margin
         }
-        z: -1
-        clip: true
-        spacing: margin
-
-        TextEdit {
-            id: nameField
-            Layout.alignment: Qt.AlignTop
-            text: fan.name
-            color: palette.text
-            onTextChanged: fan.name = text;
-            horizontalAlignment: TextEdit.AlignLeft
-            wrapMode: TextEdit.Wrap
-            font.bold: true
-            font.pointSize: 14
-            selectByMouse: true
-            Layout.fillWidth: true
-
-            MouseArea {
-                anchors.fill: parent
-                cursorShape: Qt.IBeamCursor
-                acceptedButtons: Qt.NoButton
-            }
-        }
-
-        Rectangle {
-            id: collapseButton
-            height: 16
-            width: 16
-            Layout.alignment: Qt.AlignTop
-            color: collapseMouseArea.containsMouse ? "red" : "transparent"
-            radius: width / 2
-            visible: minimizable
-            enabled: minimizable
-
-            Label {
-                anchors.fill: parent
-                text: root.state == "minimized" ? "-" : "X"
-                color: collapseMouseArea.containsMouse ? "black" : "red"
-                horizontalAlignment: Text.AlignHCenter
-                verticalAlignment: Text.AlignVCenter
-            }
+        visible: root.height >= height + margin*2
+        text: fan.name
+        color: palette.text
+        onTextChanged: fan.name = text;
+        horizontalAlignment: TextEdit.AlignLeft
+        wrapMode: TextEdit.Wrap
+        font.bold: true
+        font.pointSize: 14
+        selectByMouse: true
 
-            MouseArea {
-                id: collapseMouseArea
-                anchors.fill: parent
-                hoverEnabled: true
-                acceptedButtons: Qt.LeftButton
-                onClicked: fan.active = fan.active ? false : true
-            }
+        MouseArea {
+            anchors.fill: parent
+            cursorShape: Qt.IBeamCursor
+            acceptedButtons: Qt.NoButton
         }
     }
 
@@ -138,24 +107,21 @@ Rectangle {
         property int rightPadding: fontSize * 2
         property int topPadding: fontSize
         property int bottomPadding: fontSize * 2
+        property bool drawingEnabled: height > bottomPadding + topPadding && width > leftPadding + rightPadding
         property int plotWidth: width - leftPadding - rightPadding
         property int plotHeight: height - topPadding - bottomPadding
         property alias minTemp: root.minTemp        //needed for pwmPoints
         property alias maxTemp: root.maxTemp        //needed for pwmPoints
+        property QtObject pal: fan.hasTemp ? palette : disabledPalette
 
         id: canvas
         renderTarget: Canvas.FramebufferObject
         anchors {
             left: parent.left
             right: parent.right
-            top: header.bottom
+            top: nameField.bottom
             bottom: settingsArea.top
         }
-        opacity: state == "minimized" ? 0 : 1
-
-        Behavior on opacity {
-            NumberAnimation { duration: minimizeDuration / 2 }
-        }
 
         Rectangle {
             property real unscaledTemp: fan.temp ? fan.temp.value : minTemp
@@ -168,7 +134,7 @@ Rectangle {
             height: width
             radius: width / 2
             color: "black"
-            visible: parent.contains(Coordinates.centerOf(this)) && fan.hasTemp
+            visible: canvas.contains(Coordinates.centerOf(this)) && fan.hasTemp && canvas.drawingEnabled
             
             Behavior on unscaledTemp {
                 SpringAnimation {
@@ -187,14 +153,15 @@ Rectangle {
         }
         PwmPoint {
             id: stopPoint
-            color: "blue"
+            color: fan.hasTemp ? "blue" : Qt.tint(canvas.pal.light, Qt.rgba(0, 0, 1, 0.5))
             size: canvas.fontSize
             unit: root.unit
+            enabled: fan.hasTemp
             drag.maximumX: Math.min(canvas.scaleX(canvas.scaleTemp(maxPoint.x)-1), maxPoint.x-1)
             drag.minimumY: Math.max(canvas.scaleY(canvas.scalePwm(maxPoint.y)-1), maxPoint.y+1)
-            x: canvas.scaleX(MoreMath.bound(minTemp, fan.minTemp, maxTemp)) - width/2
-            y: canvas.scaleY(fan.minStop) - height/2
-            visible: parent.contains(Coordinates.centerOf(this)) && parent.height > 0
+            x: fan.hasTemp ? canvas.scaleX(MoreMath.bound(minTemp, fan.minTemp, maxTemp)) - width/2 : canvas.leftPadding - width/2
+            y: fan.hasTemp ? canvas.scaleY(fan.minStop) - height/2 : canvas.topPadding -height/2
+            visible: canvas.contains(Coordinates.centerOf(this)) && canvas.drawingEnabled
             drag.onActiveChanged: {
                 if (!drag.active) {
                     fan.minStop = Math.round(canvas.scalePwm(centerY));
@@ -205,14 +172,15 @@ Rectangle {
         }
         PwmPoint {
             id: maxPoint
-            color: "red"
+            color: fan.hasTemp ? "red" : Qt.tint(canvas.pal.light, Qt.rgba(1, 0, 0, 0.5))
             size: canvas.fontSize
             unit: root.unit
+            enabled: fan.hasTemp
             drag.minimumX: Math.max(canvas.scaleX(canvas.scaleTemp(stopPoint.x)+1), stopPoint.x+1)
             drag.maximumY: Math.min(canvas.scaleY(canvas.scalePwm(stopPoint.y)+1), stopPoint.y-1)
-            x: canvas.scaleX(MoreMath.bound(minTemp, fan.maxTemp, maxTemp)) - width/2
-            y: canvas.scaleY(fan.maxPwm) - height/2
-            visible: parent.contains(Coordinates.centerOf(this)) && parent.height > 0
+            x: fan.hasTemp ? canvas.scaleX(MoreMath.bound(minTemp, fan.maxTemp, maxTemp)) - width/2 : canvas.width - canvas.rightPadding - width/2
+            y: fan.hasTemp ? canvas.scaleY(fan.maxPwm) - height/2 : canvas.topPadding - height/2
+            visible: canvas.contains(Coordinates.centerOf(this)) && canvas.drawingEnabled
             drag.onActiveChanged: {
                 if (!drag.active) {
                     fan.maxPwm = Math.round(canvas.scalePwm(centerY));
@@ -240,81 +208,84 @@ Rectangle {
 
         onPaint: {
             var c = canvas.getContext("2d");
-            c.font = canvas.fontSize + "px sans-serif";
-
             c.clearRect(0, 0, width, height);
-            c.fillStyle = palette.light;
-            c.strokeStyle = palette.text
-            c.fillRect(leftPadding, topPadding, plotWidth, plotHeight);
 
-            var fillGradient = c.createLinearGradient(0, 0, width, 0);
-            fillGradient.addColorStop(0, "rgb(0, 0, 255)");
-            fillGradient.addColorStop(1, "rgb(255, 0, 0)");
-            var strokeGradient = c.createLinearGradient(0, 0, width, 0);
-            strokeGradient.addColorStop(0, "rgb(0, 0, 255)");
-            strokeGradient.addColorStop(1, "rgb(255, 0, 0)");
-            c.fillStyle = fillGradient;
-            c.strokeStyle = strokeGradient;
-            c.lineWidth = 2;
-            c.lineJoin = "round";
-            c.beginPath();
-            if (fanOffCheckBox.checked) {
-                c.moveTo(scaleX(minTemp), scaleY(0));
-                c.lineTo(stopPoint.centerX, scaleY(0));
-            } else {
-                c.moveTo(scaleX(minTemp), stopPoint.centerY);
-            }
-            c.lineTo(stopPoint.centerX, stopPoint.centerY);
-            c.lineTo(maxPoint.centerX, maxPoint.centerY);
-            c.lineTo(scaleX(maxTemp), maxPoint.centerY);
-            c.stroke();
-            c.lineTo(scaleX(maxTemp), height - bottomPadding);
-            c.lineTo(leftPadding, height - bottomPadding);
-            c.fill();
-            fillGradient = c.createLinearGradient(0, 0, 0, height);
-            fillGradient.addColorStop(0, "rgba(127, 127, 127, 0.6)");
-            fillGradient.addColorStop(1, "rgba(127, 127, 127, 0.9)");
-            c.fillStyle = fillGradient;
-            c.fill();
-            c.closePath();
+            if (canvas.drawingEnabled) {
+                c.font = canvas.fontSize + "px sans-serif";
+
+                c.fillStyle = pal.light;
+                c.strokeStyle = pal.text;
+                c.fillRect(leftPadding, topPadding, plotWidth, plotHeight);
 
-            c.textAlign = "right";
-            c.textBaseline = "middle";
-            c.strokeStyle = palette.text;
-            c.fillStyle = palette.text;
-            c.lineWidth = 1;
-            c.strokeRect(leftPadding-0.5, topPadding-0.5, plotWidth+0.5, plotHeight+1.5);
-            for (var i=0; i<=100; i+=20) {
-                var y = scaleY(i*2.55);
-                c.fillText(i + '%', leftPadding - 2, y);
-                if (i != 0 && i != 100) {
-                    for (var j=leftPadding; j<=width-rightPadding; j+=15) {
-                        c.moveTo(j, y);
-                        c.lineTo(Math.min(j+5, width-rightPadding), y);
+                var fillGradient = c.createLinearGradient(0, 0, width, 0);
+                fillGradient.addColorStop(0, "rgb(0, 0, 255)");
+                fillGradient.addColorStop(1, "rgb(255, 0, 0)");
+                var strokeGradient = c.createLinearGradient(0, 0, width, 0);
+                strokeGradient.addColorStop(0, "rgb(0, 0, 255)");
+                strokeGradient.addColorStop(1, "rgb(255, 0, 0)");
+                c.fillStyle = fillGradient;
+                c.strokeStyle = strokeGradient;
+                c.lineWidth = 2;
+                c.lineJoin = "round";
+                c.beginPath();
+                if (fanOffCheckBox.checked) {
+                    c.moveTo(scaleX(minTemp), scaleY(0));
+                    c.lineTo(stopPoint.centerX, scaleY(0));
+                } else {
+                    c.moveTo(scaleX(minTemp), stopPoint.centerY);
+                }
+                c.lineTo(stopPoint.centerX, stopPoint.centerY);
+                c.lineTo(maxPoint.centerX, maxPoint.centerY);
+                c.lineTo(scaleX(maxTemp), maxPoint.centerY);
+                c.stroke();
+                c.lineTo(scaleX(maxTemp), height - bottomPadding);
+                c.lineTo(leftPadding, height - bottomPadding);
+                c.fill();
+                fillGradient = c.createLinearGradient(0, 0, 0, height);
+                fillGradient.addColorStop(0, Colors.setAlpha(canvas.pal.light, 0.6));
+                fillGradient.addColorStop(1, Colors.setAlpha(canvas.pal.light, 0.9));
+                c.fillStyle = fillGradient;
+                c.fill();
+                c.closePath();
+
+                c.textAlign = "right";
+                c.textBaseline = "middle";
+                c.strokeStyle = pal.text;
+                c.fillStyle = pal.text;
+                c.lineWidth = 1;
+                c.strokeRect(leftPadding-0.5, topPadding-0.5, plotWidth+0.5, plotHeight+1.5);
+                for (var i=0; i<=100; i+=20) {
+                    var y = scaleY(i*2.55);
+                    c.fillText(i + '%', leftPadding - 2, y);
+                    if (i != 0 && i != 100) {
+                        for (var j=leftPadding; j<=width-rightPadding; j+=15) {
+                            c.moveTo(j, y);
+                            c.lineTo(Math.min(j+5, width-rightPadding), y);
+                        }
+                        c.stroke();
                     }
-                    c.stroke();
                 }
-            }
-            c.textAlign = "center";
-            c.textBaseline = "top";
-            var convertedMinTemp = Units.fromCelsius(minTemp, unit);
-            var convertedMaxTemp = Units.fromCelsius(maxTemp, unit);
-            var suffix = (unit == 0) ? "°C" : (unit == 1) ? "K" : "°F"
-            var lastTemp;
-            for (var i=convertedMinTemp; i<convertedMaxTemp; i+= 10) {
-                lastTemp = i;
-                var x = scaleX(Units.toCelsius(i, unit));
-                c.fillText(i + suffix, x, topPadding+plotHeight+fontSize/2);
-                if (i != convertedMinTemp) {
-                    for (var j=scaleY(255); j<=scaleY(0); j+=20) {
-                        c.moveTo(x, j);
-                        c.lineTo(x, Math.min(j+5, width-rightPadding));
+                c.textAlign = "center";
+                c.textBaseline = "top";
+                var convertedMinTemp = Units.fromCelsius(minTemp, unit);
+                var convertedMaxTemp = Units.fromCelsius(maxTemp, unit);
+                var suffix = (unit == 0) ? "°C" : (unit == 1) ? "K" : "°F"
+                var lastTemp;
+                for (var i=convertedMinTemp; i<convertedMaxTemp; i+= 10) {
+                    lastTemp = i;
+                    var x = scaleX(Units.toCelsius(i, unit));
+                    c.fillText(i + suffix, x, topPadding+plotHeight+fontSize/2);
+                    if (i != convertedMinTemp) {
+                        for (var j=scaleY(255); j<=scaleY(0); j+=20) {
+                            c.moveTo(x, j);
+                            c.lineTo(x, Math.min(j+5, width-rightPadding));
+                        }
+                        c.stroke();
                     }
-                    c.stroke();
                 }
+                if ((convertedMaxTemp - lastTemp) > 5)
+                    c.fillText(convertedMaxTemp + suffix, scaleX(maxTemp), topPadding+plotHeight+fontSize/2);
             }
-            if ((convertedMaxTemp - lastTemp) > 5)
-                c.fillText(convertedMaxTemp + suffix, scaleX(maxTemp), topPadding+plotHeight+fontSize/2);
         }
     }
 
@@ -330,7 +301,7 @@ Rectangle {
             bottom: parent.bottom
             bottomMargin: padding
         }
-        visible: root.height >= header.height + height + 2*margin
+        visible: root.height >= nameField.height + height + 2*margin
         opacity: canvas.opacity
         clip: true
         spacing: 2

+ 0 - 1
package/contents/ui/PwmFansTab.qml

@@ -57,7 +57,6 @@ ColumnLayout {
         Layout.fillWidth: true
         active: !!baseObject.loader.allPwmFans[fanCombobox.currentIndex]
         sourceComponent: PwmFan {
-            minimizable: false
             unit: baseObject.unit
             fan: loader.allPwmFans[fanCombobox.currentIndex]
             loader: root.loader

+ 2 - 2
package/contents/ui/PwmPoint.qml

@@ -47,7 +47,7 @@ Rectangle {
     MouseArea {
         id: pwmMouse
         anchors.fill: parent
-        hoverEnabled: canvas.minimized ? false : true
+        hoverEnabled: root.enabled ? true : false
         drag.target: root
         drag.axis: Drag.XAndYAxis
         drag.smoothed: false
@@ -65,7 +65,7 @@ Rectangle {
         height: pwm.height + temp.height
         radius: 4
         color: Qt.rgba(parent.color.r, parent.color.g, parent.color.b, 0.5)
-        visible: pwmMouse.containsMouse || drag.active
+        visible: root.enabled && (pwmMouse.containsMouse || drag.active)
 
         Column {
             Label {