]> git.sesse.net Git - kdenlive/commitdiff
Several move & resize fixes
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 25 Mar 2009 22:02:43 +0000 (22:02 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 25 Mar 2009 22:02:43 +0000 (22:02 +0000)
svn path=/trunk/kdenlive/; revision=3184

src/abstractclipitem.cpp
src/abstractgroupitem.cpp
src/clipitem.cpp
src/customtrackview.cpp

index e889ba5367c169862333edcab62155ba0249463a..7636b0a5aab6cb4200eac6b1028f9fe8fe87a7a3 100644 (file)
@@ -85,14 +85,15 @@ void AbstractClipItem::resizeStart(int posx, double speed) {
         if (m_cropDuration > GenTime(3, m_fps)) durationDiff = GenTime(3, m_fps);
         else return;
     }
-
+    //kDebug()<<"// DURATION DIFF: "<<durationDiff.frames(25)<<", POS: "<<pos().x();
     m_startPos += durationDiff;
     if (type() == AVWIDGET) m_cropStart += durationDiff * speed;
     m_cropDuration = m_cropDuration - durationDiff * speed;
 
     setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
-    setPos(m_startPos.frames(m_fps), pos().y());
-    if ((int) pos().x() != posx) {
+    moveBy(durationDiff.frames(m_fps), 0);
+    //setPos(m_startPos.frames(m_fps), pos().y());
+    if ((int) scenePos().x() != posx) {
         //kDebug()<<"//////  WARNING, DIFF IN XPOS: "<<pos().x()<<" == "<<m_startPos.frames(m_fps);
         GenTime diff = GenTime((int) pos().x() - posx, m_fps);
         if (type() == AVWIDGET) m_cropStart = m_cropStart + diff;
index c7e0b88cf0d58ce80e244c05026742b3510bf1be..2390bcd178cc498c33580d2083f6bb817e1b27bb 100644 (file)
@@ -105,19 +105,22 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
         const int trackHeight = KdenliveSettings::trackheight();
         QPointF start = sceneBoundingRect().topLeft();
         QPointF newPos = value.toPointF();
-        int xpos = projectScene()->getSnapPointForPos((int)(start.x() + newPos.x() - scenePos().x() + 0.5), KdenliveSettings::snaptopoints());
+        //kDebug()<<"REAL:"<<start.x()<<", PROPOSED:"<<(int)(start.x() - pos().x() + newPos.x());
+        int xpos = projectScene()->getSnapPointForPos((int)(start.x() + newPos.x() - pos().x()), KdenliveSettings::snaptopoints());
 
         xpos = qMax(xpos, 0);
-        newPos.setX((int)(scenePos().x() + xpos - (int) start.x()));
+        //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 newTrack = (start.y() + newPos.y() - scenePos().y()) / trackHeight;
-        int currTrack = start.y() / trackHeight;
-        int currTrack2 = newPos.y() / trackHeight;
+        int realTrack = (start.y() + newPos.y() - pos().y()) / trackHeight;
+        int proposedTrack = newPos.y() / trackHeight;
 
-        newTrack = qMin(newTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight);
-        newTrack = qMax(newTrack, 0);
+        int correctedTrack = qMin(realTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight);
+        correctedTrack = qMax(correctedTrack, 0);
+
+        proposedTrack += (correctedTrack - realTrack);
 
         // Check if top item is a clip or a transition
         int offset = 0;
@@ -137,7 +140,7 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
                 }
             }
         }
-        newPos.setY((int)((currTrack2) * trackHeight) + offset);
+        newPos.setY((int)((proposedTrack) * trackHeight) + offset);
         //if (newPos == start) return start;
 
         /*if (newPos.x() < 0) {
index 87927087eb019da6369b724d67513e05caef1507..773a810ab504216c929f683e40f0587b66a49d43 100644 (file)
@@ -1057,7 +1057,7 @@ void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, b
 QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value) {
     if (change == ItemPositionChange && scene()) {
         // calculate new position.
-        if (parentItem()) return pos();
+        //if (parentItem()) return pos();
         QPointF newPos = value.toPointF();
         //kDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
         int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
index 756d2d1bbb49bdbfcb85e342591acde5d80e2324..6bb7d6c2c738e5968509c927497d05520f94ff5b 100644 (file)
@@ -2344,7 +2344,17 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
             }
 
         }
-
+        if (m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+            // Item was resized, rebuild group;
+            AbstractGroupItem *group = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
+            QList <QGraphicsItem *> children = group->childItems();
+            m_document->clipManager()->removeGroup(group);
+            scene()->destroyItemGroup(group);
+            for (int i = 0; i < children.count(); i++) {
+                children.at(i)->setSelected(true);
+            }
+            groupSelectedItems(false, true);
+        }
         //m_document->renderer()->doRefresh();
     } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) {
         // resize end
@@ -2395,6 +2405,17 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
                 m_commandStack->push(command);
             }
         }
+        if (m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) {
+            // Item was resized, rebuild group;
+            AbstractGroupItem *group = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
+            QList <QGraphicsItem *> children = group->childItems();
+            m_document->clipManager()->removeGroup(group);
+            scene()->destroyItemGroup(group);
+            for (int i = 0; i < children.count(); i++) {
+                children.at(i)->setSelected(true);
+            }
+            groupSelectedItems(false, true);
+        }
         //m_document->renderer()->doRefresh();
     } else if (m_operationMode == FADEIN) {
         // resize fade in effect
@@ -2626,10 +2647,9 @@ void CustomTrackView::cutSelectedClips() {
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
-           if (item->parentItem() && item->parentItem() != m_selectionGroup) {
-               emit displayMessage(i18n("Cannot cut a clip in a group"), ErrorMessage);
-           }
-            else if (currentPos > item->startPos() && currentPos <  item->endPos()) {
+            if (item->parentItem() && item->parentItem() != m_selectionGroup) {
+                emit displayMessage(i18n("Cannot cut a clip in a group"), ErrorMessage);
+            } else if (currentPos > item->startPos() && currentPos <  item->endPos()) {
                 RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos, true);
                 m_commandStack->push(command);
             }
@@ -2797,9 +2817,7 @@ ClipItem *CustomTrackView::getClipItemAtStart(GenTime pos, int track) {
 }
 
 ClipItem *CustomTrackView::getClipItemAt(int pos, int track) {
-    QPointF p(pos, track * m_tracksHeight + m_tracksHeight / 2);
-    kDebug() << "LKING POINT:" << p;
-    QList<QGraphicsItem *> list = scene()->items(p);
+    QList<QGraphicsItem *> list = scene()->items(QPointF(pos, track * m_tracksHeight + m_tracksHeight / 2));
     ClipItem *clip = NULL;
     for (int i = 0; i < list.size(); i++) {
         if (list.at(i)->type() == AVWIDGET) {