diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2018-04-24 12:25:42 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-04-27 06:38:32 +0000 |
commit | 72c1bc5bc14fbeb8e4b81460bbec449fa2506d6b (patch) | |
tree | 991ee07a42c76f6ba082934de9574a35b38b76c1 | |
parent | 9660a3801cd5ff036802efd761af379f28f92d07 (diff) |
Fix copy, cut and paste keyframes
Task-number: QT3DS-1431
Change-Id: I65636b367bbb11e9df27c4d4849ef0d8828844fa
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
5 files changed, 109 insertions, 62 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/Doc.cpp b/src/Authoring/Client/Code/Core/Doc/Doc.cpp index 00e5891f..2dd017b7 100644 --- a/src/Authoring/Client/Code/Core/Doc/Doc.cpp +++ b/src/Authoring/Client/Code/Core/Doc/Doc.cpp @@ -1798,6 +1798,7 @@ void CDoc::HandleCut() ASSERT(0); // dispatch // m_StudioApp->GetViews( )->GetActionControl( )->OnCutAction( ); } else if (m_KeyframesManager && m_KeyframesManager->HasSelectedKeyframes()) { + m_KeyframesManager->CopyKeyframes(); m_KeyframesManager->RemoveKeyframes(true); } else if (CanCopyObject()) { CutSelectedObject(); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp index 11a404f7..fc99ec5f 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp @@ -42,12 +42,15 @@ #include "Doc.h" #include "CmdDataModelRemoveKeyframe.h" #include "CmdDataModelInsertKeyframe.h" +#include "Qt3DSDMAnimation.h" +#include "ClientDataModelBridge.h" #include "Bindings/ITimelineItemBinding.h" #include "Bindings/OffsetKeyframesCommandHelper.h" #include "Bindings/Qt3DSDMTimelineKeyframe.h" #include "StudioPreferences.h" #include "Qt3DSDMAnimation.h" #include "Dialogs.h" +#include "Bindings/PasteKeyframesCommandHelper.h" #include <qglobal.h> #include <QtCore/qhash.h> @@ -64,10 +67,17 @@ inline void PostExecuteCommand(IDoc *inDoc) theDoc->GetCore()->CommitCurrentCommand(); } -KeyframeManager::KeyframeManager(TimelineGraphicsScene *scene) : m_scene(scene) +KeyframeManager::KeyframeManager(TimelineGraphicsScene *scene) + : m_scene(scene) + , m_pasteKeyframeCommandHelper(nullptr) { } +KeyframeManager::~KeyframeManager() +{ + delete m_pasteKeyframeCommandHelper; +} + QList<Keyframe *> KeyframeManager::insertKeyframe(RowTimeline *row, double time, bool selectInsertedKeyframes) { @@ -278,66 +288,86 @@ void KeyframeManager::copySelectedKeyframes() { if (!m_selectedKeyframes.empty() && m_selectedKeyframesMasterRows.count() == 1) { - // delete old copies - for (auto keyframe : qAsConst(m_copiedKeyframes)) - delete keyframe; + if (m_pasteKeyframeCommandHelper) + m_pasteKeyframeCommandHelper->Clear(); // clear out previously copied data + else + m_pasteKeyframeCommandHelper = new CPasteKeyframeCommandHelper(); - m_copiedKeyframes.clear(); - - Keyframe *copyKeyframe; + // calc min copied frames time + double minTime = 999999.0; // in seconds (~277.78 hrs) for (auto keyframe : qAsConst(m_selectedKeyframes)) { - copyKeyframe = new Keyframe(*keyframe); - copyKeyframe->rowMaster = nullptr; - copyKeyframe->rowProperty = nullptr; - m_copiedKeyframes.append(copyKeyframe); - } - } -} - -void KeyframeManager::pasteKeyframes(RowTimeline *row) -{ - if (row == nullptr) - return; - - if (row->rowTree()->isProperty()) - row = row->parentRow(); - - if (!m_copiedKeyframes.empty()) { - // filter copied keyframes to the row supported properties - const QList<Keyframe *> filteredKeyframes = filterKeyframesForRow(row, m_copiedKeyframes); - - // calc min/max copied frames time - double minTime = 999999; // seconds (~277.78 hrs) - double maxTime = 0; - for (auto keyframe : filteredKeyframes) { if (keyframe->time < minTime) minTime = keyframe->time; - - if (keyframe->time > maxTime) - maxTime = keyframe->time; } - double dt = m_scene->playHead()->time() - minTime; + qt3dsdm::IAnimationCore *animationCore = g_StudioApp.GetCore()->GetDoc()->GetStudioSystem() + ->GetAnimationCore(); - if (maxTime + dt > m_scene->ruler()->duration()) - dt = m_scene->ruler()->duration() - maxTime; + for (auto keyframe : qAsConst(m_selectedKeyframes)) { + Qt3DSDMTimelineKeyframe *kf = keyframe->binding; + Qt3DSDMTimelineKeyframe::TKeyframeHandleList theKeyframeHandles; + kf->GetKeyframeHandles(theKeyframeHandles); + qt3dsdm::SGetOrSetKeyframeInfo info[3]; + size_t infoCount = 0; + if (!theKeyframeHandles.empty()) { + switch (theKeyframeHandles.size()) { + case 1: + info[0] = setKeyframeInfo(theKeyframeHandles[0], *animationCore); + infoCount = 1; + break; + case 3: + info[0] = setKeyframeInfo(theKeyframeHandles[0], *animationCore); + info[1] = setKeyframeInfo(theKeyframeHandles[1], *animationCore); + info[2] = setKeyframeInfo(theKeyframeHandles[2], *animationCore); + infoCount = 3; + break; + default: + break; + } - RowTree *propRow; - QList<Keyframe *> addedKeyframes; - for (auto keyframe : filteredKeyframes) { - propRow = m_scene->rowManager()->getOrCreatePropertyRow(row->rowTree(), - keyframe->propertyType); - addedKeyframes.append(insertKeyframe(propRow->rowTimeline(), keyframe->time + dt, - false)); + double dt = Qt3DSDMTimelineKeyframe::GetTimeInSecs(kf->GetTime()) - minTime; + qt3dsdm::Qt3DSDMAnimationHandle animation = + animationCore->GetAnimationForKeyframe(theKeyframeHandles[0]); + m_pasteKeyframeCommandHelper->AddKeyframeData( + animationCore->GetAnimationInfo(animation).m_Property, dt, info, infoCount); + } } + } +} - if (!addedKeyframes.empty()) { - deselectAllKeyframes(); - selectKeyframes(addedKeyframes); +qt3dsdm::SGetOrSetKeyframeInfo KeyframeManager::setKeyframeInfo( + qt3dsdm::Qt3DSDMKeyframeHandle inKeyframe, qt3dsdm::IAnimationCore &inCore) +{ + qt3dsdm::TKeyframe theKeyframeData = inCore.GetKeyframeData(inKeyframe); + qt3dsdm::SEaseInEaseOutKeyframe keyframe = + qt3dsdm::get<qt3dsdm::SEaseInEaseOutKeyframe>(theKeyframeData); + bool isDynamic = false; + if (inCore.IsFirstKeyframe(inKeyframe)) { + isDynamic = inCore.GetAnimationInfo(inCore.GetAnimationForKeyframe(inKeyframe)) + .m_DynamicFirstKeyframe; + } + + return qt3dsdm::SGetOrSetKeyframeInfo(keyframe.m_KeyframeValue, keyframe.m_EaseIn, + keyframe.m_EaseOut, isDynamic); +} + +void KeyframeManager::pasteKeyframes() +{ + CDoc *theDoc = g_StudioApp.GetCore()->GetDoc(); + if (m_pasteKeyframeCommandHelper && m_pasteKeyframeCommandHelper->HasCopiedKeyframes()) { + qt3dsdm::Qt3DSDMInstanceHandle theSelectedInstance = theDoc->GetSelectedInstance(); + if (theSelectedInstance.Valid()) { + long theCurrentViewTimeInMilliseconds = theDoc->GetCurrentViewTime(); + CCmdDataModelInsertKeyframe *theInsertKeyframesCommand = + m_pasteKeyframeCommandHelper->GetCommand(theDoc, theCurrentViewTimeInMilliseconds, + theSelectedInstance); + if (theInsertKeyframesCommand) + g_StudioApp.GetCore()->ExecuteCommand(theInsertKeyframesCommand); } } } +// Mahmoud_TODO: this method is not used anymore, will be removed by finishing the new timeline QList<Keyframe *> KeyframeManager::filterKeyframesForRow(RowTimeline *row, const QList<Keyframe *> &keyframes) { @@ -386,9 +416,11 @@ bool KeyframeManager::hasSelectedKeyframes() const bool KeyframeManager::hasCopiedKeyframes() const { - return !m_copiedKeyframes.empty(); + return m_pasteKeyframeCommandHelper != nullptr && + m_pasteKeyframeCommandHelper->HasCopiedKeyframes(); } +// IKeyframesManager interface to connect Doc and KeyframeManager // Mahmoud_TODO: rewrite a better interface for the new timeline // ITimelineKeyframesManager interface void KeyframeManager::SetKeyframeTime(long inTime) @@ -436,17 +468,24 @@ bool KeyframeManager::HasSelectedKeyframes(bool inOnlyDynamic) bool KeyframeManager::HasDynamicKeyframes() { - return true; // Mahmoud_TODO: implement + return false; // Mahmoud_TODO: implement } bool KeyframeManager::CanPerformKeyframeCopy() { - return true; // Mahmoud_TODO: implement + return !m_selectedKeyframes.empty() && m_selectedKeyframesMasterRows.count() == 1; } bool KeyframeManager::CanPerformKeyframePaste() { - return true; // Mahmoud_TODO: implement + if (m_pasteKeyframeCommandHelper && m_pasteKeyframeCommandHelper->HasCopiedKeyframes()) { + qt3dsdm::Qt3DSDMInstanceHandle theSelectedInstance = + g_StudioApp.GetCore()->GetDoc()->GetSelectedInstance(); + if (theSelectedInstance.Valid()) + return true; + } + + return false; } void KeyframeManager::CopyKeyframes() @@ -456,12 +495,14 @@ void KeyframeManager::CopyKeyframes() bool KeyframeManager::RemoveKeyframes(bool inPerformCopy) { + Q_UNUSED(inPerformCopy) + return deleteSelectedKeyframes(); } void KeyframeManager::PasteKeyframes() { - // Mahmoud_TODO: implement + pasteKeyframes(); } void KeyframeManager::SetKeyframeInterpolation() @@ -511,7 +552,7 @@ void KeyframeManager::SelectAllKeyframes() void KeyframeManager::DeselectAllKeyframes() { - // Mahmoud_TODO: implement if needed + deselectAllKeyframes(); } void KeyframeManager::SetChangedKeyframes() @@ -519,6 +560,7 @@ void KeyframeManager::SetChangedKeyframes() // Mahmoud_TODO: implement if needed } +// Mahmoud_TODO: this Map is not used anymore, will be removed by finishing the new timeline const QHash<int, QList<QString>> KeyframeManager::SUPPORTED_ROW_PROPS = { { OBJTYPE_LAYER, { "Left", diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.h index 86699184..334e95cc 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.h @@ -32,9 +32,11 @@ #include "Bindings/ITimelineKeyframesManager.h" #include <QtCore/qlist.h> #include <StudioObjectTypes.h> +#include "Qt3DSDMAnimation.h" class RowTimeline; class TimelineGraphicsScene; +class CPasteKeyframeCommandHelper; struct Keyframe; QT_FORWARD_DECLARE_CLASS(QGraphicsSceneContextMenuEvent) @@ -44,6 +46,7 @@ class KeyframeManager : public ITimelineKeyframesManager { public: KeyframeManager(TimelineGraphicsScene *m_scene); + virtual ~KeyframeManager(); QList<Keyframe *> insertKeyframe(RowTimeline *row, double time, bool selectInsertedKeyframes = true); @@ -56,7 +59,7 @@ public: void deselectAllKeyframes(); void deleteKeyframes(RowTimeline *row, bool repaint = true); void copySelectedKeyframes(); - void pasteKeyframes(RowTimeline *row); + void pasteKeyframes(); void moveSelectedKeyframes(double dx); void commitMoveSelectedKeyframes(); bool deleteSelectedKeyframes(); @@ -64,12 +67,7 @@ public: bool hasSelectedKeyframes() const; bool hasCopiedKeyframes() const; - TimelineGraphicsScene *m_scene; - - QList<Keyframe *> m_selectedKeyframes; - QList<Keyframe *> m_copiedKeyframes; // for copy, cut, paste - QList<RowTimeline *> m_selectedKeyframesMasterRows; - + // IKeyframesManager interface // Mahmoud_TODO: rewrite a better interface for the new timeline // ITimelineKeyframesManager interface void SetKeyframeTime(long inTime) override; @@ -95,6 +93,12 @@ private: static const QHash<int, QList<QString>> SUPPORTED_ROW_PROPS; QList<Keyframe *> filterKeyframesForRow(RowTimeline *row, const QList<Keyframe *> &keyframes); + qt3dsdm::SGetOrSetKeyframeInfo setKeyframeInfo(qt3dsdm::Qt3DSDMKeyframeHandle inKeyframe, + qt3dsdm::IAnimationCore &inCore); + CPasteKeyframeCommandHelper *m_pasteKeyframeCommandHelper; + TimelineGraphicsScene *m_scene; + QList<Keyframe *> m_selectedKeyframes; + QList<RowTimeline *> m_selectedKeyframesMasterRows; }; #endif // KEYFRAMEMANAGER_H diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp index 8110053e..8c2df462 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp @@ -754,7 +754,7 @@ void TimelineGraphicsScene::keyPressEvent(QKeyEvent *keyEvent) } } else if (keyEvent->key() == Qt::Key_V && ctrl) { // Ctrl+V if (m_rowManager->selectedRow() != nullptr) - m_keyframeManager->pasteKeyframes(m_rowManager->selectedRow()->rowTimeline()); + m_keyframeManager->pasteKeyframes(); } QGraphicsScene::keyPressEvent(keyEvent); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp index e185d5e8..7a3519b9 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp @@ -155,7 +155,7 @@ void RowTimelineContextMenu::copySelectedKeyframes() void RowTimelineContextMenu::pasteKeyframes() { - m_keyframeManager->pasteKeyframes(m_rowTree->rowTimeline()); + m_keyframeManager->pasteKeyframes(); } void RowTimelineContextMenu::deleteSelectedKeyframes() |