akonadi
progressspinnerdelegate_p.h
00001 /* 00002 Copyright (C) 2010 Klarälvdalens Datakonsult AB, 00003 a KDAB Group company, info@kdab.net, 00004 author Stephen Kelly <stephen@kdab.com> 00005 00006 This library is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU Library General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or (at your 00009 option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, but WITHOUT 00012 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to the 00018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 02110-1301, USA. 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 explicit 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
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:09:23 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:09:23 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.