From c18491afd6f348a5ed6ee6f9b38ee9363cf4cf23 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 28 Aug 2022 00:51:24 +0300 Subject: [PATCH] Redesign the cover page --- application/qml/components/CoverLabel.qml | 26 ++++++++++ application/qml/cover/CoverPage.qml | 62 ++++++++--------------- application/qml/harbour-batterybuddy.qml | 7 +++ application/qml/pages/MainPage.qml | 7 --- harbour-batterybuddy.pro | 3 ++ 5 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 application/qml/components/CoverLabel.qml diff --git a/application/qml/components/CoverLabel.qml b/application/qml/components/CoverLabel.qml new file mode 100644 index 0000000..150c3ae --- /dev/null +++ b/application/qml/components/CoverLabel.qml @@ -0,0 +1,26 @@ +/** + * Battery Buddy, a Sailfish application to prolong battery lifetime + * + * Copyright (C) 2019-2020 Matti Viljanen + * + * Battery Buddy is free software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * Battery Buddy 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 General Public License for more details. You should have received a copy of the GNU + * General Public License along with Battery Buddy. If not, see . + * + * Author: Matti Viljanen + */ +import QtQuick 2.6 +import Sailfish.Silica 1.0 + +Label { + width: parent.width + anchors.topMargin: height / 2 + color: Theme.highlightColor + horizontalAlignment: Text.AlignHCenter +} diff --git a/application/qml/cover/CoverPage.qml b/application/qml/cover/CoverPage.qml index acb688a..b1182fd 100644 --- a/application/qml/cover/CoverPage.qml +++ b/application/qml/cover/CoverPage.qml @@ -22,46 +22,28 @@ import "../components" CoverBackground { id: coverPage - onStatusChanged: batteryGraph.updateView() - - BatteryGraph { - id: batteryGraph - x: coverPage.width * 0.3 - y: coverPage.width * 0.25 - width: 0.4 * coverPage.width - - Component.onCompleted: updateView() - onStateChanged: updateView() - onChargerConnectedChanged: updateView() - onChargeChanged: updateView() - function updateView() { - if(charge <= settings.lowerLimit && battery.state === "discharging") { - coverText.text = qsTr("Connect charger") - } - else if(battery.charge >= settings.upperLimit && - (battery.state === "charging" || battery.state === "idle")) { - coverText.text = qsTr("Disconnect charger") - } - else if(battery.chargerConnected && battery.state === "charging") { - coverText.text = qsTr("Charging") - } - else if(battery.chargerConnected && battery.state === "discharging") { - coverText.text = qsTr("Not charging") - } - else { // Discharging - coverText.text = qsTr("Battery Buddy") - } + Column { + spacing: coverPage.width / 20 + anchors { + left: coverPage.left + right: coverPage.right + verticalCenter: parent.verticalCenter + } + BatteryGraph { + x: coverPage.width * 0.3 + y: coverPage.width * 0.25 + width: 0.35 * coverPage.width + } + CoverLabel { + id: chargeLabel + text: "🔋 " + battery.charge + "%" + } + CoverLabel { + text: "🔌 " + Math.floor(battery.current / 1000) + " mA" + } + CoverLabel { + height: text === '🌡️ ' ? 0 : chargeLabel.height + text: "🌡️ " + (battery.temperature === 0x7FFFFFFF ? '? °C' : formatTemperature(battery.temperature)) } } - Label { - id: coverText - anchors.top: batteryGraph.bottom - anchors.bottom: coverPage.bottom - anchors.horizontalCenter: coverPage.horizontalCenter - width: coverPage.width * 0.9 - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - wrapMode: Text.Wrap - maximumLineCount: 2 - } } diff --git a/application/qml/harbour-batterybuddy.qml b/application/qml/harbour-batterybuddy.qml index fd11fd1..6247049 100644 --- a/application/qml/harbour-batterybuddy.qml +++ b/application/qml/harbour-batterybuddy.qml @@ -25,4 +25,11 @@ ApplicationWindow initialPage: Component { MainPage { } } cover: Qt.resolvedUrl("cover/CoverPage.qml") allowedOrientations: Orientation.LandscapeMask | Orientation.Portrait + + function formatTemperature(temp) { + if(Qt.locale().measurementSystem === Locale.ImperialUSSystem) { + return Math.floor((battery.temperature / 10) * 1.8 + 32) + " °F" + } + return Math.floor(battery.temperature / 10) + " °C" + } } diff --git a/application/qml/pages/MainPage.qml b/application/qml/pages/MainPage.qml index e4ff703..8a7bad5 100644 --- a/application/qml/pages/MainPage.qml +++ b/application/qml/pages/MainPage.qml @@ -139,13 +139,6 @@ Page { label: qsTr("Temperature:") value: battery.temperature === 0x7FFFFFFF ? healthText["unknown"] : formatTemperature(battery.temperature) visible: battery.temperature !== 0x7FFFFFFF - - function formatTemperature(temp) { - if(Qt.locale().measurementSystem === Locale.ImperialUSSystem) { - return Math.floor((battery.temperature / 10) * 1.8 + 32) + " °F" - } - return Math.floor(battery.temperature / 10) + " °C" - } } } } diff --git a/harbour-batterybuddy.pro b/harbour-batterybuddy.pro index 31b01a9..4343a74 100644 --- a/harbour-batterybuddy.pro +++ b/harbour-batterybuddy.pro @@ -1,3 +1,6 @@ TEMPLATE = subdirs CONFIG += ordered SUBDIRS = application service + +DISTFILES += \ + application/qml/components/CoverLabel.qml