From: Jean-Baptiste M. <jb...@kd...> - 2012-12-28 02:14:07
|
Git commit 16e193e8de2f5eda3ec457bf5401fe82875b9d66 by Jean-Baptiste Mardelle. Committed on 28/12/2012 at 03:13. Pushed by mardelle into branch 'master'. Make sure we cannot move a clip to a locked track M +27 -6 src/abstractgroupitem.cpp M +10 -4 src/clipitem.cpp M +10 -2 src/customtrackview.cpp M +5 -0 src/transition.cpp http://commits.kde.org/kdenlive/16e193e8de2f5eda3ec457bf5401fe82875b9d66 diff --git a/src/abstractgroupitem.cpp b/src/abstractgroupitem.cpp index 4ea3e87..e9a30c8 100644 --- a/src/abstractgroupitem.cpp +++ b/src/abstractgroupitem.cpp @@ -173,17 +173,19 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant xpos = qMax(xpos, 0); //kDebug()<<"GRP XPOS:"<<xpos<<", START:"<<start.x()<<",NEW:"<<newPos.x()<<"; SCENE:"<<scenePos().x()<<",POS:"<<pos().x(); newPos.setX((int)(pos().x() + xpos - (int) start.x())); - - int yOffset = property("y_absolute").toInt() + newPos.y(); - int proposedTrack = yOffset / trackHeight; - + QStringList lockedTracks = property("locked_tracks").toStringList(); + int proposedTrack = (property("y_absolute").toInt() + newPos.y()) / trackHeight; // Check if top item is a clip or a transition int offset = 0; int topTrack = -1; + QList<int> groupTracks; QList<QGraphicsItem *> children = childItems(); 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 <AbstractClipItem*> (children.at(i))->track(); + if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET) { + currentTrack = static_cast <AbstractClipItem*> (children.at(i))->track(); + if (!groupTracks.contains(currentTrack)) groupTracks.append(currentTrack); + } else if (children.at(i)->type() == GROUPWIDGET) currentTrack = static_cast <AbstractGroupItem*> (children.at(i))->track(); else continue; if (children.at(i)->type() == AVWIDGET) { @@ -201,8 +203,9 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant bool clipGroup = false; for (int j = 0; j < subchildren.count(); j++) { if (subchildren.at(j)->type() == AVWIDGET) { + int subTrack = static_cast <AbstractClipItem*> (subchildren.at(j))->track(); + if (!groupTracks.contains(subTrack)) groupTracks.append(subTrack); clipGroup = true; - break; } } if (clipGroup) { @@ -218,6 +221,24 @@ 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; + 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(); + } + } + } newPos.setY((int)((proposedTrack) * trackHeight) + offset); //if (newPos == start) return start; diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 47a0c73..51ae67a 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -893,6 +893,11 @@ void ClipItem::paint(QPainter *painter, painter->drawPixmap(clipStart + startCache - cropLeft, mappedRect.y(), m_audioThumbCachePic.value(startCache)); } } + + if (m_isMainSelectedClip) { + framePen.setColor(Qt::red); + textBgColor = Qt::red; + } // only paint details if clip is big enough if (mapped.width() > 20) { @@ -919,10 +924,6 @@ void ClipItem::paint(QPainter *painter, // Draw clip name const QRectF txtBounding2 = painter->boundingRect(mapped, Qt::AlignRight | Qt::AlignTop, m_clipName + ' ').adjusted(0, -1, 0, -1); painter->setPen(Qt::NoPen); - if (m_isMainSelectedClip) { - framePen.setColor(Qt::red); - textBgColor = Qt::red; - } painter->fillRect(txtBounding2.adjusted(-3, 0, 0, 0), textBgColor); painter->setBrush(QBrush(Qt::NoBrush)); painter->setPen(textColor); @@ -1343,6 +1344,11 @@ QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) int newTrack = yOffset / KdenliveSettings::trackheight(); newTrack = qMin(newTrack, projectScene()->tracksCount() - 1); newTrack = qMax(newTrack, 0); + QStringList lockedTracks = property("locked_tracks").toStringList(); + if (lockedTracks.contains(QString::number(newTrack))) { + // Trying to move to a locked track + return pos(); + } newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + 1)); // Only one clip is moving QRectF sceneShape = rect(); diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 50a617b..4fad4c8 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -831,13 +831,21 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) m_dragItem = collisionClip; } found = true; - + QStringList lockedTracks; + for (int i = 0; i < m_document->tracksCount(); i++) { + if (m_document->trackInfoAt(i).isLocked) lockedTracks << QString::number(m_document->tracksCount() - i - 1); + } m_dragItem->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y()); + m_dragItem->setProperty("locked_tracks", lockedTracks); m_dragItemInfo = m_dragItem->info(); - if (m_selectionGroup) m_selectionGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y()); + if (m_selectionGroup) { + m_selectionGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y()); + m_selectionGroup->setProperty("locked_tracks", lockedTracks); + } if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) { dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem()); dragGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y()); + dragGroup->setProperty("locked_tracks", lockedTracks); } break; } diff --git a/src/transition.cpp b/src/transition.cpp index 799fe5d..7fb3ca6 100644 --- a/src/transition.cpp +++ b/src/transition.cpp @@ -224,6 +224,11 @@ QVariant Transition::itemChange(GraphicsItemChange change, const QVariant &value int newTrack = newPos.y() / KdenliveSettings::trackheight(); newTrack = qMin(newTrack, projectScene()->tracksCount() - 1); newTrack = qMax(newTrack, 0); + QStringList lockedTracks = property("locked_tracks").toStringList(); + if (lockedTracks.contains(QString::number(newTrack))) { + // Trying to move to a locked track + return pos(); + } newPos.setY((int)(newTrack * KdenliveSettings::trackheight() + itemOffset() + 1)); // Only one clip is moving QRectF sceneShape = rect(); |