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>
35 #include <KLocalizedString>
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 );
109 if ( item.isValid() ) {
110 emit mParent->clicked( item );
115 void EntityListView::Private::itemDoubleClicked(
const QModelIndex &index )
117 if ( !index.isValid() ) {
123 emit mParent->doubleClicked( collection );
126 if ( item.isValid() ) {
127 emit mParent->doubleClicked( item );
132 void EntityListView::Private::itemCurrentChanged(
const QModelIndex &index )
134 if ( !index.isValid() ) {
140 emit mParent->currentChanged( collection );
143 if ( item.isValid() ) {
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 ) )
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() );
247 return d->mXmlGuiClient;
250 #ifndef QT_NO_DRAGANDDROP
251 void EntityListView::startDrag( Qt::DropActions supportedActions )
253 d->mDragDropManager->startDrag( supportedActions );
259 #ifndef QT_NO_DRAGANDDROP
260 d->mDragDropManager->setShowDropActionMenu( enabled );
266 #ifndef QT_NO_DRAGANDDROP
267 return d->mDragDropManager->showDropActionMenu();
273 #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.