diff --git a/app/node/CMakeLists.txt b/app/node/CMakeLists.txt index ab42ba5d8..43ac4ae4a 100644 --- a/app/node/CMakeLists.txt +++ b/app/node/CMakeLists.txt @@ -38,8 +38,6 @@ set(OLIVE_SOURCES node/inputarray.cpp node/keyframe.h node/keyframe.cpp - node/menu.h - node/menu.cpp node/node.h node/node.cpp node/output.h diff --git a/app/node/factory.cpp b/app/node/factory.cpp index a2fcb3387..97114b992 100644 --- a/app/node/factory.cpp +++ b/app/node/factory.cpp @@ -13,6 +13,8 @@ #include "output/track/track.h" #include "output/viewer/viewer.h" +QList NodeFactory::library_; + void NodeFactory::Initialize() { Destroy(); @@ -40,7 +42,7 @@ Menu *NodeFactory::CreateMenu() QStringList path = n->Category().split('/'); - QMenu* destination = menu; + Menu* destination = menu; // Find destination menu based on category hierarchy foreach (const QString& dir_name, path) { @@ -53,8 +55,8 @@ Menu *NodeFactory::CreateMenu() bool found_cat = false; QList menu_actions = destination->actions(); foreach (QAction* action, menu_actions) { - if (action->text() == dir_name && action->menu()) { - destination = action->menu(); + if (action->menu() && action->menu()->title() == dir_name) { + destination = static_cast(action->menu()); found_cat = true; break; } @@ -62,14 +64,14 @@ Menu *NodeFactory::CreateMenu() // Create menu here if it doesn't exist if (!found_cat) { - Menu* new_category = new Menu(); - destination->addMenu(new_category); + Menu* new_category = new Menu(dir_name); + destination->InsertAlphabetically(new_category); destination = new_category; } } // Add entry to menu - QAction* a = destination->addAction(n->Name()); + QAction* a = destination->InsertAlphabetically(n->Name()); a->setToolTip(n->Description()); } diff --git a/app/node/factory.h b/app/node/factory.h index 185d5f272..a1f2acfcc 100644 --- a/app/node/factory.h +++ b/app/node/factory.h @@ -10,18 +10,18 @@ class NodeFactory { public: enum InternalID { - kAlphaOverBlend, + kViewerOutput, kClipBlock, kGapBlock, + kAlphaOverBlend, + kSolidGenerator, + kAudioInput, + kTransformDistort, kTransitionBlock, kOpacity, - kTransformDistort, - kSolidGenerator, kVideoInput, - kAudioInput, kTimelineOutput, kTrackOutput, - kViewerOutput, // Count value kInternalNodeCount @@ -33,8 +33,6 @@ public: static void Destroy(); - static void Create(const Entry& create_info); - static Menu* CreateMenu(); private: diff --git a/app/node/menu.cpp b/app/node/menu.cpp deleted file mode 100644 index 17f05e266..000000000 --- a/app/node/menu.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2019 Olive Team - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -***/ - -#include "menu.h" - -#include "blend/alphaover/alphaover.h" - -NodeMenu::NodeMenu(QWidget *parent) : - QMenu(parent) -{ -} diff --git a/app/node/menu.h b/app/node/menu.h deleted file mode 100644 index 625d3b6b3..000000000 --- a/app/node/menu.h +++ /dev/null @@ -1,38 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2019 Olive Team - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -***/ - -#ifndef NODEMENU_H -#define NODEMENU_H - -#include - -#include "node.h" - -class NodeMenu : public QMenu -{ -public: - NodeMenu(QWidget* parent = nullptr); - -private: - - -}; - -#endif // NODEMENU_H diff --git a/app/widget/menu/menu.cpp b/app/widget/menu/menu.cpp index fd2b59b2a..78db32654 100644 --- a/app/widget/menu/menu.cpp +++ b/app/widget/menu/menu.cpp @@ -47,6 +47,11 @@ Menu::Menu(QWidget *parent) : { } +Menu::Menu(const QString &s, QWidget *parent) : + QMenu(s, parent) +{ +} + QAction *Menu::AddItem(const QString &id, const QObject *receiver, const char *member, @@ -59,6 +64,34 @@ QAction *Menu::AddItem(const QString &id, return a; } +QAction* Menu::InsertAlphabetically(const QString &s) +{ + QAction* action = new QAction(s); + InsertAlphabetically(action); + return action; +} + +void Menu::InsertAlphabetically(QAction *entry) +{ + QList actions = this->actions(); + + foreach (QAction* action, actions) { + if (action->text() > entry->text()) { + insertAction(action, entry); + return; + } + } + + addAction(entry); +} + +void Menu::InsertAlphabetically(Menu *menu) +{ + QAction* action = new QAction(menu->title()); + action->setMenu(menu); + InsertAlphabetically(action); +} + QAction *Menu::CreateItem(QObject* parent, const QString &id, const QObject *receiver, diff --git a/app/widget/menu/menu.h b/app/widget/menu/menu.h index f5fe3dfb6..66dd86f0b 100644 --- a/app/widget/menu/menu.h +++ b/app/widget/menu/menu.h @@ -63,6 +63,11 @@ public: */ Menu(QWidget* parent = nullptr); + /** + * @brief Construct a popup menu + */ + Menu(const QString& s, QWidget* parent = nullptr); + /** * @brief Create a menu item and add it to this menu * @@ -91,6 +96,10 @@ public: const char* member, const QString &key = QString()); + QAction *InsertAlphabetically(const QString& s); + void InsertAlphabetically(QAction* entry); + void InsertAlphabetically(Menu* menu); + /** * @brief Create a menu item * diff --git a/app/widget/nodeview/nodeview.cpp b/app/widget/nodeview/nodeview.cpp index 6bdc32f63..e5e85fc16 100644 --- a/app/widget/nodeview/nodeview.cpp +++ b/app/widget/nodeview/nodeview.cpp @@ -20,16 +20,19 @@ #include "nodeview.h" +#include "node/factory.h" + NodeView::NodeView(QWidget *parent) : QGraphicsView(parent), graph_(nullptr) { setScene(&scene_); - setDragMode(RubberBandDrag); + setContextMenuPolicy(Qt::CustomContextMenu); connect(&scene_, SIGNAL(changed(const QList&)), this, SLOT(ItemsChanged())); connect(&scene_, SIGNAL(selectionChanged()), this, SLOT(SceneSelectionChangedSlot())); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ShowContextMenu(const QPoint &))); } NodeView::~NodeView() @@ -193,3 +196,9 @@ void NodeView::SceneSelectionChangedSlot() emit SelectionChanged(selected_nodes); } + +void NodeView::ShowContextMenu(const QPoint &pos) +{ + Menu* m = NodeFactory::CreateMenu(); + m->exec(pos); +} diff --git a/app/widget/nodeview/nodeview.h b/app/widget/nodeview/nodeview.h index 9b30aef92..c5acb7beb 100644 --- a/app/widget/nodeview/nodeview.h +++ b/app/widget/nodeview/nodeview.h @@ -132,6 +132,11 @@ private slots: */ void SceneSelectionChangedSlot(); + /** + * @brief Receiver for when the user right clicks (or otherwise requests a context menu) + */ + void ShowContextMenu(const QPoint &pos); + }; #endif // NODEVIEW_H