diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-09-26 17:28:35 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@qt.io> | 2018-09-27 03:42:54 +0000 |
commit | eda406902e1d7a08d482d05a9c715609f93ff7b2 (patch) | |
tree | f666fb429198703a73c80834f75f835f40d75c9d /src/Authoring/Studio/Palettes | |
parent | bc944ad74073362672dba0335785b4557ce65626 (diff) |
Fix dragging binding loops and the subpresentation drag dialog issues
Binding loops while dragging were caused by QML drag implementation
that was unneeded since the drag is actually handled by C++ QDrag.
Removed the superfluous QML drag things. This also seemed to fix
the duplicate drag layer/texture/cancel dialog that sometimes happened.
Additially, the layer/texture/cancel dialog was modified to use
explicit layer and texture buttons instead of renamed standard buttons.
Task-number: QT3DS-2397
Change-Id: I86c8ab61e4450b4aff3ef4bb9cae3776aa47959a
Reviewed-by: Mats Honkamaa <mats.honkamaa@qt.io>
Reviewed-by: Kimmo Leppälä <kimmo.leppala@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/Authoring/Studio/Palettes')
4 files changed, 44 insertions, 46 deletions
diff --git a/src/Authoring/Studio/Palettes/BasicObjects/BasicObjectsView.cpp b/src/Authoring/Studio/Palettes/BasicObjects/BasicObjectsView.cpp index 3b0b3ef7..e3b35963 100644 --- a/src/Authoring/Studio/Palettes/BasicObjects/BasicObjectsView.cpp +++ b/src/Authoring/Studio/Palettes/BasicObjects/BasicObjectsView.cpp @@ -57,6 +57,7 @@ QSize BasicObjectsView::sizeHint() const void BasicObjectsView::startDrag(QQuickItem *item, int row) { + item->grabMouse(); // Grab to make sure we can ungrab after the drag const auto index = m_ObjectsModel->index(row); QDrag drag(this); diff --git a/src/Authoring/Studio/Palettes/BasicObjects/BasicObjectsView.qml b/src/Authoring/Studio/Palettes/BasicObjects/BasicObjectsView.qml index 02080167..5f469a5a 100644 --- a/src/Authoring/Studio/Palettes/BasicObjects/BasicObjectsView.qml +++ b/src/Authoring/Studio/Palettes/BasicObjects/BasicObjectsView.qml @@ -53,19 +53,24 @@ Rectangle { id: dragItem anchors.fill: parent - Drag.active: dragArea.drag.active - Drag.hotSpot.x: width / 2 - Drag.hotSpot.y: height / 2 - Drag.dragType: Drag.Automatic - Drag.supportedActions: Qt.CopyAction - MouseArea { id: dragArea + property bool dragStarted: false + property point pressPoint + anchors.fill: parent - drag.target: dragItem + onPressed: { + pressPoint = Qt.point(mouse.x, mouse.y); + dragStarted = false; + } + onPositionChanged: { + if (!dragStarted && (Math.abs(mouse.x - pressPoint.x) > 4 + || Math.abs(mouse.y - pressPoint.y) > 4)) { + dragStarted = true; + _basicObjectsView.startDrag(dragItem, index); + } + } } - - Drag.onDragStarted: _basicObjectsView.startDrag(dragArea, model.index) } Row { id: contentRow diff --git a/src/Authoring/Studio/Palettes/Project/ProjectView.cpp b/src/Authoring/Studio/Palettes/Project/ProjectView.cpp index 05c68ecd..6b7a5a49 100644 --- a/src/Authoring/Studio/Palettes/Project/ProjectView.cpp +++ b/src/Authoring/Studio/Palettes/Project/ProjectView.cpp @@ -271,6 +271,7 @@ void ProjectView::mousePressEvent(QMouseEvent *event) void ProjectView::startDrag(QQuickItem *item, int row) { + item->grabMouse(); // Grab to make sure we can ungrab after the drag const auto index = m_ProjectModel->index(row); QDrag drag(this); @@ -281,6 +282,8 @@ void ProjectView::startDrag(QQuickItem *item, int row) drag.exec(Qt::IgnoreAction); else drag.exec(Qt::CopyAction); + + // Ungrab to trigger mouse release on the originating item QTimer::singleShot(0, item, &QQuickItem::ungrabMouse); } diff --git a/src/Authoring/Studio/Palettes/Project/ProjectView.qml b/src/Authoring/Studio/Palettes/Project/ProjectView.qml index f7d9c56f..0144144b 100644 --- a/src/Authoring/Studio/Palettes/Project/ProjectView.qml +++ b/src/Authoring/Studio/Palettes/Project/ProjectView.qml @@ -71,10 +71,26 @@ Rectangle { delegate: Rectangle { id: delegateItem property bool dragging: false + property bool dragStarted: false + property point pressPoint width: parent.width height: 20 color: (index == projectTree.currentIndex || dragging) ? _selectionColor : "transparent" + function handlePress(mouse) { + if (_isDraggable) { + pressPoint = Qt.point(mouse.x, mouse.y); + dragStarted = false; + } + } + function handlePositionChange(mouse, item) { + if (_isDraggable && !dragStarted + && (Math.abs(mouse.x - pressPoint.x) > 4 + || Math.abs(mouse.y - pressPoint.y) > 4)) { + dragStarted = true; + _parentView.startDrag(item, index); + } + } Row { x: _depth*28 @@ -98,54 +114,27 @@ Rectangle { } Image { + id: fileIconImage source: fileIcon - - Item { - id: dragItemIcon - - visible: _isDraggable + MouseArea { anchors.fill: parent - - Drag.active: dragAreaIcon.drag.active - Drag.hotSpot.x: width / 2 - Drag.hotSpot.y: height / 2 - Drag.dragType: Drag.Automatic - Drag.supportedActions: Qt.CopyAction - - MouseArea { - id: dragAreaIcon - anchors.fill: parent - drag.target: dragItemIcon - } - - Drag.onDragStarted: _parentView.startDrag(dragAreaIcon, index) + onPressed: delegateItem.handlePress(mouse) + onPositionChanged: delegateItem.handlePositionChange(mouse, + fileIconImage) } } StyledLabel { + id: fileNameLabel text: fileName color: _isReferenced ? _textColor : _disabledColor leftPadding: 2 - Item { - id: dragItem - - visible: _isDraggable + MouseArea { anchors.fill: parent - - Drag.active: dragArea.drag.active - Drag.hotSpot.x: width / 2 - Drag.hotSpot.y: height / 2 - Drag.dragType: Drag.Automatic - Drag.supportedActions: Qt.CopyAction - - MouseArea { - id: dragArea - anchors.fill: parent - drag.target: dragItem - } - - Drag.onDragStarted: _parentView.startDrag(dragArea, index) + onPressed: delegateItem.handlePress(mouse) + onPositionChanged: delegateItem.handlePositionChange(mouse, + fileNameLabel) } } } |