]> git.sesse.net Git - kdenlive/commitdiff
Cleanup some timeline operations
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 19 Nov 2012 15:53:47 +0000 (16:53 +0100)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 19 Nov 2012 15:53:47 +0000 (16:53 +0100)
src/abstractclipitem.cpp
src/abstractclipitem.h
src/abstractgroupitem.cpp
src/abstractgroupitem.h
src/clipmanager.cpp
src/customtrackview.cpp
src/customtrackview.h
src/docclipbase.cpp

index 713bbcfb9d99f4c942eaf52a05df3ce3e9fae25c..42c31ca975ea96279ab108df4c240bdfe891c3e7 100644 (file)
@@ -29,6 +29,7 @@
 #include <QPainter>
 #include <QToolTip>
 #include <QGraphicsSceneMouseEvent>
+#include <QParallelAnimationGroup>
 
 AbstractClipItem::AbstractClipItem(const ItemInfo &info, const QRectF& rect, double fps) :
         QObject(),
@@ -63,8 +64,9 @@ void AbstractClipItem::closeAnimation()
         return;
     }
     QPropertyAnimation *closeAnimation = new QPropertyAnimation(this, "rect");
-    connect(closeAnimation, SIGNAL(finished()), this, SLOT(deleteLater()));
+    QPropertyAnimation *closeAnimation2 = new QPropertyAnimation(this, "opacity");
     closeAnimation->setDuration(200);
+    closeAnimation2->setDuration(200);
     QRectF r = rect();
     QRectF r2 = r;
     r2.setLeft(r.left() + r.width() / 2);
@@ -74,7 +76,13 @@ void AbstractClipItem::closeAnimation()
     closeAnimation->setStartValue(r);
     closeAnimation->setEndValue(r2);
     closeAnimation->setEasingCurve(QEasingCurve::InQuad);
-    closeAnimation->start(QAbstractAnimation::DeleteWhenStopped);
+    closeAnimation2->setStartValue(1.0);
+    closeAnimation2->setEndValue(0.0);
+    QParallelAnimationGroup *group = new QParallelAnimationGroup;
+    connect(group, SIGNAL(finished()), this, SLOT(deleteLater()));
+    group->addAnimation(closeAnimation);
+    group->addAnimation(closeAnimation2);
+    group->start(QAbstractAnimation::DeleteWhenStopped);
 #endif
 }
 
index 3e6a7ad9da833db30b1d95e48168e55264380d2a..47a246c614019ef08de88a4c45031165559ad1aa 100644 (file)
@@ -38,6 +38,7 @@ class AbstractClipItem : public QObject, public QGraphicsRectItem
 {
     Q_OBJECT
     Q_PROPERTY(QRectF rect READ rect WRITE setRect)
+    Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
 
 public:
     AbstractClipItem(const ItemInfo &info, const QRectF& rect, double fps);
index 8e482f4b2dcc43f88453dea9bc7390807bb355c8..4ea3e8783134c6a489897ce0c2b0613561618949 100644 (file)
@@ -118,6 +118,11 @@ void AbstractGroupItem::addItem(QGraphicsItem * item)
     item->setFlag(QGraphicsItem::ItemIsMovable, false);
 }
 
