浏览代码

Always use Celsius units.

Malte Veerman 5 年之前
父节点
当前提交
b7c65b3e2b

+ 1 - 1
fancontrol-gui/package/contents/ui/SensorsTab.qml

@@ -94,7 +94,7 @@ Kirigami.ScrollablePage {
                         Label {
                         Label {
                             id: tempValue
                             id: tempValue
 
 
-                            text: Units.fromCelsius(hwmon.temps[index].value, Fancontrol.Base.unit) + i18n(Fancontrol.Base.unit)
+                            text: hwmon.temps[index].value + i18n("°C")
                             Layout.alignment: Qt.AlignRight
                             Layout.alignment: Qt.AlignRight
                         }
                         }
                     }
                     }

+ 1 - 2
import/CMakeLists.txt

@@ -20,8 +20,7 @@ set(QML_FILES qml/qmldir
               qml/SettingsForm.qml
               qml/SettingsForm.qml
               qml/StatusPoint.qml
               qml/StatusPoint.qml
               qml/colors.js
               qml/colors.js
-              qml/math.js
-              qml/units.js)
+              qml/math.js)
 
 
 set(LIB_PRIVATE_LIBRARIES Qt5::Qml
 set(LIB_PRIVATE_LIBRARIES Qt5::Qml
                           KF5::Auth
                           KF5::Auth

+ 6 - 10
import/qml/FanItem.qml

@@ -24,7 +24,6 @@ import QtQuick.Layouts 1.2
 import org.kde.kirigami 2.3 as Kirigami
 import org.kde.kirigami 2.3 as Kirigami
 import Fancontrol.Qml 1.0 as Fancontrol
 import Fancontrol.Qml 1.0 as Fancontrol
 import "math.js" as MoreMath
 import "math.js" as MoreMath
-import "units.js" as Units
 import "colors.js" as Colors
 import "colors.js" as Colors
 
 
 
 
@@ -39,15 +38,12 @@ Item {
     readonly property QtObject tempModel: Fancontrol.Base.tempModel
     readonly property QtObject tempModel: Fancontrol.Base.tempModel
     readonly property real minTemp: Fancontrol.Base.minTemp
     readonly property real minTemp: Fancontrol.Base.minTemp
     readonly property real maxTemp: Fancontrol.Base.maxTemp
     readonly property real maxTemp: Fancontrol.Base.maxTemp
-    readonly property string unit: Fancontrol.Base.unit
-    readonly property real convertedMinTemp: Units.fromCelsius(minTemp, unit)
-    readonly property real convertedMaxTemp: Units.fromCelsius(maxTemp, unit)
 
 
-    onConvertedMinTempChanged: {
+    onMinTempChanged: {
         meshCanvas.requestPaint();
         meshCanvas.requestPaint();
         curveCanvas.requestPaint();
         curveCanvas.requestPaint();
     }
     }
-    onConvertedMaxTempChanged: {
+    onMaxTempChanged: {
         meshCanvas.requestPaint();
         meshCanvas.requestPaint();
         curveCanvas.requestPaint();
         curveCanvas.requestPaint();
     }
     }
@@ -58,7 +54,7 @@ Item {
 
 
         property int fontSize: MoreMath.bound(8, height / 20 + 1, 16)
         property int fontSize: MoreMath.bound(8, height / 20 + 1, 16)
         property int verticalScalaCount: height > Kirigami.Units.gridUnit * 30 ? 11 : 6
         property int verticalScalaCount: height > Kirigami.Units.gridUnit * 30 ? 11 : 6
-        property var horIntervals: MoreMath.intervals(root.convertedMinTemp, root.convertedMaxTemp, 10)
+        property var horIntervals: MoreMath.intervals(root.minTemp, root.maxTemp, 10)
 
 
         anchors {
         anchors {
             left: parent.left
             left: parent.left
@@ -109,10 +105,10 @@ Item {
                 model: graph.horIntervals.length;
                 model: graph.horIntervals.length;
 
 
                 Text {
                 Text {
-                    x: graphBackground.scaleX(Units.toCelsius(graph.horIntervals[index], unit)) - width/2
+                    x: graphBackground.scaleX(graph.horIntervals[index]) - width/2
                     y: horizontalScala.height / 2 - implicitHeight / 2
                     y: horizontalScala.height / 2 - implicitHeight / 2
                     color: Kirigami.Theme.textColor
                     color: Kirigami.Theme.textColor
-                    text: Number(graph.horIntervals[index]).toLocaleString() + i18n(unit)
+                    text: Number(graph.horIntervals[index]).toLocaleString() + i18n("°C")
                     font.pixelSize: graph.fontSize
                     font.pixelSize: graph.fontSize
                 }
                 }
             }
             }
@@ -234,7 +230,7 @@ Item {
                     //vertical lines
                     //vertical lines
                     if (graph.horIntervals.length > 1) {
                     if (graph.horIntervals.length > 1) {
                         for (var i=1; i<graph.horIntervals.length; i++) {
                         for (var i=1; i<graph.horIntervals.length; i++) {
-                            var x = graphBackground.scaleX(Units.toCelsius(graph.horIntervals[i], unit));
+                            var x = graphBackground.scaleX(graph.horIntervals[i]);
                             for (var j=0; j<=height; j+=20) {
                             for (var j=0; j<=height; j+=20) {
                                 c.moveTo(x, j);
                                 c.moveTo(x, j);
                                 c.lineTo(x, Math.min(j+5, height));
                                 c.lineTo(x, Math.min(j+5, height));

+ 1 - 3
import/qml/PwmPoint.qml

@@ -22,7 +22,6 @@ import QtQuick 2.6
 import QtQuick.Controls 2.1
 import QtQuick.Controls 2.1
 import org.kde.kirigami 2.3 as Kirigami
 import org.kde.kirigami 2.3 as Kirigami
 import Fancontrol.Qml 1.0 as Fancontrol
 import Fancontrol.Qml 1.0 as Fancontrol
-import "units.js" as Units
 
 
 
 
 Rectangle {
 Rectangle {
@@ -39,7 +38,6 @@ Rectangle {
     property real minimumY: - height / 2
     property real minimumY: - height / 2
     property real maximumY: parent.height - height / 2
     property real maximumY: parent.height - height / 2
     property int size: Kirigami.Units.smallSpacing * 2
     property int size: Kirigami.Units.smallSpacing * 2
-    readonly property string unit: Fancontrol.Base.unit
     property bool draggable: true
     property bool draggable: true
 
 
     signal positionChanged()
     signal positionChanged()
@@ -94,7 +92,7 @@ Rectangle {
 
 
             Text {
             Text {
                 font.pixelSize: root.size * 1.5
                 font.pixelSize: root.size * 1.5
-                text: Number(Units.fromCelsius(root.temp, unit)).toLocaleString(Qt.locale(), 'f', 0) + i18n(unit)
+                text: Number(root.temp).toLocaleString(Qt.locale(), 'f', 0) + i18n("°C")
                 color: Kirigami.Theme.textColor
                 color: Kirigami.Theme.textColor
             }
             }
             Text {
             Text {

+ 17 - 21
import/qml/SettingsForm.qml

@@ -24,7 +24,6 @@ import QtQuick.Controls 2.1
 import QtQuick.Dialogs 1.2
 import QtQuick.Dialogs 1.2
 import org.kde.kirigami 2.3 as Kirigami
 import org.kde.kirigami 2.3 as Kirigami
 import Fancontrol.Qml 1.0 as Fancontrol
 import Fancontrol.Qml 1.0 as Fancontrol
-import "units.js" as Units
 
 
 
 
 Kirigami.FormLayout {
 Kirigami.FormLayout {
@@ -32,7 +31,6 @@ Kirigami.FormLayout {
 
 
     readonly property QtObject systemdCom: Fancontrol.Base.hasSystemdCommunicator ? Fancontrol.Base.systemdCom : null
     readonly property QtObject systemdCom: Fancontrol.Base.hasSystemdCommunicator ? Fancontrol.Base.systemdCom : null
     readonly property QtObject loader: Fancontrol.Base.loader
     readonly property QtObject loader: Fancontrol.Base.loader
-    readonly property string unit: Fancontrol.Base.unit
     property bool showAll: true
     property bool showAll: true
 
 
     SpinBox {
     SpinBox {
@@ -61,60 +59,58 @@ Kirigami.FormLayout {
     SpinBox {
     SpinBox {
         id: minTempBox
         id: minTempBox
 
 
-        readonly property int celsiusValue: Units.toCelsius(value, unit)
-        readonly property string suffix: i18n(unit)
+        readonly property string suffix: i18n("°C")
 
 
         Kirigami.FormData.label: i18n("Minimum temperature for fan graphs:")
         Kirigami.FormData.label: i18n("Minimum temperature for fan graphs:")
         Layout.fillWidth: true
         Layout.fillWidth: true
-        from: Units.fromKelvin(0, unit)
+        from: -273
         to: 999
         to: 999
         inputMethodHints: Qt.ImhFormattedNumbersOnly
         inputMethodHints: Qt.ImhFormattedNumbersOnly
         editable: true
         editable: true
-        value: Units.fromCelsius(Fancontrol.Base.minTemp, unit)
+        value: Fancontrol.Base.minTemp
         textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 2) + suffix }
         textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 2) + suffix }
         valueFromText: function(text, locale) { return Number.fromLocaleString(locale, text.replace(suffix, "")); }
         valueFromText: function(text, locale) { return Number.fromLocaleString(locale, text.replace(suffix, "")); }
 
 
-        onCelsiusValueChanged: {
-            if (celsiusValue >= maxTempBox.celsiusValue)
-                maxTempBox.value = Math.max(value + 1, Units.fromCelsius(Units.toCelsius(value, unit) + 1, unit));
-            Fancontrol.Base.minTemp = celsiusValue;
+        onValueChanged: {
+            if (value >= maxTempBox.value)
+                maxTempBox.value = value + 1;
+            Fancontrol.Base.minTemp = value;
         }
         }
 
 
         Connections {
         Connections {
             target: Fancontrol.Base
             target: Fancontrol.Base
             onMinTempChanged: {
             onMinTempChanged: {
-                if (Fancontrol.Base.minTemp !== minTempBox.celsiusValue)
-                    minTempBox.value = Units.fromCelsius(Fancontrol.Base.minTemp, unit);
+                if (Fancontrol.Base.minTemp !== minTempBox.value)
+                    minTempBox.value = Fancontrol.Base.minTemp;
             }
             }
         }
         }
     }
     }
     SpinBox {
     SpinBox {
         id: maxTempBox
         id: maxTempBox
 
 
-        readonly property int celsiusValue: Units.toCelsius(value, unit)
-        readonly property string suffix: i18n(unit)
+        readonly property string suffix: i18n("°C")
 
 
         Kirigami.FormData.label: i18n("Maximum temperature for fan graphs:")
         Kirigami.FormData.label: i18n("Maximum temperature for fan graphs:")
         Layout.fillWidth: true
         Layout.fillWidth: true
-        from: Units.fromKelvin(0, unit)
+        from: -273
         to: 999
         to: 999
         inputMethodHints: Qt.ImhFormattedNumbersOnly
         inputMethodHints: Qt.ImhFormattedNumbersOnly
         editable: true
         editable: true
-        value: Units.fromCelsius(Fancontrol.Base.maxTemp, unit)
+        value: Fancontrol.Base.maxTemp
         textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 2) + suffix }
         textFromValue: function(value, locale) { return Number(value).toLocaleString(locale, 'f', 2) + suffix }
         valueFromText: function(text, locale) { return Number.fromLocaleString(locale, text.replace(suffix, "")); }
         valueFromText: function(text, locale) { return Number.fromLocaleString(locale, text.replace(suffix, "")); }
 
 
-        onCelsiusValueChanged: {
-            if (celsiusValue <= minTempBox.celsiusValue)
-                minTempBox.value = Math.min(value - 1, Units.fromCelsius(Units.toCelsius(value, unit) - 1, unit));
-            Fancontrol.Base.maxTemp = celsiusValue;
+        onValueChanged: {
+            if (value <= minTempBox.value)
+                minTempBox.value = value - 1;
+            Fancontrol.Base.maxTemp = value;
         }
         }
 
 
         Connections {
         Connections {
             target: Fancontrol.Base
             target: Fancontrol.Base
             onMaxTempChanged: {
             onMaxTempChanged: {
                 if (Fancontrol.Base.maxTemp !== maxTempBox.celsuisValue)
                 if (Fancontrol.Base.maxTemp !== maxTempBox.celsuisValue)
-                    maxTempBox.value = Units.fromCelsius(Fancontrol.Base.maxTemp, unit);
+                    maxTempBox.value = Fancontrol.Base.maxTemp;
             }
             }
         }
         }
     }
     }

+ 1 - 3
import/qml/StatusPoint.qml

@@ -22,7 +22,6 @@ import QtQuick 2.6
 import QtQuick.Controls 2.1
 import QtQuick.Controls 2.1
 import org.kde.kirigami 2.3 as Kirigami
 import org.kde.kirigami 2.3 as Kirigami
 import Fancontrol.Qml 1.0 as Fancontrol
 import Fancontrol.Qml 1.0 as Fancontrol
-import "units.js" as Units
 import "math.js" as MoreMath
 import "math.js" as MoreMath
 
 
 
 
@@ -38,7 +37,6 @@ Rectangle {
     readonly property real centerY: y + height / 2
     readonly property real centerY: y + height / 2
     readonly property point center: Qt.point(centerX, centerY)
     readonly property point center: Qt.point(centerX, centerY)
     property int size: Kirigami.Units.smallSpacing * 2
     property int size: Kirigami.Units.smallSpacing * 2
-    readonly property string unit: Fancontrol.Base.unit
 
 
     width: size
     width: size
     height: size
     height: size
@@ -95,7 +93,7 @@ Rectangle {
 
 
             Text {
             Text {
                 font.pixelSize: root.size * 1.5
                 font.pixelSize: root.size * 1.5
-                text: Number(Units.fromCelsius(root.unscaledTemp, unit)).toLocaleString(Qt.locale(), 'f', 1) + i18n(unit)
+                text: Number(root.unscaledTemp).toLocaleString(Qt.locale(), 'f', 1) + i18n("°C")
                 color: Kirigami.Theme.textColor
                 color: Kirigami.Theme.textColor
             }
             }
             Text {
             Text {

+ 0 - 1
import/qml/qmldir

@@ -8,5 +8,4 @@ FanItem 1.0 FanItem.qml
 ErrorDialog 1.0 ErrorDialog.qml
 ErrorDialog 1.0 ErrorDialog.qml
 ProfilesDialog 1.0 ProfilesDialog.qml
 ProfilesDialog 1.0 ProfilesDialog.qml
 SettingsForm 1.0 SettingsForm.qml
 SettingsForm 1.0 SettingsForm.qml
-Units 1.0 units.js
 
 

+ 0 - 44
import/qml/units.js

@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2015  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.
- *
- */
-
-function round(number, dec) {
-    if (!dec || dec == 0) return Math.round(number);
-    return Math.round(number*Math.pow(10, dec)) / Math.pow(10, dec);
-}
-
-function toCelsius(degrees, currentUnit) {
-    var float = parseFloat(degrees);
-    if (currentUnit == "K") { return float - 273.15; }
-    if (currentUnit == "°F") { return (float - 32) * 5 / 9; }
-    return float;
-}
-
-function fromCelsius(degrees, newUnit) {
-    var float = parseFloat(degrees);
-    if (newUnit == "K") { return float + 273.15; }
-    if (newUnit == "°F") { return float * 9 / 5 + 32; }
-    return float;
-}
-
-function fromKelvin(degrees, newUnit) {
-    var float = parseFloat(degrees);
-    if (newUnit == "°C") { return float - 273.15; }
-    if (newUnit == "°F") { return float * 9 / 5 - 459.67; }
-    return float;
-}    

+ 0 - 4
import/src/guibase.cpp

@@ -46,7 +46,6 @@ GUIBase::GUIBase(QObject *parent) : QObject(parent),
     m_tempModel(new TempModel(this)),
     m_tempModel(new TempModel(this)),
     m_profileModel(new QStringListModel(this))
     m_profileModel(new QStringListModel(this))
 {
 {
-    connect(this, &GUIBase::unitChanged, m_tempModel, &TempModel::setUnit);
     connect(m_loader, &Loader::needsSaveChanged, this, &GUIBase::needsApplyChanged);
     connect(m_loader, &Loader::needsSaveChanged, this, &GUIBase::needsApplyChanged);
     connect(m_loader, &Loader::configChanged, this, &GUIBase::currentProfileChanged);
     connect(m_loader, &Loader::configChanged, this, &GUIBase::currentProfileChanged);
 
 
@@ -55,9 +54,6 @@ GUIBase::GUIBase(QObject *parent) : QObject(parent),
     connect(m_com, &SystemdCommunicator::needsApplyChanged, this, &GUIBase::needsApplyChanged);
     connect(m_com, &SystemdCommunicator::needsApplyChanged, this, &GUIBase::needsApplyChanged);
 #endif
 #endif
 
 
-    m_unit = (QLocale::system().measurementSystem() == QLocale::ImperialUSSystem) ? QStringLiteral("°F") : QStringLiteral("°C");
-    emit unitChanged(m_unit);
-
     m_loader->parseHwmons();
     m_loader->parseHwmons();
 
 
     const auto hwmons = m_loader->hwmons();
     const auto hwmons = m_loader->hwmons();

+ 0 - 4
import/src/guibase.h

@@ -57,7 +57,6 @@ class GUIBase : public QObject
     Q_PROPERTY(Loader* loader READ loader CONSTANT)
     Q_PROPERTY(Loader* loader READ loader CONSTANT)
     Q_PROPERTY(qreal minTemp READ minTemp WRITE setMinTemp NOTIFY minTempChanged)
     Q_PROPERTY(qreal minTemp READ minTemp WRITE setMinTemp NOTIFY minTempChanged)
     Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp NOTIFY maxTempChanged)
     Q_PROPERTY(qreal maxTemp READ maxTemp WRITE setMaxTemp NOTIFY maxTempChanged)
-    Q_PROPERTY(QString unit READ unit WRITE setUnit NOTIFY unitChanged)
     Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
     Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
     Q_PROPERTY(QUrl configUrl READ configUrl WRITE setConfigUrl NOTIFY configUrlChanged)
     Q_PROPERTY(QUrl configUrl READ configUrl WRITE setConfigUrl NOTIFY configUrlChanged)
     Q_PROPERTY(bool configValid READ configValid NOTIFY configUrlChanged)
     Q_PROPERTY(bool configValid READ configValid NOTIFY configUrlChanged)
@@ -83,13 +82,11 @@ public:
     QString serviceName() const;
     QString serviceName() const;
     QUrl configUrl() const;
     QUrl configUrl() const;
     bool configValid() const { return m_configValid; }
     bool configValid() const { return m_configValid; }
-    QString unit() const { return m_unit; }
     QString error() const { return m_error; }
     QString error() const { return m_error; }
     void setMinTemp(qreal minTemp);
     void setMinTemp(qreal minTemp);
     void setMaxTemp(qreal maxTemp);
     void setMaxTemp(qreal maxTemp);
     void setServiceName(const QString &name);
     void setServiceName(const QString &name);
     void setConfigUrl(const QUrl &url);
     void setConfigUrl(const QUrl &url);
-    void setUnit(const QString &unit) { if (unit != m_unit) { m_unit = unit; emit unitChanged(m_unit); } }
     bool needsApply() const;
     bool needsApply() const;
     bool showTray() const;
     bool showTray() const;
     void setShowTray(bool show);
     void setShowTray(bool show);
@@ -137,7 +134,6 @@ private:
 #endif
 #endif
 
 
     Loader *const m_loader;
     Loader *const m_loader;
-    QString m_unit;
     bool m_configValid;
     bool m_configValid;
     PwmFanModel *m_pwmFanModel;
     PwmFanModel *m_pwmFanModel;
     TempModel *m_tempModel;
     TempModel *m_tempModel;

+ 5 - 3
import/src/tempmodel.cpp

@@ -25,11 +25,13 @@
 #include "temp.h"
 #include "temp.h"
 
 
 
 
+#define UNIT_SUFFIX "°C"
+
+
 namespace Fancontrol
 namespace Fancontrol
 {
 {
 
 
-TempModel::TempModel(QObject *parent) : QAbstractListModel(parent),
-    m_unit(QStringLiteral("°C"))
+TempModel::TempModel(QObject *parent) : QAbstractListModel(parent)
 {
 {
 }
 }
 
 
@@ -61,7 +63,7 @@ QVariant TempModel::data(const QModelIndex& index, int role) const
     switch (role)
     switch (role)
     {
     {
         case DisplayRole:
         case DisplayRole:
-            return temp->id() + ": " + QString::number(temp->value()) + m_unit + "   (" + temp->path() + ")";
+            return temp->id() + ": " + QString::number(temp->value()) + UNIT_SUFFIX + "   (" + temp->path() + ")";
 
 
         case ObjectRole:
         case ObjectRole:
             return QVariant::fromValue(temp);
             return QVariant::fromValue(temp);

+ 0 - 2
import/src/tempmodel.h

@@ -55,7 +55,6 @@ public:
     virtual QVariant data(const QModelIndex &index, int role = DisplayRole) const override;
     virtual QVariant data(const QModelIndex &index, int role = DisplayRole) const override;
     virtual QHash<int, QByteArray> roleNames() const override;
     virtual QHash<int, QByteArray> roleNames() const override;
     void updateTemp(Temp *temp);
     void updateTemp(Temp *temp);
-    void setUnit(const QString &unit) { if (unit != m_unit) { m_unit = unit; updateAll(); } }
     Q_INVOKABLE QObject *temp(int index) const;
     Q_INVOKABLE QObject *temp(int index) const;
     Q_INVOKABLE int indexOf(QObject *temp) const;
     Q_INVOKABLE int indexOf(QObject *temp) const;
 
 
@@ -75,7 +74,6 @@ private:
     void updateTemp();
     void updateTemp();
 
 
     QList<Temp *> m_temps;
     QList<Temp *> m_temps;
-    QString m_unit;
 };
 };
 
 
 }
 }