This is a follow-up to merger-request #10
It shows the default cursor if no modifier is pressed, since in this case the
user will have to pick what action to take upon dropEvent - i.e. during drag
the action is undefined.
It seems a little strange to me, though. It changes the "override cursor" and I
would've expected sth like this:
void MailBoxTreeView::dragMoveEvent(QDragMoveEvent *event)
{
QTreeView::dragMoveEvent(event);
if (!event->isAccepted()) {
return;
}
if (event->keyboardModifiers() == Qt::ShiftModifier) {
event->setDropAction(Qt::MoveAction);
} else if (event->keyboardModifiers() == Qt::ControlModifier) {
event->setDropAction(Qt::CopyAction);
} else {
// Qt's default is to show a cursor indicating copy-action but we don't
want that
// because the action is undefined until the user has chosen
if(qApp->overrideCursor())
qApp->overrideCursor()->setShape(Qt::ArrowCursor);
}
}
to work. But instead this variant changes the cursor back ot ArrowCursor for
good. Meaning: even if the user moves the mouse over a region that changes
state - i.e. from "drop allowed here" to "no drop allowed here" - the cursor
stays Qt::ArrowCursor. Expected (based on noob judgement) would be a change to
Qt::ForbiddenCursor...
So the solution seems to be to check and change overrideCursor in every
if-branch (even the !isAccepted one) and manually set the cursor shape if
needed.
Oh if only someone who's probably read all QWidget sources was on this mailing
list... *cough* ;)
Cheers,
Thomas
PS: if you are reading this then the lates changes in mail-composition did not
break anything ;)From 7683f6da50a9f38068067ff7cd006d056e1c10ba Mon Sep 17 00:00:00 2001
From: Thomas Gahr <[email protected]>
Date: Fri, 20 Jul 2012 23:43:41 +0200
Subject: [PATCH] DnD: show default cursor if no modifiers are pressed
---
src/Gui/MailBoxTreeView.cpp | 20 +++++++++++++++++---
1 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/Gui/MailBoxTreeView.cpp b/src/Gui/MailBoxTreeView.cpp
index 5fec8e3..4170927 100644
--- a/src/Gui/MailBoxTreeView.cpp
+++ b/src/Gui/MailBoxTreeView.cpp
@@ -21,6 +21,7 @@
#include "MailBoxTreeView.h"
+#include <QApplication>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QMenu>
@@ -53,12 +54,25 @@ MailBoxTreeView::MailBoxTreeView()
void MailBoxTreeView::dragMoveEvent(QDragMoveEvent *event)
{
QTreeView::dragMoveEvent(event);
- if (!event->isAccepted())
+
+ if (!event->isAccepted()) {
+ if (!qApp->overrideCursor())
+ qApp->setOverrideCursor(Qt::ForbiddenCursor);
return;
- if (event->keyboardModifiers() == Qt::ShiftModifier)
+ }
+ if (event->keyboardModifiers() == Qt::ShiftModifier) {
event->setDropAction(Qt::MoveAction);
- else
+ if (!qApp->overrideCursor())
+ qApp->setOverrideCursor(Qt::DragMoveCursor);
+ } else if (event->keyboardModifiers() == Qt::ControlModifier) {
event->setDropAction(Qt::CopyAction);
+ if (!qApp->overrideCursor())
+ qApp->setOverrideCursor(Qt::DragCopyCursor);
+ } else {
+ // Qt's default is to show a cursor indicating copy-action but we don't want that
+ // because the action is undefined until the user has chosen
+ qApp->restoreOverrideCursor();
+ }
}
/** @short Reimplemented to present the user with a menu to choose between copy or move.
--
1.7.8.6