+void AbstractGroupItem::removeItem(QGraphicsItem * item)
+{
+    removeFromGroup(item);
+}
+
 void AbstractGroupItem::fixItemRect()
 {
     QPointF start = boundingRect().topLeft();
index 2c8c90f7a715bd9be193cc9f6ba661bf67d597ab..c68d22378d8c556caac56b1d222167cd40612d68 100644 (file)
@@ -38,6 +38,7 @@ public:
     virtual int type() const;
     CustomTrackScene* projectScene();
     void addItem(QGraphicsItem * item);
+    void removeItem(QGraphicsItem * item);
     int track() const;
     QPainterPath clipGroupShape(QPointF offset) const;
     QPainterPath transitionGroupShape(QPointF offset) const;
index f652fcbcb122ff2f7bc9f1c309b32098dcfb348d..486050093b77538a89c5feae324a9d234d66e73b 100644 (file)
@@ -431,12 +431,12 @@ void ClipManager::deleteClip(const QString &clipId)
 {
     for (int i = 0; i < m_clipList.count(); i++) {
         if (m_clipList.at(i)->getId() == clipId) {
-            if (m_clipList.at(i)->clipType() != COLOR && m_clipList.at(i)->clipType() != SLIDESHOW  && !m_clipList.at(i)->fileURL().isEmpty()) {
+           DocClipBase *clip = m_clipList.takeAt(i);
+            if (clip->clipType() != COLOR && clip->clipType() != SLIDESHOW  && !clip->fileURL().isEmpty()) {
                 //if (m_clipList.at(i)->clipType() == IMAGE || m_clipList.at(i)->clipType() == AUDIO || (m_clipList.at(i)->clipType() == TEXT && !m_clipList.at(i)->fileURL().isEmpty())) {
                 // listen for file change
-                m_fileWatcher.removeFile(m_clipList.at(i)->fileURL().path());
+                m_fileWatcher.removeFile(clip->fileURL().path());
             }
-            DocClipBase *clip = m_clipList.takeAt(i);
             delete clip;
             clip = NULL;
             break;
index 6cc2333ded67a005759424ded0e34f938eee0cd2..cbc29dff8eb821718903eb126610d22281cd186b 100644 (file)
@@ -1040,7 +1040,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
        if (selected == false) {
            m_dragItem = NULL;
        }
-        groupSelectedItems(QList <QGraphicsItem*>(), false, false, true);
+        groupSelectedItems(QList <QGraphicsItem*>(), false, true);
        if (m_dragItem) { 
            ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
            updateClipTypeActions(dragGroup == NULL ? clip : NULL);
@@ -1224,7 +1224,7 @@ void CustomTrackView::rebuildGroup(AbstractGroupItem *group)
            group->removeFromGroup(children.at(i));
        }*/
        scene()->destroyItemGroup(group);
-        groupSelectedItems(children, false, true, true);
+        groupSelectedItems(children, true, true);
     }
 }
 
@@ -1253,7 +1253,7 @@ void CustomTrackView::resetSelectionGroup(bool selectItems)
     }
 }
 
-void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool force, bool createNewGroup, bool selectNewGroup)
+void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool createNewGroup, bool selectNewGroup)
 {
     if (m_selectionGroup) {
         kDebug() << "///// ERROR, TRYING TO OVERRIDE EXISTING GROUP";
@@ -1280,13 +1280,14 @@ void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool
        }
     }
     if (itemsList.isEmpty() && groupsList.isEmpty()) return;
