From: Jean-Baptiste Mardelle Date: Tue, 16 Feb 2010 14:54:19 +0000 (+0000) Subject: Fix spacer tool move: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=06300ed0224d946710a2d470929d322bb5a96703;p=kdenlive Fix spacer tool move: http://www.kdenlive.org/mantis/view.php?id=1447 svn path=/trunk/kdenlive/; revision=4310 --- diff --git a/src/abstractgroupitem.cpp b/src/abstractgroupitem.cpp index d4e92104..cf5717a8 100644 --- a/src/abstractgroupitem.cpp +++ b/src/abstractgroupitem.cpp @@ -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 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 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:"<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 collindingItems; + QList 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 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 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 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; diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 42a096c9..65071ac9 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -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 children = m_selectionGroup->childItems(); QPainterPath shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0)); QList 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 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 (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 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 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 (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 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 offsetList; // create group to hold selected items m_selectionGroup = new AbstractGroupItem(m_document->fps()); scene()->addItem(m_selectionGroup); - QList 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(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(selection.at(i))->isItemLocked()) continue; QList 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(selection.at(i)->parentItem())->isItemLocked()) continue; + AbstractGroupItem *grp = static_cast(selection.at(i)->parentItem()); m_selectionGroup->addToGroup(selection.at(i)->parentItem()); selection.at(i)->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); }