]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistviewanimation.h
ba3a33dc923493c257b0ce16d46343c7ca10dfab
[dolphin.git] / src / kitemviews / private / kitemlistviewanimation.h
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef KITEMLISTVIEWANIMATION_H
21 #define KITEMLISTVIEWANIMATION_H
22
23 #include "dolphin_export.h"
24
25 #include <QHash>
26 #include <QObject>
27 #include <QVariant>
28
29 class KItemListView;
30 class QGraphicsWidget;
31 class QPropertyAnimation;
32
33 /**
34 * @brief Internal helper class for KItemListView to animate the items.
35 *
36 * Supports item animations for moving, creating, deleting and resizing
37 * an item. Several applications can be applied to one item in parallel.
38 */
39 class DOLPHIN_EXPORT KItemListViewAnimation : public QObject
40 {
41 Q_OBJECT
42
43 public:
44 enum AnimationType {
45 MovingAnimation,
46 CreateAnimation,
47 DeleteAnimation,
48 ResizeAnimation
49 };
50
51 KItemListViewAnimation(QObject* parent = nullptr);
52 ~KItemListViewAnimation() override;
53
54 void setScrollOrientation(Qt::Orientation orientation);
55 Qt::Orientation scrollOrientation() const;
56
57 void setScrollOffset(qreal scrollOffset);
58 qreal scrollOffset() const;
59
60 /**
61 * Starts the animation of the type \a type for the widget \a widget. If an animation
62 * of the type is already running, this animation will be stopped before starting
63 * the new animation.
64 */
65 void start(QGraphicsWidget* widget, AnimationType type, const QVariant& endValue = QVariant());
66
67 /**
68 * Stops the animation of the type \a type for the widget \a widget.
69 */
70 void stop(QGraphicsWidget* widget, AnimationType type);
71
72 /**
73 * Stops all animations that have been applied to the widget \a widget.
74 */
75 void stop(QGraphicsWidget* widget);
76
77 /**
78 * @return True if the animation of the type \a type has been started
79 * for the widget \a widget..
80 */
81 bool isStarted(QGraphicsWidget *widget, AnimationType type) const;
82
83 /**
84 * @return True if any animation has been started for the widget.
85 */
86 bool isStarted(QGraphicsWidget* widget) const;
87
88 signals:
89 void finished(QGraphicsWidget* widget, KItemListViewAnimation::AnimationType type);
90
91 private slots:
92 void slotFinished();
93
94 private:
95 enum { AnimationTypeCount = 4 };
96
97 Qt::Orientation m_scrollOrientation;
98 qreal m_scrollOffset;
99 QHash<QGraphicsWidget*, QPropertyAnimation*> m_animation[AnimationTypeCount];
100 };
101
102 #endif
103
104