Clean up wxDropTarget and wxWindow a bit more by moving DnD stuff fully into drop target (besides connecting and disconnecting).
Window doesn't have to know more than how to hook itself up. Impl now performs function of event filter/adapter.
This commit is contained in:
@@ -10,8 +10,6 @@
|
||||
|
||||
#define wxDROP_ICON(name) wxICON(name)
|
||||
|
||||
class QMimeData;
|
||||
|
||||
class WXDLLIMPEXP_CORE wxDropTarget : public wxDropTargetBase
|
||||
{
|
||||
public:
|
||||
@@ -24,10 +22,8 @@ public:
|
||||
|
||||
wxDataFormat GetMatchingPair();
|
||||
|
||||
void OnQtEnter(QEvent* event);
|
||||
void OnQtLeave(QEvent* event);
|
||||
void OnQtMove(QEvent* event);
|
||||
void OnQtDrop(QEvent* event);
|
||||
void ConnectToQWidget(QWidget* widget);
|
||||
void DisconnectFromQWidget(QWidget* widget);
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
|
@@ -217,16 +217,6 @@ protected:
|
||||
QWidget *m_qtWindow;
|
||||
|
||||
private:
|
||||
class DnDEventAdapter : public QObject
|
||||
{
|
||||
public:
|
||||
DnDEventAdapter();
|
||||
virtual bool eventFilter(QObject* watched, QEvent* event);
|
||||
void SetDropTarget(wxDropTarget* dropTarget, QWidget* window);
|
||||
private:
|
||||
wxDropTarget *m_dropTarget;
|
||||
};
|
||||
|
||||
void Init();
|
||||
QScrollArea *m_qtContainer;
|
||||
|
||||
@@ -249,10 +239,6 @@ private:
|
||||
bool m_processingShortcut;
|
||||
#endif // wxUSE_ACCEL
|
||||
|
||||
#if wxUSE_DRAG_AND_DROP
|
||||
DnDEventAdapter dnd_event_adapter;
|
||||
#endif
|
||||
|
||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY( wxWindowQt );
|
||||
};
|
||||
|
||||
|
148
src/qt/dnd.cpp
148
src/qt/dnd.cpp
@@ -82,13 +82,6 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class wxDropTarget::Impl
|
||||
{
|
||||
public:
|
||||
const QMimeData* m_pendingMimeData;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
class PendingMimeDataSetter
|
||||
@@ -110,9 +103,99 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
class wxDropTarget::Impl : public QObject
|
||||
{
|
||||
public:
|
||||
explicit Impl(wxDropTarget* dropTarget) : m_dropTarget(dropTarget)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool eventFilter(QObject* watched, QEvent* event) wxOVERRIDE
|
||||
{
|
||||
if ( m_dropTarget != NULL )
|
||||
{
|
||||
switch ( event->type() )
|
||||
{
|
||||
case QEvent::Drop:
|
||||
OnDrop(event);
|
||||
return true;
|
||||
|
||||
case QEvent::DragEnter:
|
||||
OnEnter(event);
|
||||
return true;
|
||||
|
||||
case QEvent::DragMove:
|
||||
OnMove(event);
|
||||
return true;
|
||||
|
||||
case QEvent::DragLeave:
|
||||
OnLeave(event);
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void OnEnter(QEvent* event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
QDragEnterEvent *e = static_cast<QDragEnterEvent*>(event);
|
||||
const QPoint where = e->pos();
|
||||
|
||||
PendingMimeDataSetter setter(m_pendingMimeData, e->mimeData());
|
||||
|
||||
wxDragResult result = m_dropTarget->OnEnter(where.x(), where.y(), DropActionToDragResult(e->proposedAction()));
|
||||
|
||||
e->setDropAction(DragResultToDropAction(result));
|
||||
}
|
||||
|
||||
void OnLeave(QEvent* event)
|
||||
{
|
||||
event->accept();
|
||||
m_dropTarget->OnLeave();
|
||||
}
|
||||
|
||||
void OnMove(QEvent* event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
QDragMoveEvent *e = static_cast<QDragMoveEvent*>(event);
|
||||
const QPoint where = e->pos();
|
||||
|
||||
PendingMimeDataSetter setter(m_pendingMimeData, e->mimeData());
|
||||
|
||||
wxDragResult result = m_dropTarget->OnDragOver(where.x(), where.y(), DropActionToDragResult(e->proposedAction()));
|
||||
|
||||
e->setDropAction(DragResultToDropAction(result));
|
||||
}
|
||||
|
||||
void OnDrop(QEvent* event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
const QDropEvent *e = static_cast<QDropEvent*>(event);
|
||||
const QPoint where = e->pos();
|
||||
|
||||
PendingMimeDataSetter setter(m_pendingMimeData, e->mimeData());
|
||||
|
||||
if ( m_dropTarget->OnDrop(where.x(), where.y()) )
|
||||
{
|
||||
m_dropTarget->OnData(where.x(), where.y(), DropActionToDragResult(e->dropAction()));
|
||||
}
|
||||
}
|
||||
|
||||
const QMimeData* m_pendingMimeData;
|
||||
wxDropTarget* m_dropTarget;
|
||||
};
|
||||
|
||||
wxDropTarget::wxDropTarget(wxDataObject *dataObject)
|
||||
: wxDropTargetBase(dataObject),
|
||||
m_pImpl(new Impl)
|
||||
m_pImpl(new Impl(this))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -163,53 +246,16 @@ wxDataFormat wxDropTarget::GetMatchingPair()
|
||||
return wxFormatInvalid;
|
||||
}
|
||||
|
||||
void wxDropTarget::OnQtEnter(QEvent* event)
|
||||
void wxDropTarget::ConnectToQWidget(QWidget* widget)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
QDragEnterEvent *e = static_cast<QDragEnterEvent*>(event);
|
||||
const QPoint where = e->pos();
|
||||
|
||||
PendingMimeDataSetter setter(m_pImpl->m_pendingMimeData, e->mimeData());
|
||||
|
||||
wxDragResult result = OnEnter(where.x(), where.y(), DropActionToDragResult(e->proposedAction()));
|
||||
|
||||
e->setDropAction(DragResultToDropAction(result));
|
||||
widget->setAcceptDrops(true);
|
||||
widget->installEventFilter(m_pImpl);
|
||||
}
|
||||
|
||||
void wxDropTarget::OnQtLeave(QEvent* event)
|
||||
void wxDropTarget::DisconnectFromQWidget(QWidget* widget)
|
||||
{
|
||||
event->accept();
|
||||
OnLeave();
|
||||
}
|
||||
|
||||
void wxDropTarget::OnQtMove(QEvent* event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
QDragMoveEvent *e = static_cast<QDragMoveEvent*>(event);
|
||||
const QPoint where = e->pos();
|
||||
|
||||
PendingMimeDataSetter setter(m_pImpl->m_pendingMimeData, e->mimeData());
|
||||
|
||||
wxDragResult result = OnDragOver(where.x(), where.y(), DropActionToDragResult(e->proposedAction()));
|
||||
|
||||
e->setDropAction(DragResultToDropAction(result));
|
||||
}
|
||||
|
||||
void wxDropTarget::OnQtDrop(QEvent* event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
const QDropEvent *e = static_cast<QDropEvent*>(event);
|
||||
const QPoint where = e->pos();
|
||||
|
||||
PendingMimeDataSetter setter(m_pImpl->m_pendingMimeData, e->mimeData());
|
||||
|
||||
if ( OnDrop(where.x(), where.y()) )
|
||||
{
|
||||
OnData(where.x(), where.y(), DropActionToDragResult(e->dropAction()));
|
||||
}
|
||||
widget->setAcceptDrops(false);
|
||||
widget->removeEventFilter(m_pImpl);
|
||||
}
|
||||
|
||||
//##############################################################################
|
||||
|
@@ -689,7 +689,20 @@ void wxWindowQt::ScrollWindow( int dx, int dy, const wxRect *rect )
|
||||
#if wxUSE_DRAG_AND_DROP
|
||||
void wxWindowQt::SetDropTarget( wxDropTarget *dropTarget )
|
||||
{
|
||||
dnd_event_adapter.SetDropTarget(dropTarget, m_qtWindow);
|
||||
if ( m_dropTarget == dropTarget )
|
||||
return;
|
||||
|
||||
if ( m_dropTarget != NULL )
|
||||
{
|
||||
m_dropTarget->DisconnectFromQWidget(m_qtWindow);
|
||||
}
|
||||
|
||||
m_dropTarget = dropTarget;
|
||||
|
||||
if (m_dropTarget != NULL)
|
||||
{
|
||||
m_dropTarget->ConnectToQWidget(m_qtWindow);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1542,60 +1555,3 @@ QPainter *wxWindowQt::QtGetPainter()
|
||||
{
|
||||
return m_qtPainter;
|
||||
}
|
||||
|
||||
//##############################################################################
|
||||
// DnDEventAdapter
|
||||
//##############################################################################
|
||||
|
||||
wxWindow::DnDEventAdapter::DnDEventAdapter() : m_dropTarget(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
bool wxWindow::DnDEventAdapter::eventFilter(QObject* watched, QEvent* event)
|
||||
{
|
||||
if ( m_dropTarget != NULL )
|
||||
{
|
||||
switch ( event->type() )
|
||||
{
|
||||
case QEvent::Drop:
|
||||
m_dropTarget->OnQtDrop(event);
|
||||
return true;
|
||||
|
||||
case QEvent::DragEnter:
|
||||
m_dropTarget->OnQtEnter(event);
|
||||
return true;
|
||||
|
||||
case QEvent::DragMove:
|
||||
m_dropTarget->OnQtMove(event);
|
||||
return true;
|
||||
|
||||
case QEvent::DragLeave:
|
||||
m_dropTarget->OnQtLeave(event);
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void wxWindow::DnDEventAdapter::SetDropTarget(wxDropTarget* dropTarget, QWidget* window)
|
||||
{
|
||||
if ( m_dropTarget == dropTarget )
|
||||
return;
|
||||
|
||||
m_dropTarget = dropTarget;
|
||||
|
||||
if ( m_dropTarget == NULL )
|
||||
{
|
||||
window->removeEventFilter(this);
|
||||
window->setAcceptDrops(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
window->installEventFilter(this);
|
||||
window->setAcceptDrops(true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user