From 6a19697c316c5ca8acabdecd51582299232555a8 Mon Sep 17 00:00:00 2001 From: Raphael Graf Date: Wed, 5 Jun 2019 22:12:22 +0200 Subject: [PATCH 1/2] Fix battery widget percentage display --- src/widget/wbattery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/wbattery.cpp b/src/widget/wbattery.cpp index e5330db6a0c..1d11142ab7b 100644 --- a/src/widget/wbattery.cpp +++ b/src/widget/wbattery.cpp @@ -86,7 +86,7 @@ QString formatMinutes(int minutes) { int pixmapIndexFromPercentage(double dPercentage, int numPixmaps) { // See WDisplay::getActivePixmapIndex for more info on this. - int result = static_cast(dPercentage * numPixmaps - 0.00001); + int result = static_cast(dPercentage * numPixmaps - 0.00001) / 100; result = math_min(numPixmaps - 1, math_max(0, result)); return result; } From ab59a232d066375dc9b844dc2bd72fbf50ebaf74 Mon Sep 17 00:00:00 2001 From: Raphael Graf Date: Sat, 8 Jun 2019 17:07:40 +0200 Subject: [PATCH 2/2] Simplify pixmapIndexFromPercentage function --- src/widget/wbattery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/wbattery.cpp b/src/widget/wbattery.cpp index 1d11142ab7b..aa647e9e68a 100644 --- a/src/widget/wbattery.cpp +++ b/src/widget/wbattery.cpp @@ -86,7 +86,7 @@ QString formatMinutes(int minutes) { int pixmapIndexFromPercentage(double dPercentage, int numPixmaps) { // See WDisplay::getActivePixmapIndex for more info on this. - int result = static_cast(dPercentage * numPixmaps - 0.00001) / 100; + int result = static_cast(dPercentage / 100.0 * numPixmaps); result = math_min(numPixmaps - 1, math_max(0, result)); return result; }