diff --git a/app/core.cpp b/app/core.cpp index 1d45fc085..56d505c01 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -35,6 +35,7 @@ #include "dialog/sequence/sequence.h" #include "dialog/preferences/preferences.h" #include "dialog/projectproperties/projectproperties.h" +#include "node/factory.h" #include "panel/panelmanager.h" #include "panel/project/project.h" #include "project/item/footage/footage.h" @@ -91,6 +92,9 @@ void Core::Start() // Declare custom types for Qt signal/slot syste DeclareTypesForQt(); + // Set up node factory/library + NodeFactory::Initialize(); + // Load application config Config::Load(); @@ -118,6 +122,8 @@ void Core::Stop() ColorManager::DestroyInstance(); + NodeFactory::Destroy(); + delete main_window_; } diff --git a/app/node/CMakeLists.txt b/app/node/CMakeLists.txt index 1c5716aea..ab42ba5d8 100644 --- a/app/node/CMakeLists.txt +++ b/app/node/CMakeLists.txt @@ -28,6 +28,8 @@ set(OLIVE_SOURCES node/dependency.cpp node/edge.h node/edge.cpp + node/factory.h + node/factory.cpp node/graph.h node/graph.cpp node/input.h diff --git a/app/node/factory.cpp b/app/node/factory.cpp new file mode 100644 index 000000000..a2fcb3387 --- /dev/null +++ b/app/node/factory.cpp @@ -0,0 +1,113 @@ +#include "factory.h" + +#include "blend/alphaover/alphaover.h" +#include "block/clip/clip.h" +#include "block/gap/gap.h" +#include "block/transition/crossdissolve/crossdissolve.h" +#include "color/opacity/opacity.h" +#include "distort/transform/transform.h" +#include "generator/solid/solid.h" +#include "input/media/video/video.h" +#include "input/media/audio/audio.h" +#include "output/timeline/timeline.h" +#include "output/track/track.h" +#include "output/viewer/viewer.h" + +void NodeFactory::Initialize() +{ + Destroy(); + + // Add internal types + for (int i=0;i(i))); + } +} + +void NodeFactory::Destroy() +{ + foreach (Node* n, library_) { + delete n; + } + library_.clear(); +} + +Menu *NodeFactory::CreateMenu() +{ + Menu* menu = new Menu(); + + foreach (Node* n, library_) { + n->Retranslate(); + + QStringList path = n->Category().split('/'); + + QMenu* destination = menu; + + // Find destination menu based on category hierarchy + foreach (const QString& dir_name, path) { + // Ignore an empty directory + if (dir_name.isEmpty()) { + continue; + } + + // See if a menu with this dir_name already exists + bool found_cat = false; + QList menu_actions = destination->actions(); + foreach (QAction* action, menu_actions) { + if (action->text() == dir_name && action->menu()) { + destination = action->menu(); + found_cat = true; + break; + } + } + + // Create menu here if it doesn't exist + if (!found_cat) { + Menu* new_category = new Menu(); + destination->addMenu(new_category); + destination = new_category; + } + } + + // Add entry to menu + QAction* a = destination->addAction(n->Name()); + a->setToolTip(n->Description()); + } + + return menu; +} + +Node *NodeFactory::CreateInternal(const NodeFactory::InternalID &id) +{ + switch (id) { + case kAlphaOverBlend: + return new AlphaOverBlend(); + case kClipBlock: + return new ClipBlock(); + case kGapBlock: + return new GapBlock(); + case kTransitionBlock: + return new CrossDissolveTransition(); + case kOpacity: + return new OpacityNode(); + case kTransformDistort: + return new TransformDistort(); + case kSolidGenerator: + return new SolidGenerator(); + case kVideoInput: + return new VideoInput(); + case kAudioInput: + return new AudioInput(); + case kTimelineOutput: + return new TimelineOutput(); + case kTrackOutput: + return new TrackOutput(); + case kViewerOutput: + return new ViewerOutput(); + + case kInternalNodeCount: + break; + } + + // We should never get here + abort(); +} diff --git a/app/node/factory.h b/app/node/factory.h new file mode 100644 index 000000000..185d5f272 --- /dev/null +++ b/app/node/factory.h @@ -0,0 +1,46 @@ +#ifndef NODEFACTORY_H +#define NODEFACTORY_H + +#include + +#include "node.h" +#include "widget/menu/menu.h" + +class NodeFactory +{ +public: + enum InternalID { + kAlphaOverBlend, + kClipBlock, + kGapBlock, + kTransitionBlock, + kOpacity, + kTransformDistort, + kSolidGenerator, + kVideoInput, + kAudioInput, + kTimelineOutput, + kTrackOutput, + kViewerOutput, + + // Count value + kInternalNodeCount + }; + + NodeFactory() = default; + + static void Initialize(); + + static void Destroy(); + + static void Create(const Entry& create_info); + + static Menu* CreateMenu(); + +private: + static Node* CreateInternal(const InternalID& id); + + static QList library_; +}; + +#endif // NODEFACTORY_H diff --git a/app/widget/menu/menu.h b/app/widget/menu/menu.h index fe197b3a4..f5fe3dfb6 100644 --- a/app/widget/menu/menu.h +++ b/app/widget/menu/menu.h @@ -61,7 +61,7 @@ public: /** * @brief Construct a popup menu */ - Menu(QWidget* parent); + Menu(QWidget* parent = nullptr); /** * @brief Create a menu item and add it to this menu @@ -159,7 +159,7 @@ public: static void SetBooleanAction(QAction* a, bool *boolean); private: - + }; #endif // WIDGETMENU_H