1 #include "qnstgraphicsentity.h"
2 #include "qnstgraphicsmedia.h"
3 #include "qnstgraphicscomposition.h"
12 setnstType(Qnst::NoType);
14 setnstGraphicsParent(parent);
17 parent->addnstGraphicsEntity(
this);
19 connect(
this, SIGNAL(entitySelected()), SLOT(requestEntitySelection()));
20 connect(
this, SIGNAL(entityAboutToChange(QMap<QString,QString>)),
21 SLOT(requestEntityPreparation(QMap<QString,QString>)));
30 QnstGraphicsEntity::~QnstGraphicsEntity()
35 void QnstGraphicsEntity::setnstId(
const QString &
id)
37 QnstEntity::setnstId(
id);
48 this->parent = parent;
51 setncgGraphicsParent(parent);
54 QSet<QnstGraphicsEntity*> QnstGraphicsEntity::getnstGraphicsEntities()
59 bool QnstGraphicsEntity::isDraggable()
64 void QnstGraphicsEntity::setDraggable(
bool isDraggable)
66 this->draggable = isDraggable;
75 if(!entities.contains(entity))
77 entities.insert(entity);
82 connect(entity, SIGNAL(cutRequested()), SIGNAL(cutRequested()));
83 connect(entity, SIGNAL(copyRequested()), SIGNAL(copyRequested()));
84 connect(entity, SIGNAL(pasteRequested()), SIGNAL(pasteRequested()));
86 connect(entity, SIGNAL(deleteRequested()), SIGNAL(deleteRequested()));
88 connect(entity, SIGNAL(exportRequested()), SIGNAL(exportRequested()));
90 connect(entity, SIGNAL(zoominRequested()), SIGNAL(zoominRequested()));
91 connect(entity, SIGNAL(zoomoutRequested()), SIGNAL(zoomoutRequested()));
92 connect(entity, SIGNAL(zoomresetRequested()), SIGNAL(zoomresetRequested()));
93 connect(entity, SIGNAL(fullscreenRequested()),
94 SIGNAL(fullscreenRequested()));
102 QMap<QString,QString>)),
104 QMap<QString,QString>)));
111 addnstEntity(entity);
112 addncgGraphicsEntity(entity);
115 entity->setnstGraphicsParent(
this);
119 qWarning() <<
"[QNST] Warning! You are adding the same entity twice as \
120 child of " << QString().sprintf(
"%p",
this) << __FILE__ << __LINE__;
129 entities.remove(entity);
131 removenstEntity(entity);
132 removencgGraphicsEntity(entity);
134 entity->setnstGraphicsParent(NULL);
138 void QnstGraphicsEntity::requestEntityChange()
140 emit entityChanged(
this);
143 void QnstGraphicsEntity::requestEntityPreparation(QMap<QString, QString> props)
145 emit entityAboutToChange(
this, props);
148 void QnstGraphicsEntity::requestEntitySelection()
150 emit entitySelected(
this);
153 bool QnstGraphicsEntity::createEntity(Qnst::EntityType type)
158 if(entity == NULL)
return false;
168 content->setSource(dropsrc);
169 QFileInfo file = QFileInfo(dropsrc);
170 QString nstId = file.baseName();
171 entity->setnstId(nstId);
181 if(composition != NULL)
183 composition->adjust();
185 composition->menu->actionPaste->setEnabled(menu->actionPaste->isEnabled());
191 emit entityAdded(entity);
194 void QnstGraphicsEntity::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
196 QncgGraphicsEntity::contextMenuEvent(event);
198 if (!event->isAccepted())
203 emit entitySelected(
this);
207 menu->exec(event->screenPos());
213 bool QnstGraphicsEntity::hasMouseHover()
218 void QnstGraphicsEntity::setMouseHover(
bool hover)
223 void QnstGraphicsEntity::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
225 QncgGraphicsEntity::hoverEnterEvent(event);
230 void QnstGraphicsEntity::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
232 QncgGraphicsEntity::hoverLeaveEvent(event);
237 void QnstGraphicsEntity::setError(
bool hasError)
239 this->hasError = hasError;
242 void QnstGraphicsEntity::setErrorMsg(QString erroMsg)
244 this->erroMsg = erroMsg;
247 void QnstGraphicsEntity::setProperties(
const QMap<QString, QString> &props)
249 if(props.contains(
"id"))
250 setnstId(props[
"id"]);
252 if (props[
"top"] !=
"")
253 setTop(props[
"top"].toDouble());
255 if (props[
"left"] !=
"")
256 setLeft(props[
"left"].toDouble());
258 if (props[
"width"] !=
"")
259 setWidth(props[
"width"].toDouble());
261 if (props[
"height"] !=
"")
262 setHeight(props[
"height"].toDouble());
265 void QnstGraphicsEntity::getProperties(QMap <QString, QString> &props)
267 props[
"id"] = getnstId();
269 props[
"top"] = QString::number(getTop());
270 props[
"left"] = QString::number(getLeft());
271 props[
"width"] = QString::number(getWidth());
272 props[
"height"] = QString::number(getHeight());
273 props[
"zIndex"] = QString::number(getzIndex());