-    if (itemsList.count() == 1) {
+    if (itemsList.count() == 1 && groupsList.isEmpty()) {
        // only one item selected:
        QSetIterator<QGraphicsItem *> it(itemsList);
        m_dragItem = static_cast<AbstractClipItem *>(it.next());
        m_dragItem->setSelected(true);
+       return;
     }
-    
+
     QRectF rectUnion;
     // Find top left position of selection
     foreach (const QGraphicsItemGroup *value, groupsList) {
@@ -1295,56 +1296,54 @@ void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool
     foreach (const QGraphicsItem *value, itemsList) {
         rectUnion = rectUnion.united(value->sceneBoundingRect());
     }
-    if (force || selection.count() > 1) {
-        bool snap = KdenliveSettings::snaptopoints();
-        KdenliveSettings::setSnaptopoints(false);
-        if (createNewGroup) {
-            AbstractGroupItem *newGroup = m_document->clipManager()->createGroup();
-            newGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
-            QPointF diff = newGroup->pos();
-            newGroup->translate(-diff.x(), -diff.y());
-            //newGroup->translate((int) -rectUnion.left(), (int) -rectUnion.top() + 1);
-
-            scene()->addItem(newGroup);
-            // Check if we are trying to include a group in a group
-           foreach (QGraphicsItemGroup *value, groupsList) {
-               QList<QGraphicsItem *> children = value->childItems();
-               for (int i = 0; i < children.count(); i++) {
-                   if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)
-                       itemsList.insert(children.at(i));
-               }
-               AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(value);
-               m_document->clipManager()->removeGroup(grp);
-               scene()->destroyItemGroup(grp);
+    bool snap = KdenliveSettings::snaptopoints();
+    KdenliveSettings::setSnaptopoints(false);
+    if (createNewGroup) {
+       AbstractGroupItem *newGroup = m_document->clipManager()->createGroup();
+        newGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
+        QPointF diff = newGroup->pos();
+        newGroup->translate(-diff.x(), -diff.y());
+        //newGroup->translate((int) -rectUnion.left(), (int) -rectUnion.top() + 1);
+
+        scene()->addItem(newGroup);
+        // Check if we are trying to include a group in a group
+       foreach (QGraphicsItemGroup *value, groupsList) {
+           QList<QGraphicsItem *> children = value->childItems();
+           for (int i = 0; i < children.count(); i++) {
+               if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)
+                   itemsList.insert(children.at(i));
            }
+           AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(value);
+           m_document->clipManager()->removeGroup(grp);
+           scene()->destroyItemGroup(grp);
+       }
 
-           foreach (QGraphicsItem *value, itemsList) {
-                newGroup->addItem(value);
-            }
-            KdenliveSettings::setSnaptopoints(snap);
-           if (selectNewGroup) newGroup->setSelected(true);
-        } else {
-            m_selectionGroup = new AbstractGroupItem(m_document->fps());
-            m_selectionGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
-            QPointF diff = m_selectionGroup->pos();
-            //m_selectionGroup->translate((int) - rectUnion.left(), (int) -rectUnion.top() + 1);
-            m_selectionGroup->translate(- diff.x(), -diff.y());
+       foreach (QGraphicsItem *value, itemsList) {
+           newGroup->addItem(value);
+        }
+        KdenliveSettings::setSnaptopoints(snap);
+       if (selectNewGroup) newGroup->setSelected(true);
+    } else {
+       m_selectionGroup = new AbstractGroupItem(m_document->fps());
+        m_selectionGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
+        QPointF diff = m_selectionGroup->pos();
+        //m_selectionGroup->translate((int) - rectUnion.left(), (int) -rectUnion.top() + 1);
+        m_selectionGroup->translate(- diff.x(), -diff.y());
 
-            scene()->addItem(m_selectionGroup);
-            foreach (QGraphicsItemGroup *value, groupsList) {
-                m_selectionGroup->addItem(value);
-            }
-            foreach (QGraphicsItem *value, itemsList) {
-                m_selectionGroup->addItem(value);
-            }
-            KdenliveSettings::setSnaptopoints(snap);
-            if (m_selectionGroup) {
-                m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
-                m_selectionGroupInfo.track = m_selectionGroup->track();
-               if (selectNewGroup) m_selectionGroup->setSelected(true);
-            }
+        scene()->addItem(m_selectionGroup);
+        foreach (QGraphicsItemGroup *value, groupsList) {
+           m_selectionGroup->addItem(value);
+        }
+        foreach (QGraphicsItem *value, itemsList) {
+           m_selectionGroup->addItem(value);
         }
-    } else resetSelectionGroup();
+        KdenliveSettings::setSnaptopoints(snap);
+        if (m_selectionGroup) {
+           m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
+            m_selectionGroupInfo.track = m_selectionGroup->track();
+           if (selectNewGroup) m_selectionGroup->setSelected(true);
+        }
+    }
 }
 
 void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event)
@@ -2734,7 +2733,7 @@ void CustomTrackView::dropEvent(QDropEvent * event)
 
         m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
         if (items.count() > 1) {
-            groupSelectedItems(items, true);
+            groupSelectedItems(items);
         } else if (items.count() == 1) {
             m_dragItem = static_cast <AbstractClipItem *>(items.at(0));
             emit clipItemSelected((ClipItem*) m_dragItem, false);
@@ -3445,24 +3444,23 @@ void CustomTrackView::deleteClip(const QString &clipId)
         if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = (ClipItem *)itemList.at(i);
             if (item->clipProducer() == clipId) {
-                count++;
+               count++;
                 if (item->parentItem()) {
-                    // Clip is in a group, destroy the group
-                    new GroupClipsCommand(this, QList<ItemInfo>() << item->info(), QList<ItemInfo>(), false, deleteCommand);
+                   // Clip is in a group, destroy the group
+                   new GroupClipsCommand(this, QList<ItemInfo>() << item->info(), QList<ItemInfo>(), false, deleteCommand);
                 }
                 new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteCommand);
             }
         }
     }
