Commit d2f545bf authored by David Edmundson's avatar David Edmundson
Browse files

Add global animation speed slider to workspace options KCM

Summary:
Introduce a new config entry into kdeglobals AnimationSpeed that will
control /all/ animation speeds in kwin and plasma themes and Qt styles
and kirigami.

The value stored is a multiplier.
i.e 1 == normal speed, 0.5 = twice as fast, 2 = twice as slow.
0 is a special value meaning "disable animations"

The QML is a bit complex to represent a logarithmic slider that goes
4x, 2x, 1x, 0.5x, 0.25x, 0.125x

but still allowing a user to type arbitrary values into their config

Test Plan: Looked at config

Reviewers: #plasma, broulik

Reviewed By: #plasma, broulik

Subscribers: ngraham, GB_2, broulik, anthonyfieroni, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D22885
parent 8a61cd18
......@@ -17,7 +17,7 @@
*/
import QtQuick 2.7
import QtQuick.Controls 2.4 as Controls
import QtQuick.Layouts 1.3 as Layouts
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kcm 1.2 as KCM
......@@ -47,6 +47,40 @@ KCM.SimpleKCM {
onCheckedChanged: kcm.visualFeedback = checked
}
// We want to show the slider in a logarithmic way. ie
// move from 4x, 3x, 2x, 1x, 0.5x, 0.25x, 0.125x
// 0 is a special case
RowLayout {
Kirigami.FormData.label: i18n("Animation speed:")
Controls.Label {
text: i18nc("Animation speed", "Slow")
}
Controls.Slider {
id: slider
Layout.fillWidth: true
from: -4
to: 4
stepSize: 1
snapMode: Controls.Slider.SnapAlways
onMoved: {
if(value === to) {
kcm.animationDurationFactor = 0;
} else {
kcm.animationDurationFactor = 1.0 / Math.pow(2, value);
}
}
value: if (kcm.animationDurationFactor === 0) {
return slider.to;
} else {
return -(Math.log(kcm.animationDurationFactor) / Math.log(2));
}
}
Controls.Label {
text: i18nc("Animation speed", "Instant")
}
}
Connections {
target: kcm
onToolTipChanged: showToolTips.checked = kcm.toolTip
......
......@@ -69,6 +69,7 @@ void KCMWorkspaceOptions::defaults()
setToolTip(true);
setVisualFeedback(true);
setSingleClick(true);
setAnimationDurationFactor(1.0);
handleNeedsSave();
}
......@@ -127,6 +128,21 @@ void KCMWorkspaceOptions::setSingleClick(bool state)
handleNeedsSave();
}
qreal KCMWorkspaceOptions::getAnimationDurationFactor() const
{
return m_animationDurationFactor;
}
void KCMWorkspaceOptions::setAnimationDurationFactor(qreal factor)
{
if (m_animationDurationFactor == factor) {
return;
}
m_animationDurationFactor = factor;
emit animationDurationFactorChanged();
handleNeedsSave();
}
void KCMWorkspaceOptions::loadPlasmarc()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("plasmarc"));
......@@ -135,7 +151,6 @@ void KCMWorkspaceOptions::loadPlasmarc()
// Load toolTip
{
const KConfigGroup cg(config, QStringLiteral("PlasmaToolTips"));
state = cg.readEntry("Delay", 0.7) > 0;
setToolTip(state);
m_toolTipOriginalState = state;
......@@ -154,16 +169,15 @@ void KCMWorkspaceOptions::loadPlasmarc()
void KCMWorkspaceOptions::loadKdeglobals()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("kdeglobals"));
bool state;
// Load singleClick
{
const KConfigGroup cg(config, QStringLiteral("KDE"));
const KConfigGroup cg(config, QStringLiteral("KDE"));
state = cg.readEntry(QStringLiteral("SingleClick"), true);
setSingleClick(state);
m_singleClickOriginalState = state;
}
bool state = cg.readEntry(QStringLiteral("SingleClick"), true);
setSingleClick(state);
m_singleClickOriginalState = state;
setAnimationDurationFactor(cg.readEntry("AnimationDurationFactor", 1.0));
m_animationOriginalDurationFactor = m_animationDurationFactor;
}
void KCMWorkspaceOptions::savePlasmarc()
......@@ -197,13 +211,15 @@ void KCMWorkspaceOptions::saveKdeglobals()
KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("kdeglobals"));
bool state;
// Save singleClick
{
KConfigGroup cg(config, QStringLiteral("KDE"));
state = getSingleClick();
cg.writeEntry("SingleClick", state);
m_singleClickOriginalState = state;
cg.writeEntry("AnimationDurationFactor", m_animationDurationFactor, KConfig::Notify);
m_animationOriginalDurationFactor = m_animationDurationFactor;
}
config->sync();
......@@ -223,7 +239,8 @@ void KCMWorkspaceOptions::handleNeedsSave()
{
setNeedsSave(m_toolTipOriginalState != getToolTip() ||
m_visualFeedbackOriginalState != getVisualFeedback() ||
m_singleClickOriginalState != getSingleClick());
m_singleClickOriginalState != getSingleClick() ||
!qFuzzyCompare(m_animationOriginalDurationFactor, getAnimationDurationFactor()));
}
#include "workspaceoptions.moc"
......@@ -26,6 +26,7 @@ class KCMWorkspaceOptions : public KQuickAddons::ConfigModule
Q_PROPERTY(bool toolTip READ getToolTip WRITE setToolTip NOTIFY toolTipChanged)
Q_PROPERTY(bool visualFeedback READ getVisualFeedback WRITE setVisualFeedback NOTIFY visualFeedbackChanged)
Q_PROPERTY(bool singleClick READ getSingleClick WRITE setSingleClick NOTIFY singleClickChanged)
Q_PROPERTY(qreal animationDurationFactor READ getAnimationDurationFactor WRITE setAnimationDurationFactor NOTIFY animationDurationFactorChanged)
public:
KCMWorkspaceOptions(QObject* parent, const QVariantList& args);
......@@ -41,6 +42,9 @@ public:
bool getSingleClick() const;
void setSingleClick(bool state);
qreal getAnimationDurationFactor() const;
void setAnimationDurationFactor(qreal speed);
public Q_SLOTS:
void load() override;
void save() override;
......@@ -50,6 +54,7 @@ Q_SIGNALS:
void toolTipChanged();
void visualFeedbackChanged();
void singleClickChanged();
void animationDurationFactorChanged();
private:
void loadPlasmarc();
......@@ -69,6 +74,9 @@ private:
bool m_singleClickOriginalState;
bool m_singleClickCurrentState;
qreal m_animationDurationFactor = 1.0;
qreal m_animationOriginalDurationFactor = 1.0;
};
#endif // _KCM_WORKSPACEOPTIONS_H
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