]> git.sesse.net Git - kdenlive/blobdiff - src/abstractgroupitem.cpp
Fix wrong project clip deletion, fixes:
[kdenlive] / src / abstractgroupitem.cpp
index 268bb930654776b8ab3abd17f03b507e4d1eac99..7e4cbb93bbdfe90db3eec78b8b774884168727e9 100644 (file)
@@ -32,6 +32,7 @@
 #include "customtrackscene.h"
 
 AbstractGroupItem::AbstractGroupItem(double fps): QGraphicsItemGroup(), m_fps(fps) {
+    setZValue(2);
     setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
 }
 
@@ -39,6 +40,10 @@ int AbstractGroupItem::type() const {
     return GROUPWIDGET;
 }
 
+const int AbstractGroupItem::track() const {
+    return (int)(scenePos().y() / KdenliveSettings::trackheight());
+}
+
 CustomTrackScene* AbstractGroupItem::projectScene() {
     if (scene()) return static_cast <CustomTrackScene*>(scene());
     return NULL;
@@ -80,16 +85,43 @@ void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWi
 QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant &value) {
     if (change == ItemPositionChange && scene()) {
         // calculate new position.
+        const int trackHeight = KdenliveSettings::trackheight();
         QPointF newPos = value.toPointF();
-        QPointF start = sceneBoundingRect().topLeft();
+        int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
+        xpos = qMax(xpos, 0);
+        newPos.setX(xpos);
+
+
+        //kDebug()<<"// GRP MOVE: "<<pos().y()<<"->"<<newPos.y();
+        QPointF start = pos();//sceneBoundingRect().topLeft();
         int posx = start.x() + newPos.x(); //projectScene()->getSnapPointForPos(start.x() + sc.x(), KdenliveSettings::snaptopoints());
 
-        int startTrack = (start.y()) / KdenliveSettings::trackheight();
-        int newTrack = (start.y() + newPos.y()) / KdenliveSettings::trackheight();
-        //kDebug()<<"// GROUP NEW TRACK: "<<newTrack<<", START TRACK: "<<startTrack;
-        newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
+        int startTrack = (start.y() + trackHeight / 2) / trackHeight;
+        int newTrack = (newPos.y()) / trackHeight;
+        //kDebug()<<"// GROUP NEW T:"<<newTrack<<",START T:"<<startTrack<<",MAX:"<<projectScene()->tracksCount() - 1;
+        newTrack = qMin(newTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight);
         newTrack = qMax(newTrack, 0);
-        newPos.setY((int)((newTrack - startTrack) * KdenliveSettings::trackheight()));
+
+        // Check if top item is a clip or a transition
+        int offset = 0;
+        int topTrack = -1;
+        QList<QGraphicsItem *> children = childItems();
+        for (int i = 0; i < children.count(); i++) {
+            int currentTrack = (int)(children.at(i)->scenePos().y() / trackHeight);
+            if (children.at(i)->type() == AVWIDGET) {
+                if (topTrack == -1 || currentTrack <= topTrack) {
+                    offset = 0;
+                    topTrack = currentTrack;
+                }
+            } else if (children.at(i)->type() == TRANSITIONWIDGET) {
+                if (topTrack == -1 || currentTrack < topTrack) {
+                    offset = (int)(trackHeight / 3 * 2 - 1);
+                    topTrack = currentTrack;
+                }
+            }
+        }
+
+        newPos.setY((int)((newTrack) * trackHeight) + offset);
 
         //kDebug() << "------------------------------------GRUOP MOVE";
 
@@ -100,7 +132,6 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
 
         QPolygonF sceneShape = groupShape(newPos - pos());
         QList<QGraphicsItem*> collindingItems = scene()->items(sceneShape, Qt::IntersectsItemShape);
-        QList<QGraphicsItem *> children = childItems();
         for (int i = 0; i < children.count(); i++) {
             collindingItems.removeAll(children.at(i));
         }