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

akonadi

entitylistview.cpp
00001 /*
00002     Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
00003     Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
00004     Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 #include "entitylistview.h"
00023 
00024 #include "dragdropmanager_p.h"
00025 #include "favoritecollectionsmodel.h"
00026 
00027 #include <QtCore/QDebug>
00028 #include <QtCore/QTimer>
00029 #include <QtGui/QApplication>
00030 #include <QtGui/QDragMoveEvent>
00031 #include <QtGui/QHeaderView>
00032 #include <QtGui/QMenu>
00033 
00034 #include <KAction>
00035 #include <KLocale>
00036 #include <KMessageBox>
00037 #include <KUrl>
00038 #include <KXMLGUIFactory>
00039 
00040 #include <kdebug.h>
00041 #include <kxmlguiclient.h>
00042 
00043 #include <akonadi/collection.h>
00044 #include <akonadi/control.h>
00045 #include <akonadi/item.h>
00046 #include <akonadi/entitytreemodel.h>
00047 
00048 #include <progressspinnerdelegate_p.h>
00049 
00050 using namespace Akonadi;
00051 
00055 class EntityListView::Private
00056 {
00057 public:
00058   Private( EntityListView *parent )
00059       : mParent( parent )
00060 #ifndef QT_NO_DRAGANDDROP
00061       , mDragDropManager( new DragDropManager( mParent ) )
00062 #endif    
00063       , mXmlGuiClient( 0 )
00064   {
00065   }
00066 
00067   void init();
00068   void itemClicked( const QModelIndex& );
00069   void itemDoubleClicked( const QModelIndex& );
00070   void itemCurrentChanged( const QModelIndex& );
00071 
00072   EntityListView *mParent;
00073   DragDropManager *mDragDropManager;
00074   KXMLGUIClient *mXmlGuiClient;
00075 };
00076 
00077 void EntityListView::Private::init()
00078 {
00079   mParent->setEditTriggers( QAbstractItemView::EditKeyPressed );
00080   mParent->setAcceptDrops( true );
00081 #ifndef QT_NO_DRAGANDDROP
00082   mParent->setDropIndicatorShown( true );
00083   mParent->setDragDropMode( DragDrop );
00084   mParent->setDragEnabled( true );
00085 #endif
00086   mParent->connect( mParent, SIGNAL(clicked(QModelIndex)),
00087                     mParent, SLOT(itemClicked(QModelIndex)) );
00088   mParent->connect( mParent, SIGNAL(doubleClicked(QModelIndex)),
00089                     mParent, SLOT(itemDoubleClicked(QModelIndex)) );
00090 
00091   DelegateAnimator *animator = new DelegateAnimator(mParent);
00092   ProgressSpinnerDelegate *customDelegate = new ProgressSpinnerDelegate(animator, mParent);
00093   mParent->setItemDelegate(customDelegate);
00094 
00095   Control::widgetNeedsAkonadi( mParent );
00096 }
00097 
00098 void EntityListView::Private::itemClicked( const QModelIndex &index )
00099 {
00100   if ( !index.isValid() )
00101     return;
00102 
00103   const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
00104   if ( collection.isValid() ) {
00105     emit mParent->clicked( collection );
00106   } else {
00107     const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
00108     if ( item.isValid() )
00109       emit mParent->clicked( item );
00110   }
00111 }
00112 
00113 void EntityListView::Private::itemDoubleClicked( const QModelIndex &index )
00114 {
00115   if ( !index.isValid() )
00116     return;
00117 
00118   const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
00119   if ( collection.isValid() ) {
00120     emit mParent->doubleClicked( collection );
00121   } else {
00122     const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
00123     if ( item.isValid() )
00124       emit mParent->doubleClicked( item );
00125   }
00126 }
00127 
00128 void EntityListView::Private::itemCurrentChanged( const QModelIndex &index )
00129 {
00130   if ( !index.isValid() )
00131     return;
00132 
00133   const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
00134   if ( collection.isValid() ) {
00135     emit mParent->currentChanged( collection );
00136   } else {
00137     const Item item = index.model()->data( index, EntityTreeModel::ItemRole ).value<Item>();
00138     if ( item.isValid() )
00139       emit mParent->currentChanged( item );
00140   }
00141 }
00142 
00143 EntityListView::EntityListView( QWidget * parent )
00144   : QListView( parent ),
00145     d( new Private( this ) )
00146 {
00147   setSelectionMode( QAbstractItemView::SingleSelection );
00148   d->init();
00149 }
00150 
00151 EntityListView::EntityListView( KXMLGUIClient *xmlGuiClient, QWidget * parent )
00152   : QListView( parent ),
00153     d( new Private( this ) )
00154 {
00155   d->mXmlGuiClient = xmlGuiClient;
00156   d->init();
00157 }
00158 
00159 EntityListView::~EntityListView()
00160 {
00161   delete d->mDragDropManager;
00162   delete d;
00163 }
00164 
00165 void EntityListView::setModel( QAbstractItemModel * model )
00166 {
00167   if ( selectionModel() ) {
00168     disconnect( selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
00169            this, SLOT(itemCurrentChanged(QModelIndex)) );
00170   }
00171 
00172   QListView::setModel( model );
00173 
00174   connect( selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
00175            SLOT(itemCurrentChanged(QModelIndex)) );
00176 }
00177 
00178 #ifndef QT_NO_DRAGANDDROP
00179 void EntityListView::dragMoveEvent( QDragMoveEvent * event )
00180 {
00181   if ( d->mDragDropManager->dropAllowed( event ) || qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) ) {
00182     // All urls are supported. process the event.
00183     QListView::dragMoveEvent( event );
00184     return;
00185   }
00186 
00187   event->setDropAction( Qt::IgnoreAction );
00188 }
00189 
00190 void EntityListView::dropEvent( QDropEvent * event )
00191 {
00192   bool menuCanceled = false;
00193   if ( d->mDragDropManager->processDropEvent( event, menuCanceled ) && !menuCanceled) {
00194     if ( menuCanceled )
00195       return;
00196     QListView::dropEvent( event );
00197   }
00198   else if ( qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) &&!menuCanceled )
00199   {
00200     QListView::dropEvent( event );
00201   }
00202 }
00203 #endif
00204 
00205 #ifndef QT_NO_CONTEXTMENU
00206 void EntityListView::contextMenuEvent( QContextMenuEvent * event )
00207 {
00208   if ( !d->mXmlGuiClient )
00209     return;
00210 
00211   const QModelIndex index = indexAt( event->pos() );
00212 
00213   QMenu *popup = 0;
00214 
00215   // check if the index under the cursor is a collection or item
00216   const Collection collection = model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
00217   if ( collection.isValid() ) {
00218     popup = static_cast<QMenu*>( d->mXmlGuiClient->factory()->container(
00219                                  QLatin1String( "akonadi_favoriteview_contextmenu" ), d->mXmlGuiClient ) );
00220   } else {
00221     popup = static_cast<QMenu*>( d->mXmlGuiClient->factory()->container(
00222                                    QLatin1String( "akonadi_favoriteview_emptyselection_contextmenu" ), d->mXmlGuiClient) );
00223   }
00224 
00225   if ( popup )
00226     popup->exec( event->globalPos() );
00227 }
00228 #endif
00229 
00230 void EntityListView::setXmlGuiClient( KXMLGUIClient *xmlGuiClient )
00231 {
00232   d->mXmlGuiClient = xmlGuiClient;
00233 }
00234 
00235 #ifndef QT_NO_DRAGANDDROP
00236 void EntityListView::startDrag( Qt::DropActions supportedActions )
00237 {
00238   d->mDragDropManager->startDrag( supportedActions );
00239 }
00240 #endif
00241 
00242 void EntityListView::setDropActionMenuEnabled( bool enabled )
00243 {
00244 #ifndef QT_NO_DRAGANDDROP
00245   d->mDragDropManager->setShowDropActionMenu( enabled );
00246 #endif
00247 }
00248 
00249 bool EntityListView::isDropActionMenuEnabled() const
00250 {
00251 #ifndef QT_NO_DRAGANDDROP
00252   return d->mDragDropManager->showDropActionMenu();
00253 #else
00254   return false;
00255 #endif
00256 }
00257 
00258 #include "entitylistview.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:52:54 by doxygen 1.7.5 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.8.3 API Reference

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