ui: make color setting undoable
This commit is contained in:
@@ -363,9 +363,13 @@ void NodeView::Duplicate()
|
||||
|
||||
void NodeView::SetColorLabel(int index)
|
||||
{
|
||||
MultiUndoCommand *command = new MultiUndoCommand();
|
||||
|
||||
for (Node* node : qAsConst(selected_nodes_)) {
|
||||
node->SetOverrideColor(index);
|
||||
command->add_child(new NodeOverrideColorCommand(node, index));
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->push(command);
|
||||
}
|
||||
|
||||
void NodeView::ZoomIn()
|
||||
|
||||
@@ -171,4 +171,26 @@ Project *NodeRenameCommand::GetRelevantProject() const
|
||||
return nodes_.isEmpty() ? nullptr : nodes_.first()->project();
|
||||
}
|
||||
|
||||
NodeOverrideColorCommand::NodeOverrideColorCommand(Node *node, int index) :
|
||||
node_(node),
|
||||
new_index_(index)
|
||||
{
|
||||
}
|
||||
|
||||
Project *NodeOverrideColorCommand::GetRelevantProject() const
|
||||
{
|
||||
return node_->project();
|
||||
}
|
||||
|
||||
void NodeOverrideColorCommand::redo()
|
||||
{
|
||||
old_index_ = node_->GetOverrideColor();
|
||||
node_->SetOverrideColor(new_index_);
|
||||
}
|
||||
|
||||
void NodeOverrideColorCommand::undo()
|
||||
{
|
||||
node_->SetOverrideColor(old_index_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -342,6 +342,27 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class NodeOverrideColorCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeOverrideColorCommand(Node *node, int index);
|
||||
|
||||
virtual Project * GetRelevantProject() const override;
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Node *node_;
|
||||
|
||||
int old_index_;
|
||||
|
||||
int new_index_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NODEVIEWUNDO_H
|
||||
|
||||
@@ -720,9 +720,13 @@ void TimelineWidget::ToggleSelectedEnabled()
|
||||
|
||||
void TimelineWidget::SetColorLabel(int index)
|
||||
{
|
||||
MultiUndoCommand *command = new MultiUndoCommand();
|
||||
|
||||
foreach (Block* b, selected_blocks_) {
|
||||
b->SetOverrideColor(index);
|
||||
command->add_child(new NodeOverrideColorCommand(b, index));
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->push(command);
|
||||
}
|
||||
|
||||
void TimelineWidget::NudgeLeft()
|
||||
|
||||
Reference in New Issue
Block a user