From b29462e68b92e089dd7169a9c3476cbbf69865bd Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 7 Aug 2018 15:01:20 +1000 Subject: [PATCH] undos now save the modified flag state --- panels/effectcontrols.cpp | 35 +------------ panels/effectcontrols.h | 13 ----- panels/project.cpp | 8 +-- project/effect.cpp | 1 - project/undo.cpp | 107 +++++++++++++++++++++++++++++++++++++- project/undo.h | 55 ++++++++++++++++++++ ui/labelslider.cpp | 13 ----- ui/labelslider.h | 12 ----- ui/sourcetable.cpp | 48 ----------------- ui/sourcetable.h | 24 --------- ui/timelinewidget.cpp | 34 ++++++------ 11 files changed, 182 insertions(+), 168 deletions(-) diff --git a/panels/effectcontrols.cpp b/panels/effectcontrols.cpp index 10c8e5e65..49b79c088 100644 --- a/panels/effectcontrols.cpp +++ b/panels/effectcontrols.cpp @@ -36,8 +36,7 @@ void EffectControls::menu_select(QAction* q) { } } undo_stack.push(ta); - reload_clips(); - project_changed = true; + reload_clips(); } void EffectControls::show_menu(bool video) { @@ -146,7 +145,6 @@ void EffectControls::delete_effects() { } if (command->clips.size() > 0) { undo_stack.push(command); - project_changed = true; } else { delete command; } @@ -192,34 +190,3 @@ bool EffectControls::is_focused() { } return false; } - -EffectDeleteCommand::EffectDeleteCommand() : done(false) {} - -EffectDeleteCommand::~EffectDeleteCommand() { - if (done) { - for (int i=0;ieffects.insert(fx.at(i), deleted_objects.at(i)); - } - panel_effect_controls->reload_clips(); - done = false; -} - -void EffectDeleteCommand::redo() { - deleted_objects.clear(); - for (int i=0;ieffects.at(fx_id)); - c->effects.removeAt(fx_id); - } - panel_effect_controls->reload_clips(); - done = true; -} diff --git a/panels/effectcontrols.h b/panels/effectcontrols.h index ff470c265..be4ac8a7b 100644 --- a/panels/effectcontrols.h +++ b/panels/effectcontrols.h @@ -56,17 +56,4 @@ private: bool done; };*/ -class EffectDeleteCommand : public QUndoCommand { -public: - EffectDeleteCommand(); - ~EffectDeleteCommand(); - void undo(); - void redo(); - QVector clips; - QVector fx; -private: - bool done; - QVector deleted_objects; -}; - #endif // EFFECTCONTROLS_H diff --git a/panels/project.cpp b/panels/project.cpp index 04c15d5e9..eac9ec342 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -155,9 +155,7 @@ void Project::new_sequence(TimelineAction *ta, Sequence *s, bool open, QTreeWidg parent->addChild(item); } if (open) set_sequence(s); - } - - project_changed = true; + } } void Project::start_preview_generator(QTreeWidgetItem* item, Media* media, bool replacing) { @@ -316,9 +314,7 @@ void Project::delete_selected_media() { // redraw clips if (redraw) { panel_timeline->redraw_all_clips(true); - } - - project_changed = true; + } } else { delete ta; } diff --git a/project/effect.cpp b/project/effect.cpp index 10f39325b..cc6b5c99a 100644 --- a/project/effect.cpp +++ b/project/effect.cpp @@ -33,7 +33,6 @@ void Effect::init() { void Effect::field_changed() { panel_viewer->viewer_widget->update(); - project_changed = true; } void Effect::checkbox_command() { diff --git a/project/undo.cpp b/project/undo.cpp index a50a449dc..cfc11d9a4 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -464,7 +464,7 @@ void TimelineAction::redo() { done = true; } -LinkCommand::LinkCommand() : link(true) {} +LinkCommand::LinkCommand() : link(true), old_project_changed(project_changed) {} void LinkCommand::undo() { for (int i=0;ilinked = old_links.at(i); } } + project_changed = old_project_changed; } void LinkCommand::redo() { @@ -492,21 +493,24 @@ void LinkCommand::redo() { c->linked.clear(); } } + project_changed = true; } -CheckboxCommand::CheckboxCommand(QCheckBox* b) : box(b), checked(box->isChecked()), done(true) {} +CheckboxCommand::CheckboxCommand(QCheckBox* b) : box(b), checked(box->isChecked()), done(true), old_project_changed(project_changed) {} CheckboxCommand::~CheckboxCommand() {} void CheckboxCommand::undo() { box->setChecked(!checked); done = false; + project_changed = old_project_changed; } void CheckboxCommand::redo() { if (!done) { box->setChecked(checked); } + project_changed = true; } ReplaceMediaCommand::ReplaceMediaCommand(QTreeWidgetItem* i, QString s) : @@ -605,3 +609,102 @@ void ReplaceClipMediaCommand::redo() { project_changed = true; } + +EffectDeleteCommand::EffectDeleteCommand() : done(false), old_project_changed(project_changed) {} + +EffectDeleteCommand::~EffectDeleteCommand() { + if (done) { + for (int i=0;ieffects.insert(fx.at(i), deleted_objects.at(i)); + } + panel_effect_controls->reload_clips(); + done = false; + project_changed = old_project_changed; +} + +void EffectDeleteCommand::redo() { + deleted_objects.clear(); + for (int i=0;ieffects.at(fx_id)); + c->effects.removeAt(fx_id); + } + panel_effect_controls->reload_clips(); + done = true; + project_changed = true; +} + +MediaMove::MediaMove(SourceTable *s) : table(s), old_project_changed(project_changed) {} + +void MediaMove::undo() { + for (int i=0;itakeTopLevelItem(table->indexOfTopLevelItem(items.at(i))); + } else { + to->removeChild(items.at(i)); + } + if (froms.at(i) == NULL) { + table->addTopLevelItem(items.at(i)); + } else { + froms.at(i)->addChild(items.at(i)); + } + } + project_changed = old_project_changed; +} + +void MediaMove::redo() { + for (int i=0;iparent(); + froms.append(parent); + if (parent == NULL) { + table->takeTopLevelItem(table->indexOfTopLevelItem(items.at(i))); + } else { + parent->removeChild(items.at(i)); + } + if (to == NULL) { + table->addTopLevelItem(items.at(i)); + } else { + to->addChild(items.at(i)); + } + } + project_changed = true; +} + +MediaRename::MediaRename() : done(true), old_project_changed(project_changed) {} + +void MediaRename::undo() { + item->setText(0, from); + done = false; + project_changed = old_project_changed; +} + +void MediaRename::redo() { + if (!done) { + item->setText(0, to); + } + project_changed = true; +} + +ValueChangeCommand::ValueChangeCommand() : done(true), old_project_changed(project_changed) {} + +void ValueChangeCommand::undo() { + source->set_value(old_val); + done = false; + project_changed = old_project_changed; +} + +void ValueChangeCommand::redo() { + if (!done) { + source->set_value(new_val); + } + project_changed = true; +} diff --git a/project/undo.h b/project/undo.h index ac4c1bbe5..33047b284 100644 --- a/project/undo.h +++ b/project/undo.h @@ -102,6 +102,7 @@ public: bool link; private: QVector< QVector > old_links; + bool old_project_changed; }; class CheckboxCommand : public QUndoCommand { @@ -114,6 +115,7 @@ private: QCheckBox* box; bool checked; bool done; + bool old_project_changed; }; class ReplaceMediaCommand : public QUndoCommand { @@ -147,4 +149,57 @@ private: void replace(bool undo); }; +class EffectDeleteCommand : public QUndoCommand { +public: + EffectDeleteCommand(); + ~EffectDeleteCommand(); + void undo(); + void redo(); + QVector clips; + QVector fx; +private: + bool done; + bool old_project_changed; + QVector deleted_objects; +}; + +class MediaMove : public QUndoCommand { +public: + MediaMove(SourceTable* s); + QVector items; + QTreeWidgetItem* to; + void undo(); + void redo(); +private: + QVector froms; + SourceTable* table; + bool old_project_changed; +}; + +class MediaRename : public QUndoCommand { +public: + MediaRename(); + QTreeWidgetItem* item; + QString from; + QString to; + void undo(); + void redo(); +private: + bool done; + bool old_project_changed; +}; + +class ValueChangeCommand : public QUndoCommand { +public: + ValueChangeCommand(); + LabelSlider* source; + float old_val; + float new_val; + void undo(); + void redo(); +private: + bool done; + bool old_project_changed; +}; + #endif // UNDO_H diff --git a/ui/labelslider.cpp b/ui/labelslider.cpp index 0aac0379b..de4696087 100644 --- a/ui/labelslider.cpp +++ b/ui/labelslider.cpp @@ -114,16 +114,3 @@ void LabelSlider::mouseReleaseEvent(QMouseEvent*) { } } } - -ValueChangeCommand::ValueChangeCommand() : done(true) {} - -void ValueChangeCommand::undo() { - source->set_value(old_val); - done = false; -} - -void ValueChangeCommand::redo() { - if (!done) { - source->set_value(new_val); - } -} diff --git a/ui/labelslider.h b/ui/labelslider.h index 91c9b4089..16fd28c92 100644 --- a/ui/labelslider.h +++ b/ui/labelslider.h @@ -39,16 +39,4 @@ signals: void valueChanged(); }; -class ValueChangeCommand : public QUndoCommand { -public: - ValueChangeCommand(); - LabelSlider* source; - float old_val; - float new_val; - void undo(); - void redo(); -private: - bool done; -}; - #endif // LABELSLIDER_H diff --git a/ui/sourcetable.cpp b/ui/sourcetable.cpp index 56adfe77c..54f8e354f 100644 --- a/ui/sourcetable.cpp +++ b/ui/sourcetable.cpp @@ -204,55 +204,7 @@ void SourceTable::dropEvent(QDropEvent* event) { mm->to = drop_item; mm->items = move_items; undo_stack.push(mm); - project_changed = true; } } } } - -MediaMove::MediaMove(SourceTable *s) : table(s) {} - -void MediaMove::undo() { - for (int i=0;itakeTopLevelItem(table->indexOfTopLevelItem(items.at(i))); - } else { - to->removeChild(items.at(i)); - } - if (froms.at(i) == NULL) { - table->addTopLevelItem(items.at(i)); - } else { - froms.at(i)->addChild(items.at(i)); - } - } -} - -void MediaMove::redo() { - for (int i=0;iparent(); - froms.append(parent); - if (parent == NULL) { - table->takeTopLevelItem(table->indexOfTopLevelItem(items.at(i))); - } else { - parent->removeChild(items.at(i)); - } - if (to == NULL) { - table->addTopLevelItem(items.at(i)); - } else { - to->addChild(items.at(i)); - } - } -} - -MediaRename::MediaRename() : done(true) {} - -void MediaRename::undo() { - item->setText(0, from); - done = false; -} - -void MediaRename::redo() { - if (!done) { - item->setText(0, to); - } -} diff --git a/ui/sourcetable.h b/ui/sourcetable.h index 34a3c333a..c21b6ac0f 100644 --- a/ui/sourcetable.h +++ b/ui/sourcetable.h @@ -30,28 +30,4 @@ private slots: void show_context_menu(const QPoint& pos); }; -class MediaMove : public QUndoCommand { -public: - MediaMove(SourceTable* s); - QVector items; - QTreeWidgetItem* to; - void undo(); - void redo(); -private: - QVector froms; - SourceTable* table; -}; - -class MediaRename : public QUndoCommand { -public: - MediaRename(); - QTreeWidgetItem* item; - QString from; - QString to; - void undo(); - void redo(); -private: - bool done; -}; - #endif // SOURCETABLE_H diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 563c30a75..d427d350c 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -524,7 +524,9 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { ta->ripple(sequence, ripple_point, ripple_length, ignore_clips); } - if (panel_timeline->tool == TIMELINE_TOOL_POINTER && (event->modifiers() & Qt::AltModifier)) { // if holding alt, duplicate rather than move + if (panel_timeline->tool == TIMELINE_TOOL_POINTER + && (event->modifiers() & Qt::AltModifier) + && panel_timeline->trim_target == -1) { // if holding alt (and not trimming), duplicate rather than move // duplicate clips QVector old_clips; QVector new_clips; @@ -808,6 +810,11 @@ void TimelineWidget::update_ghosts(QPoint& mouse_pos) { if (validator > g.media_length) frame_diff += validator - g.media_length; } } else if (g.trimming) { + MediaStream* ms = NULL; + if (c->media_type == MEDIA_TYPE_FOOTAGE) { + ms = static_cast(c->media)->get_stream_from_file_index(c->media_stream); + } + if (g.trim_in) { // prevent clip/transition length from being less than 1 frame long validator = g.ghost_length - frame_diff; @@ -819,26 +826,23 @@ void TimelineWidget::update_ghosts(QPoint& mouse_pos) { if (validator < 0) frame_diff -= validator; } - if (g.transition == NULL || g.transition == c->opening_transition) { - // prevent clip_in from going below 0 - if (c->media_type == MEDIA_TYPE_SEQUENCE - || (c->media_type == MEDIA_TYPE_FOOTAGE && !static_cast(c->media)->get_stream_from_file_index(c->media_stream)->infinite_length)) { - validator = g.old_clip_in + frame_diff; - if (validator < 0) frame_diff -= validator; - } + // prevent clip_in from going below 0 + if (c->media_type == MEDIA_TYPE_SEQUENCE + || (ms != NULL && !ms->infinite_length)) { + validator = g.old_clip_in + frame_diff; + if (validator < 0) frame_diff -= validator; } } else { // prevent clip length from being less than 1 frame long validator = g.ghost_length + frame_diff; if (validator < 1) frame_diff += (1 - validator); - if (g.transition == NULL) { - // prevent clip length exceeding media length - if (c->media_type == MEDIA_TYPE_SEQUENCE - || (c->media_type == MEDIA_TYPE_FOOTAGE && !static_cast(c->media)->get_stream_from_file_index(c->media_stream)->infinite_length)) { - validator = g.old_clip_in + g.ghost_length + frame_diff; - if (validator > g.media_length) frame_diff -= validator - g.media_length; - } + // prevent clip length exceeding media length + if (c->media_type == MEDIA_TYPE_SEQUENCE + || (ms != NULL && !ms->infinite_length)) { + validator = g.old_clip_in + g.ghost_length + frame_diff; + qDebug() << i << validator; + if (validator > g.media_length) frame_diff -= validator - g.media_length; } }