• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.0 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
progressspinnerdelegate.cpp
1 /*
2  Copyright (C) 2010 Klarälvdalens Datakonsult AB,
3  a KDAB Group company, info@kdab.net,
4  author Stephen Kelly <stephen@kdab.com>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "progressspinnerdelegate_p.h"
23 
24 #include "entitytreemodel.h"
25 
26 #include <QTimerEvent>
27 #include <QAbstractItemView>
28 
29 using namespace Akonadi;
30 
31 DelegateAnimator::DelegateAnimator(QAbstractItemView *view)
32  : QObject(view), m_view(view), m_timerId(-1)
33 {
34  m_pixmapSequence = KPixmapSequence(QLatin1String("process-working"), 22);
35 }
36 
37 void DelegateAnimator::timerEvent(QTimerEvent* event)
38 {
39  if (!(event->timerId() == m_timerId && m_view))
40  return QObject::timerEvent(event);
41 
42  QRegion region;
43  foreach (const Animation &animation, m_animations)
44  {
45  // This repaints the entire delegate.
46  // TODO: See if there's a way to repaint only part of it.
47  animation.animate();
48  region += m_view->visualRect(animation.index);
49  }
50 
51  m_view->viewport()->update(region);
52 }
53 
54 QPixmap DelegateAnimator::sequenceFrame(const QModelIndex& index)
55 {
56  foreach(const Animation &animation, m_animations)
57  {
58  if (animation.index == index)
59  {
60  return m_pixmapSequence.frameAt(animation.frame);
61  }
62  }
63  return QPixmap();
64 }
65 
66 
67 ProgressSpinnerDelegate::ProgressSpinnerDelegate(DelegateAnimator *animator, QObject* parent)
68  : QStyledItemDelegate(parent), m_animator(animator)
69 {
70 
71 }
72 
73 void ProgressSpinnerDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const
74 {
75  QStyledItemDelegate::initStyleOption(option, index);
76 
77  const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
78 
79  if (!collection.isValid())
80  {
81  m_animator->pop(index);
82  return;
83  }
84 
85  if (index.data(Akonadi::EntityTreeModel::FetchStateRole).toInt() != Akonadi::EntityTreeModel::FetchingState)
86  {
87  m_animator->pop(index);
88  return;
89  }
90 
91  m_animator->push(index);
92 
93  if (QStyleOptionViewItemV4 *v4 = qstyleoption_cast<QStyleOptionViewItemV4 *>(option)) {
94  v4->icon = m_animator->sequenceFrame(index);
95  }
96 }
97 
98 uint Akonadi::qHash(Akonadi::DelegateAnimator::Animation anim)
99 {
100  return qHash(anim.index);
101 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Mar 8 2013 21:49:51 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

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

kdepimlibs-4.10.0 API Reference

Skip menu "kdepimlibs-4.10.0 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal