mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-27 14:33:08 +00:00
Status Bar: Battery Percentage Toggle/Limit to Internal Batteries
Adds a setting to toggle displaying the battery percentage and also limits it to only display the internal batteries. Battery percentage on  Battery percentage off 
This commit is contained in:
parent
c5f0d15b14
commit
5d443aa679
4 changed files with 59 additions and 20 deletions
|
|
@ -13,6 +13,7 @@ import org.kde.kirigami 2.20 as Kirigami
|
||||||
|
|
||||||
import org.kde.plasma.components 3.0 as PlasmaComponents
|
import org.kde.plasma.components 3.0 as PlasmaComponents
|
||||||
import org.kde.plasma.workspace.components 2.0 as PW
|
import org.kde.plasma.workspace.components 2.0 as PW
|
||||||
|
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
|
||||||
import org.kde.plasma.private.mobileshell as MobileShell
|
import org.kde.plasma.private.mobileshell as MobileShell
|
||||||
import org.kde.plasma.private.battery // needed for charging state
|
import org.kde.plasma.private.battery // needed for charging state
|
||||||
|
|
||||||
|
|
@ -24,30 +25,31 @@ RowLayout {
|
||||||
ListView {
|
ListView {
|
||||||
id: batteryRepeater
|
id: batteryRepeater
|
||||||
|
|
||||||
property int batteryWidth: 0
|
spacing: 0
|
||||||
|
|
||||||
spacing: root.elementSpacing
|
|
||||||
model: MobileShell.BatteryInfo.batteries
|
model: MobileShell.BatteryInfo.batteries
|
||||||
orientation: ListView.Horizontal
|
orientation: ListView.Horizontal
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
Layout.preferredWidth: (batteryRepeater.batteryWidth + root.elementSpacing) * batteryRepeater.count
|
Layout.preferredWidth: contentItem.childrenRect.width
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Layout.fillWidth: false
|
Layout.fillWidth: false
|
||||||
|
|
||||||
delegate: RowLayout {
|
delegate: RowLayout {
|
||||||
|
id: batteryBase
|
||||||
|
|
||||||
Layout.preferredWidth: batteryRepeater.batteryWidth
|
width: (batteryBase.visible ? ((batteryLabel.visible ? batteryLabel.width : 0) + battery.width) + (ShellSettings.Settings.showBatteryPercentage ? root.elementSpacing : 0) : 0)
|
||||||
Layout.fillHeight: false
|
Layout.fillHeight: false
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
|
|
||||||
height: batteryRepeater.height
|
height: batteryRepeater.height
|
||||||
|
|
||||||
|
visible: Type === "Battery" // only show the internal battery
|
||||||
|
|
||||||
PW.BatteryIcon {
|
PW.BatteryIcon {
|
||||||
id: battery
|
id: battery
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
height: batteryLabel.height
|
Layout.fillHeight: true
|
||||||
width: batteryLabel.height
|
width: batteryLabel.height
|
||||||
|
|
||||||
hasBattery: PluggedIn
|
hasBattery: PluggedIn
|
||||||
|
|
@ -59,16 +61,12 @@ RowLayout {
|
||||||
id: batteryLabel
|
id: batteryLabel
|
||||||
text: i18n("%1%", Percent)
|
text: i18n("%1%", Percent)
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
|
Layout.fillHeight: true
|
||||||
|
|
||||||
color: Kirigami.Theme.textColor
|
color: Kirigami.Theme.textColor
|
||||||
|
visible: ShellSettings.Settings.showBatteryPercentage
|
||||||
font.pixelSize: textPixelSize
|
font.pixelSize: textPixelSize
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
// ListView & RowLayout have problems with childrenRect size,
|
|
||||||
// set it here so it propagates up nicely
|
|
||||||
batteryRepeater.batteryWidth = batteryLabel.width + battery.width
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ MobileShellSettings::MobileShellSettings(QObject *parent)
|
||||||
Q_EMIT animationsEnabledChanged();
|
Q_EMIT animationsEnabledChanged();
|
||||||
Q_EMIT dateInStatusBarChanged();
|
Q_EMIT dateInStatusBarChanged();
|
||||||
Q_EMIT statusBarScaleFactorChanged();
|
Q_EMIT statusBarScaleFactorChanged();
|
||||||
|
Q_EMIT showBatteryPercentageChanged();
|
||||||
Q_EMIT navigationPanelEnabledChanged();
|
Q_EMIT navigationPanelEnabledChanged();
|
||||||
Q_EMIT alwaysShowKeyboardToggleOnNavigationPanelChanged();
|
Q_EMIT alwaysShowKeyboardToggleOnNavigationPanelChanged();
|
||||||
Q_EMIT keyboardButtonEnabledChanged();
|
Q_EMIT keyboardButtonEnabledChanged();
|
||||||
|
|
@ -114,6 +115,19 @@ void MobileShellSettings::setStatusBarScaleFactor(float statusBarScaleFactor)
|
||||||
m_config->sync();
|
m_config->sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MobileShellSettings::showBatteryPercentage() const
|
||||||
|
{
|
||||||
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
||||||
|
return group.readEntry("showBatteryPercentage", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MobileShellSettings::setShowBatteryPercentage(bool showBatteryPercentage)
|
||||||
|
{
|
||||||
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
||||||
|
group.writeEntry("showBatteryPercentage", showBatteryPercentage, KConfigGroup::Notify);
|
||||||
|
m_config->sync();
|
||||||
|
}
|
||||||
|
|
||||||
bool MobileShellSettings::navigationPanelEnabled() const
|
bool MobileShellSettings::navigationPanelEnabled() const
|
||||||
{
|
{
|
||||||
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
||||||
|
|
@ -254,4 +268,4 @@ void MobileShellSettings::setLockscreenRightButtonAction(const LockscreenButtonA
|
||||||
auto group = KConfigGroup{m_config, LOCKSCREEN_CONFIG_GROUP};
|
auto group = KConfigGroup{m_config, LOCKSCREEN_CONFIG_GROUP};
|
||||||
group.writeEntry("lockscreenRightButtonAction", (int)action, KConfigGroup::Notify);
|
group.writeEntry("lockscreenRightButtonAction", (int)action, KConfigGroup::Notify);
|
||||||
m_config->sync();
|
m_config->sync();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,11 @@ class MobileShellSettings : public QObject
|
||||||
// status bar
|
// status bar
|
||||||
Q_PROPERTY(bool dateInStatusBar READ dateInStatusBar WRITE setDateInStatusBar NOTIFY dateInStatusBarChanged)
|
Q_PROPERTY(bool dateInStatusBar READ dateInStatusBar WRITE setDateInStatusBar NOTIFY dateInStatusBarChanged)
|
||||||
Q_PROPERTY(float statusBarScaleFactor READ statusBarScaleFactor WRITE setStatusBarScaleFactor NOTIFY statusBarScaleFactorChanged)
|
Q_PROPERTY(float statusBarScaleFactor READ statusBarScaleFactor WRITE setStatusBarScaleFactor NOTIFY statusBarScaleFactorChanged)
|
||||||
|
Q_PROPERTY(bool showBatteryPercentage READ showBatteryPercentage WRITE setShowBatteryPercentage NOTIFY showBatteryPercentageChanged)
|
||||||
|
|
||||||
// navigation panel
|
// navigation panel
|
||||||
Q_PROPERTY(bool navigationPanelEnabled READ navigationPanelEnabled WRITE setNavigationPanelEnabled NOTIFY navigationPanelEnabledChanged)
|
Q_PROPERTY(bool navigationPanelEnabled READ navigationPanelEnabled WRITE setNavigationPanelEnabled NOTIFY navigationPanelEnabledChanged)
|
||||||
Q_PROPERTY(bool alwaysShowKeyboardToggleOnNavigationPanel READ alwaysShowKeyboardToggleOnNavigationPanel WRITE setAlwaysShowKeyboardToggleOnNavigationPanel
|
Q_PROPERTY(bool alwaysShowKeyboardToggleOnNavigationPanel READ alwaysShowKeyboardToggleOnNavigationPanel WRITE setAlwaysShowKeyboardToggleOnNavigationPanel NOTIFY alwaysShowKeyboardToggleOnNavigationPanelChanged)
|
||||||
NOTIFY alwaysShowKeyboardToggleOnNavigationPanelChanged)
|
|
||||||
|
|
||||||
// action drawer
|
// action drawer
|
||||||
Q_PROPERTY(ActionDrawerMode actionDrawerTopLeftMode READ actionDrawerTopLeftMode WRITE setActionDrawerTopLeftMode NOTIFY actionDrawerTopLeftModeChanged)
|
Q_PROPERTY(ActionDrawerMode actionDrawerTopLeftMode READ actionDrawerTopLeftMode WRITE setActionDrawerTopLeftMode NOTIFY actionDrawerTopLeftModeChanged)
|
||||||
|
|
@ -49,10 +49,8 @@ class MobileShellSettings : public QObject
|
||||||
Q_PROPERTY(bool allowLogout READ allowLogout READ allowLogout NOTIFY allowLogoutChanged)
|
Q_PROPERTY(bool allowLogout READ allowLogout READ allowLogout NOTIFY allowLogoutChanged)
|
||||||
|
|
||||||
// locksreen shortcut icons
|
// locksreen shortcut icons
|
||||||
Q_PROPERTY(LockscreenButtonAction lockscreenLeftButtonAction READ lockscreenLeftButtonAction WRITE setLockscreenLeftButtonAction NOTIFY
|
Q_PROPERTY(LockscreenButtonAction lockscreenLeftButtonAction READ lockscreenLeftButtonAction WRITE setLockscreenLeftButtonAction NOTIFY lockscreenLeftButtonActionChanged)
|
||||||
lockscreenLeftButtonActionChanged)
|
Q_PROPERTY(LockscreenButtonAction lockscreenRightButtonAction READ lockscreenRightButtonAction WRITE setLockscreenRightButtonAction NOTIFY lockscreenRightButtonActionChanged)
|
||||||
Q_PROPERTY(LockscreenButtonAction lockscreenRightButtonAction READ lockscreenRightButtonAction WRITE setLockscreenRightButtonAction NOTIFY
|
|
||||||
lockscreenRightButtonActionChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MobileShellSettings(QObject *parent = nullptr);
|
MobileShellSettings(QObject *parent = nullptr);
|
||||||
|
|
@ -140,6 +138,20 @@ public:
|
||||||
*/
|
*/
|
||||||
void setStatusBarScaleFactor(float statusBarScaleFactor);
|
void setStatusBarScaleFactor(float statusBarScaleFactor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the battery percentage is shown in the status bar.
|
||||||
|
*
|
||||||
|
* If true, the percentage will be shown next to the battery in the status bar.
|
||||||
|
*/
|
||||||
|
bool showBatteryPercentage() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the battery percentage is shown in the status bar.
|
||||||
|
*
|
||||||
|
* @param showBatteryPercentage Whether the battery percentage is shown in the status bar.
|
||||||
|
*/
|
||||||
|
void setShowBatteryPercentage(bool showBatteryPercentage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the navigation panel is enabled.
|
* Whether the navigation panel is enabled.
|
||||||
*
|
*
|
||||||
|
|
@ -245,6 +257,7 @@ Q_SIGNALS:
|
||||||
void animationsEnabledChanged();
|
void animationsEnabledChanged();
|
||||||
void dateInStatusBarChanged();
|
void dateInStatusBarChanged();
|
||||||
void statusBarScaleFactorChanged();
|
void statusBarScaleFactorChanged();
|
||||||
|
void showBatteryPercentageChanged();
|
||||||
void taskSwitcherPreviewsEnabledChanged();
|
void taskSwitcherPreviewsEnabledChanged();
|
||||||
void actionDrawerTopLeftModeChanged();
|
void actionDrawerTopLeftModeChanged();
|
||||||
void actionDrawerTopRightModeChanged();
|
void actionDrawerTopRightModeChanged();
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,20 @@ KCM.SimpleKCM {
|
||||||
|
|
||||||
FormCard.FormDelegateSeparator { above: quickSettingsButton; below: topLeftActionDrawerModeDelegate }
|
FormCard.FormDelegateSeparator { above: quickSettingsButton; below: topLeftActionDrawerModeDelegate }
|
||||||
|
|
||||||
|
FormCard.FormSwitchDelegate {
|
||||||
|
id: showBatteryPercentage
|
||||||
|
text: i18n("Battery Percentage")
|
||||||
|
description: i18n("Show battery percentage in the status bar.")
|
||||||
|
checked: ShellSettings.Settings.showBatteryPercentage
|
||||||
|
onCheckedChanged: {
|
||||||
|
if (checked != ShellSettings.Settings.showBatteryPercentage) {
|
||||||
|
ShellSettings.Settings.showBatteryPercentage = checked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FormCard.FormDelegateSeparator { above: quickSettingsButton; below: topLeftActionDrawerModeDelegate }
|
||||||
|
|
||||||
FormCard.FormComboBoxDelegate {
|
FormCard.FormComboBoxDelegate {
|
||||||
id: statusBarScaleFactorDelegate
|
id: statusBarScaleFactorDelegate
|
||||||
|
|
||||||
|
|
@ -239,7 +253,7 @@ KCM.SimpleKCM {
|
||||||
}
|
}
|
||||||
onCurrentValueChanged: ShellSettings.Settings.lockscreenLeftButtonAction = currentValue
|
onCurrentValueChanged: ShellSettings.Settings.lockscreenLeftButtonAction = currentValue
|
||||||
}
|
}
|
||||||
|
|
||||||
FormCard.FormDelegateSeparator { above: lockscreenRightButtonDelegate; below: lockscreenLeftButtonDelegate }
|
FormCard.FormDelegateSeparator { above: lockscreenRightButtonDelegate; below: lockscreenLeftButtonDelegate }
|
||||||
|
|
||||||
FormCard.FormComboBoxDelegate {
|
FormCard.FormComboBoxDelegate {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue