keyframe values can now be set in graph editor

This commit is contained in:
itsmattkc
2018-12-31 22:44:34 +11:00
parent 7a4e655d2c
commit 1e1ed96bff
4 changed files with 76 additions and 2 deletions
+31
View File
@@ -1301,3 +1301,34 @@ void RippleAction::redo() {
}
ca->redo();
}
SetDouble::SetDouble(double* pointer, double new_value) :
p(pointer),
oldval(*pointer),
newval(new_value),
old_project_changed(mainWindow->isWindowModified())
{}
void SetDouble::undo() {
*p = oldval;
mainWindow->setWindowModified(old_project_changed);
}
void SetDouble::redo() {
*p = newval;
mainWindow->setWindowModified(true);
}
SetQVariant::SetQVariant(QVariant *itarget, const QVariant &iold, const QVariant &inew) :
target(itarget),
old_val(iold),
new_val(inew)
{}
void SetQVariant::undo() {
*target = old_val;
}
void SetQVariant::redo() {
*target = new_val;
}
+23
View File
@@ -524,6 +524,18 @@ private:
bool old_project_changed;
};
class SetDouble : public QUndoCommand {
public:
SetDouble(double* pointer, double new_value);
void undo();
void redo();
private:
double* p;
double oldval;
double newval;
bool old_project_changed;
};
class SetString : public QUndoCommand {
public:
SetString(QString* pointer, QString new_value);
@@ -606,4 +618,15 @@ public:
void redo();
};
class SetQVariant : public QUndoCommand {
public:
SetQVariant(QVariant* itarget, const QVariant& iold, const QVariant& inew);
void undo();
void redo();
private:
QVariant* target;
QVariant old_val;
QVariant new_val;
};
#endif // UNDO_H
+21 -2
View File
@@ -173,8 +173,13 @@ void GraphView::mousePressEvent(QMouseEvent *event) {
}
selected_keys_old_vals.clear();
selected_keys_old_doubles.clear();
for (int i=0;i<selected_keys.size();i++) {
selected_keys_old_vals.append(row->keyframe_times.at(selected_keys.at(i)));
for (int j=0;j<selected_keys_fields.size();j++) {
selected_keys_old_doubles.append(row->field(selected_keys_fields.at(j))->keyframe_data.at(selected_keys.at(i)).toDouble());
}
}
update();
@@ -191,6 +196,10 @@ void GraphView::mouseMoveEvent(QMouseEvent *event) {
} else {
for (int i=0;i<selected_keys.size();i++) {
row->keyframe_times[selected_keys.at(i)] = selected_keys_old_vals.at(i) + (double(event->pos().x() - start_x)/zoom);
for (int j=0;j<selected_keys_fields.size();j++) {
row->field(selected_keys_fields.at(j))->keyframe_data[selected_keys.at(i)] = selected_keys_old_doubles.at((i*selected_keys_fields.size())+j) + (double(start_y - event->pos().y())/zoom);
}
}
moved_keys = true;
update_ui(false);
@@ -199,15 +208,25 @@ void GraphView::mouseMoveEvent(QMouseEvent *event) {
}
void GraphView::mouseReleaseEvent(QMouseEvent *event) {
if (moved_keys) {
if (moved_keys && selected_keys.size() > 0) {
ComboAction* ca = new ComboAction();
QVector<EffectRow*> rows;
QVector<long> new_vals;
for (int i=0;i<selected_keys.size();i++) {
rows.append(row);
new_vals.append(row->keyframe_times.at(selected_keys.at(i)));
for (int j=0;j<selected_keys_fields.size();j++) {
ca->append(new SetQVariant(&row->field(selected_keys_fields.at(j))->keyframe_data[selected_keys.at(i)],
selected_keys_old_doubles.at((i*selected_keys_fields.size())+j),
row->field(selected_keys_fields.at(j))->keyframe_data.at(selected_keys.at(i))));
}
//ca->append(new KeyframeSet(row, selected_keys.at(i), 0, false));
}
undo_stack.push(new KeyframeMove(rows, selected_keys, selected_keys_old_vals, new_vals));
ca->append(new KeyframeMove(rows, selected_keys, selected_keys_old_vals, new_vals));
undo_stack.push(ca);
}
moved_keys = false;
mousedown = false;
+1
View File
@@ -41,6 +41,7 @@ private:
QVector<int> selected_keys;
QVector<int> selected_keys_fields;
QVector<long> selected_keys_old_vals;
QVector<double> selected_keys_old_doubles;
bool moved_keys;