-    deleteCommand->setText(i18np("Delete timeline clip", "Delete timeline clips", count));
     if (count == 0) {
         delete deleteCommand;
     } else {
+       deleteCommand->setText(i18np("Delete timeline clip", "Delete timeline clips", count));
+       new RefreshMonitorCommand(this, true, false, deleteCommand);
         updateTrackDuration(-1, deleteCommand);
-       new RefreshMonitorCommand(this, false, false, deleteCommand);
         m_commandStack->push(deleteCommand);
     }
-    m_document->renderer()->doRefresh();
 }
 
 void CustomTrackView::seekCursorPos(int pos)
@@ -4440,7 +4438,7 @@ void CustomTrackView::doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo>
             //clip->setSelected(true);
         }
     }
-    groupSelectedItems(list, false, true, true);
+    groupSelectedItems(list, true, true);
     setDocumentModified();
 }
 
@@ -6519,7 +6517,7 @@ void CustomTrackView::loadGroups(const QDomNodeList &groups)
                 if (clip) list.append(clip);//clip->setSelected(true);
             }
         }
-        groupSelectedItems(list, false, true);
+        groupSelectedItems(list, true);
     }
 }
 
@@ -6748,7 +6746,7 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, EffectsList ef
                         videoIx++;
                     }
                 }
-                groupSelectedItems(QList <QGraphicsItem*>()<<clip<<audioClip, false, true);
+                groupSelectedItems(QList <QGraphicsItem*>()<<clip<<audioClip, true);
             }
         }
     } else {
@@ -7029,7 +7027,7 @@ void CustomTrackView::updateProjectFps()
                     children.at(j)->setSelected(true);
                 }
             }*/
-            groupSelectedItems(children, true, true);
+            groupSelectedItems(children, true);
         } else if (itemList.at(i)->type() == GUIDEITEM) {
             Guide *g = static_cast<Guide *>(itemList.at(i));
             g->updatePos();
@@ -7111,14 +7109,14 @@ void CustomTrackView::slotSelectClipsInTrack()
            list.append(selection.at(i));
         }
     }    
-    groupSelectedItems(list, false, false, true);
+    groupSelectedItems(list, false, true);
 }
 
 void CustomTrackView::slotSelectAllClips()
 {
     m_scene->clearSelection();
     resetSelectionGroup();
-    groupSelectedItems(m_scene->items(), false, false, true);
+    groupSelectedItems(m_scene->items(), false, true);
 }
 
 void CustomTrackView::selectClip(bool add, bool group, int track, int pos)
index f4e729611b8fc470a3a05055a3990f7306e77977..5503ea55fd4a685790cf13feb20301b3b3d27dd5 100644 (file)
@@ -411,7 +411,7 @@ private:
     ClipItem *getClipUnderCursor() const;
     AbstractClipItem *getMainActiveClip() const;
     void resetSelectionGroup(bool selectItems = true);
-    void groupSelectedItems(QList <QGraphicsItem *> selection = QList <QGraphicsItem *>(), bool force = false, bool createNewGroup = false, bool selectNewGroup = false);
+    void groupSelectedItems(QList <QGraphicsItem *> selection = QList <QGraphicsItem *>(), bool createNewGroup = false, bool selectNewGroup = false);
     /** Get available space for clip move (min and max free positions) */
     void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
     /** Get available space for transition move (min and max free positions) */
index 5d41cc04cdf22899b8b9b004ea0520c663853ddc..daeb6a57d8a313489b683941fe530d637737bf6b 100644 (file)
@@ -295,7 +295,6 @@ void DocClipBase::updateAudioThumbnail(const audioByteArray& data)
 QList < GenTime > DocClipBase::snapMarkers() const
 {
     QList < GenTime > markers;
-
     for (int count = 0; count < m_snapMarkers.count(); ++count) {
         markers.append(m_snapMarkers.at(count).time());
     }