+
+ QList<QGraphicsItem*> collidingItems;
+ QPainterPath shape;
+ if (projectScene()->editMode() == NORMALEDIT) {
+ shape = clipGroupShape(newPos - pos());
+ collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
+ collidingItems.removeAll(this);
+ for (int i = 0; i < children.count(); ++i) {
+ if (children.at(i)->type() == GROUPWIDGET) {
+ QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
+ for (int j = 0; j < subchildren.count(); j++) {
+ collidingItems.removeAll(subchildren.at(j));
+ }
+ }
+ collidingItems.removeAll(children.at(i));
+ }
+ }
+ if (!collidingItems.isEmpty()) {
+ bool forwardMove = xpos > start.x();
+ int offset = 0;
+ for (int i = 0; i < collidingItems.count(); ++i) {
+ QGraphicsItem *collision = collidingItems.at(i);
+ if (collision->type() == AVWIDGET) {
+ // Collision
+ if (newPos.y() != pos().y()) {
+ // Track change results in collision, restore original position
+ return pos();
+ }
+ AbstractClipItem *item = static_cast <AbstractClipItem *>(collision);
+ if (forwardMove) {
+ // Moving forward, determine best pos
+ QPainterPath clipPath;
+ clipPath.addRect(item->sceneBoundingRect());
+ QPainterPath res = shape.intersected(clipPath);
+ offset = qMax(offset, (int)(res.boundingRect().width() + 0.5));
+ } else {
+ // Moving backward, determine best pos
+ QPainterPath clipPath;
+ clipPath.addRect(item->sceneBoundingRect());
+ QPainterPath res = shape.intersected(clipPath);
+ offset = qMax(offset, (int)(res.boundingRect().width() + 0.5));
+ }
+ }
+ }
+ if (offset > 0) {
+ if (forwardMove) {
+ newPos.setX(newPos.x() - offset);
+ } else {
+ newPos.setX(newPos.x() + offset);
+ }
+ // If there is still a collision after our position adjust, restore original pos
+ collidingItems = scene()->items(clipGroupShape(newPos - pos()), Qt::IntersectsItemShape);
+ collidingItems.removeAll(this);
+ for (int i = 0; i < children.count(); ++i) {
+ if (children.at(i)->type() == GROUPWIDGET) {
+ QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
+ for (int j = 0; j < subchildren.count(); j++) {
+ collidingItems.removeAll(subchildren.at(j));
+ }
+ }
+ collidingItems.removeAll(children.at(i));
+ }
+ for (int i = 0; i < collidingItems.count(); ++i)
+ if (collidingItems.at(i)->type() == AVWIDGET) return pos();
+ }