implemented effect copying/pasting

This commit is contained in:
itsmattkc
2018-11-29 17:32:22 +11:00
parent fb1851884d
commit 6526ece3b0
10 changed files with 193 additions and 124 deletions
+56 -23
View File
@@ -17,6 +17,7 @@
#include "panels/timeline.h"
#include "panels/viewer.h"
#include "ui/viewerwidget.h"
#include "io/clipboard.h"
#include "debug.h"
EffectControls::EffectControls(QWidget *parent) :
@@ -65,9 +66,9 @@ void EffectControls::menu_select(QAction* q) {
ComboAction* ca = new ComboAction();
for (int i=0;i<selected_clips.size();i++) {
Clip* c = sequence->clips.at(selected_clips.at(i));
if ((c->track < 0) == video_menu) {
if ((c->track < 0) == (effect_menu_subtype == EFFECT_TYPE_VIDEO)) {
const EffectMeta* meta = reinterpret_cast<const EffectMeta*>(q->data().value<quintptr>());
if (transition_menu) {
if (effect_menu_type == EFFECT_TYPE_TRANSITION) {
if (c->get_opening_transition() == NULL) {
ca->append(new AddTransitionCommand(c, NULL, NULL, meta, TA_OPENING_TRANSITION, 30));
}
@@ -80,7 +81,7 @@ void EffectControls::menu_select(QAction* q) {
}
}
undo_stack.push(ca);
if (transition_menu) {
if (effect_menu_type == EFFECT_TYPE_TRANSITION) {
update_ui(true);
} else {
reload_clips();
@@ -94,21 +95,57 @@ void EffectControls::update_keyframes() {
}
void EffectControls::delete_selected_keyframes() {
ui->keyframeView->delete_selected_keyframes();
ui->keyframeView->delete_selected_keyframes();
}
void EffectControls::show_effect_menu(bool video, bool transitions) {
video_menu = video;
transition_menu = transitions;
void EffectControls::copy(bool del) {
if (mode == TA_NO_TRANSITION) {
bool cleared = false;
ComboAction* ca = new ComboAction();
EffectDeleteCommand* del_com = (del) ? new EffectDeleteCommand() : NULL;
for (int i=0;i<selected_clips.size();i++) {
Clip* c = sequence->clips.at(selected_clips.at(i));
for (int j=0;j<c->effects.size();j++) {
Effect* effect = c->effects.at(j);
if (effect->container->selected) {
if (!cleared) {
clipboard_type = CLIPBOARD_TYPE_EFFECT;
clear_clipboard();
cleared = true;
}
clipboard.append(effect->copy(NULL));
if (del_com != NULL) {
del_com->clips.append(c);
del_com->fx.append(j);
}
}
}
}
if (del_com != NULL) {
if (del_com->clips.size() > 0) {
ca->append(del_com);
} else {
delete del_com;
}
}
undo_stack.push(ca);
}
}
void EffectControls::show_effect_menu(int type, int subtype) {
effect_menu_type = type;
effect_menu_subtype = subtype;
effects_loaded.lock();
QVector<EffectMeta>& effect_list = (video) ? video_effects : audio_effects;
QMenu effects_menu(this);
for (int i=0;i<effect_list.size();i++) {
const EffectMeta& em = effect_list.at(i);
for (int i=0;i<effects.size();i++) {
const EffectMeta& em = effects.at(i);
if ((em.type == EFFECT_TYPE_TRANSITION) == transition_menu) {
if (em.type == type && em.subtype == subtype) {
QAction* action = new QAction(&effects_menu);
action->setText(em.name);
action->setData(reinterpret_cast<quintptr>(&em));
@@ -275,24 +312,20 @@ void EffectControls::set_clips(QVector<int>& clips, int m) {
load_effects();
}
void EffectControls::on_add_video_effect_button_clicked()
{
show_effect_menu(true, false);
void EffectControls::on_add_video_effect_button_clicked() {
show_effect_menu(EFFECT_TYPE_EFFECT, EFFECT_TYPE_VIDEO);
}
void EffectControls::on_add_audio_effect_button_clicked()
{
show_effect_menu(false, false);
void EffectControls::on_add_audio_effect_button_clicked() {
show_effect_menu(EFFECT_TYPE_EFFECT, EFFECT_TYPE_AUDIO);
}
void EffectControls::on_add_video_transition_button_clicked()
{
show_effect_menu(true, true);
void EffectControls::on_add_video_transition_button_clicked() {
show_effect_menu(EFFECT_TYPE_TRANSITION, EFFECT_TYPE_VIDEO);
}
void EffectControls::on_add_audio_transition_button_clicked()
{
show_effect_menu(false, true);
void EffectControls::on_add_audio_transition_button_clicked() {
show_effect_menu(EFFECT_TYPE_TRANSITION, EFFECT_TYPE_AUDIO);
}
void EffectControls::resizeEvent(QResizeEvent*) {
+4 -3
View File
@@ -40,6 +40,7 @@ public:
void set_zoom(bool in);
bool keyframe_focus();
void delete_selected_keyframes();
void copy(bool del);
bool multiple;
QVector<int> selected_clips;
@@ -60,13 +61,13 @@ private slots:
protected:
void resizeEvent(QResizeEvent *event);
private:
void show_effect_menu(bool video, bool transitions);
void show_effect_menu(int type, int subtype);
void load_effects();
void load_keyframes();
void open_effect(QVBoxLayout* layout, Effect* e);
bool video_menu;
bool transition_menu;
int effect_menu_type;
int effect_menu_subtype;
QString panel_name;
int mode;
};
+3 -4
View File
@@ -812,10 +812,9 @@ QTreeWidgetItem* Project::find_loaded_folder_by_id(int id) {
}
const EffectMeta* get_meta_from_name(const QString& name, int type) {
QVector<EffectMeta>& effect_list = (type == EFFECT_TYPE_VIDEO) ? video_effects : audio_effects;
for (int j=0;j<effect_list.size();j++) {
if (effect_list.at(j).name == name) {
return &effect_list.at(j);
for (int j=0;j<effects.size();j++) {
if (effects.at(j).name == name) {
return &effects.at(j);
}
}
return NULL;
+73 -59
View File
@@ -839,11 +839,10 @@ void Timeline::copy(bool del) {
for (int j=0;j<sequence->selections.size();j++) {
const Selection& s = sequence->selections.at(j);
if (s.track == c->track && !((c->timeline_in <= s.in && c->timeline_out <= s.in) || (c->timeline_in >= s.out && c->timeline_out >= s.out))) {
clipboard_type = CLIPBOARD_TYPE_CLIP;
if (!cleared) {
clipboard.clear();
clear_clipboard();
cleared = true;
clipboard_type = CLIPBOARD_TYPE_CLIP;
}
Clip* copied_clip = c->copy(NULL);
@@ -904,73 +903,88 @@ void Timeline::relink_clips_using_ids(QVector<int>& old_clips, QVector<Clip*>& n
}
void Timeline::paste(bool insert) {
if (clipboard_type == CLIPBOARD_TYPE_CLIP && clipboard.size() > 0) {
ComboAction* ca = new ComboAction();
if (clipboard.size() > 0) {
if (clipboard_type == CLIPBOARD_TYPE_CLIP) {
ComboAction* ca = new ComboAction();
// create copies and delete areas that we'll be pasting to
QVector<Selection> delete_areas;
QVector<Clip*> pasted_clips;
long paste_start = LONG_MAX;
long paste_end = LONG_MIN;
for (int i=0;i<clipboard.size();i++) {
Clip* c = static_cast<Clip*>(clipboard.at(i));
// create copies and delete areas that we'll be pasting to
QVector<Selection> delete_areas;
QVector<Clip*> pasted_clips;
long paste_start = LONG_MAX;
long paste_end = LONG_MIN;
for (int i=0;i<clipboard.size();i++) {
Clip* c = static_cast<Clip*>(clipboard.at(i));
// create copy of clip and offset by playhead
Clip* cc = c->copy(sequence);
// create copy of clip and offset by playhead
Clip* cc = c->copy(sequence);
// convert frame rates
cc->timeline_in = refactor_frame_number(cc->timeline_in, c->cached_fr, sequence->frame_rate);
cc->timeline_out = refactor_frame_number(cc->timeline_out, c->cached_fr, sequence->frame_rate);
cc->clip_in = refactor_frame_number(cc->clip_in, c->cached_fr, sequence->frame_rate);
// convert frame rates
cc->timeline_in = refactor_frame_number(cc->timeline_in, c->cached_fr, sequence->frame_rate);
cc->timeline_out = refactor_frame_number(cc->timeline_out, c->cached_fr, sequence->frame_rate);
cc->clip_in = refactor_frame_number(cc->clip_in, c->cached_fr, sequence->frame_rate);
cc->timeline_in += sequence->playhead;
cc->timeline_out += sequence->playhead;
cc->track = c->track;
cc->timeline_in += sequence->playhead;
cc->timeline_out += sequence->playhead;
cc->track = c->track;
paste_start = qMin(paste_start, cc->timeline_in);
paste_end = qMax(paste_end, cc->timeline_out);
paste_start = qMin(paste_start, cc->timeline_in);
paste_end = qMax(paste_end, cc->timeline_out);
pasted_clips.append(cc);
pasted_clips.append(cc);
if (!insert) {
Selection s;
s.in = cc->timeline_in;
s.out = cc->timeline_out;
s.track = c->track;
delete_areas.append(s);
if (!insert) {
Selection s;
s.in = cc->timeline_in;
s.out = cc->timeline_out;
s.track = c->track;
delete_areas.append(s);
}
}
if (insert) {
split_cache.clear();
split_all_clips_at_point(ca, sequence->playhead);
ca->append(new RippleCommand(sequence, paste_start, paste_end - paste_start));
} else {
delete_areas_and_relink(ca, delete_areas);
}
}
if (insert) {
split_cache.clear();
split_all_clips_at_point(ca, sequence->playhead);
ca->append(new RippleCommand(sequence, paste_start, paste_end - paste_start));
} else {
delete_areas_and_relink(ca, delete_areas);
}
// correct linked clips
for (int i=0;i<clipboard.size();i++) {
// these indices should correspond
Clip* oc = static_cast<Clip*>(clipboard.at(i));
// correct linked clips
for (int i=0;i<clipboard.size();i++) {
// these indices should correspond
Clip* oc = static_cast<Clip*>(clipboard.at(i));
for (int j=0;j<oc->linked.size();j++) {
for (int k=0;k<clipboard.size();k++) { // find clip with that ID
Clip* comp = static_cast<Clip*>(clipboard.at(k));
if (comp->load_id == oc->linked.at(j)) {
pasted_clips.at(i)->linked.append(k);
for (int j=0;j<oc->linked.size();j++) {
for (int k=0;k<clipboard.size();k++) { // find clip with that ID
Clip* comp = static_cast<Clip*>(clipboard.at(k));
if (comp->load_id == oc->linked.at(j)) {
pasted_clips.at(i)->linked.append(k);
}
}
}
}
}
ca->append(new AddClipCommand(sequence, pasted_clips));
ca->append(new AddClipCommand(sequence, pasted_clips));
undo_stack.push(ca);
undo_stack.push(ca);
update_ui(true);
update_ui(true);
if (config.paste_seeks) {
panel_sequence_viewer->seek(paste_end);
if (config.paste_seeks) {
panel_sequence_viewer->seek(paste_end);
}
} else if (clipboard_type == CLIPBOARD_TYPE_EFFECT) {
for (int i=0;i<sequence->clips.size();i++) {
Clip* c = sequence->clips.at(i);
if (c != NULL && is_clip_selected(c, true)) {
for (int j=0;j<clipboard.size();j++) {
Effect* e = static_cast<Effect*>(clipboard.at(j));
if ((c->track < 0) == (e->meta->subtype == EFFECT_TYPE_VIDEO)) {
c->effects.append(e->copy(c));
}
}
}
}
update_ui(true);
}
}
}
@@ -1466,9 +1480,9 @@ void Timeline::on_toolTransitionButton_clicked() {
QMenu transition_menu(this);
for (int i=0;i<video_effects.size();i++) {
const EffectMeta& em = video_effects.at(i);
if (em.type == EFFECT_TYPE_TRANSITION) {
for (int i=0;i<effects.size();i++) {
const EffectMeta& em = effects.at(i);
if (em.type == EFFECT_TYPE_TRANSITION && em.subtype == EFFECT_TYPE_VIDEO) {
QAction* a = transition_menu.addAction(em.name);
a->setObjectName("v");
a->setData(reinterpret_cast<quintptr>(&em));
@@ -1477,9 +1491,9 @@ void Timeline::on_toolTransitionButton_clicked() {
transition_menu.addSeparator();
for (int i=0;i<audio_effects.size();i++) {
const EffectMeta& em = audio_effects.at(i);
if (em.type == EFFECT_TYPE_TRANSITION) {
for (int i=0;i<effects.size();i++) {
const EffectMeta& em = effects.at(i);
if (em.type == EFFECT_TYPE_TRANSITION && em.subtype == EFFECT_TYPE_AUDIO) {
QAction* a = transition_menu.addAction(em.name);
a->setObjectName("a");
a->setData(reinterpret_cast<quintptr>(&em));