Libplasma

units.cpp
1/*
2 SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2014 Sebastian Kügler <sebas@kde.org>
4 SPDX-FileCopyrightText: 2014 David Edmundson <davidedmunsdon@kde.org>
5 SPDX-FileCopyrightText: 2021 Jonah Brüchert <jbb@kaidan.im>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8
9*/
10
11#include "units.h"
12
13#include <KConfigGroup>
14#include <KSharedConfig>
15
16constexpr int defaultLongDuration = 200;
17
18Units::Units(QObject *parent)
19 : Kirigami::Platform::Units(parent)
20 , m_animationSpeedWatcher(KConfigWatcher::create(KSharedConfig::openConfig()))
21{
22 connect(m_animationSpeedWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) {
23 if (group.name() == QLatin1String("KDE") && names.contains(QByteArrayLiteral("AnimationDurationFactor"))) {
24 updateAnimationSpeed();
25 }
26 });
27
28 updateAnimationSpeed();
29}
30
31// It'd be nice if we could somehow share this with core/units.cpp
32void Units::updateAnimationSpeed()
33{
34 KConfigGroup generalCfg = KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("KDE"));
35 const qreal animationSpeedModifier = qMax(0.0, generalCfg.readEntry("AnimationDurationFactor", 1.0));
36
37 // Read the old longDuration value for compatibility
38 KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("plasmarc")), QStringLiteral("Units"));
39 int longDuration = cfg.readEntry("longDuration", defaultLongDuration);
40
41 longDuration = qRound(longDuration * animationSpeedModifier);
42
43 // Animators with a duration of 0 do not fire reliably
44 // see Bug 357532 and QTBUG-39766
45 longDuration = qMax(1, longDuration);
46
47 setVeryShortDuration(longDuration / 4);
48 setShortDuration(longDuration / 2);
49 setLongDuration(longDuration);
50 setVeryLongDuration(longDuration * 2);
51}
52
53#include "moc_units.cpp"
QString readEntry(const char *key, const char *aDefault=nullptr) const
void configChanged(const KConfigGroup &group, const QByteArrayList &names)
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QAction * create(StandardAction id, const Receiver *recvr, Func slot, QObject *parent, std::optional< Qt::ConnectionType > connectionType=std::nullopt)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:10:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.