From d7a891fdd6281cc757e6141031d49887d16a98d3 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 4 Jul 2018 01:21:32 +0100 Subject: [PATCH] sequence duplication for #97 --- effects/crossdissolvetransition.cpp | 4 ++++ effects/transition.cpp | 4 ++++ effects/transition.h | 2 ++ mainwindow.cpp | 6 ++++++ mainwindow.h | 2 ++ mainwindow.ui | 9 +++++++++ panels/project.cpp | 13 +++++++++++++ panels/project.h | 1 + project/clip.cpp | 4 ++++ project/sequence.cpp | 19 +++++++++++++++++++ project/sequence.h | 1 + ui/sourcetable.cpp | 11 ++++++++--- ui/sourcetable.h | 1 + 13 files changed, 74 insertions(+), 3 deletions(-) diff --git a/effects/crossdissolvetransition.cpp b/effects/crossdissolvetransition.cpp index 98f1a2144..a7cb5a976 100644 --- a/effects/crossdissolvetransition.cpp +++ b/effects/crossdissolvetransition.cpp @@ -11,3 +11,7 @@ void CrossDissolveTransition::process_transition(float progress) { glGetFloatv(GL_CURRENT_COLOR, color); glColor4f(1.0, 1.0, 1.0, color[3]*progress); } + +Transition* CrossDissolveTransition::copy() { + return new CrossDissolveTransition(); +} diff --git a/effects/transition.cpp b/effects/transition.cpp index 24719adba..1e748bbe2 100644 --- a/effects/transition.cpp +++ b/effects/transition.cpp @@ -4,4 +4,8 @@ Transition::Transition() { length = 30; } +Transition* Transition::copy() { + return new Transition(); +} + void Transition::process_transition(float) {} diff --git a/effects/transition.h b/effects/transition.h index 6c36e7cff..5f9020851 100644 --- a/effects/transition.h +++ b/effects/transition.h @@ -10,12 +10,14 @@ public: int length; QString name; virtual void process_transition(float); + virtual Transition* copy(); }; class CrossDissolveTransition : public Transition { public: CrossDissolveTransition(); void process_transition(float); + Transition* copy(); }; #endif // TRANSITION_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 18bbe5dee..24f1afdf1 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -504,3 +504,9 @@ void MainWindow::on_actionEdit_Tool_Selects_Links_triggered() { void MainWindow::on_actionEdit_Tool_Also_Seeks_triggered() { panel_timeline->edit_tool_also_seeks = !panel_timeline->edit_tool_also_seeks; } + +void MainWindow::on_actionDuplicate_triggered() { + if (panel_project->is_focused()) { + panel_project->duplicate_selected(); + } +} diff --git a/mainwindow.h b/mainwindow.h index 2be47d5ca..2f2f7d7b5 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -129,6 +129,8 @@ private slots: void toolMenu_About_To_Be_Shown(); + void on_actionDuplicate_triggered(); + private: Ui::MainWindow *ui; void setup_layout(); diff --git a/mainwindow.ui b/mainwindow.ui index fa4015445..ddda3d263 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -60,6 +60,7 @@ + @@ -529,6 +530,14 @@ Edit Tool Selects Links + + + Duplicate + + + Ctrl+D + + diff --git a/panels/project.cpp b/panels/project.cpp index 9390032c5..0c4f580a4 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -71,6 +71,19 @@ QString Project::get_next_sequence_name() { void Project::rename_media(QTreeWidgetItem* item, int column) { Media* m = get_media_from_tree(item); m->name = item->text(column); + if (m->type == MEDIA_TYPE_SEQUENCE) { + m->sequence->name = m->name; + } +} + +void Project::duplicate_selected() { + QList items = ui->treeWidget->selectedItems(); + for (int i=0;itype == MEDIA_TYPE_SEQUENCE) { + new_sequence(m->sequence->copy()); + } + } } void Project::new_sequence(Sequence *s) { diff --git a/panels/project.h b/panels/project.h index 25e2716f2..c529727e2 100644 --- a/panels/project.h +++ b/panels/project.h @@ -34,6 +34,7 @@ public: void delete_media(QTreeWidgetItem* item); void delete_selected_media(); void process_file_list(QStringList& files); + void duplicate_selected(); void new_project(); void load_project(); diff --git a/project/clip.cpp b/project/clip.cpp index c2a45fb18..9520d5b2e 100644 --- a/project/clip.cpp +++ b/project/clip.cpp @@ -1,6 +1,7 @@ #include "clip.h" #include "project/effect.h" +#include "effects/transition.h" #include "io/media.h" #include "playback/playback.h" #include "playback/cacher.h" @@ -46,6 +47,9 @@ Clip* Clip::copy() { copy->effects.append(effects.at(i)->copy(copy)); } + if (opening_transition != NULL) copy->opening_transition = opening_transition->copy(); + if (closing_transition != NULL) copy->closing_transition = closing_transition->copy(); + return copy; } diff --git a/project/sequence.cpp b/project/sequence.cpp index fb328ca66..203fcf17a 100644 --- a/project/sequence.cpp +++ b/project/sequence.cpp @@ -17,6 +17,25 @@ Sequence::~Sequence() { } } +Sequence* Sequence::copy() { + Sequence* s = new Sequence(); + s->name = name + " (copy)"; + s->width = width; + s->height = height; + s->frame_rate = frame_rate; + s->audio_frequency = audio_frequency; + s->audio_layout = audio_layout; + for (int i=0;icopy(); + copy->linked = c->linked; + s->add_clip(copy); + } + } + return s; +} + void Sequence::add_clip(Clip* c) { c->id = clip_count(); clips.append(c); diff --git a/project/sequence.h b/project/sequence.h index 28f193672..60f0d8851 100644 --- a/project/sequence.h +++ b/project/sequence.h @@ -11,6 +11,7 @@ struct Sequence { public: Sequence(); ~Sequence(); + Sequence* copy(); QString name; void add_clip(Clip* c); int clip_count(); diff --git a/ui/sourcetable.cpp b/ui/sourcetable.cpp index def96972d..dd4766ba6 100644 --- a/ui/sourcetable.cpp +++ b/ui/sourcetable.cpp @@ -18,12 +18,17 @@ SourceTable::SourceTable(QWidget* parent) : QTreeWidget(parent) { rename_timer.setInterval(500); connect(&rename_timer, SIGNAL(timeout()), this, SLOT(rename_interval())); connect(this, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(item_click(QTreeWidgetItem*,int))); +// connect(this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(stop_rename_timer())); // connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, ) } -void SourceTable::rename_interval() { +void SourceTable::stop_rename_timer() { rename_timer.stop(); +} + +void SourceTable::rename_interval() { + stop_rename_timer(); if (hasFocus() && editing_item != NULL) { editItem(editing_item, 0); } @@ -36,7 +41,7 @@ void SourceTable::item_click(QTreeWidgetItem* item, int column) { } void SourceTable::mousePressEvent(QMouseEvent* event) { - rename_timer.stop(); + stop_rename_timer(); QTreeWidget::mousePressEvent(event); } @@ -49,7 +54,7 @@ void SourceTable::mouseDoubleClickEvent(QMouseEvent* ) { if (m->type == MEDIA_TYPE_SEQUENCE) { set_sequence(m->sequence); } - } + } } void SourceTable::dragEnterEvent(QDragEnterEvent *event) { diff --git a/ui/sourcetable.h b/ui/sourcetable.h index 77a266f90..50a926886 100644 --- a/ui/sourcetable.h +++ b/ui/sourcetable.h @@ -23,6 +23,7 @@ private: private slots: void rename_interval(); void item_click(QTreeWidgetItem* item, int column); + void stop_rename_timer(); }; #endif // SOURCETABLE_H