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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 ProgressSpinnerDelegate::ProgressSpinnerDelegate(DelegateAnimator *animator, QObject* parent)
94  : QStyledItemDelegate(parent), m_animator(animator)
95 {
96 
97 }
98 
99 void ProgressSpinnerDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const
100 {
101  QStyledItemDelegate::initStyleOption(option, index);
102 
103  const QVariant fetchState = index.data( Akonadi::EntityTreeModel::FetchStateRole );
104  if (!fetchState.isValid() || fetchState.toInt() != Akonadi::EntityTreeModel::FetchingState) {
105  m_animator->pop(index);
106  return;
107  }
108 
109  m_animator->push(index);
110 
111  if (QStyleOptionViewItemV4 *v4 = qstyleoption_cast<QStyleOptionViewItemV4 *>(option)) {
112  v4->icon = m_animator->sequenceFrame(index);
113  }
114 }
115 
116 uint Akonadi::qHash(Akonadi::DelegateAnimator::Animation anim)
117 {
118  return qHash(anim.index);
119 }
Akonadi::EntityTreeModel::FetchStateRole
Returns the FetchState of a particular item.
Definition: entitytreemodel.h:350
Akonadi::EntityTreeModel::FetchingState
There is a fetch of items in this collection in progress.
Definition: entitytreemodel.h:374
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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