From b1c3f44b04e2d847dc176e618805f08e15c0c5d9 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 20 Sep 2018 21:34:36 +1000 Subject: [PATCH] implemented undos for effect fields that aren't keyframed --- dialogs/exportdialog.cpp | 5 +---- effects/effect.cpp | 23 ++++++++++++++++++++--- effects/effect.h | 1 + project/undo.cpp | 16 ++++++++++++++++ project/undo.h | 14 ++++++++++++++ ui/colorbutton.cpp | 15 +++++++-------- ui/colorbutton.h | 2 ++ ui/comboboxex.cpp | 5 +++++ ui/comboboxex.h | 2 ++ ui/fontcombobox.cpp | 14 ++++++++++++++ ui/fontcombobox.h | 7 +++++++ ui/labelslider.cpp | 11 ++++++++++- ui/labelslider.h | 2 ++ ui/texteditex.cpp | 16 +++++++++++++++- ui/texteditex.h | 6 ++++++ 15 files changed, 122 insertions(+), 17 deletions(-) diff --git a/dialogs/exportdialog.cpp b/dialogs/exportdialog.cpp index f52c1b934..8f8c96e42 100644 --- a/dialogs/exportdialog.cpp +++ b/dialogs/exportdialog.cpp @@ -536,6 +536,7 @@ void ExportDialog::on_compressionTypeCombobox_currentIndexChanged(int) { ui->videobitrateSpinbox->setMaximum(99.99); switch (ui->compressionTypeCombobox->currentData().toInt()) { case COMPRESSION_TYPE_CBR: + case COMPRESSION_TYPE_TARGETBR: ui->videoBitrateLabel->setText("Bitrate (Mbps):"); ui->videobitrateSpinbox->setValue(qMax(0.5, (double) qRound((0.01528 * sequence->height) - 4.5))); break; @@ -549,9 +550,5 @@ void ExportDialog::on_compressionTypeCombobox_currentIndexChanged(int) { ui->videoBitrateLabel->setText("Target File Size (MB):"); ui->videobitrateSpinbox->setValue(100); break; - case COMPRESSION_TYPE_TARGETBR: - ui->videoBitrateLabel->setText("Target Bitrate (Mbps):"); - ui->videobitrateSpinbox->setValue(100); - break; } } diff --git a/effects/effect.cpp b/effects/effect.cpp index efdc8bd2a..ffa2657f6 100644 --- a/effects/effect.cpp +++ b/effects/effect.cpp @@ -598,6 +598,18 @@ EffectField::EffectField(EffectRow *parent, int t) : parent_row(parent), type(t) } } +QVariant EffectField::get_previous_data() { + switch (type) { + case EFFECT_FIELD_DOUBLE: return static_cast(ui_element)->getPreviousValue(); break; + case EFFECT_FIELD_COLOR: return static_cast(ui_element)->getPreviousValue(); break; + case EFFECT_FIELD_STRING: return static_cast(ui_element)->getPreviousValue(); break; + case EFFECT_FIELD_BOOL: return !static_cast(ui_element)->isChecked(); break; + case EFFECT_FIELD_COMBO: return static_cast(ui_element)->getPreviousIndex(); break; + case EFFECT_FIELD_FONT: return static_cast(ui_element)->getPreviousValue(); break; + } + return QVariant(); +} + QVariant EffectField::get_current_data() { switch (type) { case EFFECT_FIELD_DOUBLE: return static_cast(ui_element)->value(); break; @@ -720,9 +732,14 @@ void EffectField::validate_keyframe_data(double timecode) { } void EffectField::uiElementChange() { + bool enableKeyframes = !(type == EFFECT_FIELD_DOUBLE && static_cast(ui_element)->is_dragging()); if (parent_row->isKeyframing()) { - parent_row->set_keyframe_now(!(type == EFFECT_FIELD_DOUBLE && static_cast(ui_element)->is_dragging())); - } + parent_row->set_keyframe_now(enableKeyframes); + } else if (enableKeyframes) { + // set undo + qDebug() << "h"; + undo_stack.push(new EffectFieldUndo(this)); + } emit changed(); } @@ -797,7 +814,7 @@ const QString EffectField::get_string_value(double timecode) { } void EffectField::set_string_value(const QString& s) { - static_cast(ui_element)->setText(s); + static_cast(ui_element)->setPlainTextEx(s); } const QString EffectField::get_font_name(double timecode) { diff --git a/effects/effect.h b/effects/effect.h index cb54aaad5..1e7a6878e 100644 --- a/effects/effect.h +++ b/effects/effect.h @@ -92,6 +92,7 @@ public: EffectRow* parent_row; int type; + QVariant get_previous_data(); QVariant get_current_data(); double frameToTimecode(long frame); long timecodeToFrame(double timecode); diff --git a/project/undo.cpp b/project/undo.cpp index b3d42827a..b4b8d9ae9 100644 --- a/project/undo.cpp +++ b/project/undo.cpp @@ -1302,3 +1302,19 @@ void KeyframeSet::redo() { project_changed = true; done = true; } + +EffectFieldUndo::EffectFieldUndo(EffectField* f) : field(f), done(true) { + old_val = field->get_previous_data(); + new_val = field->get_current_data(); +} + +void EffectFieldUndo::undo() { + field->set_current_data(old_val); + done = false; +} + +void EffectFieldUndo::redo() { + if (!done) { + field->set_current_data(new_val); + } +} diff --git a/project/undo.h b/project/undo.h index 539c6a1d2..4a4cc4542 100644 --- a/project/undo.h +++ b/project/undo.h @@ -7,6 +7,7 @@ class LabelSlider; class Effect; class SourceTable; class EffectRow; +class EffectField; class Transition; struct Clip; struct Sequence; @@ -15,6 +16,7 @@ struct Media; #include #include #include +#include #define TA_NO_TRANSITION 0 #define TA_OPENING_TRANSITION 1 @@ -427,4 +429,16 @@ private: bool done; }; +class EffectFieldUndo : public QUndoCommand { +public: + EffectFieldUndo(EffectField* field); + void undo(); + void redo(); +private: + EffectField* field; + QVariant old_val; + QVariant new_val; + bool done; +}; + #endif // UNDO_H diff --git a/ui/colorbutton.cpp b/ui/colorbutton.cpp index 2ddfafb22..8ba2fbfc2 100644 --- a/ui/colorbutton.cpp +++ b/ui/colorbutton.cpp @@ -15,10 +15,15 @@ QColor ColorButton::get_color() { } void ColorButton::set_color(QColor c) { + previousColor = color; color = c; set_button_color(); } +const QColor &ColorButton::getPreviousValue() { + return previousColor; +} + void ColorButton::set_button_color() { QPalette pal = palette(); pal.setColor(QPalette::Button, color); @@ -26,16 +31,10 @@ void ColorButton::set_button_color() { } void ColorButton::open_dialog() { - QColor old_color = color; QColor new_color = QColorDialog::getColor(color, NULL); - if (new_color.isValid() && old_color != new_color) { - ColorCommand* command = new ColorCommand(this, old_color, new_color); -// undo_stack.push(command); - command->redo(); - delete command; - + if (new_color.isValid() && color != new_color) { + set_color(new_color); set_button_color(); - emit color_changed(); } } diff --git a/ui/colorbutton.h b/ui/colorbutton.h index 3be4e6423..512f92c8d 100644 --- a/ui/colorbutton.h +++ b/ui/colorbutton.h @@ -11,8 +11,10 @@ public: ColorButton(QWidget* parent = 0); QColor get_color(); void set_color(QColor c); + const QColor& getPreviousValue(); private: QColor color; + QColor previousColor; void set_button_color(); signals: void color_changed(); diff --git a/ui/comboboxex.cpp b/ui/comboboxex.cpp index 6c1243561..2a05fb5c7 100644 --- a/ui/comboboxex.cpp +++ b/ui/comboboxex.cpp @@ -43,8 +43,13 @@ void ComboBoxEx::setCurrentTextEx(const QString &text) { index = currentIndex(); } +int ComboBoxEx::getPreviousIndex() { + return previousIndex; +} + void ComboBoxEx::index_changed(int i) { if (index != i) { + previousIndex = index; // undo_stack.push(new ComboBoxExCommand(this, index, i)); index = i; } diff --git a/ui/comboboxex.h b/ui/comboboxex.h index 341acf264..3fa74cdb9 100644 --- a/ui/comboboxex.h +++ b/ui/comboboxex.h @@ -10,10 +10,12 @@ public: ComboBoxEx(QWidget* parent = 0); void setCurrentIndexEx(int i); void setCurrentTextEx(const QString &text); + int getPreviousIndex(); private slots: void index_changed(int); private: int index; + int previousIndex; void wheelEvent(QWheelEvent* e); }; diff --git a/ui/fontcombobox.cpp b/ui/fontcombobox.cpp index 3d71b41f7..6528c4dd8 100644 --- a/ui/fontcombobox.cpp +++ b/ui/fontcombobox.cpp @@ -4,4 +4,18 @@ FontCombobox::FontCombobox(QWidget* parent) : ComboBoxEx(parent) { addItems(QFontDatabase().families()); + + value = currentText(); + + connect(this, SIGNAL(currentTextChanged(QString)), this, SLOT(updateInternals())); +} + +const QString& FontCombobox::getPreviousValue() { + return previousValue; +} + +void FontCombobox::updateInternals() { + qDebug() << "h"; + previousValue = value; + value = currentText(); } diff --git a/ui/fontcombobox.h b/ui/fontcombobox.h index e6df90b98..fd9ebd2c5 100644 --- a/ui/fontcombobox.h +++ b/ui/fontcombobox.h @@ -4,8 +4,15 @@ #include "comboboxex.h" class FontCombobox : public ComboBoxEx { + Q_OBJECT public: FontCombobox(QWidget* parent = 0); + const QString &getPreviousValue(); +private slots: + void updateInternals(); +private: + QString previousValue; + QString value; }; #endif // FONTCOMBOBOX_H diff --git a/ui/labelslider.cpp b/ui/labelslider.cpp index adfb9d84e..788722cae 100644 --- a/ui/labelslider.cpp +++ b/ui/labelslider.cpp @@ -47,6 +47,10 @@ QString LabelSlider::valueToString(double v) { return QString::number(v, 'f', 1); } +double LabelSlider::getPreviousValue() { + return previous_value; +} + double LabelSlider::value() { return internal_value; } @@ -76,7 +80,10 @@ double LabelSlider::get_drag_start_value() { void LabelSlider::mousePressEvent(QMouseEvent *ev) { drag_start_value = internal_value; if (ev->modifiers() & Qt::AltModifier) { - set_value(default_value, true); + if (internal_value != default_value) { + previous_value = internal_value; + set_value(default_value, true); + } } else { qApp->setOverrideCursor(Qt::BlankCursor); drag_start = true; @@ -99,10 +106,12 @@ void LabelSlider::mouseReleaseEvent(QMouseEvent*) { drag_start = false; if (drag_proc) { drag_proc = false; + previous_value = drag_start_value; emit valueChanged(); } else { double d = QInputDialog::getDouble(this, "Set Value", "New value:", internal_value); if (d != internal_value) { + previous_value = internal_value; set_value(d, true); } } diff --git a/ui/labelslider.h b/ui/labelslider.h index 2cfc5a156..d939cdf9d 100644 --- a/ui/labelslider.h +++ b/ui/labelslider.h @@ -18,6 +18,7 @@ public: double get_drag_start_value(); bool is_dragging(); virtual QString valueToString(double v); + double getPreviousValue(); protected: void mousePressEvent(QMouseEvent *ev); void mouseMoveEvent(QMouseEvent *ev); @@ -26,6 +27,7 @@ private: double default_value; double internal_value; double drag_start_value; + double previous_value; bool min_enabled; double min_value; diff --git a/ui/texteditex.cpp b/ui/texteditex.cpp index 438b1b1ea..5b8d71fe7 100644 --- a/ui/texteditex.cpp +++ b/ui/texteditex.cpp @@ -2,7 +2,10 @@ #include -TextEditEx::TextEditEx(QWidget *parent) : QTextEdit(parent) {} +TextEditEx::TextEditEx(QWidget *parent) : QTextEdit(parent) { + setUndoRedoEnabled(false); + connect(this, SIGNAL(textChanged()), this, SLOT(updateInternals())); +} void TextEditEx::setPlainTextEx(const QString &text) { blockSignals(true); @@ -15,5 +18,16 @@ void TextEditEx::setPlainTextEx(const QString &text) { newCursor.setPosition(pos); setTextCursor(newCursor); + updateInternals(); + blockSignals(false); } + +const QString &TextEditEx::getPreviousValue() { + return previousText; +} + +void TextEditEx::updateInternals() { + previousText = text; + text = toPlainText(); +} diff --git a/ui/texteditex.h b/ui/texteditex.h index 8177c72fc..ebe3f49e9 100644 --- a/ui/texteditex.h +++ b/ui/texteditex.h @@ -8,6 +8,12 @@ class TextEditEx : public QTextEdit { public: TextEditEx(QWidget* parent = 0); void setPlainTextEx(const QString &text); + const QString& getPreviousValue(); +private slots: + void updateInternals(); +private: + QString previousText; + QString text; }; #endif // TEXTEDITEX_H