Skip to content

Commit

Permalink
Fix battery display on unofficial watchfaces.
Browse files Browse the repository at this point in the history
Several of the unofficial watchfaces relied on org.freedesktop.context
for the battery charge level.  We now use Nemo.Mce to get that value, so
this change fixes four of the six affected watchfaces.

Signed-off-by: Ed Beroset <[email protected]>
  • Loading branch information
beroset authored and FlorentRevest committed Jan 28, 2022
1 parent b64d604 commit 385d0a7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import QtQuick 2.15
import QtGraphicalEffects 1.15
import org.freedesktop.contextkit 1.0
import Nemo.Mce 1.0
import org.asteroid.controls 1.0
import org.asteroid.utils 1.0

Expand All @@ -39,12 +39,8 @@ Item {

anchors.fill: parent

ContextProperty {
id: batteryChargePercentage

key: "Battery.ChargePercentage"
value: "100"
Component.onCompleted: batteryChargePercentage.subscribe()
MceBatteryLevel {
id: batteryChargePercentage
}

Image {
Expand Down Expand Up @@ -370,7 +366,7 @@ Item {
Item {
id: batteryBox

property int value: batteryChargePercentage.value
property int value: batteryChargePercentage.percent

onValueChanged: batteryArc.requestPaint()

Expand Down Expand Up @@ -406,14 +402,14 @@ Item {
ctx.closePath()
ctx.lineWidth = root.height * .005
ctx.lineCap="round"
ctx.strokeStyle = batteryChargePercentage.value < 30 ?
ctx.strokeStyle = batteryChargePercentage.percent < 30 ?
accColor : "#44BBA4"
ctx.beginPath()
ctx.arc(parent.width / 2,
parent.height / 2,
parent.width * .456,
270 * rad,
((batteryChargePercentage.value / 100 * 360) + 270) * rad,
((batteryChargePercentage.percent / 100 * 360) + 270) * rad,
false
);
ctx.stroke()
Expand All @@ -433,7 +429,7 @@ Item {
styleName:"Condensed Light"
}
color: highColor
text: batteryChargePercentage.value
text: batteryChargePercentage.percent

Text {
id: batteryPercent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import QtQuick 2.1
import QtGraphicalEffects 1.15
import org.freedesktop.contextkit 1.0
import Nemo.Mce 1.0
import org.asteroid.controls 1.0
import org.asteroid.utils 1.0

Expand All @@ -32,11 +32,8 @@ Item {
property string imgPath: "../watchfaces-img/analog-scientific-v2-"
property real rad: 0.01745

ContextProperty {
MceBatteryLevel {
id: batteryChargePercentage
key: "Battery.ChargePercentage"
value: "100"
Component.onCompleted: batteryChargePercentage.subscribe()
}

Repeater {
Expand Down Expand Up @@ -377,7 +374,7 @@ Item {

Item {
id: batteryBox
property int value: batteryChargePercentage.value
property int value: batteryChargePercentage.percent
onValueChanged: batteryArc.requestPaint()
anchors {
centerIn: parent
Expand Down Expand Up @@ -417,16 +414,16 @@ Item {
parent.width * 0.46
)
gradient.addColorStop(0.44,
batteryChargePercentage.value < 30 ?
batteryChargePercentage.percent < 30 ?
"#00EF476F" :
batteryChargePercentage.value < 60 ?
batteryChargePercentage.percent < 60 ?
"#00D0E562" :
"#0023F0C7"
)
gradient.addColorStop(0.97,
batteryChargePercentage.value < 30 ?
batteryChargePercentage.percent < 30 ?
"#ffEF476F" :
batteryChargePercentage.value < 60 ?
batteryChargePercentage.percent < 60 ?
"#ffD0E562" :
"#ff23F0C7"
)
Expand All @@ -438,7 +435,7 @@ Item {
parent.height / 2,
parent.width * 0.456,
270 * rad,
((batteryChargePercentage.value/100*360)+270) * rad,
((batteryChargePercentage.percent/100*360)+270) * rad,
false
);
ctx.lineTo(parent.width / 2,
Expand All @@ -459,7 +456,7 @@ Item {
font.family: "Outfit"
font.styleName:"Thin"
color: "#ffffffff"
text: batteryChargePercentage.value
text: batteryChargePercentage.percent

Text {
z: 9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import QtQuick 2.1
import org.freedesktop.contextkit 1.0
import Nemo.Mce 1.0
import org.asteroid.controls 1.0
import org.asteroid.utils 1.0

Expand Down Expand Up @@ -137,8 +137,8 @@ Item {
//topMargin: -parent.height*0.03
horizontalCenter: parent.horizontalCenter
}
color: batteryChargePercentage.value < 30 ? 'red': batteryChargePercentage.value < 60 ? 'yellow': Qt.rgba(0, 1, 0, 1)
width: parent.width/100*batteryChargePercentage.value
color: batteryChargePercentage.percent < 30 ? 'red': batteryChargePercentage.percent < 60 ? 'yellow': Qt.rgba(0, 1, 0, 1)
width: parent.width/100*batteryChargePercentage.percent
height: parent.height * 0.004
}

Expand All @@ -147,20 +147,17 @@ Item {
id: batteryDisplay
font.pixelSize: parent.height*0.05
font.family: "Elektra"
color: batteryChargePercentage.value < 30 ? 'red': batteryChargePercentage.value < 60 ? 'yellow': Qt.rgba(0, 1, 0, 1)
color: batteryChargePercentage.percent < 30 ? 'red': batteryChargePercentage.percent < 60 ? 'yellow': Qt.rgba(0, 1, 0, 1)
horizontalAlignment: Text.AlignHCenter
anchors {
top: batteryBack.bottom
topMargin: -parent.height*0.0055
horizontalCenter: parent.horizontalCenter
}
text: batteryChargePercentage.value
text: batteryChargePercentage.percent
}

ContextProperty {
MceBatteryLevel {
id: batteryChargePercentage
key: "Battery.ChargePercentage"
value: "100"
Component.onCompleted: batteryChargePercentage.subscribe()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import QtQuick 2.1
import org.freedesktop.contextkit 1.0
import Nemo.Mce 1.0
import org.asteroid.controls 1.0
import org.asteroid.utils 1.0

Expand Down Expand Up @@ -301,13 +301,13 @@ Item {
ctx.shadowOffsetY = 0
ctx.shadowBlur = 2
var gradient = ctx.createRadialGradient (parent.width/2, parent.height/2, 0, parent.width/2, parent.height/2, parent.width *0.46)
gradient.addColorStop(0.39, batteryChargePercentage.value < 30 ? 'red': Qt.rgba(0.318, 1, 0.051, 0.0))
gradient.addColorStop(0.95, batteryChargePercentage.value < 30 ? 'red': Qt.rgba(0.318, 1, 0.051, 0.9))
gradient.addColorStop(0.39, batteryChargePercentage.percent < 30 ? 'red': Qt.rgba(0.318, 1, 0.051, 0.0))
gradient.addColorStop(0.95, batteryChargePercentage.percent < 30 ? 'red': Qt.rgba(0.318, 1, 0.051, 0.9))
ctx.lineWidth = parent.height*0.007
ctx.lineCap="round"
ctx.strokeStyle = gradient
ctx.beginPath()
ctx.arc(parent.width/2, parent.height/2, parent.width *0.46, 270* 0.01745, ((batteryChargePercentage.value/100*360)+270)* 0.01745, false);
ctx.arc(parent.width/2, parent.height/2, parent.width *0.46, 270* 0.01745, ((batteryChargePercentage.percent/100*360)+270)* 0.01745, false);
ctx.lineTo(parent.width/2,
parent.height/2)
ctx.stroke()
Expand All @@ -319,7 +319,7 @@ Item {
z: 9
id: batteryDisplay
renderType: Text.NativeRendering
property var rotB: (batteryChargePercentage.value-25)/100
property var rotB: (batteryChargePercentage.percent-25)/100
property var centerX: parent.width/2-width/2
property var centerY: parent.height/2-height/2
font.pixelSize: parent.height/16
Expand All @@ -330,7 +330,7 @@ Item {
style: Text.Outline; styleColor: "#80000000"
x: centerX+Math.cos(rotB * 2 * Math.PI)*height*4.5
y: centerY+Math.sin(rotB * 2 * Math.PI)*height*4.5
text: "<b>" + batteryChargePercentage.value + "</b>"
text: "<b>" + batteryChargePercentage.percent + "</b>"
}

Text {
Expand Down Expand Up @@ -388,11 +388,8 @@ Item {
text: wallClock.time.toLocaleString(Qt.locale(), "dd MMMM")
}

ContextProperty {
MceBatteryLevel {
id: batteryChargePercentage
key: "Battery.ChargePercentage"
value: "100"
Component.onCompleted: batteryChargePercentage.subscribe()
}

Connections {
Expand Down

0 comments on commit 385d0a7

Please sign in to comment.