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 <libdolphin_export.h>
24
25#include <QHash>
26#include <QObject>
27#include <QVariant>
28
29class KItemListView;
30class QGraphicsWidget;
31class QPointF;
32class QPropertyAnimation;
33
34/**
35 * @brief Internal helper class for KItemListView to animate the items.
36 *
37 * Supports item animations for moving, creating, deleting and resizing
38 * an item. Several applications can be applied to one item in parallel.
39 */
40class LIBDOLPHINPRIVATE_EXPORT KItemListViewAnimation : public QObject
41{
42 Q_OBJECT
43
44public:
45 enum AnimationType {
46 MovingAnimation,
47 CreateAnimation,
48 DeleteAnimation,
49 ResizeAnimation
50 };
51
52 KItemListViewAnimation(QObject* parent = 0);
53 virtual ~KItemListViewAnimation();
54
55 void setScrollOrientation(Qt::Orientation orientation);
56 Qt::Orientation scrollOrientation() const;
57
58 void setScrollOffset(qreal scrollOffset);
59 qreal scrollOffset() const;
60
61 /**
62 * Starts the animation of the type \a type for the widget \a widget. If an animation
63 * of the type is already running, this animation will be stopped before starting
64 * the new animation.
65 */
66 void start(QGraphicsWidget* widget, AnimationType type, const QVariant& endValue = QVariant());
67
68 /**
69 * Stops the animation of the type \a type for the widget \a widget.
70 */
71 void stop(QGraphicsWidget* widget, AnimationType type);
72
73 /**
74 * Stops all animations that have been applied to the widget \a widget.
75 */
76 void stop(QGraphicsWidget* widget);
77
78 /**
79 * @return True if the animation of the type \a type has been started
80 * for the widget \a widget..
81 */
82 bool isStarted(QGraphicsWidget *widget, AnimationType type) const;
83
84 /**
85 * @return True if any animation has been started for the widget.
86 */
87 bool isStarted(QGraphicsWidget* widget) const;
88
89signals:
90 void finished(QGraphicsWidget* widget, KItemListViewAnimation::AnimationType type);
91
92private slots:
93 void slotFinished();
94
95private:
96 enum { AnimationTypeCount = 4 };
97
98 int m_animationDuration;
99 Qt::Orientation m_scrollOrientation;
100 qreal m_scrollOffset;
101 QHash<QGraphicsWidget*, QPropertyAnimation*> m_animation[AnimationTypeCount];
102};
103
104#endif
105
106
107