- t->setTextInteractionFlags(Qt::NoTextInteraction);
- } else if (item->type() == 3) {
- QGraphicsRectItem *gi = (QGraphicsRectItem*)item;
- QRectF r = gi->rect();
- r.translate(gi->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;
+ }
+ if (item != NULL && item->flags() & QGraphicsItem::ItemIsMovable) {
+ m_sceneClickPoint = e->scenePos();
+ m_selectedItem = item;
+ kDebug() << "///////// ITEM TYPE: " << item->type();
+ if (item->type() == QGraphicsTextItem::Type) {
+ QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(item);
+ if (t->textInteractionFlags() == Qt::TextEditorInteraction) {
+ QGraphicsScene::mousePressEvent(e);
+ return;
+ }
+ t->setTextInteractionFlags(Qt::NoTextInteraction);
+ setCursor(Qt::ClosedHandCursor);
+ } else if (item->type() == QGraphicsRectItem::Type || item->type() == QGraphicsSvgItem::Type || item->type() == QGraphicsPixmapItem::Type) {
+ QRectF r1;
+ if (m_selectedItem->type() == QGraphicsRectItem::Type)
+ r1 = ((QGraphicsRectItem*)m_selectedItem)->rect().normalized();
+ else
+ r1 = m_selectedItem->boundingRect().normalized();
+
+ QList<QGraphicsView*> viewlist = views();
+ QGraphicsView *view = NULL;
+ if (viewlist.size() > 0) view = viewlist[0];
+ if (view == NULL) return;
+ // Item mapped coordinates
+ QPolygon r = m_selectedItem->deviceTransform(view->viewportTransform()).map(r1).toPolygon();
+ QPainterPath top(r.point(0));
+ top.lineTo(r.point(1));
+ QPainterPath bottom(r.point(2));
+ bottom.lineTo(r.point(3));
+ QPainterPath left(r.point(0));
+ left.lineTo(r.point(3));
+ QPainterPath right(r.point(1));
+ right.lineTo(r.point(2));
+
+
+ // The area interested by the mouse pointer
+ QPoint viewPos = view->mapFromScene(e->scenePos());
+ QPainterPath mouseArea;
+ mouseArea.addRect(viewPos.x() - 4, viewPos.y() - 4, 8, 8);
+
+ // Check for collisions between the mouse and the borders
+ if (mouseArea.contains(r.point(0))) m_resizeMode = TopLeft;
+ else if (mouseArea.contains(r.point(2))) m_resizeMode = BottomRight;
+ else if (mouseArea.contains(r.point(1))) m_resizeMode = TopRight;
+ else if (mouseArea.contains(r.point(3))) m_resizeMode = BottomLeft;
+ else if (top.intersects(mouseArea)) m_resizeMode = Up;
+ else if (bottom.intersects(mouseArea)) m_resizeMode = Down;
+ else if (right.intersects(mouseArea)) m_resizeMode = Right;
+ else if (left.intersects(mouseArea)) m_resizeMode = Left;
+
+ else
+ setCursor(Qt::ClosedHandCursor);