Commit a67ab7e4 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Allow specifying a maximum percent value for volume OSDs

The volume setting in plasma-pa can exceed 100%. Currently the display is limited to 100%, which can result in a mismatch between what is shown in the applet and in the OSD.

This adds an overload to volumeChanged to keep the old one compatible given it is used by e.g. kmix
parent 7474d397
......@@ -32,6 +32,8 @@ PlasmaCore.Dialog {
// This is either a text or a number, if showingProgress is set to true,
// the number will be used as a value for the progress bar
property var osdValue
// Maximum percent value
property int osdMaxValue: 100
// Icon name to display
property string icon
// Set to true if the value is meant for progress bar,
......
......@@ -47,7 +47,7 @@ RowLayout {
Layout.rightMargin: units.smallSpacing
visible: rootItem.showingProgress
from: 0
to: 100
to: rootItem.osdMaxValue
value: Number(rootItem.osdValue)
}
......
......@@ -43,15 +43,20 @@ Osd::~Osd()
void Osd::brightnessChanged(int percent)
{
showProgress(QStringLiteral("video-display-brightness"), percent);
showProgress(QStringLiteral("video-display-brightness"), percent, 100);
}
void Osd::keyboardBrightnessChanged(int percent)
{
showProgress(QStringLiteral("input-keyboard-brightness"), percent);
showProgress(QStringLiteral("input-keyboard-brightness"), percent, 100);
}
void Osd::volumeChanged(int percent)
{
volumeChanged(percent, 100);
}
void Osd::volumeChanged(int percent, int maximumPercent)
{
QString icon;
if (percent <= 0) {
......@@ -66,7 +71,7 @@ void Osd::volumeChanged(int percent)
icon = QStringLiteral("audio-volume-high");
}
showProgress(icon, percent);
showProgress(icon, percent, maximumPercent);
}
void Osd::microphoneVolumeChanged(int percent)
......@@ -84,7 +89,7 @@ void Osd::microphoneVolumeChanged(int percent)
icon = QStringLiteral("microphone-sensitivity-high");
}
showProgress(icon, percent);
showProgress(icon, percent, 100);
}
void Osd::mediaPlayerVolumeChanged(int percent, const QString &playerName, const QString &playerIconName)
......@@ -92,7 +97,7 @@ void Osd::mediaPlayerVolumeChanged(int percent, const QString &playerName, const
if (percent == 0) {
showText(playerIconName, i18nc("OSD informing that some media app is muted, eg. Amarok Muted", "%1 Muted", playerName));
} else {
showProgress(playerIconName, percent, playerName);
showProgress(playerIconName, percent, 100, playerName);
}
}
......@@ -188,16 +193,16 @@ bool Osd::init()
return true;
}
void Osd::showProgress(const QString &icon, const int percent, const QString &additionalText)
void Osd::showProgress(const QString &icon, const int percent, const int maximumPercent, const QString &additionalText)
{
if (!init()) {
return;
}
auto *rootObject = m_osdObject->rootObject();
int value = qBound(0, percent, 100);
int value = qBound(0, percent, maximumPercent);
rootObject->setProperty("osdValue", value);
rootObject->setProperty("osdMaxValue", maximumPercent);
rootObject->setProperty("osdAdditionalText", additionalText);
rootObject->setProperty("showingProgress", true);
rootObject->setProperty("icon", icon);
......
......@@ -45,6 +45,7 @@ public Q_SLOTS:
void brightnessChanged(int percent);
void keyboardBrightnessChanged(int percent);
void volumeChanged(int percent);
void volumeChanged(int percent, int maximumPercent);
void microphoneVolumeChanged(int percent);
void mediaPlayerVolumeChanged(int percent, const QString &playerName, const QString &playerIconName);
void kbdLayoutChanged(const QString &layoutName);
......@@ -66,7 +67,7 @@ private Q_SLOTS:
private:
bool init();
void showProgress(const QString &icon, const int percent, const QString &additionalText = QString());
void showProgress(const QString &icon, const int percent, const int maximumPercent, const QString &additionalText = QString());
void showOsd();
QUrl m_osdUrl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment