]> git.sesse.net Git - kdenlive/commitdiff
Fix spacer tool move:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 16 Feb 2010 14:54:19 +0000 (14:54 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 16 Feb 2010 14:54:19 +0000 (14:54 +0000)
http://www.kdenlive.org/mantis/view.php?id=1447

svn path=/trunk/kdenlive/; revision=4310

src/abstractgroupitem.cpp
src/customtrackview.cpp

index d4e9210481b241386a17f504de906f9d4fa61c32..cf5717a85d520a531a3404a4908e6f34a83b3595 100644 (file)
@@ -86,6 +86,15 @@ QPainterPath AbstractGroupItem::clipGroupShape(QPointF offset) const
             QRectF r(children.at(i)->sceneBoundingRect());
             r.translate(offset);
             path.addRect(r);
+        } else if (children.at(i)->type() == GROUPWIDGET) {
+            QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
+            for (int j = 0; j < subchildren.count(); j++) {
+                if (subchildren.at(j)->type() == AVWIDGET) {
+                    QRectF r(subchildren.at(j)->sceneBoundingRect());
+                    r.translate(offset);
+                    path.addRect(r);
+                }
+            }
         }
     }
     return path;
@@ -100,6 +109,15 @@ QPainterPath AbstractGroupItem::transitionGroupShape(QPointF offset) const
             QRectF r(children.at(i)->sceneBoundingRect());
             r.translate(offset);
             path.addRect(r);
+        } else if (children.at(i)->type() == GROUPWIDGET) {
+            QList<QGraphicsItem *> subchildren = children.at(i)->childItems();
+            for (int j = 0; j < subchildren.count(); j++) {
+                if (subchildren.at(j)->type() == TRANSITIONWIDGET) {
+                    QRectF r(subchildren.at(j)->sceneBoundingRect());
+                    r.translate(offset);
+                    path.addRect(r);
+                }
+            }
         }
     }
     return path;
@@ -156,7 +174,6 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
         const int trackHeight = KdenliveSettings::trackheight();
         QPointF start = sceneBoundingRect().topLeft();
         QPointF newPos = value.toPointF();
-        //kDebug()<<"REAL:"<<start.x()<<", PROPOSED:"<<(int)(start.x() - pos().x() + newPos.x());
         int xpos = projectScene()->getSnapPointForPos((int)(start.x() + newPos.x() - pos().x()), KdenliveSettings::snaptopoints());
 
         xpos = qMax(xpos, 0);
@@ -219,20 +236,27 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
             return QPointF(pos().x() - start.x(), pos().y());
         }*/
 
-        QList<QGraphicsItem*> collindingItems;
+        QList<QGraphicsItem*> collidingItems;
         QPainterPath shape;
         if (projectScene()->editMode() == NORMALEDIT) {
             shape = clipGroupShape(newPos - pos());
-            collindingItems = scene()->items(shape, Qt::IntersectsItemShape);
+            collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
+            collidingItems.removeAll(this);
             for (int i = 0; i < children.count(); i++) {
-                collindingItems.removeAll(children.at(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 (!collindingItems.isEmpty()) {
+        if (!collidingItems.isEmpty()) {
             bool forwardMove = xpos > start.x();
             int offset = 0;
-            for (int i = 0; i < collindingItems.count(); i++) {
-                QGraphicsItem *collision = collindingItems.at(i);
+            for (int i = 0; i < collidingItems.count(); i++) {
+                QGraphicsItem *collision = collidingItems.at(i);
                 if (collision->type() == AVWIDGET) {
                     // Collision
                     if (newPos.y() != pos().y()) {
@@ -262,28 +286,42 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
                     newPos.setX(newPos.x() + offset);
                 }
                 // If there is still a collision after our position adjust, restore original pos
-                collindingItems = scene()->items(clipGroupShape(newPos - pos()), Qt::IntersectsItemShape);
+                collidingItems = scene()->items(clipGroupShape(newPos - pos()), Qt::IntersectsItemShape);
+                collidingItems.removeAll(this);
                 for (int i = 0; i < children.count(); i++) {
-                    collindingItems.removeAll(children.at(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 < collindingItems.count(); i++)
-                    if (collindingItems.at(i)->type() == AVWIDGET) return pos();
+                for (int i = 0; i < collidingItems.count(); i++)
+                    if (collidingItems.at(i)->type() == AVWIDGET) return pos();
             }
         }
 
         if (projectScene()->editMode() == NORMALEDIT) {
             shape = transitionGroupShape(newPos - pos());
-            collindingItems = scene()->items(shape, Qt::IntersectsItemShape);
+            collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
+            collidingItems.removeAll(this);
             for (int i = 0; i < children.count(); i++) {
-                collindingItems.removeAll(children.at(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 (collindingItems.isEmpty()) return newPos;
+        if (collidingItems.isEmpty()) return newPos;
         else {
             bool forwardMove = xpos > start.x();
             int offset = 0;
-            for (int i = 0; i < collindingItems.count(); i++) {
-                QGraphicsItem *collision = collindingItems.at(i);
+            for (int i = 0; i < collidingItems.count(); i++) {
+                QGraphicsItem *collision = collidingItems.at(i);
                 if (collision->type() == TRANSITIONWIDGET) {
                     // Collision
                     if (newPos.y() != pos().y()) {
@@ -313,12 +351,12 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
                     newPos.setX(newPos.x() + offset);
                 }
                 // If there is still a collision after our position adjust, restore original pos
-                collindingItems = scene()->items(transitionGroupShape(newPos - pos()), Qt::IntersectsItemShape);
+                collidingItems = scene()->items(transitionGroupShape(newPos - pos()), Qt::IntersectsItemShape);
                 for (int i = 0; i < children.count(); i++) {
-                    collindingItems.removeAll(children.at(i));
+                    collidingItems.removeAll(children.at(i));
                 }
-                for (int i = 0; i < collindingItems.count(); i++)
-                    if (collindingItems.at(i)->type() == TRANSITIONWIDGET) return pos();
+                for (int i = 0; i < collidingItems.count(); i++)
+                    if (collidingItems.at(i)->type() == TRANSITIONWIDGET) return pos();
             }
         }
         return newPos;
index 42a096c92507a9f007ed0cc5d907663f4d5d1cb3..65071ac9e16494d057b4026d17907799bb1cb3f9 100644 (file)
@@ -415,15 +415,49 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
             // spacer tool
             snappedPos = getSnapPointForPos(mappedXPos + m_spacerOffset);
             if (snappedPos < 0) snappedPos = 0;
+
             // Make sure there is no collision
             QList<QGraphicsItem *> children = m_selectionGroup->childItems();
             QPainterPath shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
             QList<QGraphicsItem*> collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
             collidingItems.removeAll(m_selectionGroup);
             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));
             }
             bool collision = false;
+            int offset = 0;
+            for (int i = 0; i < collidingItems.count(); i++) {
+                if (!collidingItems.at(i)->isEnabled()) continue;
+                if (collidingItems.at(i)->type() == AVWIDGET && snappedPos < m_selectionGroup->sceneBoundingRect().left()) {
+                    AbstractClipItem *item = static_cast <AbstractClipItem *>(collidingItems.at(i));
+                    // 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));
+                }
+            }
+            snappedPos += offset;
+            // make sure we have no collision
+            shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
+            collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
+            collidingItems.removeAll(m_selectionGroup);
+            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)->isEnabled()) continue;
                 if (collidingItems.at(i)->type() == AVWIDGET) {
@@ -431,12 +465,47 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
                     break;
                 }
             }
+
+
             if (!collision) {
                 // Check transitions
                 shape = m_selectionGroup->transitionGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
                 collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
                 collidingItems.removeAll(m_selectionGroup);
                 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));
+                }
+                offset = 0;
+
+                for (int i = 0; i < collidingItems.count(); i++) {
+                    if (collidingItems.at(i)->type() == TRANSITIONWIDGET && snappedPos < m_selectionGroup->sceneBoundingRect().left()) {
+                        AbstractClipItem *item = static_cast <AbstractClipItem *>(collidingItems.at(i));
+                        // 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));
+                    }
+                }
+
+                snappedPos += offset;
+                // make sure we have no collision
+                shape = m_selectionGroup->transitionGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
+                collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
+                collidingItems.removeAll(m_selectionGroup);
+                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++) {
@@ -849,10 +918,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                 kDebug() << "SELELCTING ELEMENTS WITHIN =" << event->pos().x() << "/" <<  1 << ", " << mapFromScene(sceneRect().width(), 0).x() - event->pos().x() << "/" << sceneRect().height();
             }
 
+            QList <GenTime> offsetList;
             // create group to hold selected items
             m_selectionGroup = new AbstractGroupItem(m_document->fps());
             scene()->addItem(m_selectionGroup);
-            QList <GenTime> offsetList;
+
             for (int i = 0; i < selection.count(); i++) {
                 if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET)) {
                     AbstractClipItem *item = static_cast<AbstractClipItem *>(selection.at(i));
@@ -861,7 +931,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                     offsetList.append(item->endPos());
                     m_selectionGroup->addToGroup(selection.at(i));
                     selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
-                } else if (selection.at(i)->parentItem() == 0 && selection.at(i)->type() == GROUPWIDGET) {
+                } else if (/*selection.at(i)->parentItem() == 0 && */selection.at(i)->type() == GROUPWIDGET) {
                     if (static_cast<AbstractGroupItem *>(selection.at(i))->isItemLocked()) continue;
                     QList<QGraphicsItem *> children = selection.at(i)->childItems();
                     for (int j = 0; j < children.count(); j++) {
@@ -871,8 +941,9 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                     }
                     m_selectionGroup->addToGroup(selection.at(i));
                     selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
-                } else if (selection.at(i)->parentItem()) {
+                } else if (selection.at(i)->parentItem() && !selection.contains(selection.at(i)->parentItem())) {
                     if (static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())->isItemLocked()) continue;
+                    AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(selection.at(i)->parentItem());
                     m_selectionGroup->addToGroup(selection.at(i)->parentItem());
                     selection.at(i)->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
                 }