]> git.sesse.net Git - kdenlive/blobdiff - src/abstractgroupitem.cpp
Cleanup some timeline operations
[kdenlive] / src / abstractgroupitem.cpp
index 79364deb60109700e0b875eacbbcf532c33f4fbd..4ea3e8783134c6a489897ce0c2b0613561618949 100644 (file)
@@ -32,6 +32,7 @@
 #include <QMimeData>
 #include <QGraphicsSceneMouseEvent>
 
+
 AbstractGroupItem::AbstractGroupItem(double /* fps */) :
         QObject(),
         QGraphicsItemGroup()
@@ -114,7 +115,12 @@ QPainterPath AbstractGroupItem::groupShape(GRAPHICSRECTITEM type, QPointF offset
 void AbstractGroupItem::addItem(QGraphicsItem * item)
 {
     addToGroup(item);
-    //fixItemRect();
+    item->setFlag(QGraphicsItem::ItemIsMovable, false);
+}
+
+void AbstractGroupItem::removeItem(QGraphicsItem * item)
+{
+    removeFromGroup(item);
 }
 
 void AbstractGroupItem::fixItemRect()
@@ -136,18 +142,18 @@ void AbstractGroupItem::fixItemRect()
 // virtual
 void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *)
 {
-    const double scale = option->matrix.m11();
     QColor bgcolor(100, 100, 200, 100);
     QRectF bound = option->exposedRect.adjusted(0, 0, 1, 1);
     p->setClipRect(bound);
-    p->fillRect(option->exposedRect, bgcolor);
+    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);
-    //pen.setCosmetic(true);
     p->setPen(pen);
-    p->drawRect(boundingRect().adjusted(0, 0, - 1 / scale, 0));
+    p->drawRoundedRect(mapped, 3, 3);
 }
 
 //virtual
@@ -168,22 +174,18 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
         //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 startTrack = (start.y() + trackHeight / 2) / trackHeight;
-
-        int realTrack = (start.y() + newPos.y() - pos().y()) / trackHeight;
-        int proposedTrack = newPos.y() / trackHeight;
-
-        int correctedTrack = qMin(realTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight);
-        correctedTrack = qMax(correctedTrack, 0);
-
-        proposedTrack += (correctedTrack - realTrack);
+       int yOffset = property("y_absolute").toInt() + newPos.y();
+        int proposedTrack = yOffset / 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);
+            int currentTrack = 0;
+           if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET) currentTrack = static_cast <AbstractClipItem*> (children.at(i))->track();
+           else if (children.at(i)->type() == GROUPWIDGET) currentTrack = static_cast <AbstractGroupItem*> (children.at(i))->track();
+           else continue;
             if (children.at(i)->type() == AVWIDGET) {
                 if (topTrack == -1 || currentTrack <= topTrack) {
                     offset = 0;
@@ -359,8 +361,18 @@ void AbstractGroupItem::dropEvent(QGraphicsSceneDragDropEvent * event)
     QDomDocument doc;
     doc.setContent(effects, true);
     QDomElement e = doc.documentElement();
+    e.setAttribute("kdenlive_ix", 0);
     CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
-    if (view) view->slotAddGroupEffect(e, this);
+    QPointF dropPos = event->scenePos();
+    QList<QGraphicsItem *> selection = scene()->items(dropPos);
+    AbstractClipItem *dropChild = NULL;
+    for (int i = 0; i < selection.count(); i++) {
+       if (selection.at(i)->type() == AVWIDGET) {
+            dropChild = (AbstractClipItem *) selection.at(i);
+           break;
+        }
+    }           
+    if (view) view->slotAddGroupEffect(e, this, dropChild);
 }
 
 //virtual
@@ -380,7 +392,17 @@ void AbstractGroupItem::mousePressEvent(QGraphicsSceneMouseEvent * event)
     if (event->modifiers() & Qt::ShiftModifier) {
         // User want to do a rectangle selection, so ignore the event to pass it to the view
         event->ignore();
-    } else QGraphicsItem::mousePressEvent(event);
+    } else {
+       QList <QGraphicsItem *>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();
+    }
 }
 
 void AbstractGroupItem::resizeStart(int diff)