コード例 #1
0
ファイル: embeddedLinker.cpp プロジェクト: nfrey/qreal
void EmbeddedLinker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
	hide();
	EditorViewScene* scene = dynamic_cast<EditorViewScene*>(master->scene());
	if ((scene) && (mEdge))
	{
		mEdge->hide();
		NodeElement *under = dynamic_cast<NodeElement*>(scene->itemAt(event->scenePos()));
		mEdge->show();
		int result = 0;
		UML::NodeElement* target;

		if (!under) {
			result = scene->launchEdgeMenu(mEdge, master, event->scenePos());
			if (result == -1)
				mEdge = NULL;
			else if ((result == +1) && (scene->getLastCreated()))
			{
				target = dynamic_cast<UML::NodeElement*>(scene->getLastCreated());
				if (target) {
					mEdge->placeEndTo(mapFromItem(target,target->getNearestPort(target->pos())));
					mEdge->connectToPort();	//it provokes to move target somehow, so it needs to place edge end and connect to port again
					mEdge->placeEndTo(mapFromItem(target,target->getNearestPort(target->pos())));
				}
			}
		}
		if (result != -1)
			mEdge->connectToPort();
	}
}
コード例 #2
0
ファイル: embeddedLinker.cpp プロジェクト: BogdanKl/qreal
void EmbeddedLinker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
	hide();
	master->selectionState(false);
	EditorViewScene* scene = dynamic_cast<EditorViewScene*>(master->scene());

	if (!mPressed && scene && mEdge) {
		mEdge->hide();
		QPointF const &eScenePos = event->scenePos();
		NodeElement *under = dynamic_cast<NodeElement*>(scene->itemAt(eScenePos));
		mEdge->show();
		int result = 0;

		if (!under) {
			result = scene->launchEdgeMenu(mEdge, master, eScenePos);
			NodeElement *target = dynamic_cast<NodeElement*>(scene->getLastCreated());
			if (result == -1) {
				mEdge = NULL;
			} else if ((result == +1) && target) {
				QPointF const &posRelativeToTheTarget = target->mapFromScene(eScenePos);
				mEdge->placeEndTo(mapFromItem(target, target->getNearestPort(posRelativeToTheTarget)));
				mEdge->connectToPort();	//it provokes to move target somehow, so it needs to place edge end and connect to port again
				mEdge->placeEndTo(mapFromItem(target, target->getNearestPort(posRelativeToTheTarget)));
				mEdge->adjustLink();
			}
		}
		if (result != -1) {
			mEdge->connectToPort();
		}
	}
}
コード例 #3
0
ファイル: embeddedLinker.cpp プロジェクト: dima6120/qreal
void EmbeddedLinker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
	updateMasterEdges();
	hide();
	mMaster->selectionState(false);
	EditorViewScene* scene = dynamic_cast<EditorViewScene*>(mMaster->scene());

	if (!mPressed && scene && mEdge) {
		mEdge->hide();
		QPointF const &eScenePos = event->scenePos();
		NodeElement *under = dynamic_cast<NodeElement*>(scene->itemAt(eScenePos, QTransform()));
		mEdge->show();
		int result = 0;

		commands::CreateElementCommand *createElementFromMenuCommand = NULL;
		if (!under) {
			result = scene->launchEdgeMenu(mEdge, mMaster, eScenePos, &createElementFromMenuCommand);
			NodeElement *target = dynamic_cast<NodeElement*>(scene->getLastCreated());
			if (result == -1) {
				mEdge = NULL;
			} else if ((result == 1) && target) {
				mEdge->setDst(target);
				target->storeGeometry();
			}
		}
		if (result != -1) {
			mEdge->connectToPort();
			mEdge->adjustNeighborLinks();
			mEdge->correctArrow();
			mEdge->correctInception();
			mEdge->adjustNeighborLinks();
			// This will restore edge state after undo/redo
			commands::ReshapeEdgeCommand *reshapeEdge = new commands::ReshapeEdgeCommand(mEdge);
			reshapeEdge->startTracking();
			reshapeEdge->stopTracking();
			reshapeEdge->setUndoEnabled(false);
			if (createElementFromMenuCommand) {
				createElementFromMenuCommand->addPostAction(reshapeEdge);
				mCreateEdgeCommand->addPostAction(createElementFromMenuCommand);
			} else {
				mCreateEdgeCommand->addPostAction(reshapeEdge);
			}
		}
	}
	mPressed = false;
	mEdge = NULL;
}
コード例 #4
0
ファイル: embeddedLinker.cpp プロジェクト: PavelRusinov/qreal
void EmbeddedLinker::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
	hide();
	mMaster->selectionState(false);
	EditorViewScene* scene = dynamic_cast<EditorViewScene*>(mMaster->scene());

	if (!mPressed && scene && mEdge) {
		mEdge->hide();
		QPointF const &eScenePos = event->scenePos();
		NodeElement *under = dynamic_cast<NodeElement*>(scene->itemAt(eScenePos, QTransform()));
		mEdge->show();
		int result = 0;

		commands::CreateElementCommand *createElementFromMenuCommand = NULL;
		if (!under) {
			result = scene->launchEdgeMenu(mEdge, mMaster, eScenePos, false, &createElementFromMenuCommand);
		} else {
			bool canBeConnected = false;
			foreach(PossibleEdge const &pEdge, mEdge->src()->getPossibleEdges()) {
				if (pEdge.first.second.element() == under->id().element()) {
					canBeConnected = true;
				} else {
					// pEdge.second.first is true, if edge can connect items in only one direction.
					if (!pEdge.second.first) {
						canBeConnected = (pEdge.first.first.element() == under->id().element());
					}
				}
			}

			if (under->isContainer()) {
				result = scene->launchEdgeMenu(mEdge, mMaster, eScenePos,
							canBeConnected, &createElementFromMenuCommand);
			} else {
				if (!canBeConnected) {
					result = -1;
				}
			}
		}
		NodeElement *target = dynamic_cast<NodeElement*>(scene->getLastCreated());

		if (result == -1) {
			mEdge = NULL;
		} else if ((result == 1) && target) {
			mEdge->setDst(target);
			target->storeGeometry();
		}
		if (result != -1) {
			mEdge->connectToPort();

			updateMasterEdge();
			// This will restore edge state after undo/redo
			commands::ReshapeEdgeCommand *reshapeEdge = new commands::ReshapeEdgeCommand(mEdge);
			reshapeEdge->startTracking();
			reshapeEdge->stopTracking();
			reshapeEdge->setUndoEnabled(false);
			if (createElementFromMenuCommand) {
				createElementFromMenuCommand->addPostAction(reshapeEdge);
				mCreateEdgeCommand->addPostAction(createElementFromMenuCommand);
			} else {
				mCreateEdgeCommand->addPostAction(reshapeEdge);
			}
		}
	}