NCL Composer  0.1.5
 All Classes Functions Variables Pages
qnstscene.cpp
1 #include "qnstscene.h"
2 
3 QnstScene::QnstScene(QObject* parent)
4  : QGraphicsScene(parent)
5 {
6  createObjects();
7  createConnections();
8 }
9 
10 QnstScene::~QnstScene()
11 {
12 
13 }
14 
15 QVector<QnstGraphicsEntity*> QnstScene::getRoots() const
16 {
17  return roots;
18 }
19 
20 void QnstScene::addRoot(QnstGraphicsEntity* entity)
21 {
22  if (entity != NULL)
23  {
24  roots.append(entity);
25 
26  // connect(entity, SIGNAL(undoRequested()), SIGNAL(undoRequested()));
27  // connect(entity, SIGNAL(redoRequested()), SIGNAL(redoRequested()));
28 
29  connect(entity, SIGNAL(cutRequested()), SIGNAL(cutRequested()));
30  connect(entity, SIGNAL(copyRequested()), SIGNAL(copyRequested()));
31  connect(entity, SIGNAL(pasteRequested()), SIGNAL(pasteRequested()));
32 
33  connect(entity, SIGNAL(deleteRequested()), SIGNAL(deleteRequested()));
34 
35  connect(entity, SIGNAL(exportRequested()), SIGNAL(exportRequested()));
36 
37  connect(entity, SIGNAL(zoominRequested()), SIGNAL(zoominRequested()));
38  connect(entity, SIGNAL(zoomoutRequested()), SIGNAL(zoomoutRequested()));
39  connect(entity, SIGNAL(zoomresetRequested()), SIGNAL(zoomresetRequested()));
40  connect(entity, SIGNAL(fullscreenRequested()), SIGNAL(fullscreenRequested()));
41 
42  connect(entity, SIGNAL(entityAdded(QnstGraphicsEntity*)), SIGNAL(entityAdded(QnstGraphicsEntity*)));
43  connect(entity, SIGNAL(entityChanged(QnstGraphicsEntity*)), SIGNAL(entityChanged(QnstGraphicsEntity*)));
44  connect(entity, SIGNAL(entityRemoved(QnstGraphicsEntity*)), SIGNAL(entityRemoved(QnstGraphicsEntity*)));
45  connect(entity, SIGNAL(entityAboutToChange(QnstGraphicsEntity*,QMap<QString,QString>)), SIGNAL(entityAboutToChange(QnstGraphicsEntity*,QMap<QString,QString>)));
46  connect(entity, SIGNAL(entitySelected(QnstGraphicsEntity*)), SIGNAL(entitySelected(QnstGraphicsEntity*)));
47 
48  addItem(entity);
49 
50  menu->menuInsert->setEnabled(false);
51  menu->actionAddBody->setEnabled(false);
52  }
53 }
54 
55 void QnstScene::removeRoot(QnstGraphicsEntity* entity)
56 {
57  if (entity != NULL)
58  {
59  int index = roots.indexOf(entity);
60 
61  if (index >= 0)
62  {
63  roots.remove(index);
64 
65  removeItem(entity);
66 
67  menu->menuInsert->setEnabled(true);
68  menu->actionAddBody->setEnabled(true);
69  }
70  }
71 }
72 
73 void QnstScene::createObjects()
74 {
75  menu = new QnstMenu();
76  menu->actionExport->setEnabled(true);
77 
78  menu->menuInsert->setEnabled(true);
79  menu->actionAddBody->setEnabled(true);
80 }
81 
82 void QnstScene::createConnections()
83 {
84  connect(menu, SIGNAL(exportRequested()), SIGNAL(exportRequested()));
85 
86  // \fixme Even working this is not the correct way to do that
87  connect(menu, SIGNAL(menuAddEntityTriggered(Qnst::EntityType)),
88  SLOT(performBody()));
89 }
90 
91 void QnstScene::performBody()
92 {
93  QnstGraphicsBody* entity = new QnstGraphicsBody();
94  entity->setTop(height()/2 - DEFAULT_BODY_HEIGHT/2);
95  entity->setLeft(width()/2 - DEFAULT_BODY_WIDTH/2);
96  entity->setWidth(DEFAULT_BODY_WIDTH);
97  entity->setHeight(DEFAULT_BODY_HEIGHT);
98 
99  addRoot(entity);
100 
101  emit entityAdded(entity);
102 }
103 
104 void QnstScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
105 {
106  QGraphicsScene::contextMenuEvent(event);
107 
108  if (!event->isAccepted())
109  {
110  menu->exec(event->screenPos());
111 
112  event->accept();
113  }
114 }