Commit d51a2ad7 authored by Till Theato's avatar Till Theato
Browse files

Allow cutting groups

svn path=/trunk/kdenlive/; revision=4610
parent b540689a
......@@ -203,6 +203,7 @@ set(kdenlive_SRCS
waveform.cpp
colorcorrection/waveformgenerator.cpp
testwidget.cpp
razorgroupcommand.cpp
)
......
......@@ -59,6 +59,7 @@
#include "tracksconfigdialog.h"
#include "configtrackscommand.h"
#include "rebuildgroupcommand.h"
#include "razorgroupcommand.h"
#include <KDebug>
#include <KLocale>
......@@ -1851,8 +1852,10 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
if (!item || cutTime >= item->endPos() || cutTime <= item->startPos()) {
emit displayMessage(i18n("Cannot find clip to cut"), ErrorMessage);
if (item) kDebug() << "///////// ERROR CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
else kDebug() << "/// ERROR NO CLIP at: " << info.startPos.frames(m_document->fps()) << ", track: " << info.track;
if (item)
kDebug() << "///////// ERROR CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
else
kDebug() << "/// ERROR NO CLIP at: " << info.startPos.frames(m_document->fps()) << ", track: " << info.track;
m_blockRefresh = false;
return NULL;
}
......@@ -1887,8 +1890,10 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
}
item->resizeEnd(cutPos);
scene()->addItem(dup);
if (item->checkKeyFrames()) slotRefreshEffects(item);
if (dup->checkKeyFrames()) slotRefreshEffects(dup);
if (item->checkKeyFrames())
slotRefreshEffects(item);
if (dup->checkKeyFrames())
slotRefreshEffects(dup);
item->baseClip()->addReference();
m_document->updateClip(item->baseClip()->getId());
setDocumentModified();
......@@ -1931,11 +1936,11 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
if (success) {
item->resizeEnd((int) info.endPos.frames(m_document->fps()));
setDocumentModified();
} else
} else {
emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
}
KdenliveSettings::setSnaptopoints(snap);
return item;
}
//QTimer::singleShot(3000, this, SLOT(slotEnableRefresh()));
}
......@@ -3579,12 +3584,87 @@ void CustomTrackView::cutSelectedClips()
if (itemList.at(i)->type() == AVWIDGET) {
ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
if (item->parentItem() && item->parentItem() != m_selectionGroup) {
emit displayMessage(i18n("Cannot cut a clip in a group"), ErrorMessage);
} else if (currentPos > item->startPos() && currentPos < item->endPos()) {
razorGroup((AbstractGroupItem *)item->parentItem(), currentPos);
return;
} else if (currentPos > item->startPos() && currentPos < item->endPos()) {
RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos);
m_commandStack->push(command);
}
} else if (itemList.at(i)->type() == GROUPWIDGET && itemList.at(i) != m_selectionGroup) {
razorGroup((AbstractGroupItem *)itemList.at(i), currentPos);
}
}
}
void CustomTrackView::razorGroup(AbstractGroupItem* group, GenTime cutPos)
{
if (group) {
QList <QGraphicsItem *> children = group->childItems();
QList <ItemInfo> clips1;
QList <ItemInfo> transitions1;
QList <ItemInfo> clipsCut;
QList <ItemInfo> transitionsCut;
QList <ItemInfo> clips2;
QList <ItemInfo> transitions2;
for (int i = 0; i < children.count(); ++i) {
children.at(i)->setSelected(false);
AbstractClipItem *child = static_cast <AbstractClipItem *>(children.at(i));
if (child->type() == AVWIDGET) {
if (cutPos > child->endPos())
clips1 << child->info();
else if (cutPos < child->startPos())
clips2 << child->info();
else
clipsCut << child->info();
} else {
if (cutPos > child->endPos())
transitions1 << child->info();
else if (cutPos < child->startPos())
transitions2 << child->info();
else
transitionsCut << child->info();
}
}
RazorGroupCommand *command = new RazorGroupCommand(this, clips1, transitions1, clipsCut, transitionsCut, clips2, transitions2, cutPos);
m_commandStack->push(command);
}
}
void CustomTrackView::slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, bool cut)
{
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();
clips2 << clipBehind->info();
}
}
// TODO: cut transitionsCut
doGroupClips(clips1, transitions1, true);
doGroupClips(clips2, transitions2, true);
} else {
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 <AbstractGroupItem *>(clip->parentItem());
QList <QGraphicsItem *> children = group->childItems();
QList <ItemInfo> groupClips;
QList <ItemInfo> 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);
}
}
for(int i = 0; i < clipsCut.count(); ++i)
cutClip(clipsCut.at(i), cutPos, false);
// TODO: uncut transitonsCut
doGroupClips(QList <ItemInfo>() << clips1 << clipsCut << clips2, QList <ItemInfo>() << transitions1 << transitionsCut << transitions2, true);
}
}
......@@ -3980,6 +4060,8 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
}
}
if (!reverseMove)
rebuildGroup(m_selectionGroup);
resetSelectionGroup(false);
KdenliveSettings::setSnaptopoints(snap);
m_document->renderer()->doRefresh();
......
......@@ -227,6 +227,17 @@ public slots:
* @param group The group to rebuild */
void rebuildGroup(AbstractGroupItem *group);
/** @brief Cuts a group into two parts.
* @param clips1 Clips before the cut
* @param transitions1 Transitions before the cut
* @param clipsCut Clips that need to be cut
* @param transitionsCut Transitions that need to be cut
* @param clips2 Clips behind the cut
* @param transitions2 Transitions behind the cut
* @param cutPos Absolute position of the cut
* @param cut true = cut, false = "uncut" */
void slotRazorGroup(QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, bool cut);
protected:
virtual void drawBackground(QPainter * painter, const QRectF & rect);
//virtual void drawForeground ( QPainter * painter, const QRectF & rect );
......@@ -356,6 +367,11 @@ private:
* @param command (optional) Will be used as parent command (for undo history) */
void prepareResizeClipEnd(AbstractClipItem *item, ItemInfo oldInfo, int pos, bool check = false, QUndoCommand *command = NULL);
/** @brief Collects information about the group's children to pass it on to RazorGroupCommand.
* @param group The group to cut
* @param cutPos The absolute position of the cut */
void razorGroup(AbstractGroupItem *group, GenTime cutPos);
private slots:
void slotRefreshGuides();
void slotEnableRefresh();
......
......@@ -294,7 +294,7 @@ void initEffects::parseCustomEffectsFile()
}
}
foreach(const QDomElement &effect, effectsMap)
MainWindow::customEffects.append(effect);
MainWindow::customEffects.append(effect);
}
// static
......
/***************************************************************************
* Copyright (C) 2010 by Till Theato (root@ttill.de) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "razorgroupcommand.h"
#include "customtrackview.h"
RazorGroupCommand::RazorGroupCommand(CustomTrackView *view, QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, QUndoCommand * parent) :
QUndoCommand(parent),
m_view(view),
m_clips1(clips1),
m_transitions1(transitions1),
m_clipsCut(clipsCut),
m_transitionsCut(transitionsCut),
m_clips2(clips2),
m_transitions2(transitions2),
m_cutPos(cutPos)
{
setText(i18n("Cut Group"));
}
// virtual
void RazorGroupCommand::undo()
{
m_view->slotRazorGroup(m_clips1, m_transitions1, m_clipsCut, m_transitionsCut, m_clips2, m_transitions2, m_cutPos, false);
}
// virtual
void RazorGroupCommand::redo()
{
m_view->slotRazorGroup(m_clips1, m_transitions1, m_clipsCut, m_transitionsCut, m_clips2, m_transitions2, m_cutPos, true);
}
/***************************************************************************
* Copyright (C) 2010 by Till Theato (root@ttill.de) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef RAZORGROUPCOMMAND_H
#define RAZORGROUPCOMMAND_H
#include <QUndoCommand>
#include "definitions.h"
class CustomTrackView;
class RazorGroupCommand : public QUndoCommand
{
public:
RazorGroupCommand(CustomTrackView *view, QList <ItemInfo> clips1, QList <ItemInfo> transitions1, QList <ItemInfo> clipsCut, QList <ItemInfo> transitionsCut, QList <ItemInfo> clips2, QList <ItemInfo> transitions2, GenTime cutPos, QUndoCommand * parent = 0);
virtual void undo();
virtual void redo();
private:
CustomTrackView *m_view;
QList <ItemInfo> m_clips1;
QList <ItemInfo> m_transitions1;
QList <ItemInfo> m_clipsCut;
QList <ItemInfo> m_transitionsCut;
QList <ItemInfo> m_clips2;
QList <ItemInfo> m_transitions2;
GenTime m_cutPos;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment