X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcustomtrackview.cpp;h=fc84608d5dfbd4706811dab170c553bf843e201a;hb=d731c34c1cf29491f2c31c32f337d3da67071e3b;hp=ae047716e3088900f551a109188665a3da82e635;hpb=37f30efc3ea2ecd5a736922eea5cbdd2cbfae34a;p=kdenlive diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index ae047716..fc84608d 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -33,10 +33,13 @@ #include "moveclipcommand.h" #include "resizeclipcommand.h" #include "addtimelineclipcommand.h" +#include "addeffectcommand.h" -CustomTrackView::CustomTrackView(KUndoStack *commandStack, QGraphicsScene * projectscene, QWidget *parent) - : QGraphicsView(projectscene, parent), m_commandStack(commandStack), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(0) +CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent) + : QGraphicsView(projectscene, parent), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(0), m_document(doc) { + if (doc) m_commandStack = doc->commandStack(); + else m_commandStack == NULL; setMouseTracking(true); setAcceptDrops(true); m_animationTimer = new QTimeLine(800); @@ -81,6 +84,7 @@ void CustomTrackView::wheelEvent ( QWheelEvent * e ) void CustomTrackView::mouseMoveEvent ( QMouseEvent * event ) { int pos = event->x(); + emit mousePosition(mapToScene(event->pos()).x() / m_scale); /*if (event->modifiers() == Qt::ControlModifier) setDragMode(QGraphicsView::ScrollHandDrag); else if (event->modifiers() == Qt::ShiftModifier) @@ -89,9 +93,9 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event ) if (m_dragItem) { //event->button() == Qt::LeftButton) { // a button was pressed, delete visual tips - if (m_operationMode == MOVE) { - int moveX = mapToScene(event->pos()).x(); + double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint); + double moveX = snappedPos; //mapToScene(event->pos()).x(); //kDebug()<<"/////// MOVE CLIP, EVENT Y: "<scenePos().y()<<", SCENE HEIGHT: "<sceneRect().height(); int moveTrack = (int) mapToScene(event->pos()).y() / 50; int currentTrack = m_dragItem->track(); @@ -101,7 +105,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event ) int offset = moveTrack - currentTrack; if (offset != 0) offset = 50 * offset; - m_dragItem->moveTo((moveX - m_clickPoint) / m_scale, m_scale, offset, moveTrack); + m_dragItem->moveTo(moveX / m_scale, m_scale, offset, moveTrack); } else if (m_operationMode == RESIZESTART) { int pos = mapToScene(event->pos()).x(); @@ -260,6 +264,7 @@ void CustomTrackView::mouseMoveEvent ( QMouseEvent * event ) // virtual void CustomTrackView::mousePressEvent ( QMouseEvent * event ) { + kDebug()<<"-- TIMELINE MSE PRESSED"; int pos = event->x(); if (event->modifiers() == Qt::ControlModifier) setDragMode(QGraphicsView::ScrollHandDrag); @@ -271,11 +276,22 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event ) for (int i = 0; i < collisionList.size(); ++i) { QGraphicsItem *item = collisionList.at(i); if (item->type() == 70000) { + // select item + if (!item->isSelected()) { + QList itemList = items(); + for (int i = 0; i < itemList.count(); i++) + itemList.at(i)->setSelected(false); + item->setSelected(true); + update(); + } m_dragItem = (ClipItem *) item; + emit clipItemSelected(m_dragItem); m_clickPoint = mapToScene(event->pos()).x() - m_dragItem->startPos() * m_scale; m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale); - if (m_operationMode == MOVE || m_operationMode == RESIZESTART) m_startPos = QPointF(m_dragItem->startPos(), m_dragItem->track()); - else if (m_operationMode == RESIZEEND) m_startPos = QPointF(m_dragItem->endPos(), m_dragItem->track()); + if (m_operationMode == MOVE || m_operationMode == RESIZESTART) + m_startPos = QPointF(m_dragItem->startPos(), m_dragItem->track()); + else if (m_operationMode == RESIZEEND) + m_startPos = QPointF(m_dragItem->endPos(), m_dragItem->track()); kDebug()<<"//////// ITEM CLICKED: "< itemList = items(); + for (int i = 0; i < itemList.count(); i++) + itemList.at(i)->setSelected(false); + emit clipItemSelected(NULL); setCursorPos((int) mapToScene(event->x(), 0).x()); emit cursorMoved(cursorPos()); } } + updateSnapPoints(m_dragItem); //kDebug()<mimeData()->hasText()) { - QString clip = event->mimeData()->text(); + kDebug()<<"/////////////// DRAG ENTERED, TEXT: "<mimeData()->text(); + QStringList ids = QString(event->mimeData()->text()).split(";"); + //TODO: drop of several clips + for (int i = 0; i < ids.size(); ++i) { + } + DocClipBase *clip = m_document->getBaseClip(ids.at(0).toInt()); + if (clip == NULL) kDebug()<<" WARNING))))))))) CLIP NOT FOUND : "<pos()); event->acceptProposedAction(); } } +void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) +{ + ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track); + if (clip){ + QMap effectParams = clip->addEffect(effect); + m_document->renderer()->mltAddEffect(track, pos, effectParams); + emit clipItemSelected(clip); + } +} + +void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) +{ + QString index = effect.attribute("kdenlive_ix"); + m_document->renderer()->mltRemoveEffect(track, pos, index); + ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track); + if (clip){ + clip->deleteEffect(index); + emit clipItemSelected(clip); + } +} + +void CustomTrackView::slotAddEffect(QDomElement effect) +{ + QList itemList = items(); + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == 70000 && itemList.at(i)->isSelected()) { + ClipItem *item = (ClipItem *)itemList.at(i); + // the kdenlive_ix int is used to identify an effect in the stack and in mlt's playlist + effect.setAttribute("kdenlive_ix", QString::number(item->effectsCount())); + AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - item->track(),GenTime(item->startPos(), m_document->fps()), effect, true); + m_commandStack->push(command); + } + } +} + +void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) +{ + AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - clip->track(), GenTime(clip->startPos(), m_document->fps()), effect, false); + m_commandStack->push(command); +} -void CustomTrackView::addItem(QString producer, QPoint pos) + +void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement effect) +{ + QMap effectParams = clip->getEffectArgs(effect); + m_document->renderer()->mltEditEffect(m_tracksCount - clip->track(), GenTime(clip->startPos(), m_document->fps()), effectParams); +} + + +void CustomTrackView::addItem(DocClipBase *clip, QPoint pos) { - QDomDocument doc; - doc.setContent(producer); - QDomElement elem = doc.documentElement(); - int in = elem.attribute("in", 0).toInt(); - int out = elem.attribute("out", 0).toInt() - in; - if (out == 0) out = elem.attribute("duration", 0).toInt(); - kDebug()<<"ADDING CLIP: "<duration().frames(m_document->fps()); + //kdDebug()<<"- - - -CREATING CLIP, duration = "<fileURL(); int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1; - m_dropItem = new ClipItem(elem, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out); + m_dropItem = new ClipItem(clip, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out); scene()->addItem(m_dropItem); } @@ -342,8 +413,12 @@ void CustomTrackView::dragLeaveEvent ( QDragLeaveEvent * event ) { void CustomTrackView::dropEvent ( QDropEvent * event ) { if (m_dropItem) { - AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false); + AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->clipProducer(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false, false); m_commandStack->push(command); + m_dropItem->baseClip()->addReference(); + m_document->updateClip(m_dropItem->baseClip()->getId()); + kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<track(); + m_document->renderer()->mltInsertClip(m_tracksCount - m_dropItem->track(), GenTime(m_dropItem->startPos(), m_document->fps()), m_dropItem->xml()); } m_dropItem = NULL; } @@ -386,10 +461,27 @@ void CustomTrackView::removeTrack () m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount); } -void CustomTrackView::setCursorPos(int pos) +void CustomTrackView::deleteClip(int clipId) +{ + QList itemList = items(); + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == 70000) { + ClipItem *item = (ClipItem *)itemList.at(i); + if (item->clipProducer() == clipId) { + AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->track(), item->startPos(), item->rect(), item->duration(), true, true); + m_commandStack->push(command); + //delete item; + } + } + } +} + +void CustomTrackView::setCursorPos(int pos, bool seek) { m_cursorPos = pos; m_cursorLine->setPos(pos, 0); + int frame = mapToScene(QPoint(pos, 0)).x() / m_scale; + if (seek) m_document->renderer()->seek(GenTime(frame, m_document->fps())); } int CustomTrackView::cursorPos() @@ -403,51 +495,73 @@ void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event ) setDragMode(QGraphicsView::NoDrag); if (m_dragItem == NULL) return; //kDebug()<<"/// MOVING CLIP: "<rect().x(),m_dragItem->rect().y()); - if (m_operationMode == MOVE) { + if (m_operationMode == MOVE && m_startPos.x() != m_dragItem->startPos()) { // move clip MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), false); m_commandStack->push(command); + m_document->renderer()->mltMoveClip(m_tracksCount - m_startPos.y(), m_tracksCount - m_dragItem->track(), m_startPos.x(), m_dragItem->startPos()); } else if (m_operationMode == RESIZESTART) { // resize start ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), true, false); + + m_document->renderer()->mltResizeClipStart(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->endPos(), m_document->fps()), GenTime(m_dragItem->startPos(), m_document->fps()), GenTime(m_startPos.x(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()) + GenTime(m_dragItem->endPos(), m_document->fps()) - GenTime(m_dragItem->startPos(), m_document->fps())); m_commandStack->push(command); + m_document->renderer()->doRefresh(); } else if (m_operationMode == RESIZEEND) { // resize end ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos(), m_dragItem->track()), false, false); + + m_document->renderer()->mltResizeClipEnd(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->startPos(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()) + GenTime(m_dragItem->endPos(), m_document->fps()) - GenTime(m_dragItem->startPos(), m_document->fps())); m_commandStack->push(command); + m_document->renderer()->doRefresh(); } m_operationMode = NONE; m_dragItem = NULL; } -void CustomTrackView::deleteClip ( const QRectF &rect ) +void CustomTrackView::deleteClip (int track, int startpos, const QRectF &rect ) { - ClipItem *item = (ClipItem *) scene()->itemAt(rect.x() + 1, rect.y() + 1); + ClipItem *item = getClipItemAt(startpos, track); if (!item) { kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<baseClip()->removeReference(); + m_document->updateClip(item->baseClip()->getId()); delete item; + m_document->renderer()->mltRemoveClip(m_tracksCount - track, GenTime(startpos, m_document->fps())); + m_document->renderer()->doRefresh(); } -void CustomTrackView::addClip ( QDomElement xml, int track, int startpos, const QRectF &rect, int duration ) +void CustomTrackView::addClip ( QDomElement xml, int clipId, int track, int startpos, const QRectF &rect, int duration ) { QRect r(startpos * m_scale, 50 * track, duration * m_scale, 49); - ClipItem *item = new ClipItem(xml, track, startpos, r, duration); + DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId); + ClipItem *item = new ClipItem(baseclip, track, startpos, r, duration); scene()->addItem(item); + baseclip->addReference(); + m_document->updateClip(baseclip->getId()); + m_document->renderer()->mltInsertClip(m_tracksCount - track, GenTime(startpos, m_document->fps()), xml); + m_document->renderer()->doRefresh(); +} + +ClipItem *CustomTrackView::getClipItemAt(int pos, int track) +{ + return (ClipItem *) scene()->itemAt(pos * m_scale, track * 50 + 25); } void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos ) { - ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + 1) * m_scale, startPos.y() * 50 + 25); + ClipItem *item = getClipItemAt(startPos.x() + 1, startPos.y()); if (!item) { kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<moveTo(endPos.x(), m_scale, (endPos.y() - startPos.y()) * 50, endPos.y()); + m_document->renderer()->mltMoveClip(m_tracksCount - startPos.y(), m_tracksCount - endPos.y(), startPos.x(), endPos.x()); } void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart ) @@ -455,18 +569,65 @@ void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPo int offset; if (resizeClipStart) offset = 1; else offset = -1; - ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + offset) * m_scale, startPos.y() * 50 + 25); + ClipItem *item = getClipItemAt(startPos.x() + offset, startPos.y()); if (!item) { kDebug()<<"----------------  ERROR, CANNOT find clip to resize at: "<renderer()->mltResizeClipStart(m_tracksCount - item->track(), GenTime(item->endPos(), m_document->fps()), GenTime(endPos.x(), m_document->fps()), GenTime(item->startPos(), m_document->fps()), GenTime(item->cropStart() + diff, m_document->fps()), GenTime(item->cropStart() + diff, m_document->fps()) + GenTime(item->endPos(), m_document->fps()) - GenTime(endPos.x(), m_document->fps())); item->resizeStart(endPos.x(), m_scale); } else { + m_document->renderer()->mltResizeClipEnd(m_tracksCount - item->track(), GenTime(item->startPos(), m_document->fps()), GenTime(item->cropStart(), m_document->fps()), GenTime(item->cropStart(), m_document->fps()) + GenTime(endPos.x(), m_document->fps()) - GenTime(item->startPos(), m_document->fps())); item->resizeEnd(endPos.x(), m_scale); } + m_document->renderer()->doRefresh(); +} + +double CustomTrackView::getSnapPointForPos(double pos) +{ + for (int i = 0; i < m_snapPoints.size(); ++i) { + //kDebug()<<"SNAP POINT: "< pos) break; + } + return pos; +} + +void CustomTrackView::updateSnapPoints(ClipItem *selected) +{ + m_snapPoints.clear(); + int offset = 0; + if (selected) offset = selected->duration(); + QList itemList = items(); + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == 70000 && itemList.at(i) != selected) { + ClipItem *item = (ClipItem *)itemList.at(i); + int start = item->startPos(); + int fadein = item->fadeIn() + start; + int end = item->endPos(); + int fadeout = end - item->fadeOut(); + m_snapPoints.append(start); + if (fadein != start) m_snapPoints.append(fadein); + m_snapPoints.append(end); + if (fadeout != end) m_snapPoints.append(fadeout); + if (offset != 0) { + m_snapPoints.append(start - offset); + if (fadein != start) m_snapPoints.append(fadein - offset); + m_snapPoints.append(end - offset); + if (fadeout != end) m_snapPoints.append(fadeout - offset); + } + } + } + kDebug()<<" GOT SNAPPOINTS TOTAL: "<setPen(base); + //painter->setPen(base); painter->setClipRect(rect); painter->drawLine(0, 0, rect.width(), 0); for (uint i = 0; i < m_tracksCount;i++) { - painter->drawLine(0, 50 * (i+1), width(), 50 * (i+1)); - //painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i)); + painter->drawLine(0, 50 * (i+1), width(), 50 * (i+1)); + painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i + 1)); } int lowerLimit = 50 * m_tracksCount; if (height() > lowerLimit)