2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef KITEMLISTSMOOTHSCROLLER_H
8 #define KITEMLISTSMOOTHSCROLLER_H
10 #include "dolphin_export.h"
12 #include <QAbstractAnimation>
15 class QPropertyAnimation
;
20 * @brief Helper class for KItemListContainer to have a smooth
21 * scrolling when adjusting the scrollbars.
23 class DOLPHIN_EXPORT KItemListSmoothScroller
: public QObject
28 explicit KItemListSmoothScroller(QScrollBar
* scrollBar
,
29 QObject
* parent
= nullptr);
30 ~KItemListSmoothScroller() override
;
32 void setScrollBar(QScrollBar
* scrollBar
);
33 QScrollBar
* scrollBar() const;
35 void setTargetObject(QObject
* target
);
36 QObject
* targetObject() const;
38 void setPropertyName(const QByteArray
& propertyName
);
39 QByteArray
propertyName() const;
42 * Adjusts the position of the target by \p distance
43 * pixels. Is invoked in the context of QAbstractScrollArea::scrollContentsBy()
44 * where the scrollbars already have the new position but the content
45 * has not been scrolled yet.
47 void scrollContentsBy(qreal distance
);
50 * Does a smooth-scrolling to the position \p position
51 * on the target and also adjusts the corresponding scrollbar
52 * to the new position.
54 void scrollTo(qreal position
);
57 * Must be invoked before the scrollbar should get updated to have a new
58 * maximum. True is returned if the new maximum can be applied. If false
59 * is returned the maximum has already been reached and the value will
60 * be reached at the end of the animation.
62 // TODO: This interface is tricky to understand. Try to make this more
63 // generic/readable if the corresponding code in KItemListContainer got
65 bool requestScrollBarUpdate(int newMaximum
);
68 * Forwards wheel events to the scrollbar, ensuring smooth and proper scrolling
70 void handleWheelEvent(QWheelEvent
* event
);
73 bool eventFilter(QObject
* obj
, QEvent
* event
) override
;
76 void slotAnimationStateChanged(QAbstractAnimation::State newState
,
77 QAbstractAnimation::State oldState
);
80 bool m_scrollBarPressed
;
81 bool m_smoothScrolling
;
82 QScrollBar
* m_scrollBar
;
83 QPropertyAnimation
* m_animation
;