diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2017-03-24 10:44:33 +0100 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2017-03-24 11:21:42 +0000 |
commit | 2df18ec34f13ffb84fcb5918e834c9571fd99ce2 (patch) | |
tree | a426dda76ddb236f24327ffbaabe741f4a52c964 | |
parent | 975c283ec75867070b600e0be4f649462e2e5d61 (diff) | |
download | qt-creator-2df18ec34f13ffb84fcb5918e834c9571fd99ce2.tar.gz |
QmlDesigner: Fix drag and drop
The release mouse event does not come through if we start a drag.
There was already a workaround that stopped working with 5.8 and
did rely on private API.
I removed all usage of private API and added a simple workaround
that synthesises a mouse release event.
The actual execution of the drag is now asynchronous to
ensure the release event is delivered properly.
I removed all dependencies on private API in the designer.
In Qt 5.9 the issue seems to be fixed in Qt.
The workaround does not seem to get in the way of the fix.
Eventually, the workaround can be removed.
Change-Id: I9b45b255da5e44c26aba2acf4a42f88537126f75
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
4 files changed, 11 insertions, 21 deletions
diff --git a/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemDelegate.qml b/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemDelegate.qml index 32c2f5a0c8..09f4f6c8fe 100644 --- a/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemDelegate.qml +++ b/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemDelegate.qml @@ -73,12 +73,8 @@ Item { id: mouseRegion anchors.fill: parent - property bool reallyPressed: false - property int pressedX - property int pressedY - onPressed: { - rootView.startDragAndDrop(itemLibraryEntry) + rootView.startDragAndDrop(mouseRegion, itemLibraryEntry) } } } diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp index 5b2dc1034c..e9d1ab13ba 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.cpp @@ -48,6 +48,7 @@ #include <QTabBar> #include <QImageReader> #include <QMimeData> +#include <QMouseEvent> #include <QWheelEvent> #include <QMenu> #include <QApplication> @@ -55,10 +56,6 @@ #include <QShortcut> #include <QQuickItem> -#include <private/qquickwidget_p.h> // mouse ungrabbing workaround on quickitems -#include <private/qquickwindow_p.h> // mouse ungrabbing workaround on quickitems - - namespace QmlDesigner { ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) : @@ -265,14 +262,7 @@ void ItemLibraryWidget::setResourcePath(const QString &resourcePath) updateSearch(); } -static void ungrabMouseOnQMLWorldWorkAround(QQuickWidget *quickWidget) -{ - const QQuickWidgetPrivate *widgetPrivate = QQuickWidgetPrivate::get(quickWidget); - if (widgetPrivate && widgetPrivate->offscreenWindow && widgetPrivate->offscreenWindow->mouseGrabberItem()) - widgetPrivate->offscreenWindow->mouseGrabberItem()->ungrabMouse(); -} - -void ItemLibraryWidget::startDragAndDrop(QVariant itemLibraryId) +void ItemLibraryWidget::startDragAndDrop(QQuickItem *mouseArea, QVariant itemLibraryId) { m_currentitemLibraryEntry = itemLibraryId.value<ItemLibraryEntry>(); @@ -283,9 +273,14 @@ void ItemLibraryWidget::startDragAndDrop(QVariant itemLibraryId) m_currentitemLibraryEntry.libraryEntryIconPath())); drag->setMimeData(mimeData); - drag->exec(); + /* Workaround for bug in Qt. The release event is not delivered for Qt < 5.9 if a drag is started */ + QMouseEvent event (QEvent::MouseButtonRelease, QPoint(-1, -1), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); + QApplication::sendEvent(mouseArea, &event); - ungrabMouseOnQMLWorldWorkAround(m_itemViewQuickWidget.data()); + QTimer::singleShot(0, [drag]() { + drag->exec(); + drag->deleteLater(); + }); } void ItemLibraryWidget::removeImport(const QString &name) diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h index 946dfc9b7d..a831b4c5fd 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarywidget.h @@ -84,7 +84,7 @@ public: void setModel(Model *model); - Q_INVOKABLE void startDragAndDrop(QVariant itemLibId); + Q_INVOKABLE void startDragAndDrop(QQuickItem *mouseArea, QVariant itemLibId); protected: void removeImport(const QString &name); diff --git a/src/plugins/qmldesigner/qmldesignerplugin.pro b/src/plugins/qmldesigner/qmldesignerplugin.pro index 460a77a96e..a5261e0931 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.pro +++ b/src/plugins/qmldesigner/qmldesignerplugin.pro @@ -1,5 +1,4 @@ QT += quickwidgets -QT += widgets-private quick-private quickwidgets-private core-private gui-private #mouse ungrabbing workaround on quickitems CONFIG += exceptions INCLUDEPATH += $$PWD |