22 #include "progressspinnerdelegate_p.h"
24 #include "entitytreemodel.h"
26 #include <QTimerEvent>
27 #include <QAbstractItemView>
29 using namespace Akonadi;
31 DelegateAnimator::DelegateAnimator(QAbstractItemView *view)
32 : QObject(view), m_view(view), m_timerId(-1)
34 m_pixmapSequence = KPixmapSequence(QLatin1String(
"process-working"), 22);
37 void DelegateAnimator::push(
const QModelIndex &index)
39 if (m_animations.isEmpty())
40 m_timerId = startTimer(200);
41 m_animations.insert(Animation(index));
44 void DelegateAnimator::pop(
const QModelIndex &index)
46 if (m_animations.remove(Animation(index))) {
47 if (m_animations.isEmpty() && m_timerId != -1) {
54 void DelegateAnimator::timerEvent(QTimerEvent* event)
56 if (!(event->timerId() == m_timerId && m_view))
57 return QObject::timerEvent(event);
60 foreach (
const Animation &animation, m_animations)
65 pop( animation.index );
71 animation.nextFrame();
72 const QRect rect = m_view->visualRect(animation.index);
76 if ( !region.isEmpty() ) {
77 m_view->viewport()->update(region);
81 QPixmap DelegateAnimator::sequenceFrame(
const QModelIndex& index)
83 foreach(
const Animation &animation, m_animations)
85 if (animation.index == index)
87 return m_pixmapSequence.frameAt(animation.frame);
93 ProgressSpinnerDelegate::ProgressSpinnerDelegate(DelegateAnimator *animator, QObject* parent)
94 : QStyledItemDelegate(parent), m_animator(animator)
99 void ProgressSpinnerDelegate::initStyleOption(QStyleOptionViewItem* option,
const QModelIndex& index)
const
101 QStyledItemDelegate::initStyleOption(option, index);
105 m_animator->pop(index);
109 m_animator->push(index);
111 if (QStyleOptionViewItemV4 *v4 = qstyleoption_cast<QStyleOptionViewItemV4 *>(option)) {
112 v4->icon = m_animator->sequenceFrame(index);
116 uint Akonadi::qHash(Akonadi::DelegateAnimator::Animation anim)
118 return qHash(anim.index);
Returns the FetchState of a particular item.
There is a fetch of items in this collection in progress.