NCL Composer  0.1.5
 All Classes Functions Variables Pages
scene.cpp
1 #include "scene.h"
2 
3 Scene::Scene(QObject* parent)
4  : QGraphicsScene(parent)
5 {
6  createActions();
7  createMenus();
8  createConnections();
9 }
10 
11 Scene::~Scene()
12 {
13 
14 }
15 
16 void Scene::createActions()
17 {
18  // node action
19  nodeAction = new QAction(this);
20  nodeAction->setText(tr("Node"));
21 
22  nodeAction->setEnabled(true);
23 }
24 
25 void Scene::createMenus()
26 {
27  // insert menu
28  insertMenu = new QMenu();
29  insertMenu->setTitle(tr("Insert"));
30 
31  insertMenu->addAction(nodeAction);
32 
33  insertMenu->setEnabled(true);
34 
35  // context menu
36  contextMenu = new QMenu();
37  contextMenu->addMenu(insertMenu);
38 }
39 
40 void Scene::createConnections()
41 {
42  connect(nodeAction, SIGNAL(triggered()), SLOT(performNode()));
43 }
44 
45 void Scene::performNode()
46 {
47  Node* entity = new Node();
48  entity->setTop(height()/2 - 300/2);
49  entity->setLeft(width()/2 - 300/2);
50  entity->setWidth(300);
51  entity->setHeight(300);
52  entity->adjust();
53 
54  connect(entity, SIGNAL(entityChanged(QncgGraphicsEntity*)),
55  SIGNAL(entityChanged(QncgGraphicsEntity*)));
56 
57  connect(entity, SIGNAL(entitySelected(QncgGraphicsEntity*)),
58  SIGNAL(entitySelected(QncgGraphicsEntity*)));
59 
60  addItem(entity);
61 }
62 
63 void Scene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
64 {
65  QGraphicsScene::contextMenuEvent(event);
66 
67  if (!event->isAccepted())
68  {
69  contextMenu->exec(event->screenPos());
70 
71  event->accept();
72  }
73 }
74 
75 
76 
77