X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcustomtrackview.cpp;h=7cc622012bf50053a6491d8c30e8146aad223d24;hb=af0cdc3a2441996bb29f9c2d8b4ce0dd87a6fcb0;hp=9ed99e8db4c04ee89a45a3fee2984346a6ed7e38;hpb=8b4c224d4929ace1515266709c0f24978b19d3b4;p=kdenlive diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 9ed99e8d..7cc62201 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -26,6 +26,7 @@ #include "commands/movetransitioncommand.h" #include "commands/resizeclipcommand.h" #include "commands/editguidecommand.h" +#include "commands/addextradatacommand.h" #include "commands/addtimelineclipcommand.h" #include "commands/addeffectcommand.h" #include "commands/editeffectcommand.h" @@ -51,6 +52,7 @@ #include "commands/changeeffectstatecommand.h" #include "commands/movegroupcommand.h" #include "ui_addtrack_ui.h" +#include "ui_importkeyframesdialog_ui.h" #include "initeffects.h" #include "commands/locktrackcommand.h" #include "commands/groupclipscommand.h" @@ -60,7 +62,7 @@ #include "tracksconfigdialog.h" #include "commands/configtrackscommand.h" #include "commands/rebuildgroupcommand.h" -#include "commands/razorgroupcommand.h" +#include "commands/refreshmonitorcommand.h" #include "profilesdialog.h" #include "lib/audio/audioEnvelope.h" @@ -107,35 +109,44 @@ bool sortGuidesList(const Guide *g1 , const Guide *g2) // const int duration = animate ? 1500 : 1; CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent) : - QGraphicsView(projectscene, parent), - m_tracksHeight(KdenliveSettings::trackheight()), - m_projectDuration(0), - m_cursorPos(0), - m_document(doc), - m_scene(projectscene), - m_cursorLine(NULL), - m_operationMode(NONE), - m_moveOpMode(NONE), - m_dragItem(NULL), - m_dragGuide(NULL), - m_visualTip(NULL), - m_animation(NULL), - m_clickPoint(), - m_autoScroll(KdenliveSettings::autoscroll()), - m_pasteEffectsAction(NULL), - m_ungroupAction(NULL), - m_scrollOffset(0), - m_clipDrag(false), - m_findIndex(0), - m_tool(SELECTTOOL), - m_copiedItems(), - m_menuPosition(), - m_blockRefresh(false), - m_selectionGroup(NULL), - m_selectedTrack(0), - m_audioCorrelator(NULL), - m_audioAlignmentReference(NULL), - m_controlModifier(false) + QGraphicsView(projectscene, parent) + , m_tracksHeight(KdenliveSettings::trackheight()) + , m_projectDuration(0) + , m_cursorPos(0) + , m_document(doc) + , m_scene(projectscene) + , m_cursorLine(NULL) + , m_operationMode(NONE) + , m_moveOpMode(NONE) + , m_dragItem(NULL) + , m_dragGuide(NULL) + , m_visualTip(NULL) + , m_animation(NULL) + , m_clickPoint() + , m_autoScroll(KdenliveSettings::autoscroll()) + , m_timelineContextMenu(NULL) + , m_timelineContextClipMenu(NULL) + , m_timelineContextTransitionMenu(NULL) + , m_markerMenu(NULL) + , m_autoTransition(NULL) + , m_pasteEffectsAction(NULL) + , m_ungroupAction(NULL) + , m_editGuide(NULL) + , m_deleteGuide(NULL) + , m_clipTypeGroup(NULL) + , m_scrollOffset(0) + , m_clipDrag(false) + , m_findIndex(0) + , m_tool(SELECTTOOL) + , m_copiedItems() + , m_menuPosition() + , m_blockRefresh(false) + , m_selectionGroup(NULL) + , m_selectedTrack(0) + , m_spacerOffset(0) + , m_audioCorrelator(NULL) + , m_audioAlignmentReference(NULL) + , m_controlModifier(false) { if (doc) { m_commandStack = doc->commandStack(); @@ -228,11 +239,13 @@ void CustomTrackView::setContextMenu(QMenu *timeline, QMenu *clip, QMenu *transi m_markerMenu = new QMenu(i18n("Go to marker..."), this); m_markerMenu->setEnabled(false); markermenu->addMenu(m_markerMenu); - connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *))); + connect(m_markerMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotGoToMarker(QAction*))); QList list = m_timelineContextClipMenu->actions(); for (int i = 0; i < list.count(); i++) { if (list.at(i)->data().toString() == "paste_effects") m_pasteEffectsAction = list.at(i); else if (list.at(i)->data().toString() == "ungroup_clip") m_ungroupAction = list.at(i); + else if (list.at(i)->data().toString() == "A") m_audioActions.append(list.at(i)); + else if (list.at(i)->data().toString() == "A+V") m_avActions.append(list.at(i)); } m_timelineContextTransitionMenu = transition; @@ -319,12 +332,9 @@ bool CustomTrackView::checkTrackHeight() } } double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1); - + m_cursorLine->setLine(0, 0, 0, newHeight - 1); for (int i = 0; i < m_guides.count(); i++) { - QLineF l = m_guides.at(i)->line(); - l.setP2(QPointF(l.x2(), newHeight)); - m_guides.at(i)->setLine(l); + m_guides.at(i)->setLine(0, 0, 0, newHeight - 1); } setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); @@ -402,29 +412,47 @@ void CustomTrackView::slotCheckPositionScrolling() } } +void CustomTrackView::slotAlignPlayheadToMousePos() +{ + /* get curser point ref in screen coord */ + QPoint ps = QCursor::pos(); + /* get xPos in scene coord */ + int mappedXPos = qMax((int)(mapToScene(mapFromGlobal(ps)).x() + 0.5), 0); + /* move playhead to new xPos*/ + seekCursorPos(mappedXPos); +} + +int CustomTrackView::getMousePos() const +{ + return qMax((int)(mapToScene(mapFromGlobal(QCursor::pos())).x() + 0.5), 0); +} // virtual void CustomTrackView::mouseMoveEvent(QMouseEvent * event) { int pos = event->x(); int mappedXPos = qMax((int)(mapToScene(event->pos()).x() + 0.5), 0); - double snappedPos = getSnapPointForPos(mappedXPos); emit mousePosition(mappedXPos); + if (m_operationMode == SCROLLTIMELINE) { + QGraphicsView::mouseMoveEvent(event); + return; + } + if (event->buttons() & Qt::MidButton) return; if (dragMode() == QGraphicsView::RubberBandDrag || (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && m_operationMode != RESIZESTART && m_operationMode != RESIZEEND)) { event->setAccepted(true); m_moveOpMode = NONE; - QGraphicsView::mouseMoveEvent(event); + if (event->modifiers() != Qt::ControlModifier || dragMode() == QGraphicsView::RubberBandDrag) QGraphicsView::mouseMoveEvent(event); return; } if (event->buttons() != Qt::NoButton) { bool move = (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance(); + if (m_dragItem && move) m_clipDrag = true; if (m_dragItem && m_tool == SELECTTOOL) { - if (m_operationMode == MOVE && move) { - //m_dragItem->setProperty("y_absolute", event->pos().y()); + if (m_operationMode == MOVE && m_clipDrag) { QGraphicsView::mouseMoveEvent(event); // If mouse is at a border of the view, scroll if (pos < 5) { @@ -443,7 +471,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) if (parent) parent->resizeStart((int)(snappedPos - m_dragItemInfo.startPos.frames(m_document->fps()))); } else { - m_dragItem->resizeStart((int)(snappedPos)); + m_dragItem->resizeStart((int)(snappedPos), true, false); } QString crop = m_document->timecode().getDisplayTimecode(m_dragItem->cropStart(), KdenliveSettings::frametimecode()); QString duration = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration(), KdenliveSettings::frametimecode()); @@ -456,7 +484,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) if (parent) parent->resizeEnd((int)(snappedPos - m_dragItemInfo.endPos.frames(m_document->fps()))); } else { - m_dragItem->resizeEnd((int)(snappedPos)); + m_dragItem->resizeEnd((int)(snappedPos), false); } QString duration = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration(), KdenliveSettings::frametimecode()); QString offset = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration() - m_dragItemInfo.cropDuration, KdenliveSettings::frametimecode()); @@ -488,7 +516,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) // Make sure there is no collision QList children = m_selectionGroup->childItems(); - QPainterPath shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0)); + QPainterPath shape = m_selectionGroup->clipGroupSpacerShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0)); QList collidingItems = scene()->items(shape, Qt::IntersectsItemShape); collidingItems.removeAll(m_selectionGroup); for (int i = 0; i < children.count(); i++) { @@ -514,7 +542,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) } snappedPos += offset; // make sure we have no collision - shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0)); + shape = m_selectionGroup->clipGroupSpacerShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0)); collidingItems = scene()->items(shape, Qt::IntersectsItemShape); collidingItems.removeAll(m_selectionGroup); for (int i = 0; i < children.count(); i++) { @@ -590,11 +618,8 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) if (m_tool == RAZORTOOL) { setCursor(m_razorCursor); - //QGraphicsView::mouseMoveEvent(event); - //return; } else if (m_tool == SPACERTOOL) { setCursor(m_spacerCursor); - return; } QList itemList = items(event->pos()); @@ -603,12 +628,18 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) if (itemList.count() == 1 && itemList.at(0)->type() == GUIDEITEM) { opMode = MOVEGUIDE; + setCursor(Qt::SplitHCursor); } else for (int i = 0; i < itemList.count(); i++) { - if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) { - item = (QGraphicsRectItem*) itemList.at(i); - break; - } - } + if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) { + item = (QGraphicsRectItem*) itemList.at(i); + break; + } + } + + if (m_tool == SPACERTOOL) { + event->accept(); + return; + } if (item && event->buttons() == Qt::NoButton) { AbstractClipItem *clip = static_cast (item); @@ -704,15 +735,16 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) return; } else if (opMode == MOVEGUIDE) { m_moveOpMode = opMode; - setCursor(Qt::SplitHCursor); } else { removeTipAnimation(); setCursor(Qt::ArrowCursor); if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) { QGraphicsView::mouseMoveEvent(event); m_moveOpMode = SEEK; - seekCursorPos(mappedXPos); - slotCheckPositionScrolling(); + if (mappedXPos != m_document->renderer()->getCurrentSeekPosition() && mappedXPos != cursorPos()) { + seekCursorPos(mappedXPos); + slotCheckPositionScrolling(); + } return; } else m_moveOpMode = NONE; } @@ -724,6 +756,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) { setFocus(Qt::MouseFocusReason); m_menuPosition = QPoint(); + m_clipDrag = false; // special cases (middle click button or ctrl / shift click if (event->button() == Qt::MidButton) { @@ -739,6 +772,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) setDragMode(QGraphicsView::RubberBandDrag); if (!(event->modifiers() & Qt::ControlModifier)) { resetSelectionGroup(); + if (m_dragItem) { + emit clipItemSelected(NULL); + m_dragItem = NULL; + } scene()->clearSelection(); } m_blockRefresh = false; @@ -751,7 +788,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) m_dragGuide = NULL; if (m_tool != RAZORTOOL) activateMonitor(); - else if (m_document->renderer()->playSpeed() != 0.0) { + else if (m_document->renderer()->isPlaying()) { m_document->renderer()->pause(); return; } @@ -762,12 +799,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) if (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && collisionList.count() == 0) { // Pressing Ctrl + left mouse button in an empty area scrolls the timeline setDragMode(QGraphicsView::ScrollHandDrag); - QGraphicsView::mousePressEvent(event); m_blockRefresh = false; - m_operationMode = NONE; + m_operationMode = SCROLLTIMELINE; + QGraphicsView::mousePressEvent(event); return; } - // if a guide and a clip were pressed, just select the guide for (int i = 0; i < collisionList.count(); ++i) { if (collisionList.at(i)->type() == GUIDEITEM) { @@ -792,21 +828,42 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) AbstractGroupItem *dragGroup = NULL; AbstractClipItem *collisionClip = NULL; bool found = false; + QStringList lockedTracks; + double yOffset = 0; + m_selectionMutex.lock(); while (!m_dragGuide && ct < collisionList.count()) { if (collisionList.at(ct)->type() == AVWIDGET || collisionList.at(ct)->type() == TRANSITIONWIDGET) { collisionClip = static_cast (collisionList.at(ct)); - if (collisionClip->isItemLocked()) - break; - if (collisionClip == m_dragItem) + if (collisionClip->isItemLocked() || !collisionClip->isEnabled()) { + ct++; + continue; + } + if (collisionClip == m_dragItem) { collisionClip = NULL; - else + } + else { m_dragItem = collisionClip; + } found = true; - m_dragItem->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y()); + for (int i = 0; i < m_document->tracksCount(); i++) { + if (m_document->trackInfoAt(i).isLocked) lockedTracks << QString::number(m_document->tracksCount() - i - 1); + } + yOffset = mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y(); + m_dragItem->setProperty("y_absolute", yOffset); + m_dragItem->setProperty("locked_tracks", lockedTracks); m_dragItemInfo = m_dragItem->info(); - if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) { - // kDebug()<<"// KLIK FOUND GRP: "<sceneBoundingRect(); - dragGroup = static_cast (m_dragItem->parentItem()); + if (m_selectionGroup) { + m_selectionGroup->setProperty("y_absolute", yOffset); + m_selectionGroup->setProperty("locked_tracks", lockedTracks); + } + if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) { + QGraphicsItem *topGroup = m_dragItem->parentItem(); + while (topGroup->parentItem() && topGroup->parentItem()->type() == GROUPWIDGET && topGroup->parentItem() != m_selectionGroup) { + topGroup = topGroup->parentItem(); + } + dragGroup = static_cast (topGroup); + dragGroup->setProperty("y_absolute", yOffset); + dragGroup->setProperty("locked_tracks", lockedTracks); } break; } @@ -816,30 +873,38 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) if (m_dragItem) emit clipItemSelected(NULL); m_dragItem = NULL; } -#if QT_VERSION >= 0x040600 + +#if QT_VERSION >= 0x040800 // Add shadow to dragged item, currently disabled because of painting artifacts - //TODO: re-enable when fixed - /*QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect(); - eff->setBlurRadius(5); - eff->setOffset(3, 3); - m_dragItem->setGraphicsEffect(eff);*/ + /*if (m_dragItem) { + QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect(); + eff->setBlurRadius(5); + eff->setOffset(3, 3); + m_dragItem->setGraphicsEffect(eff); + }*/ #endif - if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) { + if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET && m_dragItem->isEnabled()) { // update transition menu action m_autoTransition->setChecked(static_cast(m_dragItem)->isAutomatic()); m_autoTransition->setEnabled(true); - } else m_autoTransition->setEnabled(false); - + // A transition is selected + QPoint p; + ClipItem *transitionClip = getClipItemAt(m_dragItemInfo.startPos, m_dragItemInfo.track); + if (transitionClip && transitionClip->baseClip()) { + QString size = transitionClip->baseClip()->getProperty("frame_size"); + double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble(); + if (factor == 0) factor = 1.0; + p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5)); + p.setY(size.section('x', 1, 1).toInt()); + } + emit transitionItemSelected(static_cast (m_dragItem), getPreviousVideoTrack(m_dragItem->track()), p); + } else { + emit transitionItemSelected(NULL); + m_autoTransition->setEnabled(false); + } // context menu requested if (event->button() == Qt::RightButton) { - if (m_dragItem) { - if (dragGroup) dragGroup->setSelected(true); - else if (!m_dragItem->isSelected()) { - resetSelectionGroup(false); - m_scene->clearSelection(); - m_dragItem->setSelected(true); - } - } else if (!m_dragGuide) { + if (!m_dragItem && !m_dragGuide) { // check if there is a guide close to mouse click QList guidesCollisionList = items(event->pos().x() - 5, event->pos().y(), 10, 2); // a rect of height < 2 does not always collide with the guide for (int i = 0; i < guidesCollisionList.count(); i++) { @@ -857,17 +922,17 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) } m_operationMode = NONE; + if (dragGroup == NULL) { + if (m_dragItem && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) + dragGroup = static_cast (m_dragItem->parentItem()); + } displayContextMenu(event->globalPos(), m_dragItem, dragGroup); m_menuPosition = m_clickEvent; - m_dragItem = NULL; - event->accept(); - return; } - + m_selectionMutex.unlock(); // No item under click if (m_dragItem == NULL || m_tool == SPACERTOOL) { resetSelectionGroup(false); - setCursor(Qt::ArrowCursor); m_scene->clearSelection(); //event->accept(); updateClipTypeActions(NULL); @@ -901,6 +966,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) QList offsetList; // create group to hold selected items + m_selectionMutex.lock(); m_selectionGroup = new AbstractGroupItem(m_document->fps()); scene()->addItem(m_selectionGroup); @@ -910,8 +976,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) if (item->isItemLocked()) continue; offsetList.append(item->startPos()); offsetList.append(item->endPos()); - m_selectionGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(selection.at(i)); } else if (/*selection.at(i)->parentItem() == 0 && */selection.at(i)->type() == GROUPWIDGET) { if (static_cast(selection.at(i))->isItemLocked()) continue; QList children = selection.at(i)->childItems(); @@ -920,16 +985,14 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) offsetList.append(item->startPos()); offsetList.append(item->endPos()); } - m_selectionGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(selection.at(i)); } else if (selection.at(i)->parentItem() && !selection.contains(selection.at(i)->parentItem())) { if (static_cast(selection.at(i)->parentItem())->isItemLocked()) continue; - //AbstractGroupItem *grp = static_cast(selection.at(i)->parentItem()); - m_selectionGroup->addToGroup(selection.at(i)->parentItem()); - selection.at(i)->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(selection.at(i)->parentItem()); } } m_spacerOffset = m_selectionGroup->sceneBoundingRect().left() - (int)(mapToScene(m_clickEvent).x()); + m_selectionMutex.unlock(); if (!offsetList.isEmpty()) { qSort(offsetList); QList cleandOffsetList; @@ -943,10 +1006,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) updateSnapPoints(NULL, cleandOffsetList, true); } m_operationMode = SPACER; - } else { + } else if (event->button() != Qt::RightButton) { + setCursor(Qt::ArrowCursor); seekCursorPos((int)(mapToScene(event->x(), 0).x())); } - //QGraphicsView::mousePressEvent(event); + QGraphicsView::mousePressEvent(event); event->ignore(); return; } @@ -961,8 +1025,8 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) if (m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { razorGroup((AbstractGroupItem *)m_dragItem->parentItem(), cutPos); } else { - AbstractClipItem *clip = static_cast (m_dragItem); - RazorClipCommand* command = new RazorClipCommand(this, clip->info(), cutPos); + ClipItem *clip = static_cast (m_dragItem); + RazorClipCommand* command = new RazorClipCommand(this, clip->info(), clip->effectList(), cutPos); m_commandStack->push(command); } setDocumentModified(); @@ -973,34 +1037,82 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) } bool itemSelected = false; - if (m_dragItem->isSelected()) + if (m_dragItem->isSelected()) { itemSelected = true; - else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) + } + else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) { itemSelected = true; - else if (dragGroup && dragGroup->isSelected()) + } + else if (dragGroup && dragGroup->isSelected()) { itemSelected = true; + } - if (event->modifiers() == Qt::ControlModifier || itemSelected == false) { + if ((event->modifiers() == Qt::ControlModifier) || itemSelected == false) { if (event->modifiers() != Qt::ControlModifier) { resetSelectionGroup(false); m_scene->clearSelection(); // A refresh seems necessary otherwise in zoomed mode, some clips disappear viewport()->update(); - } else resetSelectionGroup(); - dragGroup = NULL; - if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) { - dragGroup = static_cast (m_dragItem->parentItem()); - } + } else { + resetSelectionGroup(); + } + /*if () { + dragGroup = NULL; + if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) { + dragGroup = static_cast (m_dragItem->parentItem()); + } + }*/ + bool selected = !m_dragItem->isSelected(); - if (dragGroup) + m_dragItem->setZValue(99); + if (m_dragItem->parentItem()) m_dragItem->parentItem()->setZValue(99); + QGraphicsView::mousePressEvent(event); + + if (dragGroup) { dragGroup->setSelected(selected); + QList children = dragGroup->childItems(); + for (int i = 0; i < children.count(); i++) { + children.at(i)->setSelected(selected); + } + if (dragGroup->parentItem()) { + dragGroup->parentItem()->setSelected(selected); + } + } else m_dragItem->setSelected(selected); - - groupSelectedItems(); - ClipItem *clip = static_cast (m_dragItem); - updateClipTypeActions(dragGroup == NULL ? clip : NULL); - m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); + if (selected == false) { + m_dragItem = NULL; + } + groupSelectedItems(QList (), false, true); + m_selectionMutex.lock(); + if (m_selectionGroup) { + m_selectionGroup->setProperty("y_absolute", yOffset); + m_selectionGroup->setProperty("locked_tracks", lockedTracks); + } + m_selectionMutex.unlock(); + if (m_dragItem) { + ClipItem *clip = static_cast (m_dragItem); + updateClipTypeActions(dragGroup == NULL ? clip : NULL); + m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); + } + else updateClipTypeActions(NULL); + } + else { + QGraphicsView::mousePressEvent(event); + m_selectionMutex.lock(); + if (m_selectionGroup) { + QList children = m_selectionGroup->childItems(); + for (int i = 0; i < children.count(); i++) { + children.at(i)->setSelected(itemSelected); + } + m_selectionGroup->setSelected(itemSelected); + + } + if (dragGroup) { + dragGroup->setSelected(itemSelected); + } + m_dragItem->setSelected(itemSelected); + m_selectionMutex.unlock(); } if (collisionClip != NULL || m_dragItem == NULL) { @@ -1013,9 +1125,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) } // If clicked item is selected, allow move - if (event->modifiers() != Qt::ControlModifier && m_operationMode == NONE) QGraphicsView::mousePressEvent(event); + //if (!(event->modifiers() | Qt::ControlModifier) && m_operationMode == NONE) + //QGraphicsView::mousePressEvent(event); - m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y())); + if (m_dragItem) { + m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y())); if (m_selectionGroup && m_dragItem->parentItem() == m_selectionGroup) { // all other modes break the selection, so the user probably wants to move it m_operationMode = MOVE; @@ -1026,6 +1140,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) } else m_operationMode = m_dragItem->operationMode(mapToScene(event->pos())); } + } else m_operationMode = NONE; m_controlModifier = (event->modifiers() == Qt::ControlModifier); // Update snap points @@ -1035,6 +1150,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) else updateSnapPoints(m_dragItem); } else { + m_selectionMutex.lock(); QList offsetList; QList children = m_selectionGroup->childItems(); for (int i = 0; i < children.count(); i++) { @@ -1056,6 +1172,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) } updateSnapPoints(NULL, cleandOffsetList, true); } + m_selectionMutex.unlock(); } if (m_operationMode == KEYFRAME) { @@ -1134,10 +1251,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) resetSelectionGroup(false); m_dragItem->setSelected(true); } - m_blockRefresh = false; - //kDebug()<clearSelection(); - + m_selectionMutex.lock(); + if (group == m_selectionGroup) m_selectionGroup = NULL; QList 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); + for (int i = 0; i < children.count(); i++) { + group->removeFromGroup(children.at(i)); + } + scene()->destroyItemGroup(group); + m_selectionMutex.unlock(); + groupSelectedItems(children, group != m_selectionGroup, true); } } void CustomTrackView::resetSelectionGroup(bool selectItems) { + QMutexLocker lock(&m_selectionMutex); if (m_selectionGroup) { // delete selection group bool snap = KdenliveSettings::snaptopoints(); @@ -1179,99 +1295,134 @@ void CustomTrackView::resetSelectionGroup(bool selectItems) QList children = m_selectionGroup->childItems(); scene()->destroyItemGroup(m_selectionGroup); + m_selectionGroup = NULL; for (int i = 0; i < children.count(); i++) { - if (children.at(i)->parentItem() == 0 && (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)) { - if (!static_cast (children.at(i))->isItemLocked()) { - children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true); - children.at(i)->setSelected(selectItems); - } - } else if (children.at(i)->type() == GROUPWIDGET) { - children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true); - children.at(i)->setSelected(selectItems); + if (children.at(i)->parentItem() == 0) { + if ((children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)) { + if (!static_cast (children.at(i))->isItemLocked()) { + children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true); + children.at(i)->setSelected(selectItems); + } + } else if (children.at(i)->type() == GROUPWIDGET) { + children.at(i)->setFlag(QGraphicsItem::ItemIsMovable, true); + children.at(i)->setSelected(selectItems); + } } } - - m_selectionGroup = NULL; KdenliveSettings::setSnaptopoints(snap); } } -void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup) +void CustomTrackView::groupSelectedItems(QList selection, bool createNewGroup, bool selectNewGroup) { + QMutexLocker lock(&m_selectionMutex); if (m_selectionGroup) { kDebug() << "///// ERROR, TRYING TO OVERRIDE EXISTING GROUP"; return; } - QList selection = m_scene->selectedItems(); - if (selection.isEmpty()) return; - QRectF rectUnion; - // Find top left position of selection + if (selection.isEmpty()) selection = m_scene->selectedItems(); + // Split groups and items + QSet groupsList; + QSet itemsList; + for (int i = 0; i < selection.count(); i++) { - if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) { - rectUnion = rectUnion.united(selection.at(i)->sceneBoundingRect()); - } else if (selection.at(i)->parentItem()) { - rectUnion = rectUnion.united(selection.at(i)->parentItem()->sceneBoundingRect()); - } + if (selectNewGroup) selection.at(i)->setSelected(true); + if (selection.at(i)->type() == GROUPWIDGET) { + AbstractGroupItem *it = static_cast (selection.at(i)); + while (it->parentItem() && it->parentItem()->type() == GROUPWIDGET) { + it = static_cast (it->parentItem()); + } + if (!it || it->isItemLocked()) continue; + groupsList.insert(it); + } + } + for (int i = 0; i < selection.count(); i++) { + if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) { + if (selection.at(i)->parentItem() && selection.at(i)->parentItem()->type() == GROUPWIDGET) { + AbstractGroupItem *it = static_cast (selection.at(i)->parentItem()); + while (it->parentItem() && it->parentItem()->type() == GROUPWIDGET) { + it = static_cast (it->parentItem()); + } + if (!it || it->isItemLocked()) continue; + groupsList.insert(it); + } + else { + AbstractClipItem *it = static_cast (selection.at(i)); + if (!it || it->isItemLocked()) continue; + itemsList.insert(selection.at(i)); + } + } + } + if (itemsList.isEmpty() && groupsList.isEmpty()) return; + if (itemsList.count() == 1 && groupsList.isEmpty()) { + // only one item selected: + QSetIterator it(itemsList); + m_dragItem = static_cast(it.next()); + m_dragItem->setSelected(true); + return; } - 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); + QRectF rectUnion; + // Find top left position of selection + foreach (const QGraphicsItemGroup *value, groupsList) { + rectUnion = rectUnion.united(value->sceneBoundingRect()); + } + foreach (const QGraphicsItem *value, itemsList) { + rectUnion = rectUnion.united(value->sceneBoundingRect()); + } + 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); - // Check if we are trying to include a group in a group - QList groups; - for (int i = 0; i < selection.count(); i++) { - if (selection.at(i)->type() == GROUPWIDGET && !groups.contains(static_cast(selection.at(i)))) - groups.append(static_cast(selection.at(i))); - else if (selection.at(i)->parentItem() && !groups.contains(static_cast(selection.at(i)->parentItem()))) - groups.append(static_cast(selection.at(i)->parentItem())); - } - if (!groups.isEmpty()) { - // ungroup previous groups - while (!groups.isEmpty()) { - AbstractGroupItem *grp = groups.takeFirst(); - m_document->clipManager()->removeGroup(grp); - scene()->destroyItemGroup(grp); - } - selection = m_scene->selectedItems(); - } + // Check if we are trying to include a group in a group + foreach (QGraphicsItemGroup *value, groupsList) { + newGroup->addItem(value); + } + + 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); + if (grp == m_selectionGroup) m_selectionGroup = NULL; + scene()->destroyItemGroup(grp); + } - for (int i = 0; i < selection.count(); i++) { - if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) { - newGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); - } - } - KdenliveSettings::setSnaptopoints(snap); - } 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); + } + scene()->addItem(newGroup); + 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); - for (int i = 0; i < selection.count(); i++) { - if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) { - m_selectionGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); - } - } - KdenliveSettings::setSnaptopoints(snap); - if (m_selectionGroup) { - m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps()); - m_selectionGroupInfo.track = m_selectionGroup->track(); - } + 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); } - } else resetSelectionGroup(); + } } void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) @@ -1302,10 +1453,14 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) } else*/ { // add keyframe GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart(); + int single = m_dragItem->checkForSingleKeyframe(); int val = m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y()); ClipItem * item = static_cast (m_dragItem); + QDomElement oldEffect = item->selectedEffect().cloneNode().toElement(); + if (single > -1) { + item->insertKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), (item->cropStart() + item->cropDuration()).frames(m_document->fps()) - 1, single); + } //QString previous = item->keyframes(item->selectedEffectIndex()); - QDomElement oldEffect = item->selectedEffect().cloneNode().toElement(); item->insertKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), keyFramePos.frames(m_document->fps()), val); //item->updateKeyframeEffect(); //QString next = item->keyframes(item->selectedEffectIndex()); @@ -1449,7 +1604,7 @@ void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip, Abs //build go to marker menu if (item->baseClip()) { QList markers = item->baseClip()->commentedSnapMarkers(); - int offset = item->startPos().frames(m_document->fps()); + int offset = (item->startPos()- item->cropStart()).frames(m_document->fps()); if (!markers.isEmpty()) { for (int i = 0; i < markers.count(); i++) { int pos = (int) markers.at(i).time().frames(m_document->timecode().fps()); @@ -1489,14 +1644,28 @@ void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out) pasteInfo.startPos = GenTime(m_cursorPos, m_document->fps()); pasteInfo.endPos = pasteInfo.startPos + info.endPos; pasteInfo.track = selectedTrack(); - if (!canBePastedTo(pasteInfo, AVWIDGET)) { + bool ok = canBePastedTo(pasteInfo, AVWIDGET); + if (!ok) { + // Cannot be inserted at cursor pos, insert at end of track + int duration = m_document->renderer()->mltTrackDuration(m_document->tracksCount() - pasteInfo.track) + 1; + pasteInfo.startPos = GenTime(duration, m_document->fps()); + pasteInfo.endPos = pasteInfo.startPos + info.endPos; + ok = canBePastedTo(pasteInfo, AVWIDGET); + } + if (!ok) { emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage); return; } - AddTimelineClipCommand *command = new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), pasteInfo, EffectsList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false); - updateTrackDuration(pasteInfo.track, command); - m_commandStack->push(command); + // Add refresh command for undo + QUndoCommand *addCommand = new QUndoCommand(); + addCommand->setText(i18n("Add timeline clip")); + new RefreshMonitorCommand(this, false, true, addCommand); + new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), pasteInfo, EffectsList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false, addCommand); + new RefreshMonitorCommand(this, true, false, addCommand); + updateTrackDuration(pasteInfo.track, addCommand); + + m_commandStack->push(addCommand); selectClip(true, false); // Automatic audio split @@ -1506,10 +1675,17 @@ void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out) bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos) { - if (data->hasFormat("kdenlive/clip")) { - m_clipDrag = true; - m_scene->clearSelection(); - resetSelectionGroup(false); + QPointF framePos = mapToScene(pos); + int track = framePos.y() / KdenliveSettings::trackheight(); + m_clipDrag = data->hasFormat("kdenlive/clip") || data->hasFormat("kdenlive/producerslist"); + // This is not a clip drag, maybe effect or other... + if (!m_clipDrag) return false; + m_scene->clearSelection(); + m_dragItem = NULL; + resetSelectionGroup(false); + QMutexLocker lock(&m_selectionMutex); + if (track < 0 || track > m_document->tracksCount() - 1 || m_document->trackInfoAt(m_document->tracksCount() - track - 1).isLocked) return true; + if (data->hasFormat("kdenlive/clip")) { QStringList list = QString(data->data("kdenlive/clip")).split(';'); DocClipBase *clip = m_document->getBaseClip(list.at(0)); if (clip == NULL) { @@ -1520,7 +1696,6 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos) emit displayMessage(i18n("Clip not ready"), ErrorMessage); return false; } - QPointF framePos = mapToScene(pos); ItemInfo info; info.startPos = GenTime(); info.cropStart = GenTime(list.at(1).toInt(), m_document->fps()); @@ -1540,25 +1715,24 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos) } m_selectionGroup = new AbstractGroupItem(m_document->fps()); ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth()); - m_selectionGroup->addToGroup(item); - item->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(item); QList offsetList; offsetList.append(info.endPos); updateSnapPoints(NULL, offsetList); + QStringList lockedTracks; + for (int i = 0; i < m_document->tracksCount(); i++) { + if (m_document->trackInfoAt(i).isLocked) lockedTracks << QString::number(m_document->tracksCount() - i - 1); + } + m_selectionGroup->setProperty("locked_tracks", lockedTracks); m_selectionGroup->setPos(framePos); scene()->addItem(m_selectionGroup); m_selectionGroup->setSelected(true); - return true; } else if (data->hasFormat("kdenlive/producerslist")) { - m_clipDrag = true; QStringList ids = QString(data->data("kdenlive/producerslist")).split(';'); - m_scene->clearSelection(); - resetSelectionGroup(false); QList offsetList; QList infoList; - QPointF framePos = mapToScene(pos); GenTime start = GenTime((int)(framePos.x() + 0.5), m_document->fps()); int track = (int)(framePos.y() / m_tracksHeight); framePos.setX((int)(framePos.x() + 0.5)); @@ -1566,7 +1740,8 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos) // Check if clips can be inserted at that position for (int i = 0; i < ids.size(); ++i) { - DocClipBase *clip = m_document->getBaseClip(ids.at(i)); + QString clipData = ids.at(i); + DocClipBase *clip = m_document->getBaseClip(clipData.section('/', 0, 0)); if (clip == NULL) { kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(i); return false; @@ -1577,44 +1752,72 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos) } ItemInfo info; info.startPos = start; - info.cropDuration = clip->duration(); - info.endPos = info.startPos + info.cropDuration; + if (clipData.contains('/')) { + // this is a clip zone, set in / out + int in = clipData.section('/', 1, 1).toInt(); + int out = clipData.section('/', 2, 2).toInt(); + info.cropStart = GenTime(in, m_document->fps()); + info.cropDuration = GenTime(out - in, m_document->fps()); + } + else { + info.cropDuration = clip->duration(); + } + info.endPos = info.startPos + info.cropDuration; info.track = track; infoList.append(info); - start += clip->duration(); + start += info.cropDuration; } if (!canBePastedTo(infoList, AVWIDGET)) { return true; } - m_selectionGroup = new AbstractGroupItem(m_document->fps()); + if (ids.size() > 1) m_selectionGroup = new AbstractGroupItem(m_document->fps()); start = GenTime(); for (int i = 0; i < ids.size(); ++i) { - DocClipBase *clip = m_document->getBaseClip(ids.at(i)); + QString clipData = ids.at(i); + DocClipBase *clip = m_document->getBaseClip(clipData.section('/', 0, 0)); ItemInfo info; info.startPos = start; - info.cropDuration = clip->duration(); - info.endPos = info.startPos + info.cropDuration; + if (clipData.contains('/')) { + // this is a clip zone, set in / out + int in = clipData.section('/', 1, 1).toInt(); + int out = clipData.section('/', 2, 2).toInt(); + info.cropStart = GenTime(in, m_document->fps()); + info.cropDuration = GenTime(out - in, m_document->fps()); + } + else { + info.cropDuration = clip->duration(); + } + info.endPos = info.startPos + info.cropDuration; info.track = 0; start += info.cropDuration; offsetList.append(start); ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth(), false); - item->setFlag(QGraphicsItem::ItemIsMovable, false); - m_selectionGroup->addToGroup(item); + if (ids.size() > 1) m_selectionGroup->addItem(item); + else m_dragItem = item; + item->setSelected(true); if (!clip->isPlaceHolder()) m_waitingThumbs.append(item); } updateSnapPoints(NULL, offsetList); - m_selectionGroup->setPos(framePos); - scene()->addItem(m_selectionGroup); + QStringList lockedTracks; + for (int i = 0; i < m_document->tracksCount(); i++) { + if (m_document->trackInfoAt(i).isLocked) lockedTracks << QString::number(m_document->tracksCount() - i - 1); + } + + if (m_selectionGroup) { + m_selectionGroup->setProperty("locked_tracks", lockedTracks); + m_selectionGroup->setPos(framePos); + scene()->addItem(m_selectionGroup); + } + else if (m_dragItem) { + m_dragItem->setProperty("locked_tracks", lockedTracks); + m_dragItem->setPos(framePos); + scene()->addItem(m_dragItem); + } //m_selectionGroup->setZValue(10); m_thumbsTimer.start(); - return true; - - } else { - // the drag is not a clip (may be effect, ...) - m_clipDrag = false; - return false; } + return true; } @@ -1701,10 +1904,12 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) return; } EffectsParameterList params = clip->addEffect(effect); - if (!m_document->renderer()->mltAddEffect(track, pos, params)) + if (!m_document->renderer()->mltAddEffect(track, pos, params)) { emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage); - clip->setSelectedEffect(params.paramValue("kdenlive_ix").toInt()); - if (clip->isSelected()) emit clipItemSelected(clip); + clip->deleteEffect(params.paramValue("kdenlive_ix")); + } + else clip->setSelectedEffect(params.paramValue("kdenlive_ix").toInt()); + if (clip->isMainSelectedClip()) emit clipItemSelected(clip); } else emit displayMessage(i18n("Cannot find clip to add effect"), ErrorMessage); } @@ -1739,12 +1944,12 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) } ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track); if (clip) { - clip->deleteEffect(index); - emit clipItemSelected(clip); + clip->deleteEffect(index); + if (clip->isMainSelectedClip()) emit clipItemSelected(clip); } } -void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group) +void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group, AbstractClipItem *dropTarget) { QList itemList = group->childItems(); QUndoCommand *effectCommand = new QUndoCommand(); @@ -1755,6 +1960,9 @@ void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem * else effectName = i18n("effect"); effectCommand->setText(i18n("Add %1", effectName)); for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == GROUPWIDGET) { + itemList << itemList.at(i)->childItems(); + } if (itemList.at(i)->type() == AVWIDGET) { ClipItem *item = static_cast (itemList.at(i)); if (effect.tagName() == "effectgroup") { @@ -1783,6 +1991,12 @@ void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem * m_commandStack->push(effectCommand); setDocumentModified(); } else delete effectCommand; + if (dropTarget) { + clearSelection(false); + m_dragItem = dropTarget; + m_dragItem->setSelected(true); + emit clipItemSelected(static_cast(dropTarget)); + } } void CustomTrackView::slotAddEffect(ClipItem *clip, QDomElement effect) @@ -1790,12 +2004,27 @@ void CustomTrackView::slotAddEffect(ClipItem *clip, QDomElement effect) if (clip) slotAddEffect(effect, clip->startPos(), clip->track()); } +void CustomTrackView::slotDropEffect(ClipItem *clip, QDomElement effect, GenTime pos, int track) +{ + if (clip == NULL) return; + slotAddEffect(effect, pos, track); + if (clip->parentItem()) { + // Clip is in a group, should not happen + kDebug()<<"/// DROPPED ON ITEM IN GRP"; + } + else if (clip != m_dragItem) { + clearSelection(false); + m_dragItem = clip; + clip->setSelected(true); + emit clipItemSelected(clip); + } +} + void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) { QList itemList; QUndoCommand *effectCommand = new QUndoCommand(); QString effectName; - int offset = effect.attribute("clipstart").toInt(); if (effect.tagName() == "effectgroup") { effectName = effect.attribute("name"); @@ -1849,22 +2078,34 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) if (effectCommand->childCount() > 0) { m_commandStack->push(effectCommand); setDocumentModified(); - if (effectCommand->childCount() == 1) { + /*if (effectCommand->childCount() == 1) { // Display newly added clip effect for (int i = 0; i < itemList.count(); i++) { if (itemList.at(i)->type() == AVWIDGET) { ClipItem *clip = static_cast(itemList.at(i)); clip->setSelectedEffect(clip->effectsCount()); - if (!clip->isSelected()) { + if (!clip->isSelected() && (!m_dragItem || !itemList.contains(m_dragItem))) { + kDebug()<<"// CLIP WAS NO SELECTED, DRG: "<<(m_dragItem == NULL); clearSelection(false); clip->setSelected(true); m_dragItem = clip; emit clipItemSelected(clip); + break; } - break; } } } + else { + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == AVWIDGET) { + ClipItem *clip = static_cast(itemList.at(i)); + if (clip->isMainSelectedClip()) { + emit clipItemSelected(clip); + break; + } + } + } + }*/ } else delete effectCommand; } @@ -2191,7 +2432,7 @@ void CustomTrackView::slotUpdateClipRegion(ClipItem *clip, int ix, QString regio m_commandStack->push(command); } -ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, bool execute) +ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, EffectsList oldStack, bool execute) { if (cut) { // cut clip @@ -2252,17 +2493,23 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo item->resizeEnd(cutPos); scene()->addItem(dup); - if (item->checkKeyFrames()) + + if (item->checkKeyFrames(m_document->width(), m_document->height(), info.cropDuration.frames(m_document->fps()))) slotRefreshEffects(item); - if (dup->checkKeyFrames()) + + if (dup->checkKeyFrames(m_document->width(), m_document->height(), info.cropDuration.frames(m_document->fps()), cutTime.frames(m_document->fps()))) slotRefreshEffects(dup); item->baseClip()->addReference(); m_document->updateClip(item->baseClip()->getId()); setDocumentModified(); KdenliveSettings::setSnaptopoints(snap); - if (execute && item->isSelected()) - emit clipItemSelected(item); + if (execute && item->isSelected()) { + m_scene->clearSelection(); + dup->setSelected(true); + m_dragItem = dup; + emit clipItemSelected(dup); + } return dup; } else { // uncut clip @@ -2283,18 +2530,6 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo bool snap = KdenliveSettings::snaptopoints(); KdenliveSettings::setSnaptopoints(false); - // join fade effects again - int ix = dup->hasEffect(QString(), "fadeout"); - if (ix != -1) { - QDomElement effect = dup->effectAtIndex(ix); - item->addEffect(effect); - } - ix = dup->hasEffect(QString(), "fade_to_black"); - if (ix != -1) { - QDomElement effect = dup->effectAtIndex(ix); - item->addEffect(effect); - } - m_waitingThumbs.removeAll(dup); bool selected = item->isSelected(); if (dup->isSelected()) { @@ -2310,9 +2545,10 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo ItemInfo clipinfo = item->info(); clipinfo.track = m_document->tracksCount() - clipinfo.track; - bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos); + bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos, false); if (success) { item->resizeEnd((int) info.endPos.frames(m_document->fps())); + item->setEffectList(oldStack); setDocumentModified(); } else { emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); @@ -2515,7 +2751,11 @@ void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) m_selectionGroup->setPos(pos); emit mousePosition((int)(m_selectionGroup->scenePos().x() + 0.5)); event->acceptProposedAction(); - } else { + } else if (m_dragItem) { + m_dragItem->setPos(pos); + emit mousePosition((int)(m_dragItem->scenePos().x() + 0.5)); + event->acceptProposedAction(); + } else { // Drag enter was not possible, try again at mouse position insertDropClips(event->mimeData(), event->pos()); event->accept(); @@ -2527,26 +2767,37 @@ void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) void CustomTrackView::dragLeaveEvent(QDragLeaveEvent * event) { - if (m_selectionGroup && m_clipDrag) { + if ((m_selectionGroup || m_dragItem) && m_clipDrag) { m_thumbsTimer.stop(); m_waitingThumbs.clear(); - QList items = m_selectionGroup->childItems(); + QList items; + QMutexLocker lock(&m_selectionMutex); + if (m_selectionGroup) items = m_selectionGroup->childItems(); + else if (m_dragItem) items.append(m_dragItem); qDeleteAll(items); - scene()->destroyItemGroup(m_selectionGroup); + if (m_selectionGroup) scene()->destroyItemGroup(m_selectionGroup); m_selectionGroup = NULL; + m_dragItem = NULL; + event->accept(); } else QGraphicsView::dragLeaveEvent(event); } void CustomTrackView::dropEvent(QDropEvent * event) { - if (m_selectionGroup && m_clipDrag) { - QList items = m_selectionGroup->childItems(); + if ((m_selectionGroup || m_dragItem) && m_clipDrag) { + QList items; + if (m_selectionGroup) items = m_selectionGroup->childItems(); + else if (m_dragItem) items.append(m_dragItem); resetSelectionGroup(); + m_dragItem = NULL; m_scene->clearSelection(); bool hasVideoClip = false; QUndoCommand *addCommand = new QUndoCommand(); addCommand->setText(i18n("Add timeline clip")); QList brokenClips; + + // Add refresh command for undo + new RefreshMonitorCommand(this, false, true, addCommand); for (int i = 0; i < items.count(); i++) { ClipItem *item = static_cast (items.at(i)); @@ -2581,12 +2832,17 @@ void CustomTrackView::dropEvent(QDropEvent * event) updateTrackDuration(info.track, addCommand); if (item->baseClip()->isTransparent() && getTransitionItemAtStart(info.startPos, info.track) == NULL) { - // add transparency transition - QDomElement trans = MainWindow::transitions.getEffectByTag("composite", "composite").cloneNode().toElement(); - new AddTransitionCommand(this, info, getPreviousVideoTrack(info.track), trans, false, true, addCommand); + // add transparency transition if space is available + if (canBePastedTo(info, TRANSITIONWIDGET)) { + QDomElement trans = MainWindow::transitions.getEffectByTag("affine", QString()).cloneNode().toElement(); + new AddTransitionCommand(this, info, getPreviousVideoTrack(info.track), trans, false, true, addCommand); + } } item->setSelected(true); } + // Add refresh command for redo + new RefreshMonitorCommand(this, false, false, addCommand); + qDeleteAll(brokenClips); brokenClips.clear(); if (addCommand->childCount() > 0) m_commandStack->push(addCommand); @@ -2617,11 +2873,12 @@ void CustomTrackView::dropEvent(QDropEvent * event) m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); if (items.count() > 1) { - groupSelectedItems(true); + groupSelectedItems(items); } else if (items.count() == 1) { m_dragItem = static_cast (items.at(0)); - emit clipItemSelected((ClipItem*)m_dragItem, false); + emit clipItemSelected((ClipItem*) m_dragItem, false); } + m_document->renderer()->refreshIfActive(); event->setDropAction(Qt::MoveAction); event->accept(); @@ -2661,10 +2918,12 @@ void CustomTrackView::adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInf newdupInfo.startPos = info.endPos; newdupInfo.cropStart += diff2; newdupInfo.cropDuration = clipInfo.endPos - info.endPos; - new RazorClipCommand(this, clipInfo, info.startPos, false, command); + new RazorClipCommand(this, clipInfo, clip->effectList(), info.startPos, false, command); new ResizeClipCommand(this, dupInfo, newdupInfo, false, false, command); - ClipItem *dup = cutClip(clipInfo, info.startPos, true, false); - if (dup) dup->resizeStart(info.endPos.frames(m_document->fps())); + ClipItem *dup = cutClip(clipInfo, info.startPos, true, EffectsList(), false); + if (dup) { + dup->resizeStart(info.endPos.frames(m_document->fps())); + } } else { ItemInfo newclipInfo = clip->info(); newclipInfo.endPos = info.startPos; @@ -2704,10 +2963,10 @@ void CustomTrackView::adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInf dupInfo.startPos = info.startPos; dupInfo.cropStart += diff; dupInfo.cropDuration = clipInfo.endPos - info.startPos; - new RazorClipCommand(this, clipInfo, info.startPos, false, command); + new RazorClipCommand(this, clipInfo, clip->effectList(), info.startPos, true, command); // Commented out; variable dup unused. --granjow //ClipItem *dup = cutClip(clipInfo, info.startPos, true, false); - cutClip(clipInfo, info.startPos, true, false); + //cutClip(clipInfo, info.startPos, true, false); } } // TODO: add insertspacecommand @@ -2776,6 +3035,7 @@ Qt::DropActions CustomTrackView::supportedDropActions() const void CustomTrackView::setDuration(int duration) { + if (m_projectDuration == duration) return; int diff = qAbs(duration - sceneRect().width()); if (diff * matrix().m11() > -50) { if (matrix().m11() < 0.4) setSceneRect(0, 0, (duration + 100 / matrix().m11()), sceneRect().height()); @@ -2804,13 +3064,12 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) QRectF r(0, startY, sceneRect().width(), sceneRect().height() - startY); QList selection = m_scene->items(r); resetSelectionGroup(); - + m_selectionMutex.lock(); m_selectionGroup = new AbstractGroupItem(m_document->fps()); scene()->addItem(m_selectionGroup); for (int i = 0; i < selection.count(); i++) { if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) { - m_selectionGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(selection.at(i)); } } // Move graphic items @@ -2857,19 +3116,17 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) if (tr) tr->setForcedTrack(info.forceTrack, info.a_track); else kDebug()<<"// Cannot update TRANSITION AT: "<fps()); } - + m_selectionMutex.unlock(); resetSelectionGroup(false); m_document->renderer()->unlockService(tractor); } int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); for (int i = 0; i < m_guides.count(); i++) { - QLineF l = m_guides.at(i)->line(); - l.setP2(QPointF(l.x2(), maxHeight)); - m_guides.at(i)->setLine(l); + m_guides.at(i)->setLine(0, 0, 0, maxHeight - 1); } - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1); + m_cursorLine->setLine(0, 0, 0, maxHeight - 1); setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); viewport()->update(); //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged())); @@ -2880,6 +3137,10 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) void CustomTrackView::removeTrack(int ix) { + // Clear effect stack + clearSelection(); + emit transitionItemSelected(NULL); + // Delete track in MLT playlist m_document->renderer()->mltDeleteTrack(m_document->tracksCount() - ix); m_document->deleteTrack(m_document->tracksCount() - ix - 1); @@ -2887,15 +3148,12 @@ void CustomTrackView::removeTrack(int ix) double startY = ix * (m_tracksHeight + 1) + m_tracksHeight / 2; QRectF r(0, startY, sceneRect().width(), sceneRect().height() - startY); QList selection = m_scene->items(r); - - resetSelectionGroup(); - + m_selectionMutex.lock(); m_selectionGroup = new AbstractGroupItem(m_document->fps()); scene()->addItem(m_selectionGroup); for (int i = 0; i < selection.count(); i++) { - if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) { - m_selectionGroup->addToGroup(selection.at(i)); - selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false); + if ((selection.at(i) && !selection.at(i)->parentItem() && selection.at(i)->isEnabled()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) { + m_selectionGroup->addItem(selection.at(i)); } } // Move graphic items @@ -2933,16 +3191,15 @@ void CustomTrackView::removeTrack(int ix) } } } + m_selectionMutex.unlock(); resetSelectionGroup(false); m_document->renderer()->unlockService(tractor); int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); for (int i = 0; i < m_guides.count(); i++) { - QLineF l = m_guides.at(i)->line(); - l.setP2(QPointF(l.x2(), maxHeight)); - m_guides.at(i)->setLine(l); + m_guides.at(i)->setLine(0, 0, 0, maxHeight - 1); } - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1); + m_cursorLine->setLine(0, 0, 0, maxHeight - 1); setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); m_selectedTrack = qMin(m_selectedTrack, m_document->tracksCount() - 1); @@ -3254,6 +3511,7 @@ void CustomTrackView::insertSpace(QList clipsToMove, QList t { int diff = duration.frames(m_document->fps()); resetSelectionGroup(); + m_selectionMutex.lock(); m_selectionGroup = new AbstractGroupItem(m_document->fps()); scene()->addItem(m_selectionGroup); ClipItem *clip; @@ -3272,11 +3530,9 @@ void CustomTrackView::insertSpace(QList clipsToMove, QList t clip = getClipItemAtStart(clipsToMove.at(i).startPos + offset, clipsToMove.at(i).track); if (clip) { if (clip->parentItem()) { - m_selectionGroup->addToGroup(clip->parentItem()); - clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(clip->parentItem()); } else { - m_selectionGroup->addToGroup(clip); - clip->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(clip); } if (trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track) == -1 || clipsToMove.at(i).startPos.frames(m_document->fps()) < trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track)) trackClipStartList[m_document->tracksCount() - clipsToMove.at(i).track] = clipsToMove.at(i).startPos.frames(m_document->fps()); @@ -3288,11 +3544,9 @@ void CustomTrackView::insertSpace(QList clipsToMove, QList t transition = getTransitionItemAtStart(transToMove.at(i).startPos + offset, transToMove.at(i).track); if (transition) { if (transition->parentItem()) { - m_selectionGroup->addToGroup(transition->parentItem()); - transition->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(transition->parentItem()); } else { - m_selectionGroup->addToGroup(transition); - transition->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(transition); } if (trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track) == -1 || transToMove.at(i).startPos.frames(m_document->fps()) < trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track)) trackTransitionStartList[m_document->tracksCount() - transToMove.at(i).track] = transToMove.at(i).startPos.frames(m_document->fps()); @@ -3314,6 +3568,7 @@ void CustomTrackView::insertSpace(QList clipsToMove, QList t } } } + m_selectionMutex.unlock(); resetSelectionGroup(false); if (track != -1) track = m_document->tracksCount() - track; @@ -3325,24 +3580,26 @@ void CustomTrackView::deleteClip(const QString &clipId) resetSelectionGroup(); QList itemList = items(); QUndoCommand *deleteCommand = new QUndoCommand(); + new RefreshMonitorCommand(this, false, true, deleteCommand); int count = 0; for (int i = 0; i < itemList.count(); i++) { 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); m_commandStack->push(deleteCommand); } @@ -3410,16 +3667,29 @@ void CustomTrackView::checkScrolling() void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) { if (m_moveOpMode == SEEK) m_moveOpMode = NONE; - QGraphicsView::mouseReleaseEvent(event); - setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); -#if QT_VERSION >= 0x040600 - if (m_dragItem) m_dragItem->setGraphicsEffect(NULL); + if (m_operationMode == SCROLLTIMELINE) { + m_operationMode = NONE; + setDragMode(QGraphicsView::NoDrag); + QGraphicsView::mouseReleaseEvent(event); + return; + } + if (!m_controlModifier && m_operationMode != RUBBERSELECTION) { + //event->accept(); + setDragMode(QGraphicsView::NoDrag); + if (m_clipDrag) QGraphicsView::mouseReleaseEvent(event); + } + m_clipDrag = false; + //setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); +#if QT_VERSION >= 0x040800 + if (m_dragItem) { + m_dragItem->setGraphicsEffect(NULL); + } #endif if (m_scrollTimer.isActive()) m_scrollTimer.stop(); if (event->button() == Qt::MidButton) { return; } - setDragMode(QGraphicsView::NoDrag); + if (m_operationMode == MOVEGUIDE) { setCursor(Qt::ArrowCursor); m_operationMode = NONE; @@ -3434,6 +3704,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) } m_dragGuide = NULL; m_dragItem = NULL; + QGraphicsView::mouseReleaseEvent(event); return; } else if (m_operationMode == SPACER && m_selectionGroup) { int track; @@ -3489,23 +3760,33 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) updateTrackDuration(track, command); m_commandStack->push(command); if (track != -1) track = m_document->tracksCount() - track; - kDebug() << "SPACER TRACK:" << track; m_document->renderer()->mltInsertSpace(trackClipStartList, trackTransitionStartList, track, timeOffset, GenTime()); setDocumentModified(); } } - for (int i = 0; i < groups.count(); i++) + resetSelectionGroup(); + for (int i = 0; i < groups.count(); i++) { rebuildGroup(groups.at(i)); + } - resetSelectionGroup(); clearSelection(); m_operationMode = NONE; } else if (m_operationMode == RUBBERSELECTION) { + //event->accept(); + QGraphicsView::mouseReleaseEvent(event); + setDragMode(QGraphicsView::NoDrag); + setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); + if (event->modifiers() != Qt::ControlModifier) m_dragItem = NULL; resetSelectionGroup(); groupSelectedItems(); m_operationMode = NONE; + if (m_selectionGroup == NULL && m_dragItem) { + // Only 1 item selected + if (m_dragItem->type() == AVWIDGET) + emit clipItemSelected(static_cast(m_dragItem)); + } } if (m_dragItem == NULL && m_selectionGroup == NULL) { @@ -3669,10 +3950,12 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) // Moving several clips. We need to delete them and readd them to new position, // or they might overlap each other during the move QGraphicsItemGroup *group; - if (m_selectionGroup) + if (m_selectionGroup) { group = static_cast (m_selectionGroup); - else + } + else { group = static_cast (m_dragItem->parentItem()); + } QList items = group->childItems(); QList clipsToMove; QList transitionsToMove; @@ -3756,31 +4039,43 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) if (m_selectionGroup) { m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps()); m_selectionGroupInfo.track = m_selectionGroup->track(); - - QList groupList; - for (int i = 0; i < items.count(); ++i) { - if (items.at(i)->type() == GROUPWIDGET) { - AbstractGroupItem* group = (AbstractGroupItem*)items.at(i); - if (!groupList.contains(group)) groupList.append(group); - items.removeAt(i); - --i; + items = m_selectionGroup->childItems(); + resetSelectionGroup(false); + + QSet groupList; + QSet itemList; + while (!items.isEmpty()) { + QGraphicsItem *first = items.takeFirst(); + if (first->type() == GROUPWIDGET) { + if (first != m_selectionGroup) { + groupList.insert(first); + } } - } - for (int i = 0; i < groupList.count(); ++i) { - rebuildGroup(groupList.at(i)); + else if (first->type() == AVWIDGET || first->type() == TRANSITIONWIDGET) { + if (first->parentItem() && first->parentItem()->type() == GROUPWIDGET) { + if (first->parentItem() != m_selectionGroup) { + groupList.insert(first->parentItem()); + } + else itemList.insert(first); + } + else itemList.insert(first); + } } - - for (int i = 0; i < items.count(); ++i) { - if (items.at(i)) { - items.at(i)->setSelected(true); - if (items.at(i)->parentItem()) - items.at(i)->parentItem()->setSelected(true); - } + foreach(QGraphicsItem *item, groupList) { + itemList.unite(item->childItems().toSet()); + rebuildGroup(static_cast (item)); + } + + foreach(QGraphicsItem *item, itemList) { + item->setSelected(true); + if (item->parentItem()) + item->parentItem()->setSelected(true); } resetSelectionGroup(); - groupSelectedItems(); + groupSelectedItems(itemList.toList()); } else { - rebuildGroup((AbstractGroupItem *)group); + AbstractGroupItem *grp = static_cast (group); + rebuildGroup(grp); } setDocumentModified(); } @@ -3809,6 +4104,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) } } else { prepareResizeClipStart(m_dragItem, m_dragItemInfo, m_dragItem->startPos().frames(m_document->fps())); + if (m_dragItem->type() == AVWIDGET) static_cast (m_dragItem)->slotUpdateRange(); } } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) { // resize end @@ -3834,6 +4130,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) } } else { prepareResizeClipEnd(m_dragItem, m_dragItemInfo, m_dragItem->endPos().frames(m_document->fps())); + if (m_dragItem->type() == AVWIDGET) static_cast (m_dragItem)->slotUpdateRange(); } } else if (m_operationMode == FADEIN) { // resize fade in effect @@ -3956,19 +4253,6 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect()); emit clipItemSelected(item); } - if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET && m_dragItem->isSelected()) { - // A transition is selected - QPoint p; - ClipItem *transitionClip = getClipItemAt(m_dragItemInfo.startPos, m_dragItemInfo.track); - if (transitionClip && transitionClip->baseClip()) { - QString size = transitionClip->baseClip()->getProperty("frame_size"); - double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble(); - if (factor == 0) factor = 1.0; - p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5)); - p.setY(size.section('x', 1, 1).toInt()); - } - emit transitionItemSelected(static_cast (m_dragItem), getPreviousVideoTrack(m_dragItem->track()), p); - } else emit transitionItemSelected(NULL); if (m_operationMode != NONE && m_operationMode != MOVE) setDocumentModified(); m_operationMode = NONE; } @@ -4033,11 +4317,12 @@ void CustomTrackView::deleteSelectedClips() } scene()->clearSelection(); QUndoCommand *deleteSelected = new QUndoCommand(); + new RefreshMonitorCommand(this, false, true, deleteSelected); int groupCount = 0; int clipCount = 0; int transitionCount = 0; - // expand & destroy groups + // expand & destroy groups for (int i = 0; i < itemList.count(); i++) { if (itemList.at(i)->type() == GROUPWIDGET) { groupCount++; @@ -4064,20 +4349,19 @@ void CustomTrackView::deleteSelectedClips() } else if (itemList.at(i)->parentItem() && itemList.at(i)->parentItem()->type() == GROUPWIDGET) itemList.insert(i + 1, itemList.at(i)->parentItem()); } - + emit clipItemSelected(NULL); + emit transitionItemSelected(NULL); for (int i = 0; i < itemList.count(); i++) { if (itemList.at(i)->type() == AVWIDGET) { clipCount++; ClipItem *item = static_cast (itemList.at(i)); //kDebug()<<"// DELETE CLP AT: "<info().startPos.frames(25); new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteSelected); - emit clipItemSelected(NULL); } else if (itemList.at(i)->type() == TRANSITIONWIDGET) { transitionCount++; Transition *item = static_cast (itemList.at(i)); //kDebug()<<"// DELETE TRANS AT: "<info().startPos.frames(25); new AddTransitionCommand(this, item->info(), item->transitionEndTrack(), item->toXML(), true, true, deleteSelected); - emit transitionItemSelected(NULL); } } if (groupCount > 0 && clipCount == 0 && transitionCount == 0) @@ -4088,6 +4372,7 @@ void CustomTrackView::deleteSelectedClips() deleteSelected->setText(i18np("Delete selected transition", "Delete selected transitions", transitionCount)); else deleteSelected->setText(i18n("Delete selected items")); updateTrackDuration(-1, deleteSelected); + new RefreshMonitorCommand(this, true, false, deleteSelected); m_commandStack->push(deleteSelected); } @@ -4110,7 +4395,7 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant item->updateRectGeometry(); if (item->cropDuration().frames(m_document->fps()) != endPos) item->resizeEnd((int) info.startPos.frames(m_document->fps()) + endPos - 1); - updatePositionEffects(item, info); + updatePositionEffects(item, info, false); setDocumentModified(); } else { emit displayMessage(i18n("Invalid clip"), ErrorMessage); @@ -4132,7 +4417,7 @@ void CustomTrackView::cutSelectedClips() if (!groups.contains(group)) groups << group; } else if (currentPos > item->startPos() && currentPos < item->endPos()) { - RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos); + RazorClipCommand *command = new RazorClipCommand(this, item->info(), item->effectList(), currentPos); m_commandStack->push(command); } } else if (itemList.at(i)->type() == GROUPWIDGET && itemList.at(i) != m_selectionGroup) { @@ -4150,9 +4435,15 @@ void CustomTrackView::razorGroup(AbstractGroupItem* group, GenTime cutPos) { if (group) { QList children = group->childItems(); + QUndoCommand *command = new QUndoCommand; + command->setText(i18n("Cut Group")); + groupClips(false, children, command); QList clips1, transitions1; - QList clipsCut, transitionsCut; + QList transitionsCut; QList clips2, transitions2; + QList clipsToCut; + + // Collect info for (int i = 0; i < children.count(); ++i) { children.at(i)->setSelected(false); AbstractClipItem *child = static_cast (children.at(i)); @@ -4161,71 +4452,42 @@ void CustomTrackView::razorGroup(AbstractGroupItem* group, GenTime cutPos) clips1 << child->info(); else if (cutPos < child->startPos()) clips2 << child->info(); - else - clipsCut << child->info(); + else { + clipsToCut << child; + } } else { if (cutPos > child->endPos()) transitions1 << child->info(); else if (cutPos < child->startPos()) transitions2 << child->info(); - else - transitionsCut << child->info(); + else { + //transitionsCut << child->info(); + // Transition cut not implemented, leave it in first group... + transitions1 << child->info(); + } } } - if (clipsCut.isEmpty() && transitionsCut.isEmpty() && ((clips1.isEmpty() && transitions1.isEmpty()) || (clips2.isEmpty() && transitions2.isEmpty()))) + if (clipsToCut.isEmpty() && transitionsCut.isEmpty() && ((clips1.isEmpty() && transitions1.isEmpty()) || (clips2.isEmpty() && transitions2.isEmpty()))) { + delete command; return; - RazorGroupCommand *command = new RazorGroupCommand(this, clips1, transitions1, clipsCut, transitionsCut, clips2, transitions2, cutPos); + } + // Process the cut + for (int i = 0; i < clipsToCut.count(); i++) { + ClipItem *clip = static_cast(clipsToCut.at(i)); + new RazorClipCommand(this, clip->info(), clip->effectList(), cutPos, false, command); + ClipItem *secondClip = cutClip(clip->info(), cutPos, true); + clips1 << clip->info(); + clips2 << secondClip->info(); + } + new GroupClipsCommand(this, clips1, transitions1, true, command); + new GroupClipsCommand(this, clips2, transitions2, true, command); m_commandStack->push(command); } } -void CustomTrackView::slotRazorGroup(QList clips1, QList transitions1, QList clipsCut, QList transitionsCut, QList clips2, QList transitions2, GenTime cutPos, bool cut) +void CustomTrackView::groupClips(bool group, QList itemList, QUndoCommand *command) { - if (cut) { - for (int i = 0; i < clipsCut.count(); ++i) { - ClipItem *clip = getClipItemAt(clipsCut.at(i).startPos.frames(m_document->fps()), clipsCut.at(i).track); - if (clip) { - ClipItem *clipBehind = cutClip(clipsCut.at(i), cutPos, true); - clips1 << clip->info(); - if (clipBehind != NULL) - clips2 << clipBehind->info(); - } - } - /* TODO: cut transitionsCut - * For now just append them to group1 */ - transitions1 << transitionsCut; - doGroupClips(clips1, transitions1, true); - doGroupClips(clips2, transitions2, true); - } else { - /* we might also just use clipsCut.at(0)->parentItem(). - * Do this loop just in case something went wrong during cut */ - for (int i = 0; i < clipsCut.count(); ++i) { - ClipItem *clip = getClipItemAt(cutPos.frames(m_document->fps()), clipsCut.at(i).track); - if (clip && clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) { - AbstractGroupItem *group = static_cast (clip->parentItem()); - QList children = group->childItems(); - QList groupClips; - QList groupTrans; - for (int j = 0; j < children.count(); ++j) { - if (children.at(j)->type() == AVWIDGET) - groupClips << ((AbstractClipItem *)children.at(j))->info(); - else if (children.at(j)->type() == TRANSITIONWIDGET) - groupTrans << ((AbstractClipItem *)children.at(j))->info(); - } - doGroupClips(groupClips, groupTrans, false); - break; - } - } - for (int i = 0; i < clipsCut.count(); ++i) - cutClip(clipsCut.at(i), cutPos, false); - // TODO: uncut transitonsCut - doGroupClips(QList () << clips1 << clipsCut << clips2, QList () << transitions1 << transitionsCut << transitions2, true); - } -} - -void CustomTrackView::groupClips(bool group) -{ - QList itemList = scene()->selectedItems(); + if (itemList.isEmpty()) itemList = scene()->selectedItems(); QList clipInfos; QList transitionInfos; @@ -4247,8 +4509,12 @@ void CustomTrackView::groupClips(bool group) } } if (clipInfos.count() > 0) { - GroupClipsCommand *command = new GroupClipsCommand(this, clipInfos, transitionInfos, group); - m_commandStack->push(command); + if (command) { + new GroupClipsCommand(this, clipInfos, transitionInfos, group, command); + } else { + GroupClipsCommand *command = new GroupClipsCommand(this, clipInfos, transitionInfos, group); + m_commandStack->push(command); + } } } @@ -4257,12 +4523,14 @@ void CustomTrackView::doGroupClips(QList clipInfos, QList resetSelectionGroup(); m_scene->clearSelection(); if (!group) { - for (int i = 0; i < clipInfos.count(); i++) { + // ungroup, find main group to destroy it... + for (int i = 0; i < clipInfos.count(); i++) { ClipItem *clip = getClipItemAt(clipInfos.at(i).startPos, clipInfos.at(i).track); if (clip == NULL) continue; if (clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) { AbstractGroupItem *grp = static_cast (clip->parentItem()); m_document->clipManager()->removeGroup(grp); + if (grp == m_selectionGroup) m_selectionGroup = NULL; scene()->destroyItemGroup(grp); } clip->setFlag(QGraphicsItem::ItemIsMovable, true); @@ -4273,28 +4541,31 @@ void CustomTrackView::doGroupClips(QList clipInfos, QList if (tr->parentItem() && tr->parentItem()->type() == GROUPWIDGET) { AbstractGroupItem *grp = static_cast (tr->parentItem()); m_document->clipManager()->removeGroup(grp); + if (grp == m_selectionGroup) m_selectionGroup = NULL; scene()->destroyItemGroup(grp); + grp = NULL; } tr->setFlag(QGraphicsItem::ItemIsMovable, true); } setDocumentModified(); return; } - - QList groups; + QList list; for (int i = 0; i < clipInfos.count(); i++) { ClipItem *clip = getClipItemAt(clipInfos.at(i).startPos, clipInfos.at(i).track); if (clip) { - clip->setSelected(true); + list.append(clip); + //clip->setSelected(true); } } for (int i = 0; i < transitionInfos.count(); i++) { Transition *clip = getTransitionItemAt(transitionInfos.at(i).startPos, transitionInfos.at(i).track); if (clip) { - clip->setSelected(true); + list.append(clip); + //clip->setSelected(true); } } - groupSelectedItems(false, true); + groupSelectedItems(list, true, true); setDocumentModified(); } @@ -4346,8 +4617,9 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(item->effect(i)), false); } setDocumentModified(); - if (refresh) + if (refresh) { m_document->renderer()->doRefresh(); + } if (!baseclip->isPlaceHolder()) m_waitingThumbs.append(item); m_thumbsTimer.start(); @@ -4563,7 +4835,7 @@ void CustomTrackView::moveGroup(QList startClip, QList sta // Group Items resetSelectionGroup(); m_scene->clearSelection(); - + m_selectionMutex.lock(); m_selectionGroup = new AbstractGroupItem(m_document->fps()); scene()->addItem(m_selectionGroup); @@ -4577,11 +4849,9 @@ void CustomTrackView::moveGroup(QList startClip, QList sta if (clip) { clip->setItemLocked(false); if (clip->parentItem()) { - m_selectionGroup->addToGroup(clip->parentItem()); - clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(clip->parentItem()); } else { - m_selectionGroup->addToGroup(clip); - clip->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(clip); } m_document->renderer()->mltRemoveClip(m_document->tracksCount() - startClip.at(i).track, startClip.at(i).startPos); } else kDebug() << "//MISSING CLIP AT: " << startClip.at(i).startPos.frames(25); @@ -4595,11 +4865,9 @@ void CustomTrackView::moveGroup(QList startClip, QList sta if (tr) { tr->setItemLocked(false); if (tr->parentItem()) { - m_selectionGroup->addToGroup(tr->parentItem()); - tr->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(tr->parentItem()); } else { - m_selectionGroup->addToGroup(tr); - tr->setFlag(QGraphicsItem::ItemIsMovable, false); + m_selectionGroup->addItem(tr); } m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_document->tracksCount() - startTransition.at(i).track, startTransition.at(i).startPos, startTransition.at(i).endPos, tr->toXML()); } else kDebug() << "//MISSING TRANSITION AT: " << startTransition.at(i).startPos.frames(25); @@ -4665,10 +4933,11 @@ void CustomTrackView::moveGroup(QList startClip, QList sta m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML()); } } - + m_selectionMutex.unlock(); resetSelectionGroup(false); - for (int i = 0; i < groupList.count(); i++) + for (int i = 0; i < groupList.count(); i++) { rebuildGroup(groupList.at(i)); + } clearSelection(); @@ -4747,8 +5016,9 @@ void CustomTrackView::resizeClip(const ItemInfo &start, const ItemInfo &end, boo ItemInfo clipinfo = item->info(); clipinfo.track = m_document->tracksCount() - clipinfo.track; bool success = m_document->renderer()->mltResizeClipStart(clipinfo, end.startPos - clipinfo.startPos); - if (success) + if (success) { item->resizeStart((int) end.startPos.frames(m_document->fps())); + } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); } else { @@ -4951,11 +5221,22 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI } else { // Check transition keyframes QDomElement old = transition->toXML(); - if (transition->updateKeyframes()) { + if (transition->updateKeyframes(oldInfo.cropDuration.frames(m_document->fps()) - 1)) { QDomElement xml = transition->toXML(); m_document->renderer()->mltUpdateTransition(xml.attribute("tag"), xml.attribute("tag"), xml.attribute("transition_btrack").toInt(), m_document->tracksCount() - xml.attribute("transition_atrack").toInt(), transition->startPos(), transition->endPos(), xml); new EditTransitionCommand(this, transition->track(), transition->startPos(), old, xml, false, command); } + ItemInfo info = transition->info(); + QPoint p; + ClipItem *transitionClip = getClipItemAt(info.startPos, info.track); + if (transitionClip && transitionClip->baseClip()) { + QString size = transitionClip->baseClip()->getProperty("frame_size"); + double factor = transitionClip->baseClip()->getProperty("aspect_ratio").toDouble(); + if (factor == 0) factor = 1.0; + p.setX((int)(size.section('x', 0, 0).toInt() * factor + 0.5)); + p.setY(size.section('x', 1, 1).toInt()); + } + emit transitionItemSelected(transition, getPreviousVideoTrack(info.track), p, true); new MoveTransitionCommand(this, oldInfo, info, false, command); } } @@ -5024,7 +5305,7 @@ void CustomTrackView::updatePositionEffects(ClipItem* item, ItemInfo info, bool if (effectPos != -1) { QDomElement effect = item->getEffectAtIndex(effectPos); int max = item->cropDuration().frames(m_document->fps()); - int end = max + item->cropStart().frames(m_document->fps()); + int end = max + item->cropStart().frames(m_document->fps()) - 1; if (start > max) { // Make sure the fade effect is not longer than the clip item->setFadeOut(max); @@ -5045,7 +5326,7 @@ void CustomTrackView::updatePositionEffects(ClipItem* item, ItemInfo info, bool if (effectPos != -1) { QDomElement effect = item->getEffectAtIndex(effectPos); int max = item->cropDuration().frames(m_document->fps()); - int end = max + item->cropStart().frames(m_document->fps()); + int end = max + item->cropStart().frames(m_document->fps()) - 1; if (start > max) { // Make sure the fade effect is not longer than the clip item->setFadeOut(max); @@ -5196,22 +5477,58 @@ void CustomTrackView::clipEnd() } } -void CustomTrackView::slotAddClipMarker(const QString &id, GenTime t, QString c, QUndoCommand *groupCommand) +void CustomTrackView::slotAddClipExtraData(const QString &id, const QString &key, const QString &data, QUndoCommand *groupCommand) { - QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t); - AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t, groupCommand); + DocClipBase *base = m_document->clipManager()->getClipById(id); + if (!base) return; + QMap extraData = base->analysisData(); + QString oldData = extraData.value(key); + AddExtraDataCommand *command = new AddExtraDataCommand(this, id, key, oldData, data, groupCommand); if (!groupCommand) m_commandStack->push(command); } +void CustomTrackView::slotAddClipMarker(const QString &id, QList newMarkers, QUndoCommand *groupCommand) +{ + DocClipBase *base = m_document->clipManager()->getClipById(id); + if (!base) return; + QUndoCommand *subCommand = NULL; + if (newMarkers.count() > 1 && groupCommand == NULL) { + subCommand = new QUndoCommand; + subCommand->setText("Add markers"); + } + for (int i = 0; i < newMarkers.count(); i++) { + CommentedTime oldMarker = base->markerAt(newMarkers.at(i).time()); + if (oldMarker == CommentedTime()) { + oldMarker = newMarkers.at(i); + oldMarker.setMarkerType(-1); + } + if (newMarkers.count() == 1 && !groupCommand) { + AddMarkerCommand *command = new AddMarkerCommand(this, oldMarker, newMarkers.at(i), id, groupCommand); + m_commandStack->push(command); + } + else if (groupCommand) { + (void) new AddMarkerCommand(this, oldMarker, newMarkers.at(i), id, groupCommand); + } + else { + (void) new AddMarkerCommand(this, oldMarker, newMarkers.at(i), id, subCommand); + } + } + if (subCommand) m_commandStack->push(subCommand); +} + void CustomTrackView::slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position) { - AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position); + CommentedTime oldmarker(position, comment); + CommentedTime marker = oldmarker; + marker.setMarkerType(-1); + AddMarkerCommand *command = new AddMarkerCommand(this, oldmarker, marker, id); m_commandStack->push(command); } void CustomTrackView::slotDeleteAllClipMarkers(const QString &id) { DocClipBase *base = m_document->clipManager()->getClipById(id); + if (!base) return; QList markers = base->commentedSnapMarkers(); if (markers.isEmpty()) { @@ -5222,7 +5539,10 @@ void CustomTrackView::slotDeleteAllClipMarkers(const QString &id) deleteMarkers->setText("Delete clip markers"); for (int i = 0; i < markers.size(); i++) { - new AddMarkerCommand(this, markers.at(i).comment(), QString(), id, markers.at(i).time(), deleteMarkers); + CommentedTime oldMarker = markers.at(i); + CommentedTime marker = oldMarker; + marker.setMarkerType(-1); + new AddMarkerCommand(this, oldMarker, marker, id, deleteMarkers); } m_commandStack->push(deleteMarkers); } @@ -5230,19 +5550,41 @@ void CustomTrackView::slotDeleteAllClipMarkers(const QString &id) void CustomTrackView::slotSaveClipMarkers(const QString &id) { DocClipBase *base = m_document->clipManager()->getClipById(id); + if (!base) return; QList < CommentedTime > markers = base->commentedSnapMarkers(); - QString data; - for (int i = 0; i < markers.count(); i++) { - data.append(QString::number(markers.at(i).time().seconds())); - data.append("\t"); - data.append(QString::number(markers.at(i).time().seconds())); - data.append("\t"); - data.append(markers.at(i).comment()); - data.append("\n"); - } - if (!data.isEmpty()) { - QString url = KFileDialog::getSaveFileName(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Save markers")); + if (!markers.isEmpty()) { + // Set up categories + QComboBox *cbox = new QComboBox; + cbox->insertItem(0, i18n("All categories")); + for (int i = 0; i < 5; ++i) { + cbox->insertItem(i + 1, i18n("Category %1", i)); + cbox->setItemData(i + 1, CommentedTime::markerColor(i), Qt::DecorationRole); + } + cbox->setCurrentIndex(0); + KFileDialog fd(KUrl("kfiledialog:///projectfolder"), "text/plain", this, cbox); + fd.setMode(KFile::File); + fd.setOperationMode(KFileDialog::Saving); + if (fd.exec() != QDialog::Accepted) return; + QString url = fd.selectedFile(); + //QString url = KFileDialog::getSaveFileName(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Save markers")); if (url.isEmpty()) return; + + QString data; + int category = cbox->currentIndex() - 1; + for (int i = 0; i < markers.count(); i++) { + if (category >= 0) { + // Save only the markers in selected category + if (markers.at(i).markerType() != category) continue; + } + data.append(QString::number(markers.at(i).time().seconds())); + data.append("\t"); + data.append(QString::number(markers.at(i).time().seconds())); + data.append("\t"); + data.append(markers.at(i).comment()); + data.append("\n"); + } + delete cbox; + QFile file(url); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { emit displayMessage(i18n("Cannot open file %1", url), ErrorMessage); @@ -5255,11 +5597,25 @@ void CustomTrackView::slotSaveClipMarkers(const QString &id) void CustomTrackView::slotLoadClipMarkers(const QString &id) { - KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Load marker file")); + QComboBox *cbox = new QComboBox; + for (int i = 0; i < 5; ++i) { + cbox->insertItem(i, i18n("Category %1", i)); + cbox->setItemData(i, CommentedTime::markerColor(i), Qt::DecorationRole); + } + cbox->setCurrentIndex(KdenliveSettings::default_marker_type()); + KFileDialog fd(KUrl("kfiledialog:///projectfolder"), "text/plain", this, cbox); + fd.setMode(KFile::File); + fd.setOperationMode(KFileDialog::Opening); + if (fd.exec() != QDialog::Accepted) return; + QString url = fd.selectedFile(); + + //KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Load marker file")); if (url.isEmpty()) return; - QFile file(url.path()); + int category = cbox->currentIndex(); + delete cbox; + QFile file(url); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - emit displayMessage(i18n("Cannot open file %1", url.fileName()), ErrorMessage); + emit displayMessage(i18n("Cannot open file %1", KUrl(url).fileName()), ErrorMessage); return; } QString data = QString::fromUtf8(file.readAll()); @@ -5270,6 +5626,7 @@ void CustomTrackView::slotLoadClipMarkers(const QString &id) QUndoCommand *command = new QUndoCommand(); command->setText("Load markers"); QString markerText; + QList markersList; foreach(QString line, lines) { markerText.clear(); values = line.split("\t", QString::SkipEmptyParts); @@ -5298,24 +5655,41 @@ void CustomTrackView::slotLoadClipMarkers(const QString &id) } if (!markerText.isEmpty()) { // Marker found, add it - slotAddClipMarker(id, GenTime(time1), markerText, command); - if (time2 > 0 && time2 != time1) slotAddClipMarker(id, GenTime(time2), markerText, command); + //TODO: allow user to set a marker category + CommentedTime marker1(GenTime(time1), markerText, category); + markersList << marker1; + if (time2 > 0 && time2 != time1) { + CommentedTime marker2(GenTime(time2), markerText, category); + markersList << marker2; + } } } + if (!markersList.isEmpty()) slotAddClipMarker(id, markersList, command); if (command->childCount() > 0) m_commandStack->push(command); else delete command; } -void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QString &comment) +void CustomTrackView::addMarker(const QString &id, const CommentedTime marker) { DocClipBase *base = m_document->clipManager()->getClipById(id); - if (!comment.isEmpty()) base->addSnapMarker(pos, comment); - else base->deleteSnapMarker(pos); + if (base == NULL) return; + if (marker.markerType() < 0) base->deleteSnapMarker(marker.time()); + else base->addSnapMarker(marker); emit updateClipMarkers(base); setDocumentModified(); viewport()->update(); } +void CustomTrackView::addData(const QString &id, const QString &key, const QString &data) +{ + DocClipBase *base = m_document->clipManager()->getClipById(id); + if (base == NULL) return; + base->setAnalysisData(key, data); + emit updateClipExtraData(base); + setDocumentModified(); + viewport()->update(); +} + int CustomTrackView::hasGuide(int pos, int offset) { for (int i = 0; i < m_guides.count(); i++) { @@ -5340,28 +5714,29 @@ void CustomTrackView::buildGuidesMenu(QMenu *goMenu) const void CustomTrackView::editGuide(const GenTime &oldPos, const GenTime &pos, const QString &comment) { - if (oldPos > GenTime() && pos > GenTime()) { - // move guide + if (comment.isEmpty() && pos < GenTime()) { + // Delete guide + bool found = false; for (int i = 0; i < m_guides.count(); i++) { if (m_guides.at(i)->position() == oldPos) { - Guide *item = m_guides.at(i); - item->updateGuide(pos, comment); + delete m_guides.takeAt(i); + found = true; break; } } - } else if (pos > GenTime()) addGuide(pos, comment); - else { - // remove guide - bool found = false; + if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage); + } + + else if (oldPos >= GenTime()) { + // move guide for (int i = 0; i < m_guides.count(); i++) { if (m_guides.at(i)->position() == oldPos) { - delete m_guides.takeAt(i); - found = true; + Guide *item = m_guides.at(i); + item->updateGuide(pos, comment); break; } } - if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage); - } + } else addGuide(pos, comment); qSort(m_guides.begin(), m_guides.end(), sortGuidesList); m_document->syncGuides(m_guides); } @@ -5451,7 +5826,7 @@ void CustomTrackView::slotDeleteGuide(int guidePos) bool found = false; for (int i = 0; i < m_guides.count(); i++) { if (m_guides.at(i)->position() == pos) { - EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true); + EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(-1), QString(), true); m_commandStack->push(command); found = true; break; @@ -5464,7 +5839,7 @@ void CustomTrackView::slotDeleteGuide(int guidePos) void CustomTrackView::slotDeleteTimeLineGuide() { if (m_dragGuide == NULL) return; - EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(), QString(), true); + EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(-1), QString(), true); m_commandStack->push(command); } @@ -5474,7 +5849,7 @@ void CustomTrackView::slotDeleteAllGuides() QUndoCommand *deleteAll = new QUndoCommand(); deleteAll->setText("Delete all guides"); for (int i = 0; i < m_guides.count(); i++) { - new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true, deleteAll); + new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(-1), QString(), true, deleteAll); } m_commandStack->push(deleteAll); } @@ -5482,6 +5857,16 @@ void CustomTrackView::slotDeleteAllGuides() void CustomTrackView::setTool(PROJECTTOOL tool) { m_tool = tool; + switch (m_tool) { + case RAZORTOOL: + setCursor(m_razorCursor); + break; + case SPACERTOOL: + setCursor(m_spacerCursor); + break; + default: + unsetCursor(); + } } void CustomTrackView::setScale(double scaleFactor, double verticalScale) @@ -5495,11 +5880,9 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale) setMatrix(newmatrix); if (adjust) { double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1); + m_cursorLine->setLine(0, 0, 0, newHeight - 1); for (int i = 0; i < m_guides.count(); i++) { - QLineF l = m_guides.at(i)->line(); - l.setP2(QPointF(l.x2(), newHeight)); - m_guides.at(i)->setLine(l); + m_guides.at(i)->setLine(0, 0, 0, newHeight - 1); } setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); } @@ -5527,7 +5910,9 @@ void CustomTrackView::drawBackground(QPainter * painter, const QRectF &rect) { painter->setClipRect(rect); QPen pen1 = painter->pen(); - pen1.setColor(palette().dark().color()); + QColor lineColor = palette().dark().color(); + lineColor.setAlpha(100); + pen1.setColor(lineColor); painter->setPen(pen1); double min = rect.left(); double max = rect.right(); @@ -5784,6 +6169,7 @@ void CustomTrackView::pasteClip() } QUndoCommand *pasteClips = new QUndoCommand(); pasteClips->setText("Paste clips"); + new RefreshMonitorCommand(this, false, true, pasteClips); for (int i = 0; i < m_copiedItems.count(); i++) { // parse all clip names @@ -5813,6 +6199,7 @@ void CustomTrackView::pasteClip() } } updateTrackDuration(-1, pasteClips); + new RefreshMonitorCommand(this, false, false, pasteClips); m_commandStack->push(pasteClips); } @@ -5901,7 +6288,8 @@ ClipItem *CustomTrackView::getClipUnderCursor() const QList collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect); for (int i = 0; i < collisions.count(); i++) { if (collisions.at(i)->type() == AVWIDGET) { - return static_cast < ClipItem *>(collisions.at(i)); + ClipItem *clip = static_cast < ClipItem *>(collisions.at(i)); + if (!clip->isItemLocked()) return clip; } } return NULL; @@ -6163,11 +6551,16 @@ void CustomTrackView::slotConfigTracks(int ix) void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo) { if (m_document->tracksCount() < 2) return; - double startY = ix * m_tracksHeight + 1 + m_tracksHeight / 2; + // Clear effect stack + clearSelection(); + emit transitionItemSelected(NULL); + + double startY = ix * m_tracksHeight + 1 + m_tracksHeight / 2; QRectF r(0, startY, sceneRect().width(), m_tracksHeight / 2 - 1); QList selection = m_scene->items(r); QUndoCommand *deleteTrack = new QUndoCommand(); deleteTrack->setText("Delete track"); + new RefreshMonitorCommand(this, false, true, deleteTrack); // Delete all clips in selected track for (int i = 0; i < selection.count(); i++) { @@ -6188,6 +6581,7 @@ void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo) } new AddTrackCommand(this, ix, trackinfo, false, deleteTrack); + new RefreshMonitorCommand(this, true, false, deleteTrack); m_commandStack->push(deleteTrack); } @@ -6257,19 +6651,20 @@ void CustomTrackView::loadGroups(const QDomNodeList &groups) for (int i = 0; i < groups.count(); i++) { QDomNodeList children = groups.at(i).childNodes(); scene()->clearSelection(); + QList list; for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) { QDomElement elem = children.item(nodeindex).toElement(); int pos = elem.attribute("position").toInt(); int track = elem.attribute("track").toInt(); if (elem.tagName() == "clipitem") { ClipItem *clip = getClipItemAt(pos, track); //m_document->tracksCount() - transitiontrack); - if (clip) clip->setSelected(true); + if (clip) list.append(clip);//clip->setSelected(true); } else { Transition *clip = getTransitionItemAt(pos, track); //m_document->tracksCount() - transitiontrack); - if (clip) clip->setSelected(true); + if (clip) list.append(clip);//clip->setSelected(true); } } - groupSelectedItems(false, true); + groupSelectedItems(list, true); } } @@ -6466,28 +6861,25 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, EffectsList ef } } } - kDebug() << "GOT TRK: " << track; if (freetrack == 0) { emit displayMessage(i18n("No empty space to put clip audio"), ErrorMessage); } else { ItemInfo info = clip->info(); info.track = m_document->tracksCount() - freetrack; - addClip(clip->xml(), clip->clipProducer(), info, clip->effectList()); - scene()->clearSelection(); + QDomElement xml = clip->xml(); + xml.setAttribute("audio_only", 1); + scene()->clearSelection(); + addClip(xml, clip->clipProducer(), info, clip->effectList(), false, false, false); clip->setSelected(true); ClipItem *audioClip = getClipItemAt(start, info.track); if (audioClip) { + clip->setVideoOnly(true); Mlt::Tractor *tractor = m_document->renderer()->lockService(); - clip->setVideoOnly(true); if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->videoProducer(info.track)) == false) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage); } - if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track)) == false) { - emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, info.track), ErrorMessage); - } m_document->renderer()->unlockService(tractor); audioClip->setSelected(true); - audioClip->setAudioOnly(true); // keep video effects, move audio effects to audio clip int videoIx = 0; @@ -6501,8 +6893,7 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, EffectsList ef videoIx++; } } - - groupSelectedItems(false, true); + groupSelectedItems(QList ()<setFlag(QGraphicsItem::ItemIsMovable, true); m_document->clipManager()->removeGroup(grp); + if (grp == m_selectionGroup) m_selectionGroup = NULL; scene()->destroyItemGroup(grp); } } @@ -6627,6 +7019,11 @@ void CustomTrackView::setAudioAndVideo() m_commandStack->push(videoCommand); } +void CustomTrackView::monitorRefresh() +{ + m_document->renderer()->doRefresh(); +} + void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly) { ClipItem *clip = getClipItemAt(pos, track); @@ -6664,9 +7061,27 @@ void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool video void CustomTrackView::updateClipTypeActions(ClipItem *clip) { + bool hasAudio; + bool hasAV; if (clip == NULL || (clip->clipType() != AV && clip->clipType() != PLAYLIST)) { m_clipTypeGroup->setEnabled(false); + hasAudio = clip != NULL && clip->clipType() == AUDIO; + hasAV = false; } else { + switch (clip->clipType()) { + case AV: + case PLAYLIST: + hasAudio = true; + hasAV = true; + break; + case AUDIO: + hasAudio = true; + hasAV = false; + break; + default: + hasAudio = false; + hasAV = false; + } m_clipTypeGroup->setEnabled(true); QList actions = m_clipTypeGroup->actions(); QString lookup; @@ -6680,6 +7095,13 @@ void CustomTrackView::updateClipTypeActions(ClipItem *clip) } } } + + for (int i = 0; i < m_audioActions.count(); i++) { + m_audioActions.at(i)->setEnabled(hasAudio); + } + for (int i = 0; i < m_avActions.count(); i++) { + m_avActions.at(i)->setEnabled(hasAV); + } } void CustomTrackView::slotGoToMarker(QAction *action) @@ -6770,15 +7192,16 @@ void CustomTrackView::updateProjectFps() } m_document->clipManager()->removeGroup(grp); m_scene->addItem(grp); + if (grp == m_selectionGroup) m_selectionGroup = NULL; scene()->destroyItemGroup(grp); scene()->clearSelection(); - for (int j = 0; j < children.count(); j++) { + /*for (int j = 0; j < children.count(); j++) { if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) { //children.at(j)->setParentItem(0); children.at(j)->setSelected(true); } - } - groupSelectedItems(true, true); + }*/ + groupSelectedItems(children, true); } else if (itemList.at(i)->type() == GUIDEITEM) { Guide *g = static_cast(itemList.at(i)); g->updatePos(); @@ -6851,28 +7274,23 @@ void CustomTrackView::slotSelectTrack(int ix) void CustomTrackView::slotSelectClipsInTrack() { QRectF rect(0, m_selectedTrack * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), m_tracksHeight / 2 - 1); + resetSelectionGroup(); QList selection = m_scene->items(rect); m_scene->clearSelection(); + QList list; for (int i = 0; i < selection.count(); i++) { if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET) { - selection.at(i)->setSelected(true); + list.append(selection.at(i)); } } - resetSelectionGroup(); - groupSelectedItems(); + groupSelectedItems(list, false, true); } void CustomTrackView::slotSelectAllClips() { - QList selection = m_scene->items(); m_scene->clearSelection(); - for (int i = 0; i < selection.count(); i++) { - if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET) { - selection.at(i)->setSelected(true); - } - } resetSelectionGroup(); - groupSelectedItems(); + groupSelectedItems(m_scene->items(), false, true); } void CustomTrackView::selectClip(bool add, bool group, int track, int pos) @@ -6981,6 +7399,7 @@ void CustomTrackView::insertZoneOverwrite(QStringList data, int in) void CustomTrackView::clearSelection(bool emitInfo) { + if (m_dragItem) m_dragItem->setSelected(false); resetSelectionGroup(); scene()->clearSelection(); m_dragItem = NULL; @@ -7163,18 +7582,18 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement &effect) parameters.addParam(QString("filter%1.tag").arg(subeffectix), subeffect.attribute("tag")); parameters.addParam(QString("filter%1.kdenlive_info").arg(subeffectix), subeffect.attribute("kdenlive_info")); QDomNodeList subparams = subeffect.elementsByTagName("parameter"); - adjustEffectParameters(parameters, subparams, QString("filter%1.").arg(subeffectix)); + adjustEffectParameters(parameters, subparams, m_document->mltProfile(), QString("filter%1.").arg(subeffectix)); } } QDomNodeList params = effect.elementsByTagName("parameter"); - adjustEffectParameters(parameters, params); + adjustEffectParameters(parameters, params, m_document->mltProfile()); return parameters; } -void CustomTrackView::adjustEffectParameters(EffectsParameterList ¶meters, QDomNodeList params, const QString &prefix) +void CustomTrackView::adjustEffectParameters(EffectsParameterList ¶meters, QDomNodeList params, MltVideoProfile profile, const QString &prefix) { QLocale locale; for (int i = 0; i < params.count(); i++) { @@ -7225,7 +7644,7 @@ void CustomTrackView::adjustEffectParameters(EffectsParameterList ¶meters, Q if (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0") { double fact; if (e.attribute("factor").contains('%')) { - fact = ProfilesDialog::getStringEval(m_document->mltProfile(), e.attribute("factor")); + fact = ProfilesDialog::getStringEval(profile, e.attribute("factor")); } else { fact = e.attribute("factor", "1").toDouble(); } @@ -7325,7 +7744,7 @@ void CustomTrackView::adjustEffects(ClipItem* item, ItemInfo oldInfo, QUndoComma { QMap effects = item->adjustEffectsToDuration(m_document->width(), m_document->height(), oldInfo); - if (effects.count()) { + if (!effects.isEmpty()) { QMap::const_iterator i = effects.constBegin(); while (i != effects.constEnd()) { new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), i.value(), item->effect(i.key()), i.value().attribute("kdenlive_ix").toInt(), true, true, command); @@ -7335,16 +7754,16 @@ void CustomTrackView::adjustEffects(ClipItem* item, ItemInfo oldInfo, QUndoComma } -void CustomTrackView::slotGotFilterJobResults(const QString &/*id*/, int startPos, int track, const QString &filter, stringMap filterParams) +void CustomTrackView::slotGotFilterJobResults(const QString &/*id*/, int startPos, int track, stringMap filterParams, stringMap extra) { ClipItem *clip = getClipItemAt(GenTime(startPos, m_document->fps()), track); if (clip == NULL) { - emit displayMessage(i18n("Cannot find clip for effect update %1.", filter), ErrorMessage); + emit displayMessage(i18n("Cannot find clip for effect update %1.", extra.value("finalfilter")), ErrorMessage); return; } QDomElement newEffect; QDomElement effect = clip->getEffectAtIndex(clip->selectedEffectIndex()); - if (effect.attribute("id") == filter) { + if (effect.attribute("id") == extra.value("finalfilter")) { newEffect = effect.cloneNode().toElement(); QMap::const_iterator i = filterParams.constBegin(); while (i != filterParams.constEnd()) { @@ -7359,3 +7778,97 @@ void CustomTrackView::slotGotFilterJobResults(const QString &/*id*/, int startPo } +void CustomTrackView::slotImportClipKeyframes(GRAPHICSRECTITEM type) +{ + ClipItem *item = NULL; + if (type == TRANSITIONWIDGET) { + // We want to import keyframes to a transition + if (!m_selectionGroup) { + emit displayMessage(i18n("You need to select one clip and one transition"), ErrorMessage); + return; + } + // Make sure there is no collision + QList children = m_selectionGroup->childItems(); + for (int i = 0; i < children.count(); i++) { + if (children.at(i)->type() == AVWIDGET) { + item = (ClipItem*) children.at(i); + break; + } + } + } + else { + // Import keyframes from current clip to its effect + if (m_dragItem) item = static_cast (m_dragItem); + } + + if (!item) { + emit displayMessage(i18n("No clip found"), ErrorMessage); + return; + } + QMap data = item->baseClip()->analysisData(); + if (data.isEmpty()) { + emit displayMessage(i18n("No keyframe data found in clip"), ErrorMessage); + return; + } + QPointer d = new QDialog(this); + Ui::ImportKeyframesDialog_UI ui; + ui.setupUi(d); + + // Set up data + int ix = 0; + QMap::const_iterator i = data.constBegin(); + while (i != data.constEnd()) { + ui.data_list->insertItem(ix, i.key()); + ui.data_list->setItemData(ix, i.value(), Qt::UserRole); + ++i; + ix++; + } + + if (d->exec() != QDialog::Accepted) { + delete d; + return; + } + QString keyframeData = ui.data_list->itemData(ui.data_list->currentIndex()).toString(); + + int offset = item->cropStart().frames(m_document->fps()); + Mlt::Geometry geometry(keyframeData.toUtf8().data(), item->baseClip()->maxDuration().frames(m_document->fps()), m_document->mltProfile().width, m_document->mltProfile().height); + Mlt::Geometry newGeometry(QString().toUtf8().data(), item->baseClip()->maxDuration().frames(m_document->fps()), m_document->mltProfile().width, m_document->mltProfile().height); + Mlt::GeometryItem gitem; + geometry.fetch(&gitem, offset); + gitem.frame(0); + newGeometry.insert(gitem); + int pos = offset + 1; + while (!geometry.next_key(&gitem, pos)) { + pos = gitem.frame(); + gitem.frame(pos - offset); + pos++; + newGeometry.insert(gitem); + } + QStringList keyframeList = QString(newGeometry.serialise()).split(';', QString::SkipEmptyParts); + + QString result; + if (ui.import_position->isChecked()) { + if (ui.import_size->isChecked()) { + foreach(QString key, keyframeList) { + if (key.count(':') > 1) result.append(key.section(':', 0, 1)); + else result.append(key); + result.append(';'); + } + } + else { + foreach(QString key, keyframeList) { + result.append(key.section(':', 0, 0)); + result.append(';'); + } + } + } + else if (ui.import_size->isChecked()) { + foreach(QString key, keyframeList) { + result.append(key.section(':', 1, 1)); + result.append(';'); + } + } + emit importKeyframes(type, result, ui.limit_keyframes->isChecked() ? ui.max_keyframes->value() : -1); + delete d; +} +