Implement cursor overriding for DnD on wxQt.

This uses the cursor variant (as opposed to the icon one) since these actually are cursors, the base class looks like cursors are meant to be used, and the icon thing looks like a hack.
This commit is contained in:
Jay Nabonne 2019-01-30 14:22:01 +00:00
parent abdebb1895
commit 6fa65900f9
2 changed files with 27 additions and 15 deletions

View File

@ -8,7 +8,7 @@
#ifndef _WX_QT_DND_H_
#define _WX_QT_DND_H_
#define wxDROP_ICON(name) wxICON(name)
#define wxDROP_ICON(name) wxCursor(name##_xpm)
class WXDLLIMPEXP_CORE wxDropTarget : public wxDropTargetBase
{
@ -34,15 +34,15 @@ class WXDLLIMPEXP_CORE wxDropSource: public wxDropSourceBase
{
public:
wxDropSource( wxWindow *win = NULL,
const wxIcon &copy = wxNullIcon,
const wxIcon &move = wxNullIcon,
const wxIcon &none = wxNullIcon);
const wxCursor &copy = wxNullCursor,
const wxCursor &move = wxNullCursor,
const wxCursor &none = wxNullCursor);
wxDropSource( wxDataObject& data,
wxWindow *win,
const wxIcon &copy = wxNullIcon,
const wxIcon &move = wxNullIcon,
const wxIcon &none = wxNullIcon);
const wxCursor &copy = wxNullCursor,
const wxCursor &move = wxNullCursor,
const wxCursor &none = wxNullCursor);
virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);

View File

@ -81,6 +81,12 @@ namespace
return mimeData;
}
void SetDragCursor(QDrag& drag, const wxCursor& cursor, Qt::DropAction action)
{
if ( cursor.IsOk() )
drag.setDragCursor(cursor.GetHandle().pixmap(), action);
}
}
namespace
@ -310,19 +316,21 @@ void wxDropTarget::Disconnect()
//##############################################################################
wxDropSource::wxDropSource(wxWindow *win,
const wxIcon &WXUNUSED(copy),
const wxIcon &WXUNUSED(move),
const wxIcon &WXUNUSED(none))
: m_parentWindow(win)
const wxCursor &copy,
const wxCursor &move,
const wxCursor &none)
: wxDropSourceBase(copy, move, none),
m_parentWindow(win)
{
}
wxDropSource::wxDropSource(wxDataObject& data,
wxWindow *win,
const wxIcon &WXUNUSED(copy),
const wxIcon &WXUNUSED(move),
const wxIcon &WXUNUSED(none))
: m_parentWindow(win)
const wxCursor &copy,
const wxCursor &move,
const wxCursor &none)
: wxDropSourceBase(copy, move, none),
m_parentWindow(win)
{
SetData(data);
}
@ -335,6 +343,10 @@ wxDragResult wxDropSource::DoDragDrop(int flags /*=wxDrag_CopyOnly*/)
QDrag drag(m_parentWindow->GetHandle());
drag.setMimeData(CreateMimeData(m_data));
SetDragCursor(drag, m_cursorCopy, Qt::CopyAction);
SetDragCursor(drag, m_cursorMove, Qt::MoveAction);
SetDragCursor(drag, m_cursorStop, Qt::IgnoreAction);
Qt::DropActions actions = Qt::CopyAction | Qt::MoveAction;
Qt::DropAction defaultAction = Qt::CopyAction;
switch ( flags )