Changeset View
Changeset View
Standalone View
Standalone View
src/declarativeimports/core/units.cpp
Show All 24 Lines | |||||
25 | #include <QDebug> | 25 | #include <QDebug> | ||
26 | #include <QtGlobal> | 26 | #include <QtGlobal> | ||
27 | #include <QQuickItem> | 27 | #include <QQuickItem> | ||
28 | #include <QQuickWindow> | 28 | #include <QQuickWindow> | ||
29 | #include <QScreen> | 29 | #include <QScreen> | ||
30 | #include <QFontMetrics> | 30 | #include <QFontMetrics> | ||
31 | #include <cmath> | 31 | #include <cmath> | ||
32 | 32 | | |||
33 | #include <KDirWatch> | 33 | #include <KConfigWatcher> | ||
34 | #include <KIconLoader> | 34 | #include <KIconLoader> | ||
35 | 35 | | |||
36 | QString plasmarc() { return QStringLiteral("plasmarc"); } | | |||
37 | QString groupName() { return QStringLiteral("Units"); } | | |||
38 | const int defaultLongDuration = 120; | 36 | const int defaultLongDuration = 120; | ||
39 | 37 | | |||
40 | 38 | | |||
41 | SharedAppFilter::SharedAppFilter(QObject *parent) | 39 | SharedAppFilter::SharedAppFilter(QObject *parent) | ||
42 | : QObject(parent) | 40 | : QObject(parent) | ||
43 | { | 41 | { | ||
44 | QCoreApplication::instance()->installEventFilter(this); | 42 | QCoreApplication::instance()->installEventFilter(this); | ||
45 | } | 43 | } | ||
Show All 28 Lines | 67 | { | |||
74 | m_iconSizes = new QQmlPropertyMap(this); | 72 | m_iconSizes = new QQmlPropertyMap(this); | ||
75 | m_iconSizeHints = new QQmlPropertyMap(this); | 73 | m_iconSizeHints = new QQmlPropertyMap(this); | ||
76 | updateDevicePixelRatio(); // also updates icon sizes | 74 | updateDevicePixelRatio(); // also updates icon sizes | ||
77 | updateSpacing(); // updates gridUnit and *Spacing properties | 75 | updateSpacing(); // updates gridUnit and *Spacing properties | ||
78 | 76 | | |||
79 | connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged, this, &Units::iconLoaderSettingsChanged); | 77 | connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged, this, &Units::iconLoaderSettingsChanged); | ||
80 | QObject::connect(s_sharedAppFilter, &SharedAppFilter::fontChanged, this, &Units::updateSpacing); | 78 | QObject::connect(s_sharedAppFilter, &SharedAppFilter::fontChanged, this, &Units::updateSpacing); | ||
81 | 79 | | |||
82 | const QString configFile = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + plasmarc(); | 80 | m_animationSpeedWatcher = KConfigWatcher::create(KSharedConfig::openConfig()); | ||
83 | KDirWatch::self()->addFile(configFile); | 81 | connect(m_animationSpeedWatcher.data(), &KConfigWatcher::configChanged, this, | ||
84 | 82 | [this](const KConfigGroup &group, const QByteArrayList &names) { | |||
85 | // Catch both, direct changes to the config file ... | 83 | if (group.name() == QLatin1String("KDE") && names.contains(QByteArrayLiteral("AnimationDurationFactor"))) { | ||
86 | connect(KDirWatch::self(), &KDirWatch::dirty, this, &Units::settingsFileChanged); | 84 | updateAnimationSpeed(); | ||
87 | // ... but also remove/recreate cycles, like KConfig does it | 85 | } | ||
88 | connect(KDirWatch::self(), &KDirWatch::created, this, &Units::settingsFileChanged); | 86 | }); | ||
89 | // read configuration | 87 | updateAnimationSpeed(); | ||
90 | updatePlasmaRCSettings(); | | |||
91 | } | 88 | } | ||
92 | 89 | | |||
93 | Units::~Units() | 90 | Units::~Units() | ||
94 | { | 91 | { | ||
95 | 92 | | |||
96 | } | 93 | } | ||
97 | 94 | | |||
98 | Units &Units::instance() | 95 | Units &Units::instance() | ||
99 | { | 96 | { | ||
100 | static Units units; | 97 | static Units units; | ||
101 | return units; | 98 | return units; | ||
102 | } | 99 | } | ||
103 | 100 | | |||
104 | void Units::settingsFileChanged(const QString &file) | 101 | void Units::updateAnimationSpeed() | ||
105 | { | 102 | { | ||
106 | if (file.endsWith(plasmarc())) { | 103 | KConfigGroup generalCfg = KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("KDE")); | ||
107 | KSharedConfigPtr cfg = KSharedConfig::openConfig(plasmarc()); | 104 | const qreal animationSpeedModifier = qMax(0.0, generalCfg.readEntry("AnimationDurationFactor", 1.0)); | ||
108 | cfg->reparseConfiguration(); | 105 | | ||
109 | updatePlasmaRCSettings(); | 106 | // Read the old longDuration value for compatibility | ||
110 | } | 107 | KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("plasmarc")), QStringLiteral("Units")); | ||
111 | } | 108 | int longDuration = cfg.readEntry("longDuration", defaultLongDuration); | ||
109 | | ||||
110 | longDuration = qRound(longDuration * animationSpeedModifier); | ||||
112 | 111 | | |||
113 | void Units::updatePlasmaRCSettings() | | |||
114 | { | | |||
115 | KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig(plasmarc()), groupName()); | | |||
116 | // Animators with a duration of 0 do not fire reliably | 112 | // Animators with a duration of 0 do not fire reliably | ||
117 | // see Bug 357532 and QTBUG-39766 | 113 | // see Bug 357532 and QTBUG-39766 | ||
118 | const int longDuration = qMax(1, cfg.readEntry("longDuration", defaultLongDuration)); | 114 | longDuration = qMax(1, longDuration); | ||
119 | 115 | | |||
120 | if (longDuration != m_longDuration) { | 116 | if (longDuration != m_longDuration) { | ||
121 | m_longDuration = longDuration; | 117 | m_longDuration = longDuration; | ||
122 | emit durationChanged(); | 118 | emit durationChanged(); | ||
123 | } | 119 | } | ||
124 | } | 120 | } | ||
125 | 121 | | |||
126 | 122 | | |||
▲ Show 20 Lines • Show All 157 Lines • Show Last 20 Lines |