• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • Contact Us
 

akonadi

progressspinnerdelegate.cpp
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 #include "progressspinnerdelegate_p.h"
00023 
00024 #include "entitytreemodel.h"
00025 
00026 #include <QTimerEvent>
00027 #include <QAbstractItemView>
00028 
00029 using namespace Akonadi;
00030 
00031 DelegateAnimator::DelegateAnimator(QAbstractItemView *view)
00032   : QObject(view), m_view(view), m_timerId(-1)
00033 {
00034   m_pixmapSequence = KPixmapSequence(QLatin1String("process-working"), 22);
00035 }
00036 
00037 void DelegateAnimator::timerEvent(QTimerEvent* event)
00038 {
00039   if (!(event->timerId() == m_timerId && m_view))
00040     return QObject::timerEvent(event);
00041 
00042   QRegion region;
00043   foreach (const Animation &animation, m_animations)
00044   {
00045     // This repaints the entire delegate.
00046     // TODO: See if there's a way to repaint only part of it.
00047     animation.animate();
00048     region += m_view->visualRect(animation.index);
00049   }
00050 
00051   m_view->viewport()->update(region);
00052 }
00053 
00054 QPixmap DelegateAnimator::sequenceFrame(const QModelIndex& index)
00055 {
00056   foreach(const Animation &animation, m_animations)
00057   {
00058     if (animation.index == index)
00059     {
00060       return m_pixmapSequence.frameAt(animation.frame);
00061     }
00062   }
00063   return QPixmap();
00064 }
00065 
00066 
00067 ProgressSpinnerDelegate::ProgressSpinnerDelegate(DelegateAnimator *animator, QObject* parent)
00068   : QStyledItemDelegate(parent), m_animator(animator)
00069 {
00070 
00071 }
00072 
00073 void ProgressSpinnerDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const
00074 {
00075   QStyledItemDelegate::initStyleOption(option, index);
00076 
00077   const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
00078 
00079   if (!collection.isValid())
00080   {
00081     m_animator->pop(index);
00082     return;
00083   }
00084 
00085   if (index.data(Akonadi::EntityTreeModel::FetchStateRole).toInt() != Akonadi::EntityTreeModel::FetchingState)
00086   {
00087     m_animator->pop(index);
00088     return;
00089   }
00090 
00091   m_animator->push(index);
00092 
00093   if (QStyleOptionViewItemV4 *v4 = qstyleoption_cast<QStyleOptionViewItemV4 *>(option)) {
00094     v4->icon = m_animator->sequenceFrame(index);
00095   }
00096 }
00097 
00098 uint Akonadi::qHash(Akonadi::DelegateAnimator::Animation anim)
00099 {
00100   return qHash(anim.index);
00101 }

akonadi

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • 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.5
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