Add setting for showing date in status bar

As the title said.

Requested in plasma-mobile/plasma-settings#17

I marked it as a draft because there is a small regression which removes vertical alignment of right icons.
This commit is contained in:
Mr. Athozus 2024-06-28 02:05:42 +00:00 committed by Devin Lin
parent 5e2ff03e25
commit 8f9db42e8f
5 changed files with 75 additions and 8 deletions

View file

@ -11,17 +11,34 @@ import QtQuick.Layouts 1.15
import org.kde.plasma.plasma5support 2.0 as P5Support import org.kde.plasma.plasma5support 2.0 as P5Support
import org.kde.plasma.components 3.0 as PlasmaComponents import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.private.mobileshell as MobileShell import org.kde.plasma.private.mobileshell as MobileShell
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
import org.kde.kirigami as Kirigami import org.kde.kirigami as Kirigami
PlasmaComponents.Label { RowLayout {
id: clock id: clockText
required property int fontPixelSize
required property P5Support.DataSource source required property P5Support.DataSource source
property bool is24HourTime: MobileShell.ShellUtil.isSystem24HourFormat PlasmaComponents.Label {
id: clock
text: Qt.formatTime(source.data.Local.DateTime, is24HourTime ? "h:mm" : "h:mm ap") property bool is24HourTime: MobileShell.ShellUtil.isSystem24HourFormat
color: Kirigami.Theme.textColor
verticalAlignment: Qt.AlignVCenter text: Qt.formatTime(source.data.Local.DateTime, is24HourTime ? "h:mm" : "h:mm ap")
color: Kirigami.Theme.textColor
verticalAlignment: Qt.AlignVCenter
font.pixelSize: fontPixelSize
}
PlasmaComponents.Label {
id: date
visible: ShellSettings.Settings.dateInStatusBar && !root.showSecondRow
text: Qt.formatDate(source.data.Local.DateTime, "ddd. MMMM d")
color: Kirigami.Theme.textColor
verticalAlignment: Qt.AlignVCenter
font.pixelSize: fontPixelSize
}
} }

View file

@ -113,7 +113,7 @@ Item {
ClockText { ClockText {
visible: root.showTime visible: root.showTime
Layout.fillHeight: true Layout.fillHeight: true
font.pixelSize: textPixelSize fontPixelSize: textPixelSize
source: timeSource source: timeSource
} }

View file

@ -29,6 +29,7 @@ MobileShellSettings::MobileShellSettings(QObject *parent)
Q_EMIT vibrationsEnabledChanged(); Q_EMIT vibrationsEnabledChanged();
Q_EMIT vibrationDurationChanged(); Q_EMIT vibrationDurationChanged();
Q_EMIT animationsEnabledChanged(); Q_EMIT animationsEnabledChanged();
Q_EMIT dateInStatusBarChanged();
Q_EMIT navigationPanelEnabledChanged(); Q_EMIT navigationPanelEnabledChanged();
Q_EMIT alwaysShowKeyboardToggleOnNavigationPanelChanged(); Q_EMIT alwaysShowKeyboardToggleOnNavigationPanelChanged();
Q_EMIT keyboardButtonEnabledChanged(); Q_EMIT keyboardButtonEnabledChanged();
@ -79,6 +80,19 @@ void MobileShellSettings::setAnimationsEnabled(bool animationsEnabled)
m_config->sync(); m_config->sync();
} }
bool MobileShellSettings::dateInStatusBar() const
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
return group.readEntry("dateInStatusBar", false);
}
void MobileShellSettings::setDateInStatusBar(bool dateInStatusBar)
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
group.writeEntry("dateInStatusBar", dateInStatusBar, 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};

View file

@ -29,6 +29,9 @@ class MobileShellSettings : public QObject
Q_PROPERTY(int vibrationDuration READ vibrationDuration WRITE setVibrationDuration NOTIFY vibrationDurationChanged) Q_PROPERTY(int vibrationDuration READ vibrationDuration WRITE setVibrationDuration NOTIFY vibrationDurationChanged)
Q_PROPERTY(bool animationsEnabled READ animationsEnabled WRITE setAnimationsEnabled NOTIFY animationsEnabledChanged) Q_PROPERTY(bool animationsEnabled READ animationsEnabled WRITE setAnimationsEnabled NOTIFY animationsEnabledChanged)
// status bar
Q_PROPERTY(bool dateInStatusBar READ dateInStatusBar WRITE setDateInStatusBar NOTIFY dateInStatusBarChanged)
// 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
@ -91,6 +94,20 @@ public:
*/ */
void setAnimationsEnabled(bool animationsEnabled); void setAnimationsEnabled(bool animationsEnabled);
/**
* Whether date is shown in the status bar.
*
* If true, date will be shown in the status bar next to the clock.
*/
bool dateInStatusBar() const;
/**
* Set whether date is shown in the status bar.
*
* @param dateInStatusBar Whether date is shown in the status bar.
*/
void setDateInStatusBar(bool dateInStatusBar);
/** /**
* Whether the navigation panel is enabled. * Whether the navigation panel is enabled.
* *
@ -165,6 +182,7 @@ Q_SIGNALS:
void alwaysShowKeyboardToggleOnNavigationPanelChanged(); void alwaysShowKeyboardToggleOnNavigationPanelChanged();
void keyboardButtonEnabledChanged(); void keyboardButtonEnabledChanged();
void animationsEnabledChanged(); void animationsEnabledChanged();
void dateInStatusBarChanged();
void taskSwitcherPreviewsEnabledChanged(); void taskSwitcherPreviewsEnabledChanged();
void actionDrawerTopLeftModeChanged(); void actionDrawerTopLeftModeChanged();
void actionDrawerTopRightModeChanged(); void actionDrawerTopRightModeChanged();

View file

@ -49,6 +49,24 @@ KCM.SimpleKCM {
} }
} }
FormCard.FormHeader {
title: i18n("Status bar")
}
FormCard.FormCard {
FormCard.FormSwitchDelegate {
id: dateInStatusBar
text: i18n("Date in status bar")
description: i18n("If on, date will be shown next to the clock in the status bar.")
checked: ShellSettings.Settings.dateInStatusBar
onCheckedChanged: {
if (checked != ShellSettings.Settings.dateInStatusBar) {
ShellSettings.Settings.dateInStatusBar = checked;
}
}
}
}
FormCard.FormHeader { FormCard.FormHeader {
title: i18n("Navigation Panel") title: i18n("Navigation Panel")
} }