diff options
author | Janne Kangas <janne.kangas@qt.io> | 2018-08-22 10:31:47 +0300 |
---|---|---|
committer | Janne Kangas <janne.kangas@qt.io> | 2018-08-30 09:25:35 +0000 |
commit | 0bb5569387e355fd9d21543bb297d073cd88f9dd (patch) | |
tree | 972dbdd19541661be6875f8abb859f214a3b62ab /src/Authoring/Studio/Palettes | |
parent | 56e2804ef706806b210471d84bfaff6c1cc1b8c0 (diff) |
Allow item(s) DnD to component directly from scene
Insert dragged items into a component and remove them from the current
scene. The items are inserted into master slide for the component (with
original start/end time values regardless of the time context change).
Task-ID: QT3DS-706
Change-Id: I33d43900e42dcb407524e12ec7690457cd641081
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/Authoring/Studio/Palettes')
4 files changed, 39 insertions, 6 deletions
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp index 70ef517e..73a23354 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.cpp @@ -87,6 +87,16 @@ QVector<RowTree *> RowMover::sourceRows() const return m_sourceRows; } +void RowMover::removeSourceRow(RowTree *row) +{ + m_sourceRows.remove(m_sourceRows.indexOf(row)); +} + +bool RowMover::shouldDeleteAfterMove() const +{ + return m_deleteAfterMove; +} + void RowMover::resetInsertionParent(RowTree *newParent) { if (m_insertionParent) { @@ -109,6 +119,7 @@ bool RowMover::isActive() void RowMover::start(const QVector<RowTree *> &rows) { + m_deleteAfterMove = false; m_sourceRows.clear(); if (!rows.isEmpty()) { // Remove rows that have an ancestor included in the selection or ones that are of @@ -139,6 +150,7 @@ void RowMover::end(bool force) m_active = false; for (auto row : qAsConst(m_sourceRows)) row->setDnDState(RowTree::DnDState::None, RowTree::DnDState::Any, true); + m_sourceRows.clear(); if (m_insertionTarget) @@ -280,8 +292,20 @@ void RowMover::updateTargetRow(const QPointF &scenePos, EStudioObjectType rowTyp } // calc insertion parent RowTree *insertParent = rowInsert1; - for (int i = rowInsert1->depth(); i >= depth; --i) - insertParent = insertParent->parentRow(); + // If we are dragging objects to a component, + // let insertParent be the component itself, not + // the parent for the component and set the source rows + // to be deleted soon (their duplicates will be inserted + // in the component). Do this only if m_active is true + // i.e. user is dragging a row within timeline (not from object/project panel) + // AND drop depth is larger than for the component (user is dropping items _in_ + // the component, not at the same depth as the component itself) + if (insertParent->isComponent() && depth > insertParent->depth() && m_active) { + m_deleteAfterMove = true; + } else { + for (int i = rowInsert1->depth(); i >= depth; --i) + insertParent = insertParent->parentRow(); + } resetInsertionParent(insertParent); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h index 1250739d..b9fe59d9 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/RowMover.h @@ -52,6 +52,8 @@ public: RowTree *insertionTarget() const; RowTree *insertionParent() const; QVector<RowTree *> sourceRows() const; + void removeSourceRow(RowTree *row); + bool shouldDeleteAfterMove() const; int type() const; Q3DStudio::DocumentEditorInsertType::Enum insertionType() const; @@ -68,6 +70,7 @@ private: RowTree *m_rowAutoExpand = nullptr; QVector<RowTree *> m_sourceRows; // dragged rows bool m_active = false; + bool m_deleteAfterMove = false; Q3DStudio::DocumentEditorInsertType::Enum m_insertType = Q3DStudio::DocumentEditorInsertType::Unknown; QTimer m_autoExpandTimer; diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp index 37d3700f..44080a1a 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp @@ -406,6 +406,16 @@ void TimelineGraphicsScene::commitMoveRows() if (!m_rowMover->insertionParent()->expanded()) m_rowMover->insertionParent()->updateExpandStatus(RowTree::ExpandState::Expanded, false); + // Remove sourcerows for items that will be deleted as result of RearrangeObjects, + // f.ex objects that will be moved to a component; otherwise we try to update + // timeline rows that no longer have valid scene objects linked to them. + // Note that we remove all sourcerows that are being dragged currently, because they + // all share the same drop target anyway. + if (m_rowMover->shouldDeleteAfterMove()) { + for (auto sourceRow : sourceRows) + m_rowMover->removeSourceRow(sourceRow); + } + Q3DStudio::SCOPED_DOCUMENT_EDITOR(*g_StudioApp.GetCore()->GetDoc(), QObject::tr("Move Rows")) ->RearrangeObjects(sourceHandles, handleTarget, m_rowMover->insertionType()); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp index c8878aa6..3df04d98 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTree.cpp @@ -975,15 +975,11 @@ void RowTree::setActionStates(ActionStates states) bool RowTree::isContainer() const { - if (isComponent() && m_indexInLayout == 1) // root element inside a component - return true; - return !m_isProperty && m_rowType != OBJTYPE_ALIAS && m_rowType != OBJTYPE_MATERIAL && m_rowType != OBJTYPE_IMAGE && m_rowType != OBJTYPE_TEXT - && m_rowType != OBJTYPE_COMPONENT && m_rowType != OBJTYPE_BEHAVIOR && m_rowType != OBJTYPE_EFFECT; } |