NCL Composer  0.1.5
 All Classes Functions Variables Pages
qnstgraphicslink.cpp
1 #include "qnstgraphicslink.h"
2 
3 QnstGraphicsLink::QnstGraphicsLink(QnstGraphicsEntity* parent)
4  : QnstGraphicsNode(parent)
5 {
6  setnstType(Qnst::Link);
7 
8  // setnstType(Qnst::Aggregator);
9 
10  setResizable(false);
11 
12  createObjects();
13  createConnections();
14 
15  /* Default position for aggregator */
16  if(parent)
17  {
18  setTop(parent->getHeight()/2 - DEFAULT_AGGREGATOR_HEIGHT/2);
19  setLeft(parent->getWidth()/2 - DEFAULT_AGGREGATOR_WIDTH/2);
20  }
21  else
22  {
23  setTop(0);
24  setLeft(0);
25  }
26 
27  setWidth(DEFAULT_AGGREGATOR_WIDTH);
28  setHeight(DEFAULT_AGGREGATOR_HEIGHT);
29 }
30 
31 QnstGraphicsLink::~QnstGraphicsLink()
32 {
33 
34 }
35 
36 void QnstGraphicsLink::createObjects()
37 {
38  menu = new QnstMenu();
39  menu->actionCut->setEnabled(true);
40  menu->actionCopy->setEnabled(true);
41 
42  menu->actionDelete->setEnabled(true);
43 
44  menu->actionExport->setEnabled(true);
45 }
46 
47 void QnstGraphicsLink::createConnections()
48 {
49  // connect(menu, SIGNAL(undoRequested()), SIGNAL(undoRequested()));
50  // connect(menu, SIGNAL(redoRequested()), SIGNAL(redoRequested()));
51 
52  connect(menu, SIGNAL(cutRequested()), SIGNAL(cutRequested()));
53  connect(menu, SIGNAL(copyRequested()), SIGNAL(copyRequested()));
54  connect(menu, SIGNAL(pasteRequested()), SIGNAL(pasteRequested()));
55 
56  connect(menu, SIGNAL(deleteRequested()), SIGNAL(deleteRequested()));
57 
58  connect(menu, SIGNAL(exportRequested()), SIGNAL(exportRequested()));
59 
60  connect(menu, SIGNAL(zoominRequested()), SIGNAL(zoominRequested()));
61  connect(menu, SIGNAL(zoomoutRequested()), SIGNAL(zoomoutRequested()));
62  connect(menu, SIGNAL(zoomresetRequested()), SIGNAL(zoomresetRequested()));
63  connect(menu, SIGNAL(fullscreenRequested()), SIGNAL(fullscreenRequested()));
64 }
65 
66 void QnstGraphicsLink::draw(QPainter* painter)
67 {
68  painter->setRenderHint(QPainter::Antialiasing, true);
69 
70  painter->setBrush(Qt::black);
71 
72  painter->drawEllipse(4 + 8/2, 4 + 8/2, getWidth()-8, getHeight()-8);
73 
74  // Draw MouseHover rectangle
75  if (!isSelected() && hasMouseHover())
76  {
77  painter->setBrush(Qt::NoBrush);
78  painter->setPen(QPen(QBrush(QColor("#999999")), 0, Qt::DashLine)); // 0px = cosmetic border
79 
80  painter->drawRect(4, 4, getWidth(), getHeight());
81  }
82 
83  if (isMoving())
84  {
85  painter->setBrush(Qt::NoBrush);
86  painter->setPen(QPen(QBrush(Qt::black), 0)); // 0px = cosmetic border
87 
88  painter->setRenderHint(QPainter::Antialiasing,false);
89  painter->drawRect(getMoveLeft()+4-getLeft(), getMoveTop()+4-getTop(),
90  getWidth()-1, getHeight()-1);
91  }
92 }
93 
94 void QnstGraphicsLink::delineate(QPainterPath* painter) const
95 {
96  painter->addRect(4, 4, getWidth(), getHeight());
97 }
98 
99 QString QnstGraphicsLink::getxConnector() const
100 {
101  return xconnector;
102 }
103 
104 void QnstGraphicsLink::setxConnector(QString xconnector)
105 {
106  this->xconnector = xconnector;
107 }
108 
109 QString QnstGraphicsLink::getxConnectorUID() const
110 {
111  return xconnectorUID;
112 }
113 
114 void QnstGraphicsLink::setxConnectorUID(QString xconnectorUID)
115 {
116  this->xconnectorUID = xconnectorUID;
117 }
118 
119 QMap<QString, QnstGraphicsBind*> QnstGraphicsLink::getActions() const
120 {
121  return actions;
122 }
123 
124 void QnstGraphicsLink::addAction(QnstGraphicsBind* action)
125 {
126  if (action != NULL)
127  {
128  actions.insert(action->getnstUid(), action);
129  action->setLink(this);
130  }
131 }
132 
133 void QnstGraphicsLink::removeAction(QnstGraphicsBind* action)
134 {
135  if (action != NULL)
136  {
137  actions.remove(action->getnstUid());
138  action->setLink(NULL);
139  }
140 }
141 
142 QMap<QString, QnstGraphicsBind*> QnstGraphicsLink::getConditions() const
143 {
144  return conditions;
145 }
146 
147 void QnstGraphicsLink::addCondition(QnstGraphicsBind* condition)
148 {
149  if (condition != NULL)
150  {
151  conditions.insert(condition->getnstUid(), condition);
152  condition->setLink(this);
153  }
154 }
155 
156 void QnstGraphicsLink::removeCondition(QnstGraphicsBind* condition)
157 {
158  if (condition != NULL)
159  {
160  conditions.remove(condition->getnstUid());
161  condition->setLink(NULL);
162  }
163 }
164 
165 void QnstGraphicsLink::setProperties(const QMap<QString, QString> &properties)
166 {
167  QnstGraphicsNode::setProperties(properties);
168 
169  if (properties["xconnector"] != "")
170  setxConnector(properties["xconnector"]);
171 
172  if (properties["xconnectorUID"] != "")
173  setxConnectorUID(properties["xconnectorUID"]);
174 }
175 
176 void QnstGraphicsLink::getProperties(QMap<QString, QString> &properties)
177 {
178  QnstGraphicsNode::getProperties(properties);
179 
180  properties["xconnector"] = getxConnector();
181  properties["xconnectorUID"] = getxConnectorUID();
182 }