standardized gizmos and made them keyframable

This commit is contained in:
itsmattkc
2018-12-02 18:23:15 +11:00
parent cc41123106
commit 021a50477c
18 changed files with 188 additions and 139 deletions
+19 -1
View File
@@ -854,7 +854,25 @@ void Effect::process_audio(double, double, quint8*, int, int) {
}
void Effect::gizmo_draw(double, GLTextureCoords &) {}
void Effect::gizmo_move(EffectGizmo* , int , int , double ) {}
void Effect::gizmo_move(EffectGizmo* gizmo, int x_movement, int y_movement, double timecode, bool done) {
for (int i=0;i<gizmos.size();i++) {
if (gizmos.at(i) == gizmo) {
ComboAction* ca = NULL;
if (done) ca = new ComboAction();
if (gizmo->x_field != NULL) {
gizmo->x_field->set_double_value(gizmo->x_field->get_double_value(timecode) + x_movement*gizmo->x_field_multi);
gizmo->x_field->make_key_from_change(ca);
}
if (gizmo->y_field != NULL) {
gizmo->y_field->set_double_value(gizmo->y_field->get_double_value(timecode) + y_movement*gizmo->y_field_multi);
gizmo->y_field->make_key_from_change(ca);
}
if (done) undo_stack.push(ca);
break;
}
}
}
void Effect::gizmo_world_to_screen() {
GLfloat view_val[16];
+1 -1
View File
@@ -159,7 +159,7 @@ public:
virtual void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count);
virtual void gizmo_draw(double timecode, GLTextureCoords& coords);
virtual void gizmo_move(EffectGizmo* sender, int x_movement, int y_movement, double timecode);
void gizmo_move(EffectGizmo* sender, int x_movement, int y_movement, double timecode, bool done);
void gizmo_world_to_screen();
bool are_gizmos_enabled();
public slots:
+23 -13
View File
@@ -17,20 +17,24 @@
#include "io/math.h"
#include <QtMath>
EffectField::EffectField(EffectRow *parent, int t, const QString &i) : parent_row(parent), type(t), id(i) {
EffectField::EffectField(EffectRow *parent, int t, const QString &i) :
parent_row(parent),
type(t),
id(i)
{
switch (t) {
case EFFECT_FIELD_DOUBLE:
{
LabelSlider* ls = new LabelSlider();
ui_element = ls;
connect(ls, SIGNAL(valueChanged()), this, SLOT(uiElementChange()));
connect(ls, SIGNAL(valueChanged()), this, SLOT(ui_element_change()));
}
break;
case EFFECT_FIELD_COLOR:
{
ColorButton* cb = new ColorButton();
ui_element = cb;
connect(cb, SIGNAL(color_changed()), this, SLOT(uiElementChange()));
connect(cb, SIGNAL(color_changed()), this, SLOT(ui_element_change()));
}
break;
case EFFECT_FIELD_STRING:
@@ -38,14 +42,14 @@ EffectField::EffectField(EffectRow *parent, int t, const QString &i) : parent_ro
TextEditEx* edit = new TextEditEx();
edit->setUndoRedoEnabled(true);
ui_element = edit;
connect(edit, SIGNAL(textChanged()), this, SLOT(uiElementChange()));
connect(edit, SIGNAL(textChanged()), this, SLOT(ui_element_change()));
}
break;
case EFFECT_FIELD_BOOL:
{
CheckboxEx* cb = new CheckboxEx();
ui_element = cb;
connect(cb, SIGNAL(clicked(bool)), this, SLOT(uiElementChange()));
connect(cb, SIGNAL(clicked(bool)), this, SLOT(ui_element_change()));
connect(cb, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
}
break;
@@ -53,14 +57,14 @@ EffectField::EffectField(EffectRow *parent, int t, const QString &i) : parent_ro
{
ComboBoxEx* cb = new ComboBoxEx();
ui_element = cb;
connect(cb, SIGNAL(activated(int)), this, SLOT(uiElementChange()));
connect(cb, SIGNAL(activated(int)), this, SLOT(ui_element_change()));
}
break;
case EFFECT_FIELD_FONT:
{
FontCombobox* fcb = new FontCombobox();
ui_element = fcb;
connect(fcb, SIGNAL(activated(int)), this, SLOT(uiElementChange()));
connect(fcb, SIGNAL(activated(int)), this, SLOT(ui_element_change()));
}
break;
}
@@ -231,15 +235,21 @@ QVariant EffectField::validate_keyframe_data(double timecode, bool async) {
return QVariant();
}
void EffectField::uiElementChange() {
bool enableKeyframes = !(type == EFFECT_FIELD_DOUBLE && static_cast<LabelSlider*>(ui_element)->is_dragging());
void EffectField::ui_element_change() {
bool dragging_double = (type == EFFECT_FIELD_DOUBLE && static_cast<LabelSlider*>(ui_element)->is_dragging());
ComboAction* ca = NULL;
if (!dragging_double) ca = new ComboAction();
make_key_from_change(ca);
if (!dragging_double) undo_stack.push(ca);
}
void EffectField::make_key_from_change(ComboAction* ca) {
if (parent_row->isKeyframing()) {
parent_row->set_keyframe_now(enableKeyframes);
} else if (enableKeyframes) {
parent_row->set_keyframe_now(ca);
} else if (ca != NULL) {
// set undo
undo_stack.push(new EffectFieldUndo(this));
ca->append(new EffectFieldUndo(this));
}
emit changed();
}
QWidget* EffectField::get_ui_element() {
+4 -1
View File
@@ -13,6 +13,7 @@
#include <QVector>
class EffectRow;
class ComboAction;
class EffectField : public QObject {
Q_OBJECT
@@ -59,10 +60,12 @@ public:
void set_enabled(bool e);
QVector<QVariant> keyframe_data;
QWidget* ui_element;
void make_key_from_change(ComboAction* ca);
private:
bool hasKeyframes();
private slots:
void uiElementChange();
void ui_element_change();
signals:
void changed();
void toggled(bool);
+12
View File
@@ -1,6 +1,13 @@
#include "effectgizmo.h"
#include "ui/labelslider.h"
#include "effectfield.h"
EffectGizmo::EffectGizmo(int type) :
x_field(NULL),
x_field_multi(1.0),
y_field(NULL),
y_field_multi(1.0),
type(type),
cursor(-1)
{
@@ -11,6 +18,11 @@ EffectGizmo::EffectGizmo(int type) :
color = Qt::white;
}
void EffectGizmo::set_previous_value() {
if (x_field != NULL) static_cast<LabelSlider*>(x_field->ui_element)->set_previous_value();
if (y_field != NULL) static_cast<LabelSlider*>(y_field->ui_element)->set_previous_value();
}
int EffectGizmo::get_point_count() {
return world_pos.size();
}
+8 -1
View File
@@ -19,9 +19,16 @@ class EffectGizmo
public:
EffectGizmo(int type);
QVector<EffectField*> fields;
QVector<QPoint> world_pos;
QVector<QPoint> screen_pos;
EffectField* x_field;
double x_field_multi;
EffectField* y_field;
double y_field_multi;
void set_previous_value();
QColor color;
int get_point_count();
+9 -5
View File
@@ -80,7 +80,9 @@ void EffectRow::setKeyframing(bool b) {
void EffectRow::set_keyframe_enabled(bool enabled) {
if (enabled) {
set_keyframe_now(true);
ComboAction* ca = new ComboAction();
set_keyframe_now(ca);
undo_stack.push(ca);
} else {
if (QMessageBox::question(panel_effect_controls, "Disable Keyframes", "Disabling keyframes will delete all current keyframes. Are you sure you want to do this?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
// clear
@@ -127,7 +129,9 @@ void EffectRow::toggle_key() {
}
if (index < 0) {
// keyframe doesn't exist, set one
set_keyframe_now(true);
ComboAction* ca = new ComboAction();
set_keyframe_now(ca);
undo_stack.push(ca);
} else {
KeyframeDelete* kd = new KeyframeDelete();
delete_keyframe(kd, index);
@@ -164,7 +168,7 @@ EffectRow::~EffectRow() {
}
}
void EffectRow::set_keyframe_now(bool undoable) {
void EffectRow::set_keyframe_now(ComboAction* ca) {
int index = -1;
long time = sequence->playhead-parent_effect->parent_clip->timeline_in+parent_effect->parent_clip->clip_in;
for (int i=0;i<keyframe_times.size();i++) {
@@ -176,9 +180,9 @@ void EffectRow::set_keyframe_now(bool undoable) {
KeyframeSet* ks = new KeyframeSet(this, index, time, just_made_unsafe_keyframe);
if (undoable) {
if (ca != NULL) {
just_made_unsafe_keyframe = false;
undo_stack.push(ks);
ca->append(ks);
} else {
if (index == -1) just_made_unsafe_keyframe = true;
ks->redo();
+2 -1
View File
@@ -10,6 +10,7 @@ class EffectField;
class QLabel;
class KeyframeDelete;
class QPushButton;
class ComboAction;
class EffectRow : public QObject {
Q_OBJECT
@@ -19,7 +20,7 @@ public:
EffectField* add_field(int type, const QString &id, int colspan = 1);
EffectField* field(int i);
int fieldCount();
void set_keyframe_now(bool undoable);
void set_keyframe_now(ComboAction *ca);
void delete_keyframe(KeyframeDelete *kd, int index);
void delete_keyframe_at_time(KeyframeDelete* kd, long time);
QLabel* label;
+3 -3
View File
@@ -868,7 +868,7 @@ KeyframeSet::KeyframeSet(EffectRow* r, int i, long t, bool justMadeKeyframe) :
EffectField* field = row->field(i);
if (index != -1) {
if (field->type == EFFECT_FIELD_DOUBLE) {
old_values[i] = static_cast<LabelSlider*>(field->ui_element)->get_drag_start_value();
old_values[i] = static_cast<LabelSlider*>(field->ui_element)->getPreviousValue();
} else {
old_values[i] = field->keyframe_data.at(index);
}
@@ -1300,7 +1300,7 @@ void SetPointer::redo() {
mainWindow->setWindowModified(true);
}
MoveGizmo::MoveGizmo(Effect *e, EffectGizmo *g, int x_movement, int y_movement, double tc) :
/*MoveGizmo::MoveGizmo(Effect *e, EffectGizmo *g, int x_movement, int y_movement, double tc) :
effect(e),
gizmo(g),
x(x_movement),
@@ -1322,4 +1322,4 @@ void MoveGizmo::redo() {
mainWindow->setWindowModified(true);
done = true;
}
}
}*/
+2 -2
View File
@@ -598,7 +598,7 @@ private:
void* old_data;
};
class MoveGizmo : public QUndoCommand {
/*class MoveGizmo : public QUndoCommand {
public:
MoveGizmo(Effect* e, EffectGizmo* g, int x_movement, int y_movement, double tc);
void undo();
@@ -611,6 +611,6 @@ private:
double timecode;
bool done;
bool old_changed;
};
};*/
#endif // UNDO_H