Skip to content

Commit 67eb588

Browse files
committed
feat: add option to show temperature at the top-left corner of the graph
By adding config item "Plasmoid.configuration.thirdLineToLeftTopCorner" in ConfigAppearance.qml, and adding positioning anchors control in GraphText.qml. And after enabling this feature, the temperature with one decimal digit, such as "45.6°C", is not beautiful,so in CpuTemperature.qml:getFormattedValue(), precision control is implemented to keep the temperature always integer.
1 parent 47cd7e2 commit 67eb588

File tree

6 files changed

+26
-2
lines changed

6 files changed

+26
-2
lines changed

package/contents/config/main.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
<entry name="graphFillOpacity" type="Int">
4747
<default>25</default>
4848
</entry>
49+
<entry name="thirdLineToLeftTopCorner" type="Bool">
50+
<default>false</default>
51+
</entry>
4952

5053
<entry name="enableShadows" type="Bool">
5154
<default>true</default>

package/contents/ui/components/graph/base/GraphText.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Item {
7777
id: secondLine
7878
readonly property int index: 1
7979
text: "..."
80+
anchors.top: firstLine.bottom
8081

8182
width: parent.width
8283
enabled: hints[index] !== ""
@@ -94,7 +95,8 @@ Item {
9495
readonly property int index: 2
9596
text: "..."
9697

97-
width: parent.width
98+
anchors.top: Plasmoid.configuration.thirdLineToLeftTopCorner ? textContainer.top : secondLine.bottom
99+
width: Plasmoid.configuration.thirdLineToLeftTopCorner ? 0.4 * parent.width : parent.width
98100
enabled: hints[index] !== ""
99101
visible: enabled
100102

package/contents/ui/components/sensors/CpuTemperature.qml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import QtQuick
2+
import org.kde.plasma.plasmoid
23
import org.kde.ksysguard.sensors as Sensors
34
import org.kde.ksysguard.formatter as Formatter
45
import org.kde.plasma.plasma5support as Plasma5Support
@@ -27,7 +28,18 @@ Item {
2728
}
2829

2930
function getFormattedValue() {
30-
return Formatter.Formatter.formatValueShowNull(value, 1000 /* Formatter.Unit.UnitCelsius */);
31+
// return Formatter.Formatter.formatValueWithPrecision(value, 1000 /* Formatter.Unit.UnitCelsius */,
32+
// Plasmoid.configuration.thirdLineToLeftTopCorner ? 0 : 1);
33+
// // There should be `QString KSysGuard::FormatterWrapper::formatValueWithPrecision`, according to https://api.kde.org/plasma/libksysguard/html/classKSysGuard_1_1FormatterWrapper.html,
34+
// // However in my environment this function does not exists. So, as workaround, I manually implements the precision control as below.
35+
36+
let result = Formatter.Formatter.formatValueShowNull(value, 1000 /* Formatter.Unit.UnitCelsius */);
37+
if (Plasmoid.configuration.thirdLineToLeftTopCorner) {
38+
let [_, resultNumber, resultUnit] = result.match(/(-?[\d.]+)(.*)/)
39+
resultNumber = Number(resultNumber).toFixed(0)
40+
result = resultNumber + resultUnit
41+
}
42+
return result
3143
}
3244

3345
readonly property var _sensor: Sensors.Sensor {

package/contents/ui/config/ConfigAppearance.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ KCM.AbstractKCM {
2020
property alias cfg_graphHeight: graphHeight.value
2121
property alias cfg_graphSpacing: graphSpacing.value
2222
property alias cfg_graphFillOpacity: graphFillOpacity.value
23+
property alias cfg_thirdLineToLeftTopCorner: thirdLineToLeftTopCorner.checked
2324

2425
// Text
2526
property alias cfg_enableShadows: enableShadows.checked
@@ -160,6 +161,10 @@ KCM.AbstractKCM {
160161
to: 100
161162
suffix: "%"
162163
}
164+
QQC2.CheckBox {
165+
id: thirdLineToLeftTopCorner
166+
text: i18n("Show temperature at the top-left corner?")
167+
}
163168
}
164169

165170
// Text

package/contents/ui/config/ConfigGraph.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ KCM.ScrollViewKCM {
2727
property var cfg_graphHeight
2828
property var cfg_graphSpacing
2929
property var cfg_graphFillOpacity
30+
property var cfg_thirdLineToLeftTopCorner
3031
property var cfg_enableShadows
3132
property var cfg_fontScale
3233
property var cfg_placement

package/contents/ui/config/ConfigMisc.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ KCM.SimpleKCM {
2121
property var cfg_graphHeight
2222
property var cfg_graphSpacing
2323
property var cfg_graphFillOpacity
24+
property var cfg_thirdLineToLeftTopCorner
2425
property var cfg_enableShadows
2526
property var cfg_fontScale
2627
property var cfg_placement

0 commit comments

Comments
 (0)