Skip to content

Commit

Permalink
ticket:5908 Don't propagate mouse event when creating connection
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Apr 8, 2020
1 parent a2d6db2 commit 36a3ec8
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3158,48 +3158,51 @@ void GraphicsView::mousePressEvent(QMouseEvent *event)
if (event->button() == Qt::RightButton) {
return;
}
/* Ticket:4379 Select multiple objects with [Shift] key (not with [Control] key)
* To provide multi select we switch the shift key with control.
*/
if (event->modifiers() & Qt::ShiftModifier) {
event->setModifiers((event->modifiers() & ~Qt::ShiftModifier) | Qt::ControlModifier);
}
QGraphicsView::mousePressEvent(event);
// if user is starting panning.
if (QApplication::keyboardModifiers() == Qt::ControlModifier) {
setIsPanning(true);
mLastMouseEventPos = event->pos();
QGraphicsView::mousePressEvent(event);
return;
}
MainWindow *pMainWindow = MainWindow::instance();
QPointF snappedPoint = snapPointToGrid(mapToScene(event->pos()));
bool eventConsumed = false;
// if left button presses and we are creating a connector
if (isCreatingConnection()) {
if (mpModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
mpConnectionLineAnnotation->addPoint(roundPoint(mapToScene(event->pos())));
} else {
mpConnectionLineAnnotation->addPoint(snappedPoint);
}
eventConsumed = true;
} else if (isCreatingTransition()) {
mpTransitionLineAnnotation->addPoint(snappedPoint);
eventConsumed = true;
} else if (pMainWindow->getLineShapeAction()->isChecked()) {
/* if line shape tool button is checked then create a line */
createLineShape(snappedPoint);
eventConsumed = true;
} else if (pMainWindow->getPolygonShapeAction()->isChecked()) {
/* if polygon shape tool button is checked then create a polygon */
createPolygonShape(snappedPoint);
eventConsumed = true;
} else if (pMainWindow->getRectangleShapeAction()->isChecked()) {
/* if rectangle shape tool button is checked then create a rectangle */
createRectangleShape(snappedPoint);
eventConsumed = true;
} else if (pMainWindow->getEllipseShapeAction()->isChecked()) {
/* if ellipse shape tool button is checked then create an ellipse */
createEllipseShape(snappedPoint);
eventConsumed = true;
} else if (pMainWindow->getTextShapeAction()->isChecked()) {
/* if text shape tool button is checked then create a text */
createTextShape(snappedPoint);
eventConsumed = true;
} else if (pMainWindow->getBitmapShapeAction()->isChecked()) {
/* if bitmap shape tool button is checked then create a bitmap */
createBitmapShape(snappedPoint);
eventConsumed = true;
} else if (dynamic_cast<ResizerItem*>(itemAt(event->pos()))) {
// do nothing if resizer item is clicked. It will be handled in its class mousePressEvent();
} else if (dynamic_cast<CornerItem*>(itemAt(event->pos()))) {
Expand Down Expand Up @@ -3235,22 +3238,25 @@ void GraphicsView::mousePressEvent(QMouseEvent *event)
mpClickedComponent = pComponent;
} else if (isCreatingConnection()) {
addConnection(pComponent); // end the connection
/* we set this flag here instead of the constructor
* to avoid the unnecessary itemChange calls while creating the connection.
*/
mpConnectionLineAnnotation->setFlag(QGraphicsItem::ItemIsSelectable);
eventConsumed = true; // consume the event so that connection line or end component will not become selected
}
} else if (Component *pComponent = stateComponentAtPosition(event->pos())) {
if (!isCreatingTransition()) {
mpClickedState = pComponent;
} else if (isCreatingTransition()) {
addTransition(pComponent); // end the transition
/* we set this flag here instead of the constructor
* to avoid the unnecessary itemChange calls while creating the transition.
*/
mpTransitionLineAnnotation->setFlag(QGraphicsItem::ItemIsSelectable);
eventConsumed = true; // consume the event so that transition line or end component will not become selected
}
}
if (!eventConsumed) {
/* Ticket:4379 Select multiple objects with [Shift] key (not with [Control] key)
* To provide multi select we switch the shift key with control.
*/
if (event->modifiers() & Qt::ShiftModifier) {
event->setModifiers((event->modifiers() & ~Qt::ShiftModifier) | Qt::ControlModifier);
}
QGraphicsView::mousePressEvent(event);
}
setFocus(Qt::ActiveWindowFocusReason);
}

Expand All @@ -3261,7 +3267,6 @@ void GraphicsView::mousePressEvent(QMouseEvent *event)
*/
void GraphicsView::mouseMoveEvent(QMouseEvent *event)
{
QGraphicsView::mouseMoveEvent(event);
// if we are in panning mode
if (isPanning()) {
QScrollBar *pHorizontalScrollBar = horizontalScrollBar();
Expand Down Expand Up @@ -3330,30 +3335,18 @@ void GraphicsView::mouseMoveEvent(QMouseEvent *event)
mpClickedState->setSelected(false);
}
}
QGraphicsView::mouseMoveEvent(event);
}

void GraphicsView::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
return;
}

setIsPanning(false);
mpClickedComponent = 0;
mpClickedState = 0;

if (isCreatingShape() || isCreatingConnection() || isCreatingTransition()) {
return;
}
/* Ticket:4379 Select multiple objects with [Shift] key (not with [Control] key)
* To provide multi select we switch the shift key with control.
* Yes we need to do this in both mousePressEvent and mouseReleaseEvent.
*/
if (event->modifiers() & Qt::ShiftModifier) {
event->setModifiers((event->modifiers() & ~Qt::ShiftModifier) | Qt::ControlModifier);
}
QGraphicsView::mouseReleaseEvent(event);

if (isMovingComponentsAndShapes()) {
setIsMovingComponentsAndShapes(false);
bool hasComponentMoved = false;
Expand Down Expand Up @@ -3396,6 +3389,14 @@ void GraphicsView::mouseReleaseEvent(QMouseEvent *event)
mpModelWidget->endMacro();
}
}
/* Ticket:4379 Select multiple objects with [Shift] key (not with [Control] key)
* To provide multi select we switch the shift key with control.
* Yes we need to do this in both mousePressEvent and mouseReleaseEvent.
*/
if (event->modifiers() & Qt::ShiftModifier) {
event->setModifiers((event->modifiers() & ~Qt::ShiftModifier) | Qt::ControlModifier);
}
QGraphicsView::mouseReleaseEvent(event);
}

bool GraphicsView::handleDoubleClickOnComponent(QMouseEvent *event)
Expand Down

0 comments on commit 36a3ec8

Please sign in to comment.