diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-05-02 16:17:59 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-05-03 09:37:35 +0000 |
commit | 5f8acf1bb4c1c8df100a547efd84a709a276a848 (patch) | |
tree | e1ec507308d8215453c095b98e34ce162027c78e | |
parent | 3b8b3b2ef97936922557e7eaa1aaef82555f79d7 (diff) |
Add context menu item for making animations dynamic
Task-number: QT3DS-1511
Change-Id: If273e56ae5f8af4e29322be8eaf3441e49a127ec
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
4 files changed, 87 insertions, 4 deletions
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp index b03c6926..ab585928 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.cpp @@ -43,6 +43,7 @@ #include "StudioClipboard.h" #include "CmdDataModelRemoveKeyframe.h" #include "CmdDataModelInsertKeyframe.h" +#include "CmdDataModelChangeKeyframe.h" #include "Qt3DSDMAnimation.h" #include "ClientDataModelBridge.h" #include "Bindings/ITimelineItemBinding.h" @@ -157,6 +158,11 @@ void KeyframeManager::selectKeyframes(const QList<Keyframe *> &keyframes) } } +QList<Keyframe *> KeyframeManager::selectedKeyframes() const +{ + return m_selectedKeyframes; +} + // update bindings after selected keyframes are moved void KeyframeManager::commitMoveSelectedKeyframes() { @@ -424,6 +430,16 @@ bool KeyframeManager::hasCopiedKeyframes() const m_pasteKeyframeCommandHelper->HasCopiedKeyframes(); } +bool KeyframeManager::hasDynamicKeyframes(RowTree *row) const +{ + const QList<Keyframe *> keyframes = row->rowTimeline()->keyframes(); + for (const auto keyframe : keyframes) { + if (keyframe->binding->IsDynamic()) + return true; + } + return false; +} + // IKeyframesManager interface to connect Doc and KeyframeManager // Mahmoud_TODO: rewrite a better interface for the new timeline // ITimelineKeyframesManager interface @@ -436,7 +452,30 @@ void KeyframeManager::SetKeyframeTime(long inTime) void KeyframeManager::SetKeyframesDynamic(bool inDynamic) { - // Mahmoud_TODO: implement if needed + if (!hasSelectedKeyframes()) + return; + + CDoc *doc = g_StudioApp.GetCore()->GetDoc(); + IAnimationCore *animationCore = doc->GetStudioSystem()->GetAnimationCore(); + + for (int i = 0; i < m_selectedKeyframes.size(); ++i) { + Qt3DSDMTimelineKeyframe *timelineKeyframe = m_selectedKeyframes[i]->binding; + Qt3DSDMTimelineKeyframe::TKeyframeHandleList keyframeHandles; + CCmdDataModelChangeDynamicKeyframe *cmd = nullptr; + timelineKeyframe->GetKeyframeHandles(keyframeHandles); + + for (size_t keyIndex = 0; keyIndex < keyframeHandles.size(); ++keyIndex) { + qt3dsdm::Qt3DSDMAnimationHandle animation( + animationCore->GetAnimationForKeyframe(keyframeHandles.at(keyIndex))); + if (!cmd) + cmd = new CCmdDataModelChangeDynamicKeyframe(doc, animation, inDynamic); + else + cmd->AddHandle(animation); + } + + if (cmd) + g_StudioApp.GetCore()->ExecuteCommand(cmd); + } } long KeyframeManager::OffsetSelectedKeyframes(long inOffset) diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.h index 334e95cc..e08f1483 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/KeyframeManager.h @@ -35,6 +35,7 @@ #include "Qt3DSDMAnimation.h" class RowTimeline; +class RowTree; class TimelineGraphicsScene; class CPasteKeyframeCommandHelper; struct Keyframe; @@ -54,6 +55,7 @@ public: void selectConnectedKeyframes(Keyframe *keyframe); void selectKeyframesInRect(const QRectF &rect); void selectKeyframes(const QList<Keyframe *> &keyframes); + QList<Keyframe *> selectedKeyframes() const; void deselectKeyframe(Keyframe *keyframe); void deselectConnectedKeyframes(Keyframe *keyframe); void deselectAllKeyframes(); @@ -66,6 +68,7 @@ public: bool oneMasterRowSelected() const; bool hasSelectedKeyframes() const; bool hasCopiedKeyframes() const; + bool hasDynamicKeyframes(RowTree *row) const; // IKeyframesManager interface // Mahmoud_TODO: rewrite a better interface for the new timeline diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp index bacb464b..15dfd779 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.cpp @@ -109,6 +109,20 @@ void RowTimelineContextMenu::initialize() m_keyframeManager->deselectAllKeyframes(); } + if (m_rowTree->rowTimeline()->keyframes().size()) { + m_hasDynamicKeyframes = m_keyframeManager->hasDynamicKeyframes(m_rowTree); + QString label; + if (m_hasDynamicKeyframes) + label = tr("Make Animations Static"); + else + label = tr("Make Animations Dynamic"); + + m_dynamicKeyframesAction = new QAction(label, this); + connect(m_dynamicKeyframesAction, &QAction::triggered, this, + &RowTimelineContextMenu::toggleDynamicKeyframes); + addAction(m_dynamicKeyframesAction); + } + addSeparator(); if (m_keyframe) { @@ -120,9 +134,6 @@ void RowTimelineContextMenu::initialize() addAction(m_setInterpolationAction); m_setKeyframeTimeAction = new QAction(tr("Set Keyframe Time..."), this); - // TODO: Shortcut TBD - //m_setKeyframeTimeAction->setShortcut(Qt::Key_Foobar); - m_setKeyframeTimeAction->setShortcutVisibleInContextMenu(true); connect(m_setKeyframeTimeAction, &QAction::triggered, this, &RowTimelineContextMenu::setKeyframeTime); addAction(m_setKeyframeTimeAction); @@ -229,3 +240,30 @@ void RowTimelineContextMenu::setTimeBarTime() m_timelineControl->showDurationEditDialog(); } } + +void RowTimelineContextMenu::toggleDynamicKeyframes() +{ + // Store old selection, as we must change the selection for making keyframes dynamic + QList<Keyframe *> selectedKeyframes = m_keyframeManager->selectedKeyframes(); + + m_keyframeManager->deselectAllKeyframes(); + QList<Keyframe *> keyframes; + // If property row is clicked, only make that property's first keyframe dynamic. + // Otherwise make all properties' first keyframes dynamic + // Note that it doesn't matter which keyframe we make dynamic, as the dynamic keyframe will + // automatically change to the first one in time order. + if (m_rowTree->isProperty()) { + keyframes.append(m_rowTree->rowTimeline()->keyframes().first()); + } else { + const auto childProps = m_rowTree->childProps(); + for (const auto prop : childProps) + keyframes.append(prop->rowTimeline()->keyframes().first()); + } + + m_keyframeManager->selectKeyframes(keyframes); + m_keyframeManager->SetKeyframesDynamic(!m_hasDynamicKeyframes); + + // Restore selection + m_keyframeManager->deselectAllKeyframes(); + m_keyframeManager->selectKeyframes(selectedKeyframes); +} diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.h index 6111d976..b8c2f922 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTimelineContextMenu.h @@ -64,6 +64,7 @@ private: void setKeyframeTime(); void changeTimeBarColor(); void setTimeBarTime(); + void toggleDynamicKeyframes(); RowTree *m_rowTree = nullptr; Keyframe *m_keyframe = nullptr; @@ -79,7 +80,9 @@ private: QAction *m_setKeyframeTimeAction = nullptr; QAction *m_setTimeBarColorAction = nullptr; QAction *m_setTimeBarTimeAction = nullptr; + QAction *m_dynamicKeyframesAction = nullptr; TimelineControl *m_timelineControl = nullptr; + bool m_hasDynamicKeyframes = false; }; #endif // ROWTIMELINECONTEXTMENU_H |