Redesign the cover page

This commit is contained in:
Matti Viljanen 2022-08-28 00:51:24 +03:00
parent 317cd5bb6a
commit c18491afd6
No known key found for this signature in database
GPG key ID: CF32A1495158F888
5 changed files with 58 additions and 47 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
*
* 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
}

View file

@ -22,46 +22,28 @@ import "../components"
CoverBackground { CoverBackground {
id: coverPage id: coverPage
onStatusChanged: batteryGraph.updateView() Column {
spacing: coverPage.width / 20
BatteryGraph { anchors {
id: batteryGraph left: coverPage.left
x: coverPage.width * 0.3 right: coverPage.right
y: coverPage.width * 0.25 verticalCenter: parent.verticalCenter
width: 0.4 * coverPage.width }
BatteryGraph {
Component.onCompleted: updateView() x: coverPage.width * 0.3
onStateChanged: updateView() y: coverPage.width * 0.25
onChargerConnectedChanged: updateView() width: 0.35 * coverPage.width
onChargeChanged: updateView() }
function updateView() { CoverLabel {
if(charge <= settings.lowerLimit && battery.state === "discharging") { id: chargeLabel
coverText.text = qsTr("Connect charger") text: "🔋 " + battery.charge + "%"
} }
else if(battery.charge >= settings.upperLimit && CoverLabel {
(battery.state === "charging" || battery.state === "idle")) { text: "🔌 " + Math.floor(battery.current / 1000) + " mA"
coverText.text = qsTr("Disconnect charger") }
} CoverLabel {
else if(battery.chargerConnected && battery.state === "charging") { height: text === '🌡️ ' ? 0 : chargeLabel.height
coverText.text = qsTr("Charging") text: "🌡️ " + (battery.temperature === 0x7FFFFFFF ? '? °C' : formatTemperature(battery.temperature))
}
else if(battery.chargerConnected && battery.state === "discharging") {
coverText.text = qsTr("Not charging")
}
else { // Discharging
coverText.text = qsTr("Battery Buddy")
}
} }
} }
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
}
} }

View file

@ -25,4 +25,11 @@ ApplicationWindow
initialPage: Component { MainPage { } } initialPage: Component { MainPage { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml") cover: Qt.resolvedUrl("cover/CoverPage.qml")
allowedOrientations: Orientation.LandscapeMask | Orientation.Portrait 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"
}
} }

View file

@ -139,13 +139,6 @@ Page {
label: qsTr("Temperature:") label: qsTr("Temperature:")
value: battery.temperature === 0x7FFFFFFF ? healthText["unknown"] : formatTemperature(battery.temperature) value: battery.temperature === 0x7FFFFFFF ? healthText["unknown"] : formatTemperature(battery.temperature)
visible: battery.temperature !== 0x7FFFFFFF 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"
}
} }
} }
} }

View file

@ -1,3 +1,6 @@
TEMPLATE = subdirs TEMPLATE = subdirs
CONFIG += ordered CONFIG += ordered
SUBDIRS = application service SUBDIRS = application service
DISTFILES += \
application/qml/components/CoverLabel.qml