fixed all undos biatch
This commit is contained in:
+76
-10
@@ -5,11 +5,13 @@
|
||||
#include <QDebug>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "panels/panels.h"
|
||||
#include "effects/effects.h"
|
||||
#include "project/clip.h"
|
||||
#include "project/effect.h"
|
||||
#include "ui/collapsiblewidget.h"
|
||||
#include "project/sequence.h"
|
||||
#include "project/undo.h"
|
||||
|
||||
EffectControls::EffectControls(QWidget *parent) :
|
||||
QDockWidget(parent),
|
||||
@@ -26,13 +28,15 @@ EffectControls::~EffectControls()
|
||||
}
|
||||
|
||||
void EffectControls::menu_select(QAction* q) {
|
||||
EffectAddCommand* command = new EffectAddCommand();
|
||||
for (int i=0;i<selected_clips.size();i++) {
|
||||
Clip* clip = sequence->get_clip(selected_clips.at(i));
|
||||
if ((clip->track < 0 && video_menu) || (clip->track >= 0 && !video_menu)) {
|
||||
clip->effects.append(create_effect(q->data().toInt(), clip));
|
||||
command->clips.append(clip);
|
||||
command->effects.append(create_effect(q->data().toInt(), clip));
|
||||
}
|
||||
}
|
||||
reload_clips();
|
||||
undo_stack.push(command);
|
||||
}
|
||||
|
||||
void EffectControls::show_menu(bool video) {
|
||||
@@ -117,22 +121,21 @@ void EffectControls::load_effects() {
|
||||
|
||||
void EffectControls::delete_effects() {
|
||||
// load in new clips
|
||||
QVector<Effect*> fx_to_del;
|
||||
EffectDeleteCommand* command = new EffectDeleteCommand();
|
||||
for (int i=0;i<selected_clips.size();i++) {
|
||||
Clip* c = sequence->get_clip(selected_clips.at(i));
|
||||
for (int j=0;j<c->effects.size();j++) {
|
||||
Effect* effect = c->effects.at(j);
|
||||
if (effect->container->selected) {
|
||||
c->effects.removeAt(j);
|
||||
fx_to_del.append(effect);
|
||||
command->clips.append(c);
|
||||
command->fx.append(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fx_to_del.size() > 0) {
|
||||
reload_clips();
|
||||
for (int i=0;i<fx_to_del.size();i++) {
|
||||
delete fx_to_del.at(i);
|
||||
}
|
||||
if (command->clips.size() > 0) {
|
||||
undo_stack.push(command);
|
||||
} else {
|
||||
delete command;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,3 +179,66 @@ bool EffectControls::is_focused() {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
EffectAddCommand::EffectAddCommand() : done(false) {}
|
||||
|
||||
EffectAddCommand::~EffectAddCommand() {
|
||||
if (!done) {
|
||||
for (int i=0;i<effects.size();i++) {
|
||||
delete effects.at(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EffectAddCommand::undo() {
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
Clip* c = clips.at(i);
|
||||
for (int j=0;j<c->effects.size();j++) {
|
||||
if (c->effects.at(j) == effects.at(i)) {
|
||||
c->effects.removeAt(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
panel_effect_controls->reload_clips();
|
||||
done = false;
|
||||
}
|
||||
|
||||
void EffectAddCommand::redo() {
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
clips.at(i)->effects.append(effects.at(i));
|
||||
}
|
||||
panel_effect_controls->reload_clips();
|
||||
done = true;
|
||||
}
|
||||
|
||||
EffectDeleteCommand::EffectDeleteCommand() : done(false) {}
|
||||
|
||||
EffectDeleteCommand::~EffectDeleteCommand() {
|
||||
if (done) {
|
||||
for (int i=0;i<deleted_objects.size();i++) {
|
||||
delete deleted_objects.at(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EffectDeleteCommand::undo() {
|
||||
for (int i=0;i<clips.size();i++) {
|
||||
Clip* c = clips.at(i);
|
||||
c->effects.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;i<clips.size();i++) {
|
||||
Clip* c = clips.at(i);
|
||||
int fx_id = fx.at(i);
|
||||
deleted_objects.append(c->effects.at(fx_id));
|
||||
c->effects.removeAt(fx_id);
|
||||
}
|
||||
panel_effect_controls->reload_clips();
|
||||
done = true;
|
||||
}
|
||||
|
||||
+29
-1
@@ -2,9 +2,11 @@
|
||||
#define EFFECTCONTROLS_H
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QUndoCommand>
|
||||
|
||||
struct Clip;
|
||||
class QMenu;
|
||||
class Effect;
|
||||
|
||||
namespace Ui {
|
||||
class EffectControls;
|
||||
@@ -22,6 +24,7 @@ public:
|
||||
void clear_effects(bool clear_cache);
|
||||
void delete_effects();
|
||||
bool is_focused();
|
||||
void reload_clips();
|
||||
|
||||
private slots:
|
||||
void menu_select(QAction* q);
|
||||
@@ -37,8 +40,33 @@ private:
|
||||
QVector<int> selected_clips;
|
||||
void show_menu(bool video);
|
||||
void load_effects();
|
||||
void reload_clips();
|
||||
|
||||
bool video_menu;
|
||||
};
|
||||
|
||||
class EffectAddCommand : public QUndoCommand {
|
||||
public:
|
||||
EffectAddCommand();
|
||||
~EffectAddCommand();
|
||||
void undo();
|
||||
void redo();
|
||||
QVector<Clip*> clips;
|
||||
QVector<Effect*> effects;
|
||||
private:
|
||||
bool done;
|
||||
};
|
||||
|
||||
class EffectDeleteCommand : public QUndoCommand {
|
||||
public:
|
||||
EffectDeleteCommand();
|
||||
~EffectDeleteCommand();
|
||||
void undo();
|
||||
void redo();
|
||||
QVector<Clip*> clips;
|
||||
QVector<int> fx;
|
||||
private:
|
||||
bool done;
|
||||
QVector<Effect*> deleted_objects;
|
||||
};
|
||||
|
||||
#endif // EFFECTCONTROLS_H
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef SEQUENCE_H
|
||||
#define SEQUENCE_H
|
||||
|
||||
#define UNDO_LIMIT 100
|
||||
|
||||
#include <QVector>
|
||||
|
||||
#include "project/clip.h"
|
||||
|
||||
+41
-1
@@ -1,5 +1,7 @@
|
||||
#include "labelslider.h"
|
||||
|
||||
#include "project/undo.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QInputDialog>
|
||||
#include <QApplication>
|
||||
@@ -25,6 +27,7 @@ void LabelSlider::set_value(float v) {
|
||||
} else {
|
||||
internal_value = v;
|
||||
}
|
||||
|
||||
setText(QString::number(internal_value));
|
||||
emit valueChanged();
|
||||
}
|
||||
@@ -51,9 +54,16 @@ void LabelSlider::set_maximum_value(float v) {
|
||||
|
||||
void LabelSlider::mousePressEvent(QMouseEvent *ev) {
|
||||
if (ev->modifiers() & Qt::AltModifier) {
|
||||
ValueChangeCommand* vcc = new ValueChangeCommand();
|
||||
vcc->source = this;
|
||||
vcc->old_val = internal_value;
|
||||
vcc->new_val = default_value;
|
||||
undo_stack.push(vcc);
|
||||
|
||||
set_value(default_value);
|
||||
} else {
|
||||
qApp->setOverrideCursor(Qt::BlankCursor);
|
||||
drag_start_value = internal_value;
|
||||
drag_start = true;
|
||||
drag_start_x = cursor().pos().x();
|
||||
drag_start_y = cursor().pos().y();
|
||||
@@ -73,9 +83,39 @@ void LabelSlider::mouseReleaseEvent(QMouseEvent*) {
|
||||
qApp->restoreOverrideCursor();
|
||||
drag_start = false;
|
||||
if (drag_proc) {
|
||||
// send undo event
|
||||
ValueChangeCommand* vcc = new ValueChangeCommand();
|
||||
vcc->source = this;
|
||||
vcc->old_val = drag_start_value;
|
||||
vcc->new_val = internal_value;
|
||||
undo_stack.push(vcc);
|
||||
|
||||
drag_proc = false;
|
||||
} else {
|
||||
set_value(QInputDialog::getDouble(this, "Set Value", "New value:", internal_value));
|
||||
double d = QInputDialog::getDouble(this, "Set Value", "New value:", internal_value);
|
||||
if (d != internal_value) {
|
||||
ValueChangeCommand* vcc = new ValueChangeCommand();
|
||||
vcc->source = this;
|
||||
vcc->old_val = internal_value;
|
||||
|
||||
set_value(d);
|
||||
|
||||
vcc->new_val = internal_value;
|
||||
undo_stack.push(vcc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ValueChangeCommand::ValueChangeCommand() : done(true) {}
|
||||
|
||||
void ValueChangeCommand::undo() {
|
||||
source->set_value(old_val);
|
||||
done = false;
|
||||
}
|
||||
|
||||
void ValueChangeCommand::redo() {
|
||||
if (!done) {
|
||||
source->set_value(new_val);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-1
@@ -2,6 +2,7 @@
|
||||
#define LABELSLIDER_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QUndoCommand>
|
||||
|
||||
class LabelSlider : public QLabel
|
||||
{
|
||||
@@ -18,8 +19,9 @@ protected:
|
||||
void mouseMoveEvent(QMouseEvent *ev);
|
||||
void mouseReleaseEvent(QMouseEvent *ev);
|
||||
private:
|
||||
float internal_value;
|
||||
float default_value;
|
||||
float internal_value;
|
||||
float drag_start_value;
|
||||
|
||||
bool min_enabled;
|
||||
float min_value;
|
||||
@@ -34,4 +36,16 @@ 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
|
||||
|
||||
@@ -13,10 +13,23 @@
|
||||
#include <QDebug>
|
||||
|
||||
SourceTable::SourceTable(QWidget* parent) : QTreeWidget(parent) {
|
||||
editing_item = NULL;
|
||||
sortByColumn(0, Qt::AscendingOrder);
|
||||
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(itemChanged(QTreeWidgetItem*,int)), this, SLOT(item_renamed(QTreeWidgetItem*)));
|
||||
}
|
||||
|
||||
void SourceTable::item_renamed(QTreeWidgetItem* item) {
|
||||
if (editing_item == item) {
|
||||
MediaRename* mr = new MediaRename();
|
||||
mr->from = editing_item_name;
|
||||
mr->item = editing_item;
|
||||
mr->to = editing_item->text(0);
|
||||
undo_stack.push(mr);
|
||||
editing_item = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void SourceTable::stop_rename_timer() {
|
||||
@@ -26,6 +39,7 @@ void SourceTable::stop_rename_timer() {
|
||||
void SourceTable::rename_interval() {
|
||||
stop_rename_timer();
|
||||
if (hasFocus() && editing_item != NULL) {
|
||||
editing_item_name = editing_item->text(0);
|
||||
editItem(editing_item, 0);
|
||||
}
|
||||
}
|
||||
@@ -154,3 +168,16 @@ void MediaMove::redo() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MediaRename::MediaRename() : done(true) {}
|
||||
|
||||
void MediaRename::undo() {
|
||||
item->setText(0, from);
|
||||
done = false;
|
||||
}
|
||||
|
||||
void MediaRename::redo() {
|
||||
if (!done) {
|
||||
item->setText(0, to);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,12 @@ protected:
|
||||
private:
|
||||
QTimer rename_timer;
|
||||
QTreeWidgetItem* editing_item;
|
||||
QString editing_item_name;
|
||||
private slots:
|
||||
void rename_interval();
|
||||
void item_click(QTreeWidgetItem* item, int column);
|
||||
void stop_rename_timer();
|
||||
void item_renamed(QTreeWidgetItem *item);
|
||||
};
|
||||
|
||||
class MediaMove : public QUndoCommand {
|
||||
@@ -39,4 +41,16 @@ private:
|
||||
SourceTable* table;
|
||||
};
|
||||
|
||||
class MediaRename : public QUndoCommand {
|
||||
public:
|
||||
MediaRename();
|
||||
QTreeWidgetItem* item;
|
||||
QString from;
|
||||
QString to;
|
||||
void undo();
|
||||
void redo();
|
||||
private:
|
||||
bool done;
|
||||
};
|
||||
|
||||
#endif // SOURCETABLE_H
|
||||
|
||||
Reference in New Issue
Block a user