• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 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::push(const QModelIndex &index)
38 {
39  if (m_animations.isEmpty())
40  m_timerId = startTimer(200);
41  m_animations.insert(Animation(index));
42 }
43 
44 void DelegateAnimator::pop(const QModelIndex &index)
45 {
46  if (m_animations.remove(Animation(index))) {
47  if (m_animations.isEmpty() && m_timerId != -1) {
48  killTimer(m_timerId);
49  m_timerId = -1;
50  }
51  }
52 }
53 
54 void DelegateAnimator::timerEvent(QTimerEvent* event)
55 {
56  if (!(event->timerId() == m_timerId && m_view))
57  return QObject::timerEvent(event);
58 
59  QRegion region;
60  foreach (const Animation &animation, m_animations)
61  {
62  // Check if loading is finished (we might not be notified, if the index is scrolled out of view)
63  const QVariant fetchState = animation.index.data(Akonadi::EntityTreeModel::FetchStateRole);
64  if ( fetchState.toInt() != Akonadi::EntityTreeModel::FetchingState ) {
65  pop( animation.index );
66  continue;
67  }
68 
69  // This repaints the entire delegate (icon and text).
70  // TODO: See if there's a way to repaint only part of it (the icon).
71  animation.nextFrame();
72  const QRect rect = m_view->visualRect(animation.index);
73  region += rect;
74  }
75 
76  if ( !region.isEmpty() ) {
77  m_view->viewport()->update(region);
78  }
79 }
80 
81 QPixmap DelegateAnimator::sequenceFrame(const QModelIndex& index)
82 {
83  foreach(const Animation &animation, m_animations)
84  {
85  if (animation.index == index)
86  {
87  return m_pixmapSequence.frameAt(animation.frame);
88  }
89  }
90  return QPixmap();
91 }
92 
93 
94 ProgressSpinnerDelegate::ProgressSpinnerDelegate(DelegateAnimator *animator, QObject* parent)
95  : QStyledItemDelegate(parent), m_animator(animator)
96 {
97 
98 }
99 
100 void ProgressSpinnerDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const
101 {
102  QStyledItemDelegate::initStyleOption(option, index);
103 
104  const QVariant fetchState = index.data( Akonadi::EntityTreeModel::FetchStateRole );
105  if (!fetchState.isValid() || fetchState.toInt() != Akonadi::EntityTreeModel::FetchingState) {
106  m_animator->pop(index);
107  return;
108  }
109 
110  m_animator->push(index);
111 
112  if (QStyleOptionViewItemV4 *v4 = qstyleoption_cast<QStyleOptionViewItemV4 *>(option)) {
113  v4->icon = m_animator->sequenceFrame(index);
114  }
115 }
116 
117 uint Akonadi::qHash(Akonadi::DelegateAnimator::Animation anim)
118 {
119  return qHash(anim.index);
120 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:40 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.5 API Reference

Skip menu "kdepimlibs-4.10.5 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