• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

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   }
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

akonadi

Skip menu "akonadi"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal