File indexing completed on 2024-11-24 04:59:27
0001 /* 0002 SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2014 Sebastian Kügler <sebas@kde.org> 0004 SPDX-FileCopyrightText: 2014 David Edmundson <davidedmunsdon@kde.org> 0005 SPDX-FileCopyrightText: 2021 Jonah Brüchert <jbb@kaidan.im> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 0009 */ 0010 0011 #include "units.h" 0012 0013 #include <KConfigGroup> 0014 #include <KSharedConfig> 0015 0016 constexpr int defaultLongDuration = 200; 0017 0018 Units::Units(QObject *parent) 0019 : Kirigami::Platform::Units(parent) 0020 , m_animationSpeedWatcher(KConfigWatcher::create(KSharedConfig::openConfig())) 0021 { 0022 connect(m_animationSpeedWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) { 0023 if (group.name() == QLatin1String("KDE") && names.contains(QByteArrayLiteral("AnimationDurationFactor"))) { 0024 updateAnimationSpeed(); 0025 } 0026 }); 0027 0028 updateAnimationSpeed(); 0029 } 0030 0031 // It'd be nice if we could somehow share this with core/units.cpp 0032 void Units::updateAnimationSpeed() 0033 { 0034 KConfigGroup generalCfg = KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("KDE")); 0035 const qreal animationSpeedModifier = qMax(0.0, generalCfg.readEntry("AnimationDurationFactor", 1.0)); 0036 0037 // Read the old longDuration value for compatibility 0038 KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("plasmarc")), QStringLiteral("Units")); 0039 int longDuration = cfg.readEntry("longDuration", defaultLongDuration); 0040 0041 longDuration = qRound(longDuration * animationSpeedModifier); 0042 0043 // Animators with a duration of 0 do not fire reliably 0044 // see Bug 357532 and QTBUG-39766 0045 longDuration = qMax(1, longDuration); 0046 0047 setVeryShortDuration(longDuration / 4); 0048 setShortDuration(longDuration / 2); 0049 setLongDuration(longDuration); 0050 setVeryLongDuration(longDuration * 2); 0051 } 0052 0053 #include "moc_units.cpp"