From: Jean-Baptiste Mardelle Date: Mon, 19 Nov 2012 15:53:47 +0000 (+0100) Subject: Cleanup some timeline operations X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=27ac7e68c934a04d2922986b07ea8e5dde2cad50;p=kdenlive Cleanup some timeline operations --- diff --git a/src/abstractclipitem.cpp b/src/abstractclipitem.cpp index 713bbcfb..42c31ca9 100644 --- a/src/abstractclipitem.cpp +++ b/src/abstractclipitem.cpp @@ -29,6 +29,7 @@ #include #include #include +#include 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 } diff --git a/src/abstractclipitem.h b/src/abstractclipitem.h index 3e6a7ad9..47a246c6 100644 --- a/src/abstractclipitem.h +++ b/src/abstractclipitem.h @@ -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); diff --git a/src/abstractgroupitem.cpp b/src/abstractgroupitem.cpp index 8e482f4b..4ea3e878 100644 --- a/src/abstractgroupitem.cpp +++ b/src/abstractgroupitem.cpp @@ -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(); diff --git a/src/abstractgroupitem.h b/src/abstractgroupitem.h index 2c8c90f7..c68d2237 100644 --- a/src/abstractgroupitem.h +++ b/src/abstractgroupitem.h @@ -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; diff --git a/src/clipmanager.cpp b/src/clipmanager.cpp index f652fcbc..48605009 100644 --- a/src/clipmanager.cpp +++ b/src/clipmanager.cpp @@ -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; diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 6cc2333d..cbc29dff 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -1040,7 +1040,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) if (selected == false) { m_dragItem = NULL; } - groupSelectedItems(QList (), false, false, true); + groupSelectedItems(QList (), false, true); if (m_dragItem) { ClipItem *clip = static_cast (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 selection, bool force, bool createNewGroup, bool selectNewGroup) +void CustomTrackView::groupSelectedItems(QList selection, bool createNewGroup, bool selectNewGroup) { if (m_selectionGroup) { kDebug() << "///// ERROR, TRYING TO OVERRIDE EXISTING GROUP"; @@ -1280,13 +1280,14 @@ void CustomTrackView::groupSelectedItems(QList selection, bool } } if (itemsList.isEmpty() && groupsList.isEmpty()) return; - if (itemsList.count() == 1) { + if (itemsList.count() == 1 && groupsList.isEmpty()) { // only one item selected: QSetIterator it(itemsList); m_dragItem = static_cast(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 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 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(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 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(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 (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() << item->info(), QList(), false, deleteCommand); + // Clip is in a group, destroy the group + new GroupClipsCommand(this, QList() << item->info(), QList(), 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 clipInfos, QList //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 ()<()<setSelected(true); } }*/ - groupSelectedItems(children, true, true); + groupSelectedItems(children, true); } else if (itemList.at(i)->type() == GUIDEITEM) { Guide *g = static_cast(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) diff --git a/src/customtrackview.h b/src/customtrackview.h index f4e72961..5503ea55 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -411,7 +411,7 @@ private: ClipItem *getClipUnderCursor() const; AbstractClipItem *getMainActiveClip() const; void resetSelectionGroup(bool selectItems = true); - void groupSelectedItems(QList selection = QList (), bool force = false, bool createNewGroup = false, bool selectNewGroup = false); + void groupSelectedItems(QList selection = QList (), 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) */ diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 5d41cc04..daeb6a57 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -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()); }