File indexing completed on 2024-04-21 04:00:35

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 "plasmadesktopunits.h"
0012 
0013 #include <KConfigGroup>
0014 #include <KSharedConfig>
0015 
0016 #include "animationspeedprovider.h"
0017 
0018 namespace
0019 {
0020 constexpr int defaultLongDuration = 200;
0021 }
0022 
0023 PlasmaDesktopUnits::PlasmaDesktopUnits(QObject *parent)
0024     : Kirigami::Platform::Units(parent)
0025 #if defined(Q_OS_WIN)
0026     , m_animationSpeedProvider(new WindowsAnimationSpeedProvider)
0027 #elif defined(Q_OS_UNIX)
0028     , m_animationSpeedProvider(new KConfigAnimationSpeedProvider)
0029 #endif
0030 {
0031     m_notifier = m_animationSpeedProvider->animationSpeedModifier().addNotifier([this] {
0032         updateAnimationSpeed();
0033     });
0034     updateAnimationSpeed();
0035 }
0036 
0037 // Copy from plasma-framework/src/declarativeimports/core/units.cpp, since we don't want to depend on plasma-framework here
0038 void PlasmaDesktopUnits::updateAnimationSpeed()
0039 {
0040     // Read the old longDuration value for compatibility
0041     KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("plasmarc")), QStringLiteral("Units"));
0042     int longDuration = cfg.readEntry("longDuration", defaultLongDuration);
0043 
0044     const qreal animationSpeedModifier = m_animationSpeedProvider->animationSpeedModifier().value();
0045     longDuration = qRound(longDuration * animationSpeedModifier);
0046 
0047     // Animators with a duration of 0 do not fire reliably
0048     // see Bug 357532 and QTBUG-39766
0049     longDuration = qMax(1, longDuration);
0050 
0051     setVeryShortDuration(longDuration / 4);
0052     setShortDuration(longDuration / 2);
0053     setLongDuration(longDuration);
0054     setVeryLongDuration(longDuration * 2);
0055 }
0056 
0057 #include "moc_plasmadesktopunits.cpp"