completed node 'add' menu
This commit is contained in:
@@ -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<QAction*> 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,
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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<QRectF>&)), 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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user