22#include "entitylistview.h"
24#include "dragdropmanager_p.h"
25#include "favoritecollectionsmodel.h"
27#include <QtCore/QDebug>
28#include <QtCore/QTimer>
29#include <QDragMoveEvent>
33#include <kxmlguiclient.h>
34#include <KXMLGUIFactory>
36#include <akonadi/collection.h>
37#include <akonadi/control.h>
38#include <akonadi/item.h>
39#include <akonadi/entitytreemodel.h>
41#include <progressspinnerdelegate_p.h>
48class EntityListView::Private
53#ifndef QT_NO_DRAGANDDROP
54 , mDragDropManager(new DragDropManager(mParent))
61 void itemClicked(
const QModelIndex &index);
62 void itemDoubleClicked(
const QModelIndex &index);
63 void itemCurrentChanged(
const QModelIndex &index);
66 DragDropManager *mDragDropManager;
67 KXMLGUIClient *mXmlGuiClient;
70void EntityListView::Private::init()
72 mParent->setEditTriggers(QAbstractItemView::EditKeyPressed);
73 mParent->setAcceptDrops(
true);
74#ifndef QT_NO_DRAGANDDROP
75 mParent->setDropIndicatorShown(
true);
76 mParent->setDragDropMode(DragDrop);
77 mParent->setDragEnabled(
true);
79 mParent->connect(mParent, SIGNAL(clicked(QModelIndex)),
80 mParent, SLOT(itemClicked(QModelIndex)));
81 mParent->connect(mParent, SIGNAL(doubleClicked(QModelIndex)),
82 mParent, SLOT(itemDoubleClicked(QModelIndex)));
84 DelegateAnimator *animator =
new DelegateAnimator(mParent);
85 ProgressSpinnerDelegate *customDelegate =
new ProgressSpinnerDelegate(animator, mParent);
86 mParent->setItemDelegate(customDelegate);
91void EntityListView::Private::itemClicked(
const QModelIndex &index)
93 if (!index.isValid()) {
98 if (collection.isValid()) {
99 emit mParent->clicked(collection);
102 if (item.isValid()) {
103 emit mParent->clicked(item);
108void EntityListView::Private::itemDoubleClicked(
const QModelIndex &index)
110 if (!index.isValid()) {
115 if (collection.isValid()) {
116 emit mParent->doubleClicked(collection);
119 if (item.isValid()) {
120 emit mParent->doubleClicked(item);
125void EntityListView::Private::itemCurrentChanged(
const QModelIndex &index)
127 if (!index.isValid()) {
132 if (collection.isValid()) {
133 emit mParent->currentChanged(collection);
136 if (item.isValid()) {
137 emit mParent->currentChanged(item);
144 , d(new Private(this))
146 setSelectionMode(QAbstractItemView::SingleSelection);
152 , d(new Private(this))
160 delete d->mDragDropManager;
166 if (selectionModel()) {
167 disconnect(selectionModel(), SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
168 this, SLOT(itemCurrentChanged(QModelIndex)));
171 QListView::setModel(model);
173 connect(selectionModel(), SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
174 SLOT(itemCurrentChanged(QModelIndex)));
177#ifndef QT_NO_DRAGANDDROP
178void EntityListView::dragMoveEvent(QDragMoveEvent *event)
180 if (d->mDragDropManager->dropAllowed(event) ||
181 qobject_cast<Akonadi::FavoriteCollectionsModel *>(model())) {
183 QListView::dragMoveEvent(event);
187 event->setDropAction(Qt::IgnoreAction);
190void EntityListView::dropEvent(QDropEvent *event)
192 bool menuCanceled =
false;
193 if (d->mDragDropManager->processDropEvent(event, menuCanceled) &&
198 QListView::dropEvent(event);
199 }
else if (qobject_cast<Akonadi::FavoriteCollectionsModel *>(model()) &&
201 QListView::dropEvent(event);
206#ifndef QT_NO_CONTEXTMENU
207void EntityListView::contextMenuEvent(QContextMenuEvent *event)
209 if (!d->mXmlGuiClient) {
213 const QModelIndex index = indexAt(event->pos());
219 if (collection.isValid()) {
220 popup =
static_cast<QMenu *
>(d->mXmlGuiClient->factory()->container(
221 QLatin1String(
"akonadi_favoriteview_contextmenu"), d->mXmlGuiClient));
223 popup =
static_cast<QMenu *
>(d->mXmlGuiClient->factory()->container(
224 QLatin1String(
"akonadi_favoriteview_emptyselection_contextmenu"), d->mXmlGuiClient));
228 popup->exec(event->globalPos());
240 return d->mXmlGuiClient;
243#ifndef QT_NO_DRAGANDDROP
244void EntityListView::startDrag(Qt::DropActions supportedActions)
246 d->mDragDropManager->startDrag(supportedActions);
252#ifndef QT_NO_DRAGANDDROP
253 d->mDragDropManager->setShowDropActionMenu(enabled);
259#ifndef QT_NO_DRAGANDDROP
260 return d->mDragDropManager->showDropActionMenu();
266#include "moc_entitylistview.cpp"
Represents a collection of PIM items.
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.
void setDropActionMenuEnabled(bool enabled)
Sets whether the drop action menu is enabled and will be shown on drop operation.
void currentChanged(const Akonadi::Collection &collection)
This signal is emitted whenever the current collection in the view has changed.
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.
virtual void setModel(QAbstractItemModel *model)
virtual ~EntityListView()
Destroys the favorite collections view.
KXMLGUIClient * xmlGuiClient() const
Return the XML GUI client which the view is used in.
@ CollectionRole
The collection.
FreeBusyManager::Singleton.