Honor global animation speed factor

Multiplies the animation speed by the given factor.

Differential Revision: https://phabricator.kde.org/D23857
This commit is contained in:
Kai Uwe Broulik 2019-09-25 15:55:17 +02:00
parent 455b41bc62
commit d5a5d07f0f
2 changed files with 23 additions and 25 deletions

View File

@ -30,11 +30,9 @@
#include <QFontMetrics> #include <QFontMetrics>
#include <cmath> #include <cmath>
#include <KDirWatch> #include <KConfigWatcher>
#include <KIconLoader> #include <KIconLoader>
QString plasmarc() { return QStringLiteral("plasmarc"); }
QString groupName() { return QStringLiteral("Units"); }
const int defaultLongDuration = 120; const int defaultLongDuration = 120;
@ -79,15 +77,14 @@ Units::Units(QObject *parent)
connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged, this, &Units::iconLoaderSettingsChanged); connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged, this, &Units::iconLoaderSettingsChanged);
QObject::connect(s_sharedAppFilter, &SharedAppFilter::fontChanged, this, &Units::updateSpacing); QObject::connect(s_sharedAppFilter, &SharedAppFilter::fontChanged, this, &Units::updateSpacing);
const QString configFile = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + plasmarc(); m_animationSpeedWatcher = KConfigWatcher::create(KSharedConfig::openConfig());
KDirWatch::self()->addFile(configFile); connect(m_animationSpeedWatcher.data(), &KConfigWatcher::configChanged, this,
[this](const KConfigGroup &group, const QByteArrayList &names) {
// Catch both, direct changes to the config file ... if (group.name() == QLatin1String("KDE") && names.contains(QByteArrayLiteral("AnimationDurationFactor"))) {
connect(KDirWatch::self(), &KDirWatch::dirty, this, &Units::settingsFileChanged); updateAnimationSpeed();
// ... but also remove/recreate cycles, like KConfig does it }
connect(KDirWatch::self(), &KDirWatch::created, this, &Units::settingsFileChanged); });
// read configuration updateAnimationSpeed();
updatePlasmaRCSettings();
} }
Units::~Units() Units::~Units()
@ -101,21 +98,20 @@ Units &Units::instance()
return units; return units;
} }
void Units::settingsFileChanged(const QString &file) void Units::updateAnimationSpeed()
{ {
if (file.endsWith(plasmarc())) { KConfigGroup generalCfg = KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("KDE"));
KSharedConfigPtr cfg = KSharedConfig::openConfig(plasmarc()); const qreal animationSpeedModifier = qMax(0.0, generalCfg.readEntry("AnimationDurationFactor", 1.0));
cfg->reparseConfiguration();
updatePlasmaRCSettings(); // Read the old longDuration value for compatibility
} KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("plasmarc")), QStringLiteral("Units"));
} int longDuration = cfg.readEntry("longDuration", defaultLongDuration);
longDuration = qRound(longDuration * animationSpeedModifier);
void Units::updatePlasmaRCSettings()
{
KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig(plasmarc()), groupName());
// Animators with a duration of 0 do not fire reliably // Animators with a duration of 0 do not fire reliably
// see Bug 357532 and QTBUG-39766 // see Bug 357532 and QTBUG-39766
const int longDuration = qMax(1, cfg.readEntry("longDuration", defaultLongDuration)); longDuration = qMax(1, longDuration);
if (longDuration != m_longDuration) { if (longDuration != m_longDuration) {
m_longDuration = longDuration; m_longDuration = longDuration;

View File

@ -26,6 +26,8 @@
#include <Plasma/Theme> #include <Plasma/Theme>
#include <KConfigWatcher>
class QQuickItem; class QQuickItem;
class SharedAppFilter : public QObject class SharedAppFilter : public QObject
@ -205,7 +207,6 @@ Q_SIGNALS:
private Q_SLOTS: private Q_SLOTS:
void iconLoaderSettingsChanged(); void iconLoaderSettingsChanged();
void settingsFileChanged(const QString &file);
void updateSpacing(); void updateSpacing();
private: private:
@ -216,7 +217,7 @@ private:
Units& operator=(Units &&) = delete; // Move assign Units& operator=(Units &&) = delete; // Move assign
void updateDevicePixelRatio(); void updateDevicePixelRatio();
void updatePlasmaRCSettings(); void updateAnimationSpeed();
/** /**
* @return The dpi-adjusted size for a given icon size * @return The dpi-adjusted size for a given icon size
*/ */
@ -232,6 +233,7 @@ private:
int m_smallSpacing; int m_smallSpacing;
int m_largeSpacing; int m_largeSpacing;
KConfigWatcher::Ptr m_animationSpeedWatcher;
int m_longDuration; int m_longDuration;
}; };