22 #include "entitylistview.h"
24 #include "dragdropmanager_p.h"
25 #include "favoritecollectionsmodel.h"
27 #include <QtCore/QDebug>
28 #include <QtCore/QTimer>
29 #include <QDragMoveEvent>
34 #include <kxmlguiclient.h>
35 #include <KXMLGUIFactory>
37 #include <akonadi/collection.h>
38 #include <akonadi/control.h>
39 #include <akonadi/item.h>
40 #include <akonadi/entitytreemodel.h>
42 #include <progressspinnerdelegate_p.h>
44 using namespace Akonadi;
49 class EntityListView::Private
54 #ifndef QT_NO_DRAGANDDROP
55 , mDragDropManager( new DragDropManager( mParent ) )
62 void itemClicked(
const QModelIndex& );
63 void itemDoubleClicked(
const QModelIndex& );
64 void itemCurrentChanged(
const QModelIndex& );
67 DragDropManager *mDragDropManager;
68 KXMLGUIClient *mXmlGuiClient;
71 void EntityListView::Private::init()
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 );
80 mParent->connect( mParent, SIGNAL(clicked(QModelIndex)),
81 mParent, SLOT(itemClicked(QModelIndex)) );
82 mParent->connect( mParent, SIGNAL(doubleClicked(QModelIndex)),
83 mParent, SLOT(itemDoubleClicked(QModelIndex)) );
85 DelegateAnimator *animator =
new DelegateAnimator( mParent );
86 ProgressSpinnerDelegate *customDelegate =
new ProgressSpinnerDelegate( animator, mParent );
87 mParent->setItemDelegate( customDelegate );
92 void EntityListView::Private::itemClicked(
const QModelIndex &index )
94 if ( !index.isValid() ) {
100 emit mParent->clicked( collection );
103 if ( item.isValid() ) {
104 emit mParent->clicked( item );
109 void EntityListView::Private::itemDoubleClicked(
const QModelIndex &index )
111 if ( !index.isValid() ) {
117 emit mParent->doubleClicked( collection );
120 if ( item.isValid() ) {
121 emit mParent->doubleClicked( item );
126 void EntityListView::Private::itemCurrentChanged(
const QModelIndex &index )
128 if ( !index.isValid() ) {
134 emit mParent->currentChanged( collection );
137 if ( item.isValid() ) {
138 emit mParent->currentChanged( item );
144 : QListView( parent ),
145 d( new Private( this ) )
147 setSelectionMode( QAbstractItemView::SingleSelection );
152 : QListView( parent ),
153 d( new Private( this ) )
161 delete d->mDragDropManager;
167 if ( selectionModel() ) {
168 disconnect( selectionModel(), SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
169 this, SLOT(itemCurrentChanged(QModelIndex)) );
172 QListView::setModel( model );
174 connect( selectionModel(), SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
175 SLOT(itemCurrentChanged(QModelIndex)) );
178 #ifndef QT_NO_DRAGANDDROP
179 void EntityListView::dragMoveEvent( QDragMoveEvent * event )
181 if ( d->mDragDropManager->dropAllowed( event ) ||
184 QListView::dragMoveEvent( event );
188 event->setDropAction( Qt::IgnoreAction );
191 void EntityListView::dropEvent( QDropEvent * event )
193 bool menuCanceled =
false;
194 if ( d->mDragDropManager->processDropEvent( event, menuCanceled ) &&
196 if ( menuCanceled ) {
199 QListView::dropEvent( event );
200 }
else if ( qobject_cast<Akonadi::FavoriteCollectionsModel*>( model() ) &&
202 QListView::dropEvent( event );
207 #ifndef QT_NO_CONTEXTMENU
208 void EntityListView::contextMenuEvent( QContextMenuEvent * event )
210 if ( !d->mXmlGuiClient ) {
214 const QModelIndex index = indexAt( event->pos() );
221 popup =
static_cast<QMenu*
>( d->mXmlGuiClient->factory()->container(
222 QLatin1String(
"akonadi_favoriteview_contextmenu" ), d->mXmlGuiClient ) );
224 popup =
static_cast<QMenu*
>( d->mXmlGuiClient->factory()->container(
225 QLatin1String(
"akonadi_favoriteview_emptyselection_contextmenu" ), d->mXmlGuiClient ) );
229 popup->exec( event->globalPos() );
241 return d->mXmlGuiClient;
244 #ifndef QT_NO_DRAGANDDROP
245 void EntityListView::startDrag( Qt::DropActions supportedActions )
247 d->mDragDropManager->startDrag( supportedActions );
253 #ifndef QT_NO_DRAGANDDROP
254 d->mDragDropManager->setShowDropActionMenu( enabled );
260 #ifndef QT_NO_DRAGANDDROP
261 return d->mDragDropManager->showDropActionMenu();
267 #include "moc_entitylistview.cpp"
virtual void setModel(QAbstractItemModel *model)
KXMLGUIClient * xmlGuiClient() const
Return the XML GUI client which the view is used in.
Represents a collection of PIM items.
void currentChanged(const Akonadi::Collection &collection)
This signal is emitted whenever the current collection in the view has changed.
void setDropActionMenuEnabled(bool enabled)
Sets whether the drop action menu is enabled and will be shown on drop operation. ...
void setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
Sets the XML GUI client which the view is used in.
EntityListView(QWidget *parent=0)
Creates a new favorite collections view.
bool isDropActionMenuEnabled() const
Returns whether the drop action menu is enabled and will be shown on drop operation.
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
A view to show an item/collection list provided by an EntityTreeModel.
virtual ~EntityListView()
Destroys the favorite collections view.
bool isValid() const
Returns whether the entity is valid.
A model that lists a set of favorite collections.