X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fabstractgroupitem.cpp;h=2b74e01e108e7459cfe7c80d1ea605b060b818de;hb=f69a24d18f8134c93e407ea485967ac31187da47;hp=e9a30c8555013871e11e89eb8e3b10896a02bc40;hpb=16e193e8de2f5eda3ec457bf5401fe82875b9d66;p=kdenlive diff --git a/src/abstractgroupitem.cpp b/src/abstractgroupitem.cpp index e9a30c85..2b74e01e 100644 --- a/src/abstractgroupitem.cpp +++ b/src/abstractgroupitem.cpp @@ -34,8 +34,8 @@ AbstractGroupItem::AbstractGroupItem(double /* fps */) : - QObject(), - QGraphicsItemGroup() + QObject(), + QGraphicsItemGroup() { setZValue(1); setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); @@ -48,12 +48,25 @@ AbstractGroupItem::AbstractGroupItem(double /* fps */) : int AbstractGroupItem::type() const { - return GROUPWIDGET; + return GroupWidget; } int AbstractGroupItem::track() const { - return (int)(scenePos().y() / KdenliveSettings::trackheight()); + //return (int)(scenePos().y() / KdenliveSettings::trackheight()); + int topTrack = -1; + QList children = childItems(); + for (int i = 0; i < children.count(); ++i) { + if (children.at(i)->type() == GroupWidget) { + children.append(children.at(i)->childItems()); + continue; + } + AbstractClipItem *item = static_cast (children.at(i)); + if (item && (topTrack == -1 || topTrack > item->track())) { + topTrack = item->track(); + } + } + return topTrack; } void AbstractGroupItem::setItemLocked(bool locked) @@ -79,31 +92,61 @@ CustomTrackScene* AbstractGroupItem::projectScene() return NULL; } -QPainterPath AbstractGroupItem::clipGroupShape(QPointF offset) const +QPainterPath AbstractGroupItem::clipGroupSpacerShape(const QPointF &offset) const { - return groupShape(AVWIDGET, offset); + return spacerGroupShape(AVWidget, offset); } -QPainterPath AbstractGroupItem::transitionGroupShape(QPointF offset) const +QPainterPath AbstractGroupItem::clipGroupShape(const QPointF &offset) const { - return groupShape(TRANSITIONWIDGET, offset); + return groupShape(AVWidget, offset); +} + +QPainterPath AbstractGroupItem::transitionGroupShape(const QPointF &offset) const +{ + return groupShape(TransitionWidget, offset); +} + +QPainterPath AbstractGroupItem::groupShape(GraphicsRectItem type, const QPointF &offset) const +{ + QPainterPath path; + QList children = childItems(); + for (int i = 0; i < children.count(); ++i) { + if (children.at(i)->type() == (int)type) { + 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() == (int)type) { + QRectF r(subchildren.at(j)->sceneBoundingRect()); + r.translate(offset); + path.addRect(r); + } + } + } + } + return path; } -QPainterPath AbstractGroupItem::groupShape(GRAPHICSRECTITEM type, QPointF offset) const +QPainterPath AbstractGroupItem::spacerGroupShape(GraphicsRectItem type, const QPointF &offset) const { QPainterPath path; QList children = childItems(); - for (int i = 0; i < children.count(); i++) { + for (int i = 0; i < children.count(); ++i) { if (children.at(i)->type() == (int)type) { QRectF r(children.at(i)->sceneBoundingRect()); r.translate(offset); + r.setRight(scene()->width()); path.addRect(r); - } else if (children.at(i)->type() == GROUPWIDGET) { + } 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() == (int)type) { QRectF r(subchildren.at(j)->sceneBoundingRect()); r.translate(offset); + r.setRight(scene()->width()); path.addRect(r); } } @@ -145,15 +188,13 @@ void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *optio QColor bgcolor(100, 100, 200, 100); QRectF bound = option->exposedRect.adjusted(0, 0, 1, 1); p->setClipRect(bound); - const QRectF mapped = p->worldTransform().mapRect(option->exposedRect); - p->setWorldMatrixEnabled(false); p->setBrush(bgcolor); QPen pen = p->pen(); pen.setColor(QColor(200, 90, 90)); pen.setStyle(Qt::DashLine); pen.setWidthF(0.0); p->setPen(pen); - p->drawRoundedRect(mapped, 3, 3); + p->drawRoundedRect(boundingRect().adjusted(0, 0, -1, 0), 3, 3); } //virtual @@ -171,40 +212,42 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant int xpos = projectScene()->getSnapPointForPos((int)(start.x() + newPos.x() - pos().x()), KdenliveSettings::snaptopoints()); xpos = qMax(xpos, 0); - //kDebug()<<"GRP XPOS:"< groupTracks; + QList groupTracks; QList children = childItems(); - for (int i = 0; i < children.count(); i++) { + for (int i = 0; i < children.count(); ++i) { int currentTrack = 0; - if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET) { - currentTrack = static_cast (children.at(i))->track(); - if (!groupTracks.contains(currentTrack)) groupTracks.append(currentTrack); - } - else if (children.at(i)->type() == GROUPWIDGET) currentTrack = static_cast (children.at(i))->track(); - else continue; - if (children.at(i)->type() == AVWIDGET) { + if (children.at(i)->type() == AVWidget || children.at(i)->type() == TransitionWidget) { + currentTrack = static_cast (children.at(i))->track(); + if (!groupTracks.contains(currentTrack)) groupTracks.append(currentTrack); + } + else if (children.at(i)->type() == GroupWidget) { + currentTrack = static_cast (children.at(i))->track(); + } + else continue; + if (children.at(i)->type() == AVWidget) { if (topTrack == -1 || currentTrack <= topTrack) { offset = 0; topTrack = currentTrack; } - } else if (children.at(i)->type() == TRANSITIONWIDGET) { + } else if (children.at(i)->type() == TransitionWidget) { if (topTrack == -1 || currentTrack < topTrack) { offset = (int)(trackHeight / 3 * 2 - 1); topTrack = currentTrack; } - } else if (children.at(i)->type() == GROUPWIDGET) { + } else if (children.at(i)->type() == GroupWidget) { QList subchildren = children.at(i)->childItems(); bool clipGroup = false; for (int j = 0; j < subchildren.count(); j++) { - if (subchildren.at(j)->type() == AVWIDGET) { - int subTrack = static_cast (subchildren.at(j))->track(); - if (!groupTracks.contains(subTrack)) groupTracks.append(subTrack); + if (subchildren.at(j)->type() == AVWidget || subchildren.at(j)->type() == TransitionWidget) { + int subTrack = static_cast (subchildren.at(j))->track(); + if (!groupTracks.contains(subTrack)) groupTracks.append(subTrack); clipGroup = true; } } @@ -223,22 +266,22 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant } // Check no clip in the group goes outside of existing tracks int maximumTrack = projectScene()->tracksCount() - 1; - int groupHeight = 0; - for (int i = 0; i < groupTracks.count(); i++) { - int offset = groupTracks.at(i) - topTrack; - if (offset > groupHeight) groupHeight = offset; - } - maximumTrack -= groupHeight; + int groupHeight = 0; + for (int i = 0; i < groupTracks.count(); ++i) { + int offset = groupTracks.at(i) - topTrack; + if (offset > groupHeight) groupHeight = offset; + } + maximumTrack -= groupHeight; proposedTrack = qMin(proposedTrack, maximumTrack); proposedTrack = qMax(proposedTrack, 0); - int groupOffset = proposedTrack - topTrack; - if (!lockedTracks.isEmpty()) { - for (int i = 0; i < groupTracks.count(); i++) { - if (lockedTracks.contains(QString::number(groupTracks.at(i) + groupOffset))) { - return pos(); - } - } - } + int groupOffset = proposedTrack - topTrack; + if (!lockedTracks.isEmpty()) { + for (int i = 0; i < groupTracks.count(); ++i) { + if (lockedTracks.contains(QString::number(groupTracks.at(i) + groupOffset))) { + return pos(); + } + } + } newPos.setY((int)((proposedTrack) * trackHeight) + offset); //if (newPos == start) return start; @@ -249,12 +292,12 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant QList collidingItems; QPainterPath shape; - if (projectScene()->editMode() == NORMALEDIT) { + 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) { + 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)); @@ -266,9 +309,9 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant if (!collidingItems.isEmpty()) { bool forwardMove = xpos > start.x(); int offset = 0; - for (int i = 0; i < collidingItems.count(); i++) { + for (int i = 0; i < collidingItems.count(); ++i) { QGraphicsItem *collision = collidingItems.at(i); - if (collision->type() == AVWIDGET) { + if (collision->type() == AVWidget) { // Collision if (newPos.y() != pos().y()) { // Track change results in collision, restore original position @@ -299,8 +342,8 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant // 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) { + 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)); @@ -308,17 +351,17 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant } collidingItems.removeAll(children.at(i)); } - for (int i = 0; i < collidingItems.count(); i++) - if (collidingItems.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) { + if (projectScene()->editMode() == NormalEdit) { shape = transitionGroupShape(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) { + 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)); @@ -331,9 +374,9 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant else { bool forwardMove = xpos > start.x(); int offset = 0; - for (int i = 0; i < collidingItems.count(); i++) { + for (int i = 0; i < collidingItems.count(); ++i) { QGraphicsItem *collision = collidingItems.at(i); - if (collision->type() == TRANSITIONWIDGET) { + if (collision->type() == TransitionWidget) { // Collision if (newPos.y() != pos().y()) { // Track change results in collision, restore original position @@ -363,11 +406,11 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant } // If there is still a collision after our position adjust, restore original pos collidingItems = scene()->items(transitionGroupShape(newPos - pos()), Qt::IntersectsItemShape); - for (int i = 0; i < children.count(); i++) { + for (int i = 0; i < children.count(); ++i) { collidingItems.removeAll(children.at(i)); } - for (int i = 0; i < collidingItems.count(); i++) - if (collidingItems.at(i)->type() == TRANSITIONWIDGET) return pos(); + for (int i = 0; i < collidingItems.count(); ++i) + if (collidingItems.at(i)->type() == TransitionWidget) return pos(); } } return newPos; @@ -387,12 +430,12 @@ void AbstractGroupItem::dropEvent(QGraphicsSceneDragDropEvent * event) QPointF dropPos = event->scenePos(); QList selection = scene()->items(dropPos); AbstractClipItem *dropChild = NULL; - for (int i = 0; i < selection.count(); i++) { - if (selection.at(i)->type() == AVWIDGET) { + for (int i = 0; i < selection.count(); ++i) { + if (selection.at(i)->type() == AVWidget) { dropChild = (AbstractClipItem *) selection.at(i); - break; + break; } - } + } if (view) view->slotAddGroupEffect(e, this, dropChild); } @@ -414,15 +457,15 @@ void AbstractGroupItem::mousePressEvent(QGraphicsSceneMouseEvent * event) // User want to do a rectangle selection, so ignore the event to pass it to the view event->ignore(); } else { - QList list = scene()->items(event->scenePos()); - // only allow group move if we click over an item in the group - foreach(const QGraphicsItem *item, list) { - if (item->type() == TRANSITIONWIDGET || item->type() == AVWIDGET) { - QGraphicsItem::mousePressEvent(event); - return; - } - } - event->ignore(); + QList list = scene()->items(event->scenePos()); + // only allow group move if we click over an item in the group + foreach(const QGraphicsItem *item, list) { + if (item->type() == TransitionWidget || item->type() == AVWidget) { + QGraphicsItem::mousePressEvent(event); + return; + } + } + event->ignore(); } } @@ -437,7 +480,7 @@ void AbstractGroupItem::resizeStart(int diff) int itemcount = 0; for (int i = 0; i < children.count(); ++i) { AbstractClipItem *item = static_cast (children.at(i)); - if (item && item->type() == AVWIDGET) { + if (item && item->type() == AVWidget) { items << item; if (info) m_resizeInfos << item->info(); @@ -464,7 +507,7 @@ void AbstractGroupItem::resizeEnd(int diff) int itemcount = 0; for (int i = 0; i < children.count(); ++i) { AbstractClipItem *item = static_cast (children.at(i)); - if (item && item->type() == AVWIDGET) { + if (item && item->type() == AVWidget) { items << item; if (info) m_resizeInfos << item->info(); @@ -497,7 +540,7 @@ GenTime AbstractGroupItem::duration() GenTime start = GenTime(-1.0); GenTime end = GenTime(); for (int i = 0; i < children.count(); ++i) { - if (children.at(i)->type() != GROUPWIDGET) { + if (children.at(i)->type() != GroupWidget) { AbstractClipItem *item = static_cast (children.at(i)); if (item) { if (start < GenTime() || item->startPos() < start) @@ -511,3 +554,5 @@ GenTime AbstractGroupItem::duration() } return end - start; } + +#include "abstractgroupitem.moc"