diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2019-03-19 15:43:38 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2019-03-20 08:48:43 +0000 |
commit | 3c0842d66e28db8a9e40232d790d8f2ed9792ef4 (patch) | |
tree | 57dcfa75b0396cdc2641a94dc9264efb382093e1 | |
parent | 17ab0fc4f669cd31902a7b58bbfef710bcc221e8 (diff) |
Allow dropping on entire timeline row if insertion above is invalid
This improves user experience when dragging things under scene or
the topmost layer.
Task-number: QT3DS-2652
Change-Id: I278504f1da14fa47941f8fa1b5d931b68b267958
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r-- | src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp | 27 | ||||
-rw-r--r-- | src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h | 3 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp index dcc04bfc..3e35a361 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp @@ -65,8 +65,8 @@ void RowMover::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q_UNUSED(widget) static const QPolygon polygon({QPoint(0, 0), QPoint(0, 3), QPoint(7, 3), QPoint(7, 1), - QPoint(TimelineConstants::TREE_BOUND_W, 1), - QPoint(TimelineConstants::TREE_BOUND_W, 0)}); + QPoint(int(TimelineConstants::TREE_BOUND_W), 1), + QPoint(int(TimelineConstants::TREE_BOUND_W), 0)}); painter->setPen(QPen(CStudioPreferences::timelineRowMoverColor(), 1)); painter->setBrush(CStudioPreferences::timelineRowMoverColor()); painter->drawConvexPolygon(polygon); @@ -204,7 +204,8 @@ bool RowMover::isSourceRowsDescendant(RowTree *row) const // rowType parameter is used to highlight the target row when RowMover is not active, // i.e. when dragging from project or basic objects palettes void RowMover::updateTargetRow(const QPointF &scenePos, EStudioObjectType rowType, - Q3DStudio::DocumentEditorFileType::Enum fileType) + Q3DStudio::DocumentEditorFileType::Enum fileType, + bool firstTry) { // DnD a presentation / Qml stream from the project panel (to set it as a subpresentation) if (rowType == OBJTYPE_PRESENTATION || rowType == OBJTYPE_QML_STREAM @@ -272,6 +273,14 @@ void RowMover::updateTargetRow(const QPointF &scenePos, EStudioObjectType rowTyp RowTree *rowInsert2 = m_scene->rowManager() ->getRowAtPos(scenePos + QPointF(0, TimelineConstants::ROW_H * .5)); + // If on top half of the top row, adjust half row down, as we can never insert anything + // above the top row + if (!rowInsert1 && rowInsert2 && rowInsert2->index() == 0) { + rowInsert1 = m_scene->rowManager()->getRowAtPos(scenePos); + rowInsert2 = m_scene->rowManager() + ->getRowAtPos(scenePos + QPointF(0, TimelineConstants::ROW_H)); + } + bool valid = rowInsert1 && theRowType != OBJTYPE_MATERIAL && theRowType != OBJTYPE_CUSTOMMATERIAL; @@ -319,7 +328,7 @@ void RowMover::updateTargetRow(const QPointF &scenePos, EStudioObjectType rowTyp depth = 3; // effects can only be moved on depth 3 (layer direct child) } else { static const int LEFT_MARGIN = 20; - depth = (scenePos.x() - LEFT_MARGIN) / TimelineConstants::ROW_DEPTH_STEP; + depth = (int(scenePos.x()) - LEFT_MARGIN) / TimelineConstants::ROW_DEPTH_STEP; depth = qBound(depthMin, depth, depthMax); } // calc insertion parent @@ -402,13 +411,21 @@ void RowMover::updateTargetRow(const QPointF &scenePos, EStudioObjectType rowTyp && !rowInsert1->empty() && !isSourceRowsDescendant(rowInsert1) && depth == rowInsert1->depth() + 1) { updateTargetRowLater = std::bind(&RowMover::updateTargetRow, this, - scenePos, rowType, fileType); + scenePos, rowType, fileType, true); m_rowAutoExpand = rowInsert1; m_autoExpandTimer.start(TimelineConstants::AUTO_EXPAND_TIME); } else { m_rowAutoExpand = nullptr; m_autoExpandTimer.stop(); } + } else if (firstTry && rowInsert2 + && m_scene->rowManager()->getRowAtPos(scenePos) == rowInsert2) { + // If the current drop location turns out to be invalid and we are on the upper half of + // a row, we try to resolve target row as if we were half row below. This allows drags + // to be accepted over the entire row if inserting above the row is not valid. + updateTargetRow(scenePos + QPointF(0, TimelineConstants::ROW_H * .5), + rowType, fileType, false); + valid = !m_insertionTarget.isNull(); } } diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h index adfe31b5..a8fc99e5 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h @@ -50,7 +50,8 @@ public: void end(bool force = false); void updateTargetRow(const QPointF &scenePos, EStudioObjectType rowType = OBJTYPE_UNKNOWN, Q3DStudio::DocumentEditorFileType::Enum fileType - = Q3DStudio::DocumentEditorFileType::Unknown); + = Q3DStudio::DocumentEditorFileType::Unknown, + bool firstTry = true); bool isActive() const; RowTree *insertionTarget() const; RowTree *insertionParent() const; |