- } else r = m_selectedItem->boundingRect();
-
- r.translate(item->scenePos());
- if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
- resizeMode = TopLeft;
- } else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
- resizeMode = BottomLeft;
- } else if ((r.toRect().topRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
- resizeMode = TopRight;
- } else if ((r.toRect().bottomRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
- resizeMode = BottomRight;
- } else if (qAbs(r.toRect().left() - e->scenePos().toPoint().x()) < 3 / zoom) {
- resizeMode = Left;
- } else if (qAbs(r.toRect().right() - e->scenePos().toPoint().x()) < 3 / zoom) {
- resizeMode = Right;
- } else if (qAbs(r.toRect().top() - e->scenePos().toPoint().y()) < 3 / zoom) {
- resizeMode = Up;
- } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / zoom) {
- resizeMode = Down;
- } else setCursor(Qt::ClosedHandCursor);
+ else
+ r = m_selectedItem->boundingRect();
+ /*
+ * The vertices of the rectangle (check for matrix
+ * transformation); to be replaced by QTransform::map()?
+ */
+ QPointF itemOrigin = item->scenePos();
+ QTransform transform = item->transform();
+ QPointF topLeft(transform.m11() * r.toRect().left() + transform.m21() * r.toRect().top() + transform.m31() + itemOrigin.x(), transform.m22() * r.toRect().top() + transform.m12() * r.toRect().left() + transform.m32() + itemOrigin.y());
+ QPointF bottomLeft(transform.m11() * r.toRect().left() + transform.m21() * r.toRect().bottom() + transform.m31() + itemOrigin.x(), transform.m22() * r.toRect().bottom() + transform.m12() * r.toRect().left() + transform.m32() + itemOrigin.y());
+ QPointF topRight(transform.m11() * r.toRect().right() + transform.m21() * r.toRect().top() + transform.m31() + itemOrigin.x(), transform.m22() * r.toRect().top() + transform.m12() * r.toRect().right() + transform.m32() + itemOrigin.y());
+ QPointF bottomRight(transform.m11() * r.toRect().right() + transform.m21() * r.toRect().bottom() + transform.m31() + itemOrigin.x(), transform.m22() * r.toRect().bottom() + transform.m12() * r.toRect().right() + transform.m32() + itemOrigin.y());
+ // The borders (using the transformed coordinates)
+ QGraphicsLineItem borderTop(topLeft.x(), topLeft.y(), topRight.x(), topRight.y());
+ QGraphicsLineItem borderRight(topRight.x(), topRight.y(), bottomRight.x(), bottomRight.y());
+ QGraphicsLineItem borderBottom(bottomRight.x(), bottomRight.y(), bottomLeft.x(), bottomLeft.y());
+ QGraphicsLineItem borderLeft(bottomLeft.x(), bottomLeft.y(), topLeft.x(), topLeft.y());
+ // The area interested by the mouse pointer
+ QPainterPath mouseArea;
+ mouseArea.addRect(e->scenePos().toPoint().x() - 4 / m_zoom, e->scenePos().toPoint().y() - 4 / m_zoom, 8 / m_zoom, 8 / m_zoom);
+ // Check for collisions between the mouse and the borders
+ if (borderLeft.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea))
+ m_resizeMode = TopLeft;
+ else if (borderLeft.collidesWithPath(mouseArea) && borderBottom.collidesWithPath(mouseArea))
+ m_resizeMode = BottomLeft;
+ else if (borderRight.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea))
+ m_resizeMode = TopRight;
+ else if (borderRight.collidesWithPath(mouseArea) && borderBottom.collidesWithPath(mouseArea))
+ m_resizeMode = BottomRight;
+ else if (borderLeft.collidesWithPath(mouseArea))
+ m_resizeMode = Left;
+ else if (borderRight.collidesWithPath(mouseArea))
+ m_resizeMode = Right;
+ else if (borderTop.collidesWithPath(mouseArea))
+ m_resizeMode = Up;
+ else if (borderBottom.collidesWithPath(mouseArea))
+ m_resizeMode = Down;
+ else
+ setCursor(Qt::ClosedHandCursor);