00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PROGRESSSPINNERDELEGATE_P_H
00023 #define PROGRESSSPINNERDELEGATE_P_H
00024
00025 #include <QStyledItemDelegate>
00026 #include <QSet>
00027
00028 #include <kpixmapsequence.h>
00029
00030 namespace Akonadi {
00031
00032 class DelegateAnimator : public QObject
00033 {
00034 Q_OBJECT
00035 public:
00036 DelegateAnimator(QAbstractItemView *view);
00037
00038 void push(const QModelIndex &index) {
00039 if (m_animations.isEmpty())
00040 m_timerId = startTimer(200);
00041 m_animations.insert(Animation(index));
00042 }
00043 void pop(const QModelIndex &index) {
00044 m_animations.remove(Animation(index));
00045 if (m_animations.isEmpty() && m_timerId != -1)
00046 killTimer(m_timerId);
00047 }
00048
00049 QPixmap sequenceFrame(const QModelIndex &index);
00050
00051 static const int sCount = 7;
00052 struct Animation {
00053 inline Animation(const QPersistentModelIndex &idx)
00054 : frame(0), index(idx)
00055 {
00056 }
00057
00058 bool operator==(const Animation &other) const
00059 { return index == other.index; }
00060
00061
00062 inline void animate() const { frame = ( frame + 1 ) % sCount; }
00063 mutable int frame;
00064 QPersistentModelIndex index;
00065 };
00066
00067 protected:
00068 virtual void timerEvent(QTimerEvent *event);
00069
00070 private:
00071
00072 mutable QSet<Animation> m_animations;
00073 QAbstractItemView *m_view;
00074 KPixmapSequence m_pixmapSequence;
00075 int m_timerId;
00076 };
00077
00078 uint qHash(Akonadi::DelegateAnimator::Animation anim);
00079
00083 class ProgressSpinnerDelegate : public QStyledItemDelegate
00084 {
00085 Q_OBJECT
00086 public:
00087 ProgressSpinnerDelegate(DelegateAnimator *animator, QObject* parent = 0);
00088
00089 protected:
00090 virtual void initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const;
00091
00092 private:
00093 DelegateAnimator *m_animator;
00094 };
00095
00096 }
00097
00098 #endif