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

akonadi

  • akonadi
entitylistview.cpp
1 /*
2  Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3  Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
4  Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
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 "entitylistview.h"
23 
24 #include "dragdropmanager_p.h"
25 #include "favoritecollectionsmodel.h"
26 
27 #include <QtCore/QDebug>
28 #include <QtCore/QTimer>
29 #include <QDragMoveEvent>
30 #include <QMenu>
31 
32 
33 #include <kdebug.h>
34 #include <kxmlguiclient.h>
35 #include <KXMLGUIFactory>
36 
37 #include <akonadi/collection.h>
38 #include <akonadi/control.h>
39 #include <akonadi/item.h>
40 #include <akonadi/entitytreemodel.h>
41 
42 #include <progressspinnerdelegate_p.h>
43 
44 using namespace Akonadi;
45 
49 class EntityListView::Private
50 {
51 public:
52  Private( EntityListView *parent )
53  : mParent( parent )
54 #ifndef QT_NO_DRAGANDDROP
55  , mDragDropManager( new DragDropManager( mParent ) )
56 #endif
57  , mXmlGuiClient( 0 )
58  {
59  }
60 
61  void init();
62  void itemClicked( const QModelIndex& );
63  void itemDoubleClicked( const QModelIndex& );
64  void itemCurrentChanged( const QModelIndex& );
65 
66  EntityListView *mParent;
67  DragDropManager *mDragDropManager;
68  KXMLGUIClient *mXmlGuiClient;
69 };
70 
71 void EntityListView::Private::init()
72 {
73  mParent->setEditTriggers( QAbstractItemView::EditKeyPressed );
74  mParent->setAcceptDrops( true );
75 #ifndef QT_NO_DRAGANDDROP
76  mParent->setDropIndicatorShown( true );
77  mParent->setDragDropMode( DragDrop );
78  mParent->setDragEnabled( true );
79 #endif
80  mParent->connect( mParent, SIGNAL(clicked(QModelIndex)),
81  mParent, SLOT(itemClicked(QModelIndex)) );
82  mParent->connect( mParent, SIGNAL(doubleClicked(QModelIndex)),
83  mParent, SLOT(itemDoubleClicked(QModelIndex)) );
84 
85  DelegateAnimator *animator = new DelegateAnimator( mParent );
86  ProgressSpinnerDelegate *customDelegate = new ProgressSpinnerDelegate( animator, mParent );
87  mParent->setItemDelegate( customDelegate );
88 
89  Control::widgetNeedsAkonadi( mParent );
90 }
91 
92 void EntityListView::Private::itemClicked( const QModelIndex &index )
93 {
94  if ( !index.isValid() ) {
95  return;
96  }
97 
98  const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
99  if ( collection.isValid() ) {
100  emit mParent->clicked( collection );
101  } else {
102  const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
103  if ( item.isValid() ) {
104  emit mParent->clicked( item );
105  }
106  }
107 }
108 
109 void EntityListView::Private::itemDoubleClicked( const QModelIndex &index )
110 {
111  if ( !index.isValid() ) {
112  return;
113  }
114 
115  const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
116  if ( collection.isValid() ) {
117  emit mParent->doubleClicked( collection );
118  } else {
119  const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
120  if ( item.isValid() ) {
121  emit mParent->doubleClicked( item );
122  }
123  }
124 }
125 
126 void EntityListView::Private::itemCurrentChanged( const QModelIndex &index )
127 {
128  if ( !index.isValid() ) {
129  return;
130  }
131 
132  const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
133  if ( collection.isValid() ) {
134  emit mParent->currentChanged( collection );
135  } else {
136  const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
137  if ( item.isValid() ) {
138  emit mParent->currentChanged( item );
139  }
140  }
141 }
142 
143 EntityListView::EntityListView( QWidget * parent )
144  : QListView( parent ),
145  d( new Private( this ) )
146 {
147  setSelectionMode( QAbstractItemView::SingleSelection );
148  d->init();
149 }
150 
151 EntityListView::EntityListView( KXMLGUIClient *xmlGuiClient, QWidget * parent )
152  : QListView( parent ),
153  d( new Private( this ) )
154 {
155  d->mXmlGuiClient = xmlGuiClient;
156  d->init();
157 }
158 
159 EntityListView::~EntityListView()
160 {
161  delete d->mDragDropManager;
162  delete d;
163 }
164 
165 void EntityListView::setModel( QAbstractItemModel * model )
166 {
167  if ( selectionModel() ) {
168  disconnect( selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
169  this, SLOT(itemCurrentChanged(QModelIndex)) );
170  }
171 
172  QListView::setModel( model );
173 
174  connect( selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
175  SLOT(itemCurrentChanged(QModelIndex)) );
176 }
177 
178 #ifndef QT_NO_DRAGANDDROP
179 void EntityListView::dragMoveEvent( QDragMoveEvent * event )
180 {
181  if ( d->mDragDropManager->dropAllowed( event ) ||
182  qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) ) {
183  // All urls are supported. process the event.
184  QListView::dragMoveEvent( event );
185  return;
186  }
187 
188  event->setDropAction( Qt::IgnoreAction );
189 }
190 
191 void EntityListView::dropEvent( QDropEvent * event )
192 {
193  bool menuCanceled = false;
194  if ( d->mDragDropManager->processDropEvent( event, menuCanceled ) &&
195  !menuCanceled ) {
196  if ( menuCanceled ) {
197  return;
198  }
199  QListView::dropEvent( event );
200  } else if ( qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) &&
201  !menuCanceled ) {
202  QListView::dropEvent( event );
203  }
204 }
205 #endif
206 
207 #ifndef QT_NO_CONTEXTMENU
208 void EntityListView::contextMenuEvent( QContextMenuEvent * event )
209 {
210  if ( !d->mXmlGuiClient ) {
211  return;
212  }
213 
214  const QModelIndex index = indexAt( event->pos() );
215 
216  QMenu *popup = 0;
217 
218  // check if the index under the cursor is a collection or item
219  const Collection collection = model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
220  if ( collection.isValid() ) {
221  popup = static_cast<QMenu*>( d->mXmlGuiClient->factory()->container(
222  QLatin1String( "akonadi_favoriteview_contextmenu" ), d->mXmlGuiClient ) );
223  } else {
224  popup = static_cast<QMenu*>( d->mXmlGuiClient->factory()->container(
225  QLatin1String( "akonadi_favoriteview_emptyselection_contextmenu" ), d->mXmlGuiClient ) );
226  }
227 
228  if ( popup ) {
229  popup->exec( event->globalPos() );
230  }
231 }
232 #endif
233 
234 void EntityListView::setXmlGuiClient( KXMLGUIClient *xmlGuiClient )
235 {
236  d->mXmlGuiClient = xmlGuiClient;
237 }
238 
239 KXMLGUIClient *EntityListView::xmlGuiClient() const
240 {
241  return d->mXmlGuiClient;
242 }
243 
244 #ifndef QT_NO_DRAGANDDROP
245 void EntityListView::startDrag( Qt::DropActions supportedActions )
246 {
247  d->mDragDropManager->startDrag( supportedActions );
248 }
249 #endif
250 
251 void EntityListView::setDropActionMenuEnabled( bool enabled )
252 {
253 #ifndef QT_NO_DRAGANDDROP
254  d->mDragDropManager->setShowDropActionMenu( enabled );
255 #endif
256 }
257 
258 bool EntityListView::isDropActionMenuEnabled() const
259 {
260 #ifndef QT_NO_DRAGANDDROP
261  return d->mDragDropManager->showDropActionMenu();
262 #else
263  return false;
264 #endif
265 }
266 
267 #include "moc_entitylistview.cpp"
Akonadi::EntityListView::setModel
virtual void setModel(QAbstractItemModel *model)
Definition: entitylistview.cpp:165
Akonadi::EntityListView::xmlGuiClient
KXMLGUIClient * xmlGuiClient() const
Return the XML GUI client which the view is used in.
Definition: entitylistview.cpp:239
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::EntityListView::currentChanged
void currentChanged(const Akonadi::Collection &collection)
This signal is emitted whenever the current collection in the view has changed.
Akonadi::EntityListView::setDropActionMenuEnabled
void setDropActionMenuEnabled(bool enabled)
Sets whether the drop action menu is enabled and will be shown on drop operation. ...
Definition: entitylistview.cpp:251
Akonadi::EntityListView::setXmlGuiClient
void setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
Sets the XML GUI client which the view is used in.
Definition: entitylistview.cpp:234
Akonadi::EntityListView::EntityListView
EntityListView(QWidget *parent=0)
Creates a new favorite collections view.
Definition: entitylistview.cpp:143
Akonadi::EntityListView::isDropActionMenuEnabled
bool isDropActionMenuEnabled() const
Returns whether the drop action menu is enabled and will be shown on drop operation.
Definition: entitylistview.cpp:258
Akonadi::Control::widgetNeedsAkonadi
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
Definition: control.cpp:259
Akonadi::EntityTreeModel::CollectionRole
The collection.
Definition: entitytreemodel.h:335
Akonadi::EntityListView
A view to show an item/collection list provided by an EntityTreeModel.
Definition: entitylistview.h:75
Akonadi::EntityListView::~EntityListView
virtual ~EntityListView()
Destroys the favorite collections view.
Definition: entitylistview.cpp:159
Akonadi::EntityTreeModel::ItemRole
The Item.
Definition: entitytreemodel.h:331
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi::FavoriteCollectionsModel
A model that lists a set of favorite collections.
Definition: favoritecollectionsmodel.h:66
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:52 by doxygen 1.8.6 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.13.3 API Reference

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