diff --git a/src/folder/favoritecollectionorderproxymodel.h b/src/folder/favoritecollectionorderproxymodel.h --- a/src/folder/favoritecollectionorderproxymodel.h +++ b/src/folder/favoritecollectionorderproxymodel.h @@ -33,8 +33,6 @@ explicit FavoriteCollectionOrderProxyModel(QObject *parent = nullptr); virtual ~FavoriteCollectionOrderProxyModel(); - Qt::ItemFlags flags(const QModelIndex &index) const override; - protected: Akonadi::Collection parentCollection(const QModelIndex &index) const override; diff --git a/src/folder/favoritecollectionorderproxymodel.cpp b/src/folder/favoritecollectionorderproxymodel.cpp --- a/src/folder/favoritecollectionorderproxymodel.cpp +++ b/src/folder/favoritecollectionorderproxymodel.cpp @@ -42,16 +42,6 @@ delete d; } -Qt::ItemFlags FavoriteCollectionOrderProxyModel::flags(const QModelIndex &index) const -{ - Qt::ItemFlags flags = KRecursiveFilterProxyModel::flags(index); - // Don't allow dropping on folders - if (index.isValid()) { - flags &= ~Qt::ItemIsDropEnabled; - } - return flags; -} - Akonadi::Collection FavoriteCollectionOrderProxyModel::parentCollection(const QModelIndex &index) const { Q_UNUSED(index); diff --git a/src/widgets/favoritecollectionwidget.h b/src/widgets/favoritecollectionwidget.h --- a/src/widgets/favoritecollectionwidget.h +++ b/src/widgets/favoritecollectionwidget.h @@ -58,7 +58,9 @@ void newTabRequested(bool); private: + bool acceptEvent(QDropEvent *event) const; void createMenu(KActionCollection *ac); + class Private; Private *const d; }; diff --git a/src/widgets/favoritecollectionwidget.cpp b/src/widgets/favoritecollectionwidget.cpp --- a/src/widgets/favoritecollectionwidget.cpp +++ b/src/widgets/favoritecollectionwidget.cpp @@ -31,6 +31,7 @@ #include #include #include +#include using namespace MailCommon; @@ -245,33 +246,70 @@ } } +static bool isCollection(const QMimeData *mimeData) +{ + const QList urls = mimeData->urls(); + for (const QUrl &url : urls) { + const Akonadi::Collection collection = Akonadi::Collection::fromUrl(url); + if (collection.isValid()) { + return true; + } + } + return false; +} + +bool FavoriteCollectionWidget::acceptEvent(QDropEvent *event) const +{ + const bool draggingCollection = isCollection(event->mimeData()); + const bool droppingOnCollection = dropIndicatorPosition() == QAbstractItemView::OnItem; + if (event->source() == this) { + if (draggingCollection && !droppingOnCollection) // Re-ordering favorites + return true; + } else { + if ((draggingCollection && !droppingOnCollection) // Adding a new favorite collection + || (!draggingCollection && droppingOnCollection)) // Dropping emails onto a favorite collection + return true; + } + event->ignore(); + return false; +} + void FavoriteCollectionWidget::dragEnterEvent(QDragEnterEvent *event) { if (event->source() == this) { - // skip EntityListView logic (we want to reorder favorites, not trigger moving/copying of actual folders) - QListView::dragEnterEvent(event); + QListView::dragEnterEvent(event); // Re-ordering favourites } else { - Akonadi::EntityListView::dragEnterEvent(event); + Akonadi::EntityListView::dragEnterEvent(event); // Dropping emails onto a favorite collection } } void FavoriteCollectionWidget::dragMoveEvent(QDragMoveEvent *event) { + // We need to ask QListView to update dropIndicatorPosition() first... + QListView::dragMoveEvent(event); if (event->source() == this) { - // skip EntityListView logic (we want to reorder favorites, not trigger moving/copying of actual folders) - QListView::dragMoveEvent(event); + if (acceptEvent(event)) { + event->setDropAction(Qt::MoveAction); + event->acceptProposedAction(); // Re-ordering favourites + } } else { - Akonadi::EntityListView::dragMoveEvent(event); + if (acceptEvent(event)) + Akonadi::EntityListView::dragMoveEvent(event); // Dropping emails onto a favorite collection } } void FavoriteCollectionWidget::dropEvent(QDropEvent *event) { if (event->source() == this) { - // skip EntityListView logic (we want to reorder favorites, not trigger moving/copying of actual folders) - QListView::dropEvent(event); + if (acceptEvent(event)) + QListView::dropEvent(event); // Re-ordering favourites } else { - Akonadi::EntityListView::dropEvent(event); + if (acceptEvent(event)) { + if (dropIndicatorPosition() == QAbstractItemView::OnItem) + Akonadi::EntityListView::dropEvent(event); // Dropping emails onto a favorite collection + else + QListView::dropEvent(event); // Add new favorite + } } }