]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistsmoothscroller.h
Check if the item supports sequencing before looking for sequence pixmaps
[dolphin.git] / src / kitemviews / private / kitemlistsmoothscroller.h
1 /*
2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef KITEMLISTSMOOTHSCROLLER_H
8 #define KITEMLISTSMOOTHSCROLLER_H
9
10 #include "dolphin_export.h"
11
12 #include <QAbstractAnimation>
13 #include <QObject>
14
15 class QPropertyAnimation;
16 class QScrollBar;
17 class QWheelEvent;
18
19 /**
20 * @brief Helper class for KItemListContainer to have a smooth
21 * scrolling when adjusting the scrollbars.
22 */
23 class DOLPHIN_EXPORT KItemListSmoothScroller : public QObject
24 {
25 Q_OBJECT
26
27 public:
28 explicit KItemListSmoothScroller(QScrollBar *scrollBar, QObject *parent = nullptr);
29 ~KItemListSmoothScroller() override;
30
31 void setScrollBar(QScrollBar *scrollBar);
32 QScrollBar *scrollBar() const;
33
34 void setTargetObject(QObject *target);
35 QObject *targetObject() const;
36
37 void setPropertyName(const QByteArray &propertyName);
38 QByteArray propertyName() const;
39
40 /**
41 * Adjusts the position of the target by \p distance
42 * pixels. Is invoked in the context of QAbstractScrollArea::scrollContentsBy()
43 * where the scrollbars already have the new position but the content
44 * has not been scrolled yet.
45 */
46 void scrollContentsBy(qreal distance);
47
48 /**
49 * Does a smooth-scrolling to the position \p position
50 * on the target and also adjusts the corresponding scrollbar
51 * to the new position.
52 */
53 void scrollTo(qreal position);
54
55 /**
56 * Must be invoked before the scrollbar should get updated to have a new
57 * maximum. True is returned if the new maximum can be applied. If false
58 * is returned the maximum has already been reached and the value will
59 * be reached at the end of the animation.
60 */
61 // TODO: This interface is tricky to understand. Try to make this more
62 // generic/readable if the corresponding code in KItemListContainer got
63 // stable.
64 bool requestScrollBarUpdate(int newMaximum);
65
66 /**
67 * Forwards wheel events to the scrollbar, ensuring smooth and proper scrolling
68 */
69 void handleWheelEvent(QWheelEvent *event);
70
71 bool isAnimating();
72 Q_SIGNALS:
73 /**
74 * Emitted when the scrolling animation has finished
75 */
76 void scrollingStopped();
77
78 protected:
79 bool eventFilter(QObject *obj, QEvent *event) override;
80
81 private Q_SLOTS:
82 void slotAnimationStateChanged(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
83 /**
84 * Calculates the duration of the smooth scrolling animation.
85 * If \p isSmoothScrollingEnabled is true, the duration will be calculated
86 * using the widget animation duration from the current style. Otherwise,
87 * the animation will be instantaneous.
88 */
89 void updateAnimationDuration(bool isSmoothScrollingEnabled);
90
91 private:
92 bool m_scrollBarPressed;
93 bool m_smoothScrolling;
94 QScrollBar *m_scrollBar;
95 QPropertyAnimation *m_animation;
96 };
97
98 #endif