started node factory class for making nodes at runtime
This commit is contained in:
@@ -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_;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<kInternalNodeCount;i++) {
|
||||
library_.append(CreateInternal(static_cast<InternalID>(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<QAction*> 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();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef NODEFACTORY_H
|
||||
#define NODEFACTORY_H
|
||||
|
||||
#include <QList>
|
||||
|
||||
#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<Node*> library_;
|
||||
};
|
||||
|
||||
#endif // NODEFACTORY_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
|
||||
|
||||
Reference in New Issue
Block a user