diff options
author | Jere Tuliniemi <jere.tuliniemi@qt.io> | 2018-10-09 13:22:38 +0300 |
---|---|---|
committer | Jere Tuliniemi <jere.tuliniemi@qt.io> | 2018-10-19 10:53:58 +0000 |
commit | 871bfa4458efde3b73b76c4e44080163973e53bb (patch) | |
tree | 4785b313c20d60cdb7de60414901b46e7b502439 | |
parent | 7d0db8a7fb440b8129bffe2914c48d296c2f9075 (diff) |
Add Make Animatable to ref material timeline menu
This button automatically changes the reference material to a standard
or custom material with the same properties to allow animating it.
Task-number: QT3DS-2307
Change-Id: Ia3874c05b7d920c6c901455fb2b0230a559a9e2e
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
6 files changed, 70 insertions, 0 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp index 8337903d..9160e18b 100644 --- a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp +++ b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp @@ -3193,6 +3193,28 @@ public: return component; } + void makeAnimatable(const qt3dsdm::TInstanceHandleList &instances) override + { + for (auto &instance : instances) { + const Q3DStudio::CString oldType = GetObjectTypeName(instance); + if (oldType == "ReferencedMaterial") { + qt3dsdm::Qt3DSDMInstanceHandle refMaterial; + getMaterialReference(instance, refMaterial); + + const Q3DStudio::CString refType = GetObjectTypeName(refMaterial); + + Q3DStudio::CString v; + if (refType == "CustomMaterial") + v = m_Bridge.GetSourcePath(refMaterial); + else + v = "Standard Material"; + + SetMaterialType(instance, v); + copyMaterialProperties(refMaterial, instance); + } + } + } + // Moves specified instances into target component by a simulated cut and paste. // This is only necessary when moving objects from outside the component into the component. // Returns true if move was done. Returns false if instances are already in target component, diff --git a/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h b/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h index 81c3ef6c..f436cc3a 100644 --- a/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h +++ b/src/Authoring/Client/Code/Core/Doc/IDocumentEditor.h @@ -344,6 +344,8 @@ public: // Returns the new component. virtual TInstanceHandle MakeComponent(const qt3dsdm::TInstanceHandleList &inInstances) = 0; + virtual void makeAnimatable(const qt3dsdm::TInstanceHandleList &instances) = 0; + virtual qt3dsdm::TInstanceHandleList DuplicateInstances(const qt3dsdm::TInstanceHandleList &inInstances, TInstanceHandle inDest, DocumentEditorInsertType::Enum inInsertType) = 0; diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h b/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h index 02979934..9535c599 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/ITimelineItemBinding.h @@ -71,6 +71,7 @@ public: EUserTransaction_Delete, EUserTransaction_MakeComponent, EUserTransaction_EditComponent, + EUserTransaction_MakeAnimatable, EUserTransaction_Group, EUserTransaction_Ungroup, EUserTransaction_AddLayer, diff --git a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp index 7fa26eaa..8401a523 100644 --- a/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp +++ b/src/Authoring/Studio/Palettes/Timeline/Bindings/Qt3DSDMTimelineItemBinding.cpp @@ -609,6 +609,14 @@ bool Qt3DSDMTimelineItemBinding::IsValidTransaction(EUserTransaction inTransacti case EUserTransaction_EditComponent: return (GetObjectType() == OBJTYPE_COMPONENT); + case EUserTransaction_MakeAnimatable: + if (theInstance.Valid()) { + CClientDataModelBridge *bridge = m_StudioSystem->GetClientDataModelBridge(); + EStudioObjectType type = bridge->GetObjectType(theInstance); + return !IsLocked() && type == OBJTYPE_REFERENCEDMATERIAL; + } + return false; + case EUserTransaction_Group: return g_StudioApp.canGroupSelectedObjects(); @@ -644,6 +652,11 @@ inline void DoMakeComponent(CDoc &inDoc, const qt3dsdm::TInstanceHandleList &inI SCOPED_DOCUMENT_EDITOR(inDoc, QObject::tr("Make Component"))->MakeComponent(inInstances); } +inline void doMakeAnimatable(CDoc &doc, const qt3dsdm::TInstanceHandleList &instances) +{ + SCOPED_DOCUMENT_EDITOR(doc, QObject::tr("Make Animatable"))->makeAnimatable(instances); +} + inline void DoGroupObjects(CDoc &inDoc, const qt3dsdm::TInstanceHandleList &inInstances) { g_StudioApp.groupSelectedObjects(); @@ -702,6 +715,10 @@ void Qt3DSDMTimelineItemBinding::PerformTransaction(EUserTransaction inTransacti theDispatch.FireOnAsynchronousCommand( std::bind(DoMakeComponent, std::ref(*theDoc), theInstances)); } break; + case EUserTransaction_MakeAnimatable: { + theDispatch.FireOnAsynchronousCommand( + std::bind(doMakeAnimatable, std::ref(*theDoc), theInstances)); + } break; case EUserTransaction_Group: { theDispatch.FireOnAsynchronousCommand( std::bind(DoGroupObjects, std::ref(*theDoc), theInstances)); diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.cpp index 24c5f1dd..dcf5df07 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.cpp +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.cpp @@ -131,6 +131,12 @@ void RowTreeContextMenu::initialize() addAction(m_inspectAction); } + if (canMakeAnimatable()) { + m_animAction = new QAction(tr("Make Animatable"), this); + connect(m_animAction, &QAction::triggered, this, &RowTreeContextMenu::makeAnimatable); + addAction(m_animAction); + } + addSeparator(); m_copyPathAction = new QAction(tr("Copy Object Path"), this); @@ -311,6 +317,25 @@ void RowTreeContextMenu::makeComponent() } /** + * Returns true if the object is a referenced material and thus can be made animatable + */ +bool RowTreeContextMenu::canMakeAnimatable() const +{ + return m_TimelineItemBinding->IsValidTransaction( + ITimelineItemBinding::EUserTransaction_MakeAnimatable); +} + +/** + * Makes a referenced material animatable aka changing it to a standard or a custom material + * with the same properties + */ +void RowTreeContextMenu::makeAnimatable() +{ + m_TimelineItemBinding->PerformTransaction( + ITimelineItemBinding::EUserTransaction_MakeAnimatable); +} + +/** * Get the full Scripting path of the object and copy it to the clipboard. * This will figure out the proper way to address the object via scripting * and put that path into the clipboard. diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.h index 06389d86..69ba8788 100644 --- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.h +++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/RowTreeContextMenu.h @@ -54,6 +54,7 @@ private Q_SLOTS: void groupObjects(); void inspectComponent(); void makeComponent(); + void makeAnimatable(); void copyObject(); void copyObjectPath(); void pasteObject(); @@ -71,6 +72,7 @@ private: bool canUngroupObjects() const; bool canInspectComponent() const; bool canMakeComponent() const; + bool canMakeAnimatable() const; bool canCopyObject() const; bool canPasteObject() const; bool canCutObject() const; @@ -86,6 +88,7 @@ private: QAction *m_addLayerAction = nullptr; QAction *m_inspectAction = nullptr; QAction *m_makeAction = nullptr; + QAction *m_animAction = nullptr; QAction *m_copyPathAction = nullptr; QAction *m_cutAction = nullptr; QAction *m_copyAction = nullptr; |