From 9566143b580d9d0e5f076c6131518e198913a272 Mon Sep 17 00:00:00 2001 From: Jay Nabonne Date: Thu, 7 Feb 2019 12:05:34 +0000 Subject: [PATCH] Get rid of logic error - no need for state variables and all that, by just doing things at the right time. This fixes the problem of the mouse position being wrong during endDrag. --- src/qt/treectrl.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/qt/treectrl.cpp b/src/qt/treectrl.cpp index 037164aeda..899e63f8c9 100644 --- a/src/qt/treectrl.cpp +++ b/src/qt/treectrl.cpp @@ -103,8 +103,7 @@ class wxQTreeWidget : public wxQtEventSignalHandler public: wxQTreeWidget(wxWindow *parent, wxTreeCtrl *handler) : wxQtEventSignalHandler(parent, handler), - m_editorFactory(handler), - m_dropped(false) + m_editorFactory(handler) { connect(this, &QTreeWidget::currentItemChanged, this, &wxQTreeWidget::OnCurrentItemChanged); connect(this, &QTreeWidget::itemActivated, this, &wxQTreeWidget::OnItemActivated); @@ -233,8 +232,6 @@ private: void tryStartDrag(const QMouseEvent *event) { - m_dropped = false; - wxEventType command = (event->buttons() & Qt::RightButton) ? wxEVT_TREE_BEGIN_RDRAG : wxEVT_TREE_BEGIN_DRAG; @@ -260,10 +257,11 @@ private: } } - void endDrag(const QMouseEvent* event) + void endDrag(QPoint position) { - const wxPoint pos = wxQtConvertPoint(event->pos()); - QTreeWidgetItem *hitItem = itemAt(event->pos()); + const wxPoint pos = wxQtConvertPoint(position); + QTreeWidgetItem *hitItem = itemAt(position); + OutputDebugStringA(hitItem->text(0).toUtf8().data()); wxTreeEvent tree_event( wxEVT_TREE_END_DRAG, @@ -271,14 +269,14 @@ private: wxQtConvertTreeItem(hitItem) ); - tree_event.SetPoint(wxQtConvertPoint(event->pos())); + tree_event.SetPoint(wxQtConvertPoint(position)); EmitEvent(tree_event); } virtual void dropEvent(QDropEvent* event) wxOVERRIDE { - m_dropped = true; + endDrag(event->pos()); // We don't want Qt to actually do the drop. event->ignore(); @@ -288,18 +286,12 @@ private: { const bool wasDragging = state() == DraggingState; wxQtEventSignalHandler::mouseMoveEvent(event); + const bool nowDragging = state() == DraggingState; if ( !wasDragging && nowDragging ) { tryStartDrag(event); } - else if ( wasDragging && !nowDragging ) - { - // Only emit "end drag" if we have dropped - // (e.g. not hit escape to cancel). - if ( m_dropped ) - endDrag(event); - } } int ChooseBestImage(QTreeWidgetItem *item) const @@ -336,7 +328,6 @@ private: typedef std::map ImageStateMap; ImageStateMap m_imageStates; - bool m_dropped; }; wxTreeCtrl::wxTreeCtrl() :