Commit ace9cfb4 authored by David Faure's avatar David Faure

Fix dropping of emails onto favorites

Summary:
and dropping a collection to define a new favorite.

BUG: 387873

Test Plan:
Tested all three features, reordering, adding, and dropping a mail.

Two issues left:
- adding a new favourite at a specific position (patch pending
      for akonadi's favoritecollectionsmodel)
- the "+" when moving to reorder shouldn't appear, should be MoveAction only,
      don't know if that's possible here though.

Reviewers: dvratil, mlaurent, mkoller

Reviewed By: dvratil

Subscribers: #kde_pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D9403
parent 37717cb5
......@@ -42,16 +42,6 @@ FavoriteCollectionOrderProxyModel::~FavoriteCollectionOrderProxyModel()
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);
......
......@@ -33,8 +33,6 @@ public:
explicit FavoriteCollectionOrderProxyModel(QObject *parent = nullptr);
virtual ~FavoriteCollectionOrderProxyModel();
Qt::ItemFlags flags(const QModelIndex &index) const override;
protected:
Akonadi::Collection parentCollection(const QModelIndex &index) const override;
......
......@@ -31,6 +31,7 @@
#include <QPainter>
#include <QFontDatabase>
#include <QMouseEvent>
#include <QMimeData>
using namespace MailCommon;
......@@ -245,33 +246,70 @@ void FavoriteCollectionWidget::paintEvent(QPaintEvent *event)
}
}
static bool isCollection(const QMimeData *mimeData)
{
const QList<QUrl> 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
}
}
}
......
......@@ -58,7 +58,9 @@ Q_SIGNALS:
void newTabRequested(bool);
private:
bool acceptEvent(QDropEvent *event) const;
void createMenu(KActionCollection *ac);
class Private;
Private *const d;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment