┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorNathan Misner <[email protected]>2024-07-05 15:49:47 +0000
committerFelix Ernst <[email protected]>2024-07-05 15:49:47 +0000
commitb94b172f5163fe5daab50dc197171d3662ee7c0d (patch)
tree961b0e12ee6e5cc52a1cea7c19a1e86dd92b5902 /src/kitemviews
parent19e0a829083d72f17830a4af1093d7fb9804ae64 (diff)
Add support for Plasma's global smooth scrolling setting
KItemListSmoothScroller now checks whether smooth scrolling is enabled globally and listens for any changes to the setting via DBus.
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/private/kitemlistsmoothscroller.cpp30
-rw-r--r--src/kitemviews/private/kitemlistsmoothscroller.h7
2 files changed, 34 insertions, 3 deletions
diff --git a/src/kitemviews/private/kitemlistsmoothscroller.cpp b/src/kitemviews/private/kitemlistsmoothscroller.cpp
index 3e325b934..1fc452542 100644
--- a/src/kitemviews/private/kitemlistsmoothscroller.cpp
+++ b/src/kitemviews/private/kitemlistsmoothscroller.cpp
@@ -6,7 +6,11 @@
#include "kitemlistsmoothscroller.h"
+#include <KConfigGroup>
+#include <KSharedConfig>
+
#include <QApplication>
+#include <QDBusConnection>
#include <QPropertyAnimation>
#include <QScrollBar>
#include <QStyle>
@@ -20,9 +24,17 @@ KItemListSmoothScroller::KItemListSmoothScroller(QScrollBar *scrollBar, QObject
, 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);
@@ -177,6 +189,18 @@ void KItemListSmoothScroller::slotAnimationStateChanged(QAbstractAnimation::Stat
}
}
+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;
diff --git a/src/kitemviews/private/kitemlistsmoothscroller.h b/src/kitemviews/private/kitemlistsmoothscroller.h
index d1cfcf9d9..32effa3d6 100644
--- a/src/kitemviews/private/kitemlistsmoothscroller.h
+++ b/src/kitemviews/private/kitemlistsmoothscroller.h
@@ -79,6 +79,13 @@ protected:
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;