From 2e577330b98dfe271eb097cb10d9efe11196280e Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 12 Oct 2018 20:41:22 +1100 Subject: [PATCH] progress on sequence editing --- dialogs/newsequencedialog.cpp | 29 +++++++++++++------- dialogs/newsequencedialog.h | 3 ++- panels/project.cpp | 6 ++--- project/undo.cpp | 50 +++++++++++++++++++++++++++++++++++ project/undo.h | 26 ++++++++++++++++++ ui/keyframeview.cpp | 21 ++++++++------- ui/labelslider.cpp | 2 ++ ui/timelinewidget.cpp | 2 +- 8 files changed, 113 insertions(+), 26 deletions(-) diff --git a/dialogs/newsequencedialog.cpp b/dialogs/newsequencedialog.cpp index fbb0078e7..5adbef49c 100644 --- a/dialogs/newsequencedialog.cpp +++ b/dialogs/newsequencedialog.cpp @@ -5,6 +5,8 @@ #include "panels/project.h" #include "project/sequence.h" #include "project/undo.h" +#include "panels/timeline.h" +#include "playback/playback.h" #include #include @@ -74,21 +76,28 @@ void NewSequenceDialog::showEvent(QShowEvent *) { } void NewSequenceDialog::on_buttonBox_accepted() { - Sequence* s = (existing_sequence != NULL) ? existing_sequence : new Sequence(); - - s->name = ui->lineEdit->text(); - s->width = ui->width_numeric->value(); - s->height = ui->height_numeric->value(); - s->frame_rate = ui->frame_rate_combobox->currentData().toDouble(); - s->audio_frequency = ui->audio_frequency_combobox->currentData().toInt(); - s->audio_layout = AV_CH_LAYOUT_STEREO; - if (existing_sequence == NULL) { + Sequence* s = new Sequence(); + + s->name = ui->lineEdit->text(); + s->width = ui->width_numeric->value(); + s->height = ui->height_numeric->value(); + s->frame_rate = ui->frame_rate_combobox->currentData().toDouble(); + s->audio_frequency = ui->audio_frequency_combobox->currentData().toInt(); + s->audio_layout = AV_CH_LAYOUT_STEREO; + ComboAction* ca = new ComboAction(); panel_project->new_sequence(ca, s, true, NULL); undo_stack.push(ca); } else { - // TODO make editing undoable + EditSequenceCommand* esc = new EditSequenceCommand(existing_item, existing_sequence); + esc->name = ui->lineEdit->text(); + esc->width = ui->width_numeric->value(); + esc->height = ui->height_numeric->value(); + esc->frame_rate = ui->frame_rate_combobox->currentData().toDouble(); + esc->audio_frequency = ui->audio_frequency_combobox->currentData().toInt(); + esc->audio_layout = AV_CH_LAYOUT_STEREO; + undo_stack.push(esc); } } diff --git a/dialogs/newsequencedialog.h b/dialogs/newsequencedialog.h index f676658f2..af219bb83 100644 --- a/dialogs/newsequencedialog.h +++ b/dialogs/newsequencedialog.h @@ -4,6 +4,7 @@ #include class Project; +class QTreeWidgetItem; struct Sequence; namespace Ui { @@ -18,6 +19,7 @@ public: explicit NewSequenceDialog(QWidget *parent = 0); ~NewSequenceDialog(); Sequence* existing_sequence; + QTreeWidgetItem* existing_item; void set_sequence_name(const QString& s); protected: @@ -25,7 +27,6 @@ protected: private slots: void on_buttonBox_accepted(); - void on_comboBox_currentIndexChanged(int index); private: diff --git a/panels/project.cpp b/panels/project.cpp index 7d0bff7db..d87b7eee2 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -158,10 +158,8 @@ void Project::open_properties() { NewSequenceDialog nsd(this); Sequence* s = get_sequence_from_tree(item); nsd.existing_sequence = s; - if (nsd.exec() == QDialog::Accepted) { - set_sequence_of_tree(item, s); - panel_timeline->repaint_timeline(true); - } + nsd.existing_item = item; + nsd.exec(); } break; default: diff --git a/project/undo.cpp b/project/undo.cpp index d4230f5d4..8b36e9cc0 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -1538,3 +1538,53 @@ void SetEnableCommand::redo() { clip->enabled = new_val; mainWindow->setWindowModified(true); } + +EditSequenceCommand::EditSequenceCommand(QTreeWidgetItem* i, Sequence *s) : + item(i), + seq(s), + old_project_changed(mainWindow->isWindowModified()), + old_name(s->name), + old_width(s->width), + old_height(s->height), + old_frame_rate(s->frame_rate), + old_audio_frequency(s->audio_frequency), + old_audio_layout(s->audio_layout) +{} + +void EditSequenceCommand::undo() { + seq->name = old_name; + seq->width = old_width; + seq->height = old_height; + seq->frame_rate = old_frame_rate; + seq->audio_frequency = old_audio_frequency; + seq->audio_layout = old_audio_layout; + update(); +} + +void EditSequenceCommand::redo() { + seq->name = name; + seq->width = width; + seq->height = height; + seq->frame_rate = frame_rate; + seq->audio_frequency = audio_frequency; + seq->audio_layout = audio_layout; + update(); +} + +void EditSequenceCommand::update() { + // update tooltip + set_sequence_of_tree(item, seq); + + for (int i=0;iclips.size();i++) { + // TODO shift in/out/clipin points to match new frame rate + // BUT ALSO copy/paste must need a similar routine, no? + // See if one exists or if you have to make one, make it + // re-usable + + seq->clips.at(i)->refresh(); + } + + if (sequence == seq) { + set_sequence(seq); + } +} diff --git a/project/undo.h b/project/undo.h index b893d843d..30dffb627 100644 --- a/project/undo.h +++ b/project/undo.h @@ -467,4 +467,30 @@ private: bool old_project_changed; }; +class EditSequenceCommand : public QUndoCommand { +public: + EditSequenceCommand(QTreeWidgetItem *i, Sequence* s); + void undo(); + void redo(); + void update(); + + QString name; + int width; + int height; + double frame_rate; + int audio_frequency; + int audio_layout; +private: + QTreeWidgetItem* item; + Sequence* seq; + bool old_project_changed; + + QString old_name; + int old_width; + int old_height; + double old_frame_rate; + int old_audio_frequency; + int old_audio_layout; +}; + #endif // UNDO_H diff --git a/ui/keyframeview.cpp b/ui/keyframeview.cpp index 64ce0806a..dbd0dc102 100644 --- a/ui/keyframeview.cpp +++ b/ui/keyframeview.cpp @@ -46,13 +46,17 @@ void KeyframeView::paintEvent(QPaintEvent*) { rows.clear(); if (panel_effect_controls->selected_clips.size() > 0) { - long effects_in = LONG_MAX; - long effects_out = 0; + visible_in = LONG_MAX; + visible_out = 0; for (int j=0;jselected_clips.size();j++) { - Clip* c = sequence->clips.at(panel_effect_controls->selected_clips.at(j)); - effects_in = qMin(effects_in, c->timeline_in); - effects_out = qMax(effects_out, c->timeline_out); + Clip* c = sequence->clips.at(panel_effect_controls->selected_clips.at(j)); + visible_in = qMin(visible_in, c->timeline_in); + visible_out = qMax(visible_out, c->timeline_out); + } + + for (int j=0;jselected_clips.size();j++) { + Clip* c = sequence->clips.at(panel_effect_controls->selected_clips.at(j)); for (int i=0;ieffects.size();i++) { Effect* e = c->effects.at(i); if (e->container->is_expanded()) { @@ -77,16 +81,12 @@ void KeyframeView::paintEvent(QPaintEvent*) { } } - visible_in = effects_in; - visible_out = effects_out; - int max_width = getScreenPointFromFrame(panel_effect_controls->zoom, visible_out - visible_in); - qDebug() << max_width << width(); if (max_width < width()) { p.fillRect(QRect(max_width, 0, width(), height()), QColor(0, 0, 0, 64)); } panel_effect_controls->ui->horizontalScrollBar->setMaximum(qMax(max_width - width(), 0)); - header->set_visible_in(effects_in); + header->set_visible_in(visible_in); int playhead_x = getScreenPointFromFrame(panel_effect_controls->zoom, sequence->playhead-visible_in) - x_scroll; if (dragging && panel_timeline->snapped) { @@ -150,6 +150,7 @@ void KeyframeView::draw_keyframe(QPainter &p, int x, int y, bool darker) { p.setPen(QColor(0, 0, 0)); p.setBrush(QColor(color, color, color)); p.drawPolygon(points, KEYFRAME_POINT_COUNT); + qDebug() << "drew key at" << x << y; } void KeyframeView::mousePressEvent(QMouseEvent *event) { diff --git a/ui/labelslider.cpp b/ui/labelslider.cpp index fa7d6de6f..155bef818 100644 --- a/ui/labelslider.cpp +++ b/ui/labelslider.cpp @@ -75,6 +75,8 @@ double LabelSlider::value() { } void LabelSlider::set_default_value(double v) { + if (internal_value == default_value) set = false; // TODO: CONTROVERSIAL - may be undesirable behaviour + default_value = v; if (!set) { set_value(v, false); diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index ae996dfcf..e20f1c87d 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -1009,10 +1009,10 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { if (redraw) { panel_timeline->repaint_timeline(true); } else { + panel_timeline->update_effect_controls(); if (repaint) { panel_timeline->repaint_timeline(false); } - panel_timeline->update_effect_controls(); } } }