2019-01-29 02:09:54 +03:00
|
|
|
/**
|
|
|
|
* Battery Buddy, a Sailfish application to prolong battery lifetime
|
|
|
|
*
|
2022-08-28 10:36:38 +03:00
|
|
|
* Copyright (C) 2019-2022 Matti Viljanen
|
2019-01-29 02:09:54 +03:00
|
|
|
*
|
|
|
|
* 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
|
2020-03-24 11:02:30 +03:00
|
|
|
* General Public License along with Battery Buddy. If not, see <http://www.gnu.org/licenses/>.
|
2019-01-29 02:09:54 +03:00
|
|
|
*
|
|
|
|
* Author: Matti Viljanen
|
|
|
|
*/
|
2022-03-20 21:16:24 +03:00
|
|
|
import QtQuick 2.6
|
2019-01-29 02:09:54 +03:00
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: batteryGraph
|
2022-08-28 00:54:50 +03:00
|
|
|
property real borderSize: width * 0.1
|
|
|
|
property bool enableLowBatteryAnimation
|
|
|
|
property int _charge: battery.charge
|
|
|
|
|
2019-01-29 02:09:54 +03:00
|
|
|
height: 1.75 * width
|
|
|
|
|
2022-08-28 00:54:50 +03:00
|
|
|
// Timer {
|
|
|
|
// id: debugChargeAnimation
|
|
|
|
// property int newCharge: -20
|
|
|
|
// repeat: true
|
|
|
|
// running: true
|
|
|
|
// interval: 300
|
|
|
|
// onTriggered: {
|
|
|
|
// newCharge = newCharge + 5
|
|
|
|
// if(newCharge > 120)
|
|
|
|
// newCharge = -20
|
|
|
|
// _charge = newCharge < 0 ? 0 : newCharge > 100 ? 100 : newCharge
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: lowChargeBlink
|
|
|
|
property int counter: 0
|
2022-08-28 09:55:22 +03:00
|
|
|
running: (enableLowBatteryAnimation
|
2022-08-28 00:54:50 +03:00
|
|
|
&& !battery.chargerConnected
|
2023-02-23 18:07:05 +03:00
|
|
|
&& !battery.acConnected
|
2022-08-28 00:54:50 +03:00
|
|
|
&& _charge <= settings.lowAlert)
|
|
|
|
repeat: true
|
|
|
|
interval: 400
|
|
|
|
onTriggered: {
|
|
|
|
counter = (counter + 1) % 5
|
|
|
|
if(counter === 0) {
|
|
|
|
batteryLevel.opacity = 0.0
|
|
|
|
restoreOpacity.start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: restoreOpacity
|
|
|
|
running: false
|
|
|
|
repeat: false
|
|
|
|
interval: opacityAnimation.duration
|
|
|
|
onTriggered: batteryLevel.opacity = 1.0
|
|
|
|
}
|
|
|
|
|
2019-01-29 02:09:54 +03:00
|
|
|
Rectangle {
|
|
|
|
id: battTip
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
width: 2 * borderSize
|
2022-08-28 00:54:50 +03:00
|
|
|
height: 1.5 * borderSize
|
2022-08-28 09:54:16 +03:00
|
|
|
color: Theme.secondaryColor
|
2022-08-28 00:54:50 +03:00
|
|
|
radius: borderSize / 2
|
2019-01-29 02:09:54 +03:00
|
|
|
}
|
|
|
|
Rectangle {
|
|
|
|
id: battBody
|
2022-08-28 00:54:50 +03:00
|
|
|
anchors {
|
|
|
|
top: battTip.verticalCenter
|
|
|
|
bottom: parent.bottom
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
width: parent.width * 0.75
|
|
|
|
color: "transparent"
|
2022-08-28 09:54:16 +03:00
|
|
|
border.color: Theme.secondaryColor
|
2019-01-29 02:09:54 +03:00
|
|
|
border.width: borderSize
|
2022-08-28 00:54:50 +03:00
|
|
|
radius: borderSize
|
2019-01-29 02:09:54 +03:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: batteryLevel
|
2022-08-28 00:54:50 +03:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.bottomMargin: borderSize * 1.5
|
|
|
|
width: parent.width - 3 * borderSize
|
|
|
|
height: (borderSize) + ((parent.height - 4 * borderSize) * _charge / 100.0)
|
|
|
|
radius: borderSize / 2
|
|
|
|
opacity: 1.0
|
2022-08-28 09:54:16 +03:00
|
|
|
color: _charge >= 80 ? Theme.secondaryColor
|
2022-08-28 00:54:50 +03:00
|
|
|
: _charge >= 50 ? Theme.highlightFromColor("green", Theme.colorScheme)
|
|
|
|
: _charge >= 20 ? Theme.highlightFromColor("yellow", Theme.colorScheme)
|
|
|
|
: Theme.highlightFromColor("red", Theme.colorScheme)
|
|
|
|
Behavior on color {
|
|
|
|
ColorAnimation {}
|
|
|
|
}
|
|
|
|
Behavior on opacity {
|
|
|
|
NumberAnimation {
|
|
|
|
id: opacityAnimation
|
|
|
|
}
|
|
|
|
}
|
2019-01-29 02:09:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|