22 #include "entitylistview.h"
24 #include "dragdropmanager_p.h"
25 #include "favoritecollectionsmodel.h"
27 #include <QtCore/QDebug>
28 #include <QtCore/QTimer>
29 #include <QApplication>
30 #include <QDragMoveEvent>
31 #include <QHeaderView>
36 #include <KMessageBox>
38 #include <KXMLGUIFactory>
41 #include <kxmlguiclient.h>
43 #include <akonadi/collection.h>
44 #include <akonadi/control.h>
45 #include <akonadi/item.h>
46 #include <akonadi/entitytreemodel.h>
48 #include <progressspinnerdelegate_p.h>
50 using namespace Akonadi;
55 class EntityListView::Private
60 #ifndef QT_NO_DRAGANDDROP
61 , mDragDropManager( new DragDropManager( mParent ) )
68 void itemClicked(
const QModelIndex& );
69 void itemDoubleClicked(
const QModelIndex& );
70 void itemCurrentChanged(
const QModelIndex& );
73 DragDropManager *mDragDropManager;
74 KXMLGUIClient *mXmlGuiClient;
77 void EntityListView::Private::init()
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 );
86 mParent->connect( mParent, SIGNAL(clicked(QModelIndex)),
87 mParent, SLOT(itemClicked(QModelIndex)) );
88 mParent->connect( mParent, SIGNAL(doubleClicked(QModelIndex)),
89 mParent, SLOT(itemDoubleClicked(QModelIndex)) );
91 DelegateAnimator *animator =
new DelegateAnimator( mParent );
92 ProgressSpinnerDelegate *customDelegate =
new ProgressSpinnerDelegate( animator, mParent );
93 mParent->setItemDelegate( customDelegate );
98 void EntityListView::Private::itemClicked(
const QModelIndex &index )
100 if ( !index.isValid() ) {
106 emit mParent->clicked( collection );
110 emit mParent->clicked( item );
115 void EntityListView::Private::itemDoubleClicked(
const QModelIndex &index )
117 if ( !index.isValid() ) {
123 emit mParent->doubleClicked( collection );
127 emit mParent->doubleClicked( item );
132 void EntityListView::Private::itemCurrentChanged(
const QModelIndex &index )
134 if ( !index.isValid() ) {
140 emit mParent->currentChanged( collection );
144 emit mParent->currentChanged( item );
150 : QListView( parent ),
151 d( new Private( this ) )
153 setSelectionMode( QAbstractItemView::SingleSelection );
158 : QListView( parent ),
159 d( new Private( this ) )
161 d->mXmlGuiClient = xmlGuiClient;
167 delete d->mDragDropManager;
173 if ( selectionModel() ) {
174 disconnect( selectionModel(), SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
175 this, SLOT(itemCurrentChanged(QModelIndex)) );
178 QListView::setModel( model );
180 connect( selectionModel(), SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
181 SLOT(itemCurrentChanged(QModelIndex)) );
184 #ifndef QT_NO_DRAGANDDROP
185 void EntityListView::dragMoveEvent( QDragMoveEvent * event )
187 if ( d->mDragDropManager->dropAllowed( event ) ||
190 QListView::dragMoveEvent( event );
194 event->setDropAction( Qt::IgnoreAction );
197 void EntityListView::dropEvent( QDropEvent * event )
199 bool menuCanceled =
false;
200 if ( d->mDragDropManager->processDropEvent( event, menuCanceled ) &&
202 if ( menuCanceled ) {
205 QListView::dropEvent( event );
206 }
else if ( qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) &&
208 QListView::dropEvent( event );
213 #ifndef QT_NO_CONTEXTMENU
214 void EntityListView::contextMenuEvent( QContextMenuEvent * event )
216 if ( !d->mXmlGuiClient ) {
220 const QModelIndex index = indexAt( event->pos() );
227 popup =
static_cast<QMenu*
>( d->mXmlGuiClient->factory()->container(
228 QLatin1String(
"akonadi_favoriteview_contextmenu" ), d->mXmlGuiClient ) );
230 popup =
static_cast<QMenu*
>( d->mXmlGuiClient->factory()->container(
231 QLatin1String(
"akonadi_favoriteview_emptyselection_contextmenu" ), d->mXmlGuiClient ) );
235 popup->exec( event->globalPos() );
242 d->mXmlGuiClient = xmlGuiClient;
245 #ifndef QT_NO_DRAGANDDROP
246 void EntityListView::startDrag( Qt::DropActions supportedActions )
248 d->mDragDropManager->startDrag( supportedActions );
254 #ifndef QT_NO_DRAGANDDROP
255 d->mDragDropManager->setShowDropActionMenu( enabled );
261 #ifndef QT_NO_DRAGANDDROP
262 return d->mDragDropManager->showDropActionMenu();
268 #include "moc_entitylistview.cpp"