- QRectF rect = QRectF(0, 0, sc->width(), sc->height());
- QPointF newPos = value.toPointF();
- if (!rect.contains(newPos)) {
- // Keep the item inside the scene rect.
- newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
- newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
- return newPos;
+ newPos.setX(qMax(newPos.x(), 0));
+ newPos.setY(qMax(newPos.y(), 0));
+ if (newPos.x() + sceneShape.width() > sc->width())
+ newPos.setX(sc->width() - sceneShape.width());
+ if (newPos.y() + sceneShape.height() > sc->height())
+ newPos.setY(sc->height() - sceneShape.height());
+
+ sceneShape.translate(newPos - pos());
+ QList<QGraphicsItem*> list = scene()->items(sceneShape, Qt::IntersectsItemShape);
+ list.removeAll(this);
+ if (!list.isEmpty()) {
+ for (int i = 0; i < list.count(); ++i) {
+ if (list.at(i)->type() == Type)
+ return pos();
+ }