Units reads longDuration from config file.

This reads the global animation duration value from plasmarc, and gets
notified of changes: change the file, all animations are updated
automatically.

Put this into your plasmarc to disable animations globally:

[Units]
longDuration=0

As you might guess, other values will work as well.

shortDuration will always be 1/5 of this. (For now.)
This commit is contained in:
Sebastian Kügler 2014-02-04 03:25:08 +01:00
parent 09564783a3
commit 52c489eee5
2 changed files with 32 additions and 1 deletions

View File

@ -28,13 +28,18 @@
#include <QScreen>
#include <cmath>
#include <KDirWatch>
#include <KIconLoader>
const QString plasmarc = QStringLiteral("plasmarc");
const QString groupName = QStringLiteral("Units");
const int defaultLongDuration = 250;
Units::Units (QObject *parent)
: QObject(parent),
m_gridUnit(-1),
m_devicePixelRatio(-1),
m_longDuration(250) // default base value for animations
m_longDuration(defaultLongDuration) // default base value for animations
{
m_iconSizes = new QQmlPropertyMap(this);
updateDevicePixelRatio();
@ -48,12 +53,37 @@ Units::Units (QObject *parent)
connect(&m_theme, SIGNAL(themeChanged()),
this, SLOT(themeChanged()));
installEventFilter(qApp);
const QString configFile = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + plasmarc;
KDirWatch::self()->addFile(configFile);
// Catch both, direct changes to the config file ...
connect(KDirWatch::self(), &KDirWatch::dirty, this, &Units::settingsFileChanged);
// ... but also remove/recreate cycles, like KConfig does it
connect(KDirWatch::self(), &KDirWatch::created, this, &Units::settingsFileChanged);
// Trigger configuration read
settingsFileChanged(plasmarc);
}
Units::~Units()
{
}
void Units::settingsFileChanged(const QString &file)
{
if (file.endsWith(plasmarc)) {
KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig(plasmarc), groupName);
cfg.config()->reparseConfiguration();
const int longDuration = cfg.readEntry("longDuration", defaultLongDuration);
if (longDuration != m_longDuration) {
m_longDuration = longDuration;
emit durationChanged();
}
}
}
void Units::iconLoaderSettingsChanged()
{
// These are not scaled, we respect the user's setting over dpi scaling

View File

@ -150,6 +150,7 @@ Q_SIGNALS:
private Q_SLOTS:
void themeChanged();
void iconLoaderSettingsChanged();
void settingsFileChanged(const QString &settings);
private:
void updateDevicePixelRatio();