#include "kitemlistsmoothscroller.h"
+#include <KConfigGroup>
+#include <KSharedConfig>
+
#include <QApplication>
+#include <QDBusConnection>
#include <QPropertyAnimation>
#include <QScrollBar>
#include <QStyle>
, m_animation(nullptr)
{
m_animation = new QPropertyAnimation(this);
- const int animationDuration = m_scrollBar->style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, m_scrollBar);
- const bool animationEnabled = (animationDuration > 0);
- m_animation->setDuration(animationEnabled ? animationDuration : 1);
+
+ KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::IncludeGlobals);
+ KConfigGroup configGroup(globalConfig, QStringLiteral("KDE"));
+ updateAnimationDuration(configGroup.readEntry("SmoothScroll", true));
+
+ QDBusConnection::sessionBus().connect(QStringLiteral(""),
+ QStringLiteral("/SmoothScroll"),
+ QStringLiteral("org.kde.SmoothScroll"),
+ QStringLiteral("notifyChange"),
+ this,
+ SLOT(updateAnimationDuration(bool)));
connect(m_animation, &QPropertyAnimation::stateChanged, this, &KItemListSmoothScroller::slotAnimationStateChanged);
m_scrollBar->installEventFilter(this);
}
}
+void KItemListSmoothScroller::updateAnimationDuration(bool isSmoothScrollingEnabled)
+{
+ if (isSmoothScrollingEnabled) {
+ // Breeze sets SH_Widget_Animation_Duration from the KDE global animation speed setting
+ const int animationDuration = m_scrollBar->style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, m_scrollBar);
+ const bool animationEnabled = (animationDuration > 0);
+ m_animation->setDuration(animationEnabled ? animationDuration : 1);
+ } else {
+ m_animation->setDuration(1);
+ }
+}
+
void KItemListSmoothScroller::handleWheelEvent(QWheelEvent *event)
{
const bool previous = m_smoothScrolling;
private Q_SLOTS:
void slotAnimationStateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
+ /**
+ * Calculates the duration of the smooth scrolling animation.
+ * If \p isSmoothScrollingEnabled is true, the duration will be calculated
+ * using the widget animation duration from the current style. Otherwise,
+ * the animation will be instantaneous.
+ */
+ void updateAnimationDuration(bool isSmoothScrollingEnabled);
private:
bool m_scrollBarPressed;