X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcustomtrackview.cpp;h=1701e96eb8caa7682390995f1096e2f0e14a836d;hb=23f110ad06d4524f47de721a8f35e46228d8682b;hp=db8588d948e778a44343ee0cc0a0c3290440cdd0;hpb=0dc379c5294a981179781cc45928b0e1c9f1a5d5;p=kdenlive diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index db8588d9..1701e96e 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -67,7 +67,6 @@ #include #include #include -#include #include #include @@ -124,7 +123,8 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen m_menuPosition(), m_blockRefresh(false), m_selectionGroup(NULL), - m_selectedTrack(0) + m_selectedTrack(0), + m_controlModifier(false) { if (doc) m_commandStack = doc->commandStack(); else m_commandStack = NULL; @@ -134,8 +134,9 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen setLineWidth(0); //setCacheMode(QGraphicsView::CacheBackground); //setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + setAutoFillBackground(false); setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); - + m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme())); pixmapCache = new KPixmapCache("kdenlive-thumbs"); KdenliveSettings::setTrackheight(m_tracksHeight); m_animationTimer = new QTimeLine(800); @@ -279,7 +280,7 @@ void CustomTrackView::checkTrackHeight() } } double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight); + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1); for (int i = 0; i < m_guides.count(); i++) { QLineF l = m_guides.at(i)->line(); @@ -394,7 +395,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) } } else if (m_operationMode == RESIZESTART && move) { m_document->renderer()->pause(); - if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { AbstractGroupItem *parent = static_cast (m_dragItem->parentItem()); if (parent) parent->resizeStart((int)(snappedPos) - m_dragItemInfo.startPos.frames(m_document->fps())); @@ -403,7 +404,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) } } else if (m_operationMode == RESIZEEND && move) { m_document->renderer()->pause(); - if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { AbstractGroupItem *parent = static_cast (m_dragItem->parentItem()); if (parent) parent->resizeEnd((int)(snappedPos) - m_dragItemInfo.endPos.frames(m_document->fps())); @@ -938,6 +939,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y())); m_operationMode = m_dragItem->operationMode(mapToScene(event->pos())); + m_controlModifier = (event->modifiers() == Qt::ControlModifier); // Update snap points if (m_selectionGroup == NULL) { @@ -1553,6 +1555,7 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) // Add track effect m_document->addTrackEffect(track - 1, effect); m_document->renderer()->mltAddTrackEffect(track, getEffectArgs(effect)); + emit updateTrackEffectState(track - 1); emit showTrackEffects(track, m_document->trackInfoAt(track - 1)); return; } @@ -1587,6 +1590,7 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) // Delete track effect m_document->removeTrackEffect(track - 1, effect); m_document->renderer()->mltRemoveTrackEffect(track, index, true); + emit updateTrackEffectState(track - 1); emit showTrackEffects(track, m_document->trackInfoAt(track - 1)); return; } @@ -1789,6 +1793,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE return; } QDomElement effect = insertedEffect.cloneNode().toElement(); + //kDebug() << "// update effect ix: " << effect.attribute("kdenlive_ix")<<", TRACK: "<renderer()->mltEditEffect(m_document->tracksCount() - track, pos, effectParams)) emit displayMessage(i18n("Problem editing effect"), ErrorMessage); - m_document->setTrackEffect(track - 1, ix, effect); + m_document->setTrackEffect(m_document->tracksCount() - track - 1, ix, effect); + emit updateTrackEffectState(track); + setDocumentModified(); return; } @@ -1985,6 +1992,10 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo slotRefreshEffects(item); if (dup->checkKeyFrames()) slotRefreshEffects(dup); + + updatePanZoom(item); + updatePanZoom(dup, cutTime - item->startPos()); + item->baseClip()->addReference(); m_document->updateClip(item->baseClip()->getId()); setDocumentModified(); @@ -2026,6 +2037,9 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos); if (success) { item->resizeEnd((int) info.endPos.frames(m_document->fps())); + + updatePanZoom(item); + setDocumentModified(); } else { emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); @@ -2195,7 +2209,8 @@ void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTr return; } bool force = false; - if (oldTransition.attribute("transition_atrack") != transition.attribute("transition_atrack") || oldTransition.attribute("transition_btrack") != transition.attribute("transition_btrack")) force = true; + if (oldTransition.attribute("transition_atrack") != transition.attribute("transition_atrack") || oldTransition.attribute("transition_btrack") != transition.attribute("transition_btrack")) + force = true; m_document->renderer()->mltUpdateTransition(oldTransition.attribute("tag"), transition.attribute("tag"), transition.attribute("transition_btrack").toInt(), m_document->tracksCount() - transition.attribute("transition_atrack").toInt(), item->startPos(), item->endPos(), transition, force); //kDebug() << "ORIGINAL TRACK: "<< oldTransition.attribute("transition_btrack") << ", NEW TRACK: "<setTransitionParameters(transition); @@ -2324,6 +2339,7 @@ void CustomTrackView::dropEvent(QDropEvent * event) m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); if (items.count() > 1) groupSelectedItems(true); + else if (items.count() == 1) m_dragItem = static_cast (items.at(0)); event->setDropAction(Qt::MoveAction); event->accept(); } else QGraphicsView::dropEvent(event); @@ -2529,10 +2545,7 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) if (clip->speed() != 1.0) continue; // We add a move clip command so that we get the correct producer for new track number if (clip->clipType() == AV || clip->clipType() == AUDIO) { - Mlt::Producer *prod; - if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track); - else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer(); - else prod = clip->baseClip()->producer(clipinfo.track); + Mlt::Producer *prod = clip->getProducer(clipinfo.track); if (m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod) == false) { // problem updating clip emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage); @@ -2555,12 +2568,14 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) l.setP2(QPointF(l.x2(), maxHeight)); m_guides.at(i)->setLine(l); } - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight); + + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1); setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); viewport()->update(); - emit tracksChanged(); //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged())); //setFixedHeight(50 * m_tracksCount); + + updateTrackNames(ix, true); } void CustomTrackView::removeTrack(int ix) @@ -2602,10 +2617,7 @@ void CustomTrackView::removeTrack(int ix) ItemInfo clipinfo = clip->info(); // We add a move clip command so that we get the correct producer for new track number if (clip->clipType() == AV || clip->clipType() == AUDIO) { - Mlt::Producer *prod; - if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track); - else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer(); - else prod = clip->baseClip()->producer(clipinfo.track); + Mlt::Producer *prod = clip->getProducer(clipinfo.track); if (!m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage); } @@ -2628,12 +2640,13 @@ void CustomTrackView::removeTrack(int ix) l.setP2(QPointF(l.x2(), maxHeight)); m_guides.at(i)->setLine(l); } - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight); + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1); setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); m_selectedTrack = qMin(m_selectedTrack, m_document->tracksCount() - 1); viewport()->update(); - emit tracksChanged(); + + updateTrackNames(ix, false); //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged())); } @@ -2642,6 +2655,7 @@ void CustomTrackView::configTracks(QList < TrackInfo > trackInfos) for (int i = 0; i < trackInfos.count(); ++i) { m_document->setTrackType(i, trackInfos.at(i)); m_document->renderer()->mltChangeTrackState(i + 1, m_document->trackInfoAt(i).isMute, m_document->trackInfoAt(i).isBlind); + lockTrack(m_document->tracksCount() - i - 1, m_document->trackInfoAt(i).isLocked, false); } QTimer::singleShot(300, this, SIGNAL(trackHeightChanged())); @@ -2667,24 +2681,71 @@ void CustomTrackView::slotSwitchTrackLock(int ix) } -void CustomTrackView::lockTrack(int ix, bool lock) +void CustomTrackView::lockTrack(int ix, bool lock, bool requestUpdate) { int tracknumber = m_document->tracksCount() - ix - 1; m_document->switchTrackLock(tracknumber, lock); - emit doTrackLock(ix, lock); + if (requestUpdate) + emit doTrackLock(ix, lock); AbstractClipItem *clip = NULL; QList selection = m_scene->items(0, ix * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), m_tracksHeight / 2 - 2); for (int i = 0; i < selection.count(); i++) { - if (selection.at(i)->type() != AVWIDGET && selection.at(i)->type() != TRANSITIONWIDGET) continue; - if (selection.at(i)->isSelected()) { - if (selection.at(i)->type() == AVWIDGET) emit clipItemSelected(NULL); - else emit transitionItemSelected(NULL); + if (selection.at(i)->type() == GROUPWIDGET && (AbstractGroupItem *)selection.at(i) != m_selectionGroup) { + if (selection.at(i)->parentItem() && m_selectionGroup) { + selection.removeAll((QGraphicsItem*)m_selectionGroup); + resetSelectionGroup(); + } + + bool changeGroupLock = true; + bool hasClipOnTrack = false; + QList children = selection.at(i)->childItems(); + for (int j = 0; j < children.count(); ++j) { + if (children.at(j)->isSelected()) { + if (children.at(j)->type() == AVWIDGET) + emit clipItemSelected(NULL); + else if (children.at(j)->type() == TRANSITIONWIDGET) + emit transitionItemSelected(NULL); + else + continue; + } + + AbstractClipItem * child = static_cast (children.at(j)); + if (child == m_dragItem) + m_dragItem = NULL; + + // only unlock group, if it is not locked by another track too + if (!lock && child->track() != ix && m_document->trackInfoAt(m_document->tracksCount() - child->track() - 1).isLocked) + changeGroupLock = false; + + // only (un-)lock if at least one clip is on the track + if (child->track() == ix) + hasClipOnTrack = true; + } + if (changeGroupLock && hasClipOnTrack) + ((AbstractGroupItem*)selection.at(i))->setItemLocked(lock); + } else if((selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET)) { + if (selection.at(i)->parentItem()) { + if (selection.at(i)->parentItem() == m_selectionGroup) { + selection.removeAll((QGraphicsItem*)m_selectionGroup); + resetSelectionGroup(); + } else { + // groups are handled separately + continue; + } + } + + if (selection.at(i)->isSelected()) { + if (selection.at(i)->type() == AVWIDGET) + emit clipItemSelected(NULL); + else + emit transitionItemSelected(NULL); + } + clip = static_cast (selection.at(i)); + clip->setItemLocked(lock); + if (clip == m_dragItem) + m_dragItem = NULL; } - clip = static_cast (selection.at(i)); - clip->setItemLocked(lock); - if (clip == m_dragItem) - m_dragItem = NULL; } kDebug() << "NEXT TRK STATE: " << m_document->trackInfoAt(tracknumber).isLocked; viewport()->update(); @@ -3078,10 +3139,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) // we are moving one clip, easy if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) { ClipItem *item = static_cast (m_dragItem); - Mlt::Producer *prod; - if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(info.track); - else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer(); - else prod = item->baseClip()->producer(info.track); + Mlt::Producer *prod = item->getProducer(info.track); bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - info.track), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(info.startPos.frames(m_document->fps())), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); if (success) { @@ -3282,15 +3340,8 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) if (item->type() == AVWIDGET) { ClipItem *clip = static_cast (item); info.track = m_document->tracksCount() - info.track; - Mlt::Producer *prod; adjustTimelineClips(m_scene->editMode(), clip, ItemInfo(), moveGroup); - if (clip->isAudioOnly()) - prod = clip->baseClip()->audioProducer(info.track); - else if (clip->isVideoOnly()) - prod = clip->baseClip()->videoProducer(); - else - prod = clip->baseClip()->producer(info.track); - m_document->renderer()->mltInsertClip(info, clip->xml(), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); + m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); for (int i = 0; i < clip->effectsCount(); i++) { m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false); } @@ -3341,7 +3392,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) m_document->renderer()->doRefresh(); } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) { // resize start - if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { AbstractGroupItem *parent = static_cast (m_dragItem->parentItem()); if (parent) { QUndoCommand *resizeCommand = new QUndoCommand(); @@ -3365,7 +3416,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) } } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) { // resize end - if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { AbstractGroupItem *parent = static_cast (m_dragItem->parentItem()); if (parent) { QUndoCommand *resizeCommand = new QUndoCommand(); @@ -3667,7 +3718,9 @@ void CustomTrackView::changeClipSpeed() void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id) { - DocClipBase *baseclip = m_document->clipManager()->getClipById(id); + Q_UNUSED(id); + //DocClipBase *baseclip = m_document->clipManager()->getClipById(id); + ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track); if (!item) { kDebug() << "ERROR: Cannot find clip for speed change"; @@ -3675,22 +3728,17 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant return; } info.track = m_document->tracksCount() - item->track(); - int endPos; - if (item->isVideoOnly()) - endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->videoProducer()); - else if (item->isAudioOnly()) - endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->audioProducer(item->track())); - else - endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->producer()); + int endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, item->getProducer(item->track(), false)); if (endPos >= 0) { item->setSpeed(speed, strobe); item->updateRectGeometry(); - if (item->cropDuration().frames(m_document->fps()) != endPos) { + if (item->cropDuration().frames(m_document->fps()) != endPos) item->resizeEnd((int) info.startPos.frames(m_document->fps()) + endPos - 1); - } updatePositionEffects(item, info); setDocumentModified(); - } else emit displayMessage(i18n("Invalid clip"), ErrorMessage); + } else { + emit displayMessage(i18n("Invalid clip"), ErrorMessage); + } } void CustomTrackView::cutSelectedClips() @@ -3917,17 +3965,15 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i baseclip->addReference(); m_document->updateClip(baseclip->getId()); info.track = m_document->tracksCount() - info.track; - Mlt::Producer *prod; - if (item->isAudioOnly()) prod = baseclip->audioProducer(info.track); - else if (item->isVideoOnly()) prod = baseclip->videoProducer(); - else prod = baseclip->producer(info.track); - m_document->renderer()->mltInsertClip(info, xml, prod, overwrite, push); + m_document->renderer()->mltInsertClip(info, xml, item->getProducer(info.track), overwrite, push); for (int i = 0; i < item->effectsCount(); i++) { m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(item->effectAt(i)), false); } setDocumentModified(); - if (refresh) m_document->renderer()->doRefresh(); - if (!baseclip->isPlaceHolder()) m_waitingThumbs.append(item); + if (refresh) + m_document->renderer()->doRefresh(); + if (!baseclip->isPlaceHolder()) + m_waitingThumbs.append(item); m_thumbsTimer.start(); } @@ -4064,10 +4110,7 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool re kDebug() << "---------------- ERROR, CANNOT find clip to move at.. "; return; } - Mlt::Producer *prod; - if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(end.track); - else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer(); - else prod = item->baseClip()->producer(end.track); + Mlt::Producer *prod = item->getProducer(end.track); bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - start.track), (int)(m_document->tracksCount() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()), prod); if (success) { @@ -4191,14 +4234,7 @@ void CustomTrackView::moveGroup(QList startClip, QList sta if (item->type() == AVWIDGET) { ClipItem *clip = static_cast (item); info.track = m_document->tracksCount() - info.track; - Mlt::Producer *prod; - if (clip->isAudioOnly()) - prod = clip->baseClip()->audioProducer(info.track); - else if (clip->isVideoOnly()) - prod = clip->baseClip()->videoProducer(); - else - prod = clip->baseClip()->producer(info.track); - m_document->renderer()->mltInsertClip(info, clip->xml(), prod); + m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track)); for (int i = 0; i < clip->effectsCount(); i++) { m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false); } @@ -4382,7 +4418,11 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol new MoveTransitionCommand(this, trInfo, newTrInfo, true, command); } + /* + TODO: cleanup the effect update process + */ ClipItem *clip = static_cast < ClipItem * >(item); + updatePositionEffects(clip, oldInfo); // check keyframes @@ -4477,7 +4517,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI if (item->type() == AVWIDGET) { ItemInfo resizeinfo = info; resizeinfo.track = m_document->tracksCount() - resizeinfo.track; - bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.endPos - resizeinfo.startPos); + bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.cropDuration); if (success) { // Check if there is an automatic transition on that clip (lower track) Transition *tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track); @@ -4501,8 +4541,11 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI } - // check keyframes ClipItem *clip = static_cast < ClipItem * >(item); + + updatePositionEffects(clip, oldInfo); + + // check keyframes QDomDocument doc; QDomElement root = doc.createElement("list"); doc.appendChild(root); @@ -4533,8 +4576,6 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI } else { new ResizeClipCommand(this, oldInfo, info, false, false, command); } - - updatePositionEffects(clip, oldInfo); } else { KdenliveSettings::setSnaptopoints(false); item->resizeEnd((int) oldInfo.endPos.frames(m_document->fps())); @@ -4659,22 +4700,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) } } - effectPos = item->hasEffect("affine", "pan_zoom"); - if (effectPos != -1) { - QDomElement oldeffect = item->effectAt(effectPos); - int start = item->cropStart().frames(m_document->fps()); - int max = start + item->cropDuration().frames(m_document->fps()); - if (start < 0) { - max -= start; - start = 0; - } - oldeffect.setAttribute("in", start); - oldeffect.setAttribute("out", max); - if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect))) - emit displayMessage(i18n("Problem editing effect"), ErrorMessage); - // if effect is displayed, update the effect edit widget with new clip duration - if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos); - } + updatePanZoom(item); } double CustomTrackView::getSnapPointForPos(double pos) @@ -4747,6 +4773,11 @@ void CustomTrackView::updateSnapPoints(AbstractClipItem *selected, QList zone(); + snaps.append(GenTime(z.x(), m_document->fps())); + snaps.append(GenTime(z.y(), m_document->fps())); + qSort(snaps); m_scene->setSnapList(snaps); //for (int i = 0; i < m_snapPoints.size(); ++i) @@ -4989,13 +5020,12 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale) newmatrix = newmatrix.scale(scaleFactor, verticalScale); m_scene->setScale(scaleFactor, verticalScale); removeTipAnimation(); - double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y(); bool adjust = false; if (verticalScale != matrix().m22()) adjust = true; 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); + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1); for (int i = 0; i < m_guides.count(); i++) { QLineF l = m_guides.at(i)->line(); l.setP2(QPointF(l.x2(), newHeight)); @@ -5011,6 +5041,7 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale) else setSceneRect(0, 0, (m_projectDuration + 300), sceneRect().height()); } + double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y(); centerOn(QPointF(cursorPos(), verticalPos)); } @@ -5024,35 +5055,27 @@ void CustomTrackView::slotRefreshGuides() void CustomTrackView::drawBackground(QPainter * painter, const QRectF &rect) { - //kDebug() << "// DRAW BG: " << rect.width(); painter->setClipRect(rect); - KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window); QPen pen1 = painter->pen(); - pen1.setColor(scheme.shade(KColorScheme::DarkShade)); + pen1.setColor(palette().dark().color()); painter->setPen(pen1); double min = rect.left(); double max = rect.right(); painter->drawLine(QPointF(min, 0), QPointF(max, 0)); int maxTrack = m_document->tracksCount(); - QColor lockedColor = scheme.background(KColorScheme::NegativeBackground).color(); + QColor lockedColor = palette().button().color(); QColor audioColor = palette().alternateBase().color(); - QColor base = scheme.background(KColorScheme::NormalBackground).color(); for (int i = 0; i < maxTrack; i++) { TrackInfo info = m_document->trackInfoAt(maxTrack - i - 1); if (info.isLocked || info.type == AUDIOTRACK || i == m_selectedTrack) { const QRectF track(min, m_tracksHeight * i + 1, max - min, m_tracksHeight - 1); if (i == m_selectedTrack) - painter->fillRect(track, scheme.background(KColorScheme::ActiveBackground).color()); + painter->fillRect(track, m_activeTrackBrush.brush(this)); else painter->fillRect(track, info.isLocked ? lockedColor : audioColor); } painter->drawLine(QPointF(min, m_tracksHeight *(i + 1)), QPointF(max, m_tracksHeight *(i + 1))); } - int lowerLimit = m_tracksHeight * maxTrack + 1; - if (height() > lowerLimit) { - const QRectF bg(min, lowerLimit, max - min, height() - lowerLimit); - painter->fillRect(bg, base); - } } bool CustomTrackView::findString(const QString &text) @@ -5240,16 +5263,24 @@ void CustomTrackView::pasteClip() return; } QPoint position; + int track = -1; + GenTime pos = GenTime(-1); if (m_menuPosition.isNull()) { position = mapFromGlobal(QCursor::pos()); if (!contentsRect().contains(position) || mapToScene(position).y() / m_tracksHeight > m_document->tracksCount()) { - emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage); - return; + track = m_selectedTrack; + pos = GenTime(m_cursorPos, m_document->fps()); + /*emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage); + return;*/ } - } else position = m_menuPosition; + } else { + position = m_menuPosition; + } - GenTime pos = GenTime((int)(mapToScene(position).x()), m_document->fps()); - int track = (int)(mapToScene(position).y() / m_tracksHeight); + if (pos == GenTime(-1)) + pos = GenTime((int)(mapToScene(position).x()), m_document->fps()); + if (track == -1) + track = (int)(mapToScene(position).y() / m_tracksHeight); GenTime leftPos = m_copiedItems.at(0)->startPos(); int lowerTrack = m_copiedItems.at(0)->track(); @@ -6237,12 +6268,14 @@ void CustomTrackView::clearSelection() void CustomTrackView::updatePalette() { + m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme())); if (m_cursorLine) { QPen pen1 = QPen(); pen1.setWidth(1); pen1.setColor(palette().text().color()); m_cursorLine->setPen(pen1); } + emit tracksChanged(); } void CustomTrackView::removeTipAnimation() @@ -6376,8 +6409,8 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect) QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts); double factor = e.attribute("factor", "1").toDouble(); for (int j = 0; j < values.count(); j++) { - QString pos = values.at(j).section(":", 0, 0); - double val = values.at(j).section(":", 1, 1).toDouble() / factor; + QString pos = values.at(j).section(':', 0, 0); + double val = values.at(j).section(':', 1, 1).toDouble() / factor; values[j] = pos + "=" + QString::number(val); } // kDebug() << "/ / / /SENDING KEYFR:" << values; @@ -6420,4 +6453,58 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect) } } return parameters; -} \ No newline at end of file +} + +void CustomTrackView::updatePanZoom(ClipItem* item, GenTime cutPos) +{ + QList effects = item->updatePanZoom(m_document->width(), m_document->height(), cutPos.frames(m_document->fps())); + for (int i = 0; i < effects.count(); ++i) { + if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(item->effectAt(effects.at(i))))) + emit displayMessage(i18n("Problem editing effect"), ErrorMessage); + + // if effect is displayed, update the effect edit widget with new clip duration + /*if (item->isSelected() && effects.at(i) == item->selectedEffectIndex()) + emit clipItemSelected(item, effects.at(i));*/ + } + // update always, otherwise there might problems when resizing groups + if (effects.count() > 0) + emit clipItemSelected(item, item->selectedEffectIndex()); +} + +void CustomTrackView::updateTrackNames(int track, bool added) +{ + QList tracks = m_document->tracksList(); + int max = tracks.count(); + int docTrack = max - track - 1; + + // count number of tracks of each type + int videoTracks = 0; + int audioTracks = 0; + for (int i = max - 1; i >= 0; --i) { + TrackInfo info = tracks.at(i); + if (info.type == VIDEOTRACK) + videoTracks++; + else + audioTracks++; + + if (i <= docTrack) { + QString type = (info.type == VIDEOTRACK ? "Video " : "Audio "); + int typeNumber = (info.type == VIDEOTRACK ? videoTracks : audioTracks); + + if (added) { + if (i == docTrack || info.trackName == type + QString::number(typeNumber - 1)) { + info.trackName = type + QString::number(typeNumber); + m_document->setTrackType(i, info); + } + } else { + if (info.trackName == type + QString::number(typeNumber + 1)) { + info.trackName = type + QString::number(typeNumber); + m_document->setTrackType(i, info); + } + } + } + } + + emit tracksChanged(); +} +