#include "Dispatcher.h"
#include "Parameters.h"
#include "BoxItem.h"
+#include "SourceItem.h"
#include "AbstractBlock.h"
#include "AbstractInterface.h"
#include "ConnectedInterface.h"
selected = false;
- setZValue(-100);
+ setZValue(100);
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
parentItem = NULL;
rectTitle = QRectF(0,-(nameHeight+2*nameMargin),nameWidth+2*nameMargin,nameHeight+2*nameMargin);
selected = false;
- setZValue(-100);
+ setZValue(100);
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
updateGeometry(InterfaceMove);
if (getScene() == NULL) return;
- QList<BoxItem *> blocks = getScene()->getBlockItems();
+ QList<BoxItem *> blocks = getScene()->getBoxItems();
if(blocks.length() > 0) {
// first, search for blocks that are at (0,0)
int xMaxZero = 0;
originPoint.setY(y);
if ((boxSizeChanged) || (newSize != oldSize) || (originPoint != oldOrigin)) {
- cout << "must change group item shape" << endl;
+ //cout << "GroupItem: must change group item shape" << endl;
prepareGeometryChange();
return true;
}
return false;
}
+void GroupItem::nameChanged() {
+
+
+ QFontMetrics fmId(params->defaultBlockFont);
+ nameWidth = fmId.width(refBlock->getName());
+ nameHeight = fmId.height();
+ // changing the BoxItem in the upperscene
+ if (parentItem != NULL) {
+ parentItem->nameChanged();
+ }
+ updateGeometry(InterfaceMove);
+ // force the update in case of the size has not changed
+ update();
+}
+
+
void GroupItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
- if(params->editState == Parameters::EditGroupMove) {
- QPointF absPos = currentPosition + originPoint;
+ if(params->editState == Parameters::EditGroupMove) {
int gapX = event->scenePos().x() - cursorPosition.x();
int gapY = event->scenePos().y() - cursorPosition.y();
- //cout << "block abs. pos: " << absPos.x() << "," << absPos.y() << " | ";
- //cout << "block current. pos: " << currentPosition.x() << "," << currentPosition.y() << " | ";
-/*
- if (absPos.x()+gapX < 0) {
- gapX = -absPos.x();
+ bool canMove = true;
+ if (refBlock->isTopGroupBlock()) {
+ QRectF rectGroup = boundingRectInScene();
+ rectGroup.moveTo(rectGroup.x()+gapX,rectGroup.y()+gapY);
+ foreach(SourceItem* source, getScene()->getSourceItems()) {
+ QRectF rectSource = source->boundingRectInScene();
+ if (rectGroup.intersects(rectSource)) canMove = false;
+ }
}
- if (absPos.y()+gapY < 0) {
- gapY = -absPos.y();
+
+ if (canMove) {
+ QPointF gap(gapX,gapY);
+ currentPosition = currentPosition+gap;
+ setPos(currentPosition);
+
+ // updating all connections of the scene.
+ getScene()->updateConnectionItemsShape();
}
- */
- //cout << "gap: " << gapX << "," << gapY << " | ";
- //cout << "scene: " << getScene()->sceneRect().x() << "," << getScene()->sceneRect().y() << endl;
- QPointF gap(gapX,gapY);
- currentPosition = currentPosition+gap;
- setPos(currentPosition);
cursorPosition = event->scenePos();
}
else if(params->editState == Parameters::EditGroupResize) {
dispatcher->setCurrentGroupWidget(getScene()->getGroupWidget());
- /* NOTE : commneted because group interface are normally
- created and the connected directly to a block within
- the group. Furthermore, there can be a single connection
- from a groupe interface.
-
if ((mode == GroupScene::AddConnection) && (params->cursorState == Parameters::CursorOnInterface)) {
InterfaceItem *inter = getInterfaceFromCursor(x,y);
if (inter != NULL) {
}
}
}
- }
- */
- if (mode == GroupScene::ItemEdition) {
+ }
+ else if (mode == GroupScene::ItemEdition) {
if (params->cursorState == Parameters::CursorOnInterface) {
InterfaceItem *inter = getInterfaceFromCursor(x,y);
int mode = getScene()->getEditionMode();
- /* NOTE : commneted because group interface are normally
- created and the connected directly to a block within
- the group. Furthermore, there can be a single connection
- from a groupe interface.
-
if (mode == GroupScene::AddConnection) {
if (params->editState == Parameters::EditStartConnection) {
}
else if (params->editState == Parameters::EditCloseConnection) {
InterfaceItem* iface1 = getScene()->getSelectedInterface(1);
- InterfaceItem* iface2 = getScene()->getSelectedInterface(2);
- bool ok = dispatcher->connect(iface1,iface2);
+ InterfaceItem* iface2 = getScene()->getSelectedInterface(2);
+ bool ok = dispatcher->createConnectionItem(iface1,iface2);
if (ok) {
iface1->selected = false;
update(iface1->boundingRect());
+ iface2->selected = false;
+ update(iface2->boundingRect());
getScene()->setSelectedInterface(1,NULL);
getScene()->setSelectedInterface(2,NULL);
params->setEditState(Parameters::EditNoOperation);
}
+ else {
+ //QMessageBox::warning(NULL,"Error","Cannot connect selected interfaces", QMessageBox::Ok);
+ getScene()->setSelectedInterface(2,NULL);
+ params->setEditState(Parameters::EditStartConnection);
+ }
}
- }
- */
- if (mode == GroupScene::ItemEdition) {
+ }
+ else if (mode == GroupScene::ItemEdition) {
currentInterface = NULL;
setFlag(ItemIsMovable, true);
params->editState = Parameters::EditNoOperation;
}
}
}
- QGraphicsItem::hoverMoveEvent(event);
+ //QGraphicsItem::hoverMoveEvent(event);
+ event->ignore();
}
void GroupItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
if(ifaceItem != NULL)
dispatcher->renameInterface(ifaceItem);
else
- dispatcher->renameBlockOrGroup(this);
+ dispatcher->renameGroupBlock(this);
}
else if(selectedAction == showProperties){
dispatcher->showProperties(ifaceItem);
}
else if(selectedAction == showParameters) {
new ParametersWindow(refBlock, params, NULL);
- }
+ }
}
InterfaceItem* GroupItem::isHoverInterface(QPointF point) {
QString name = currentInterfaceNode.attribute("name","none");
if(name == "none") throw(Exception(PROJECTFILE_CORRUPTED));
- QString levelStr = currentInterfaceNode.attribute("level","none");
- int level = AbstractInterface::getIntLevel(levelStr);
- if(level == -1) throw(Exception(PROJECTFILE_CORRUPTED));
-
QString directionStr = currentInterfaceNode.attribute("direction","none");
int direction = AbstractInterface::getIntDirection(directionStr);
if(direction == -1) throw(Exception(PROJECTFILE_CORRUPTED));
double position = currentInterfaceNode.attribute("position","none").toDouble(&ok);
if(!ok) throw(Exception(PROJECTFILE_CORRUPTED));
- GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,level);
+ GroupInterface *groupInterface = new GroupInterface(groupBlock,name,direction,AbstractInterface::Data);
InterfaceItem *interfaceItem = new InterfaceItem(position,orientation,groupInterface,this,params);
interfaceItem->setId(id);
if(parentItem != NULL){
attrUpperItem = QString::number(parentItem->getId());
}
- QString attrPos = QString::number(pos().x()).append(",").append(QString::number(pos().y()));
+ QString attrPos = QString::number((int)(pos().x())).append(",").append(QString::number((int)(pos().y())));
QString attrDim = QString::number(getWidth()).append(",").append(QString::number(getHeight()));
writer.writeStartElement("group_iface");
writer.writeAttribute("id",QString::number(item->getId()));
- writer.writeAttribute("name",item->getName());
- writer.writeAttribute("level",QString(item->refInter->getLevelString()));
+ writer.writeAttribute("name",item->getName());
writer.writeAttribute("direction",QString(item->refInter->getDirectionString()));
writer.writeAttribute("orientation",item->getStrOrientation());
writer.writeAttribute("position",QString::number(item->getPositionRatio()));