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 m_timerId = -1;
00048 }
00049 }
00050
00051 QPixmap sequenceFrame(const QModelIndex &index);
00052
00053 static const int sCount = 7;
00054 struct Animation {
00055 inline Animation(const QPersistentModelIndex &idx)
00056 : frame(0), index(idx)
00057 {
00058 }
00059
00060 bool operator==(const Animation &other) const
00061 { return index == other.index; }
00062
00063
00064 inline void animate() const { frame = ( frame + 1 ) % sCount; }
00065 mutable int frame;
00066 QPersistentModelIndex index;
00067 };
00068
00069 protected:
00070 virtual void timerEvent(QTimerEvent *event);
00071
00072 private:
00073
00074 mutable QSet<Animation> m_animations;
00075 QAbstractItemView *m_view;
00076 KPixmapSequence m_pixmapSequence;
00077 int m_timerId;
00078 };
00079
00080 uint qHash(Akonadi::DelegateAnimator::Animation anim);
00081
00085 class ProgressSpinnerDelegate : public QStyledItemDelegate
00086 {
00087 Q_OBJECT
00088 public:
00089 ProgressSpinnerDelegate(DelegateAnimator *animator, QObject* parent = 0);
00090
00091 protected:
00092 virtual void initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const;
00093
00094 private:
00095 DelegateAnimator *m_animator;
00096 };
00097
00098 }
00099
00100 #endif