• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 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 <QtGui/QApplication>
30 #include <QtGui/QDragMoveEvent>
31 #include <QtGui/QHeaderView>
32 #include <QtGui/QMenu>
33 
34 #include <KAction>
35 #include <KLocale>
36 #include <KMessageBox>
37 #include <KUrl>
38 #include <KXMLGUIFactory>
39 
40 #include <kdebug.h>
41 #include <kxmlguiclient.h>
42 
43 #include <akonadi/collection.h>
44 #include <akonadi/control.h>
45 #include <akonadi/item.h>
46 #include <akonadi/entitytreemodel.h>
47 
48 #include <progressspinnerdelegate_p.h>
49 
50 using namespace Akonadi;
51 
55 class EntityListView::Private
56 {
57 public:
58  Private( EntityListView *parent )
59  : mParent( parent )
60 #ifndef QT_NO_DRAGANDDROP
61  , mDragDropManager( new DragDropManager( mParent ) )
62 #endif
63  , mXmlGuiClient( 0 )
64  {
65  }
66 
67  void init();
68  void itemClicked( const QModelIndex& );
69  void itemDoubleClicked( const QModelIndex& );
70  void itemCurrentChanged( const QModelIndex& );
71 
72  EntityListView *mParent;
73  DragDropManager *mDragDropManager;
74  KXMLGUIClient *mXmlGuiClient;
75 };
76 
77 void EntityListView::Private::init()
78 {
79  mParent->setEditTriggers( QAbstractItemView::EditKeyPressed );
80  mParent->setAcceptDrops( true );
81 #ifndef QT_NO_DRAGANDDROP
82  mParent->setDropIndicatorShown( true );
83  mParent->setDragDropMode( DragDrop );
84  mParent->setDragEnabled( true );
85 #endif
86  mParent->connect( mParent, SIGNAL(clicked(QModelIndex)),
87  mParent, SLOT(itemClicked(QModelIndex)) );
88  mParent->connect( mParent, SIGNAL(doubleClicked(QModelIndex)),
89  mParent, SLOT(itemDoubleClicked(QModelIndex)) );
90 
91  DelegateAnimator *animator = new DelegateAnimator(mParent);
92  ProgressSpinnerDelegate *customDelegate = new ProgressSpinnerDelegate(animator, mParent);
93  mParent->setItemDelegate(customDelegate);
94 
95  Control::widgetNeedsAkonadi( mParent );
96 }
97 
98 void EntityListView::Private::itemClicked( const QModelIndex &index )
99 {
100  if ( !index.isValid() )
101  return;
102 
103  const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
104  if ( collection.isValid() ) {
105  emit mParent->clicked( collection );
106  } else {
107  const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
108  if ( item.isValid() )
109  emit mParent->clicked( item );
110  }
111 }
112 
113 void EntityListView::Private::itemDoubleClicked( const QModelIndex &index )
114 {
115  if ( !index.isValid() )
116  return;
117 
118  const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
119  if ( collection.isValid() ) {
120  emit mParent->doubleClicked( collection );
121  } else {
122  const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
123  if ( item.isValid() )
124  emit mParent->doubleClicked( item );
125  }
126 }
127 
128 void EntityListView::Private::itemCurrentChanged( const QModelIndex &index )
129 {
130  if ( !index.isValid() )
131  return;
132 
133  const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
134  if ( collection.isValid() ) {
135  emit mParent->currentChanged( collection );
136  } else {
137  const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
138  if ( item.isValid() )
139  emit mParent->currentChanged( item );
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 ) || qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) ) {
182  // All urls are supported. process the event.
183  QListView::dragMoveEvent( event );
184  return;
185  }
186 
187  event->setDropAction( Qt::IgnoreAction );
188 }
189 
190 void EntityListView::dropEvent( QDropEvent * event )
191 {
192  bool menuCanceled = false;
193  if ( d->mDragDropManager->processDropEvent( event, menuCanceled ) && !menuCanceled) {
194  if ( menuCanceled )
195  return;
196  QListView::dropEvent( event );
197  }
198  else if ( qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) &&!menuCanceled )
199  {
200  QListView::dropEvent( event );
201  }
202 }
203 #endif
204 
205 #ifndef QT_NO_CONTEXTMENU
206 void EntityListView::contextMenuEvent( QContextMenuEvent * event )
207 {
208  if ( !d->mXmlGuiClient )
209  return;
210 
211  const QModelIndex index = indexAt( event->pos() );
212 
213  QMenu *popup = 0;
214 
215  // check if the index under the cursor is a collection or item
216  const Collection collection = model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
217  if ( collection.isValid() ) {
218  popup = static_cast<QMenu*>( d->mXmlGuiClient->factory()->container(
219  QLatin1String( "akonadi_favoriteview_contextmenu" ), d->mXmlGuiClient ) );
220  } else {
221  popup = static_cast<QMenu*>( d->mXmlGuiClient->factory()->container(
222  QLatin1String( "akonadi_favoriteview_emptyselection_contextmenu" ), d->mXmlGuiClient) );
223  }
224 
225  if ( popup )
226  popup->exec( event->globalPos() );
227 }
228 #endif
229 
230 void EntityListView::setXmlGuiClient( KXMLGUIClient *xmlGuiClient )
231 {
232  d->mXmlGuiClient = xmlGuiClient;
233 }
234 
235 #ifndef QT_NO_DRAGANDDROP
236 void EntityListView::startDrag( Qt::DropActions supportedActions )
237 {
238  d->mDragDropManager->startDrag( supportedActions );
239 }
240 #endif
241 
242 void EntityListView::setDropActionMenuEnabled( bool enabled )
243 {
244 #ifndef QT_NO_DRAGANDDROP
245  d->mDragDropManager->setShowDropActionMenu( enabled );
246 #endif
247 }
248 
249 bool EntityListView::isDropActionMenuEnabled() const
250 {
251 #ifndef QT_NO_DRAGANDDROP
252  return d->mDragDropManager->showDropActionMenu();
253 #else
254  return false;
255 #endif
256 }
257 
258 #include "entitylistview.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Dec 10 2012 13:48:09 by doxygen 1.8.1.2 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.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • 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
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