Browse Source

a few cleanups

Malte Veerman 9 years ago
parent
commit
db1d7b9e04

+ 0 - 38
package/contents/scripts/coordinates.js

@@ -1,38 +0,0 @@
-/*
- * 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 absoluteCoordinatesOf(item) {
-    if (typeof item === "undefined") {
-        item = this;
-    }
-    var offset = Qt.point(0, 0);
-    while (item.parent) {
-        offset.x += item.x;
-        offset.y += item.y;
-        item = item.parent
-    }
-    return offset;
-}
-
-function centerOf(item) {
-    var p = Qt.point(0, 0);
-    p.x = item.x + item.width / 2;
-    p.y = item.y + item.height / 2;
-    return p;
-}

+ 16 - 19
package/contents/ui/PwmFan.qml

@@ -24,7 +24,6 @@ import QtQuick.Layouts 1.1
 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
 
 
@@ -215,20 +214,16 @@ Rectangle {
                 onPaint: {
                     var c = bgCanvas.getContext("2d");
                     c.clearRect(0, 0, width, height);
-                    var fillGradient = c.createLinearGradient(0, 0, width, 0);
-                    fillGradient.addColorStop(0, "rgb(0, 0, 255)");
-                    fillGradient.addColorStop(1, "rgb(255, 0, 0)");
-                    c.fillStyle = fillGradient;
+                    var gradient = c.createLinearGradient(0, 0, width, 0);
+                    gradient.addColorStop(0, "rgb(0, 0, 255)");
+                    gradient.addColorStop(1, "rgb(255, 0, 0)");
+                    c.fillStyle = gradient;
                     c.lineWidth = 2;
-                    var strokeGradient = c.createLinearGradient(0, 0, width, 0);
-                    strokeGradient.addColorStop(0, "rgb(0, 0, 255)");
-                    strokeGradient.addColorStop(1, "rgb(255, 0, 0)");
-                    c.strokeStyle = strokeGradient;
+                    c.strokeStyle = gradient;
                     c.lineJoin = "round";
                     c.beginPath();
                     if (fanOffCheckBox.checked) {
-                        c.moveTo(0, height);
-                        c.lineTo(stopPoint.centerX, height);
+                        c.moveTo(stopPoint.centerX, height);
                     } else {
                         c.moveTo(0, stopPoint.centerY);
                     }
@@ -237,14 +232,18 @@ Rectangle {
                     c.lineTo(width, maxPoint.centerY);
                     c.stroke();
                     c.lineTo(width, height);
-                    c.lineTo(0, height);
+                    if (fanOffCheckBox.checked) {
+                        c.lineTo(stopPoint.centerX, height);
+                    } else {
+                        c.lineTo(0, height);
+                    }
                     c.fill();
 
                     //blend background
-                    fillGradient = c.createLinearGradient(0, 0, 0, height);
-                    fillGradient.addColorStop(0, Colors.setAlpha(background.color, 0.5));
-                    fillGradient.addColorStop(1, Colors.setAlpha(background.color, 0.9));
-                    c.fillStyle = fillGradient;
+                    gradient = c.createLinearGradient(0, 0, 0, height);
+                    gradient.addColorStop(0, Colors.setAlpha(background.color, 0.5));
+                    gradient.addColorStop(1, Colors.setAlpha(background.color, 0.9));
+                    c.fillStyle = gradient;
                     c.fill();
 
                     //draw mesh
@@ -273,7 +272,7 @@ Rectangle {
             StatusPoint {
                 id: currentPwm
                 size: graph.fontSize
-                visible: background.contains(Coordinates.centerOf(this)) && fan.hasTemp
+                visible: background.contains(center) && fan.hasTemp
                 fan: root.fan
                 unit: root.unit
             }
@@ -287,7 +286,6 @@ Rectangle {
                 drag.minimumY: Math.max(background.scaleY(background.scalePwm(maxPoint.y)-1), maxPoint.y+1)
                 x: fan.hasTemp ? background.scaleX(MoreMath.bound(minTemp, fan.minTemp, maxTemp)) - width/2 : -width/2
                 y: fan.hasTemp ? background.scaleY(fan.minStop) - height/2 : -height/2
-                visible: background.contains(Coordinates.centerOf(this))
                 drag.onActiveChanged: {
                     if (!drag.active) {
                         fan.minStop = Math.round(background.scalePwm(centerY));
@@ -307,7 +305,6 @@ Rectangle {
                 drag.maximumY: Math.min(background.scaleY(background.scalePwm(stopPoint.y)+1), stopPoint.y-1)
                 x: fan.hasTemp ? background.scaleX(MoreMath.bound(minTemp, fan.maxTemp, maxTemp)) - width/2 : background.width - width/2
                 y: fan.hasTemp ? background.scaleY(fan.maxPwm) - height/2 : -height/2
-                visible: background.contains(Coordinates.centerOf(this))
                 drag.onActiveChanged: {
                     if (!drag.active) {
                         fan.maxPwm = Math.round(background.scalePwm(centerY));

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

@@ -27,9 +27,9 @@ Rectangle {
     id: root
 
     property Item background: parent
-    property point center: Qt.point(x + width / 2, y + height / 2);
     readonly property real centerX: x + width / 2
     readonly property real centerY: y + height / 2
+    readonly property point center: Qt.point(centerX, centerY)
     property alias drag: pwmMouse.drag
     property int size: 10
     property int unit: 0

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

@@ -32,6 +32,7 @@ Rectangle {
     property var locale: Qt.locale()
     readonly property real centerX: x + width / 2
     readonly property real centerY: y + height / 2
+    readonly property point center: Qt.point(centerX, centerY)
     property int size: 10
     property int unit: 0