From d51a2ad77286163618fd725c12a2e5ca786b3b6e Mon Sep 17 00:00:00 2001 From: Till Theato Date: Tue, 20 Jul 2010 20:37:28 +0000 Subject: [PATCH] Allow cutting groups svn path=/trunk/kdenlive/; revision=4610 --- src/CMakeLists.txt | 1 + src/customtrackview.cpp | 98 +++++++++++++++++++++++++++++++++++---- src/customtrackview.h | 16 +++++++ src/initeffects.cpp | 2 +- src/razorgroupcommand.cpp | 48 +++++++++++++++++++ src/razorgroupcommand.h | 48 +++++++++++++++++++ 6 files changed, 204 insertions(+), 9 deletions(-) create mode 100644 src/razorgroupcommand.cpp create mode 100644 src/razorgroupcommand.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d528b169..efe2e323 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -203,6 +203,7 @@ set(kdenlive_SRCS waveform.cpp colorcorrection/waveformgenerator.cpp testwidget.cpp + razorgroupcommand.cpp ) diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 75fc7f2b..28feba2e 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -59,6 +59,7 @@ #include "tracksconfigdialog.h" #include "configtrackscommand.h" #include "rebuildgroupcommand.h" +#include "razorgroupcommand.h" #include #include @@ -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 (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 children = group->childItems(); + QList clips1; + QList transitions1; + QList clipsCut; + QList transitionsCut; + QList clips2; + QList transitions2; + for (int i = 0; i < children.count(); ++i) { + children.at(i)->setSelected(false); + AbstractClipItem *child = static_cast (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 clips1, QList transitions1, QList clipsCut, QList transitionsCut, QList clips2, QList 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 (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); + } } + 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); } } @@ -3980,6 +4060,8 @@ 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()); } } + if (!reverseMove) + rebuildGroup(m_selectionGroup); resetSelectionGroup(false); KdenliveSettings::setSnaptopoints(snap); m_document->renderer()->doRefresh(); diff --git a/src/customtrackview.h b/src/customtrackview.h index fc6c2ff7..ff6ac879 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -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 clips1, QList transitions1, QList clipsCut, QList transitionsCut, QList clips2, QList 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(); diff --git a/src/initeffects.cpp b/src/initeffects.cpp index 7e445d13..91bbd8b3 100644 --- a/src/initeffects.cpp +++ b/src/initeffects.cpp @@ -294,7 +294,7 @@ void initEffects::parseCustomEffectsFile() } } foreach(const QDomElement &effect, effectsMap) - MainWindow::customEffects.append(effect); + MainWindow::customEffects.append(effect); } // static diff --git a/src/razorgroupcommand.cpp b/src/razorgroupcommand.cpp new file mode 100644 index 00000000..e419761b --- /dev/null +++ b/src/razorgroupcommand.cpp @@ -0,0 +1,48 @@ +/*************************************************************************** + * 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 clips1, QList transitions1, QList clipsCut, QList transitionsCut, QList clips2, QList 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); +} diff --git a/src/razorgroupcommand.h b/src/razorgroupcommand.h new file mode 100644 index 00000000..e7a53374 --- /dev/null +++ b/src/razorgroupcommand.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * 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 + +#include "definitions.h" + +class CustomTrackView; + +class RazorGroupCommand : public QUndoCommand +{ +public: + RazorGroupCommand(CustomTrackView *view, QList clips1, QList transitions1, QList clipsCut, QList transitionsCut, QList clips2, QList transitions2, GenTime cutPos, QUndoCommand * parent = 0); + virtual void undo(); + virtual void redo(); + +private: + CustomTrackView *m_view; + QList m_clips1; + QList m_transitions1; + QList m_clipsCut; + QList m_transitionsCut; + QList m_clips2; + QList m_transitions2; + GenTime m_cutPos; +}; + +#endif -- 2.39.5