|
From: Tapio V. <aa...@us...> - 2011-01-17 11:07:32
|
Module: editor
Branch: master
Commit: c483fec6c119d10c4ae8438bdc678cb4f49214e6
Author: Tapio Vierros <tap...@gm...>
Date: Mon Jan 17 13:07:02 2011 +0200
Redo.
---
editorapp.cc | 34 +++++++++++++++++++++++++++++++---
editorapp.hh | 2 ++
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 84fddc8..d4eb5ce 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -65,6 +65,7 @@ void EditorApp::operationDone(const Operation &op)
//std::cout << "Push op: " << op.dump() << std::endl;
opStack.push(op);
updateMenuStates();
+ redoStack.clear();
}
void EditorApp::doOpStack()
@@ -85,9 +86,14 @@ void EditorApp::doOpStack()
void EditorApp::updateMenuStates()
{
+ // Undo menu
if (opStack.isEmpty() || opStack.top().op() == "BLOCK")
ui.actionUndo->setEnabled(false);
else ui.actionUndo->setEnabled(true);
+ // Redo menu
+ if (redoStack.isEmpty())
+ ui.actionRedo->setEnabled(false);
+ else ui.actionRedo->setEnabled(true);
}
void EditorApp::updateNoteInfo(NoteLabel *note)
@@ -291,15 +297,37 @@ void EditorApp::on_actionUndo_triggered()
updateMenuStates();
return;
} else if (opStack.top().op() == "COMBINER") {
+ // Special handling to add the ops in the right order
int count = opStack.top().i(1);
- for (int i = 0; i < count; ++i) opStack.pop();
- // TODO: Redo handling
+ int start = opStack.size() - count - 1;
+ for (int i = start; i < start + count; ++i) {
+ redoStack.push(opStack.at(i));
+ }
+ opStack.remove(start, count);
}
- // TODO: Move popped to redo stack
+ redoStack.push(opStack.top());
opStack.pop();
doOpStack();
}
+void EditorApp::on_actionRedo_triggered()
+{
+ if (redoStack.isEmpty())
+ return;
+ else if (redoStack.top().op() == "COMBINER") {
+ // Special handling to add the ops in the right order
+ int count = redoStack.top().i(1);
+ int start = redoStack.size() - count - 1;
+ for (int i = start; i < start + count; ++i) {
+ opStack.push(redoStack.at(i));
+ }
+ redoStack.remove(start, count);
+ }
+ opStack.push(redoStack.top());
+ redoStack.pop();
+ doOpStack();
+}
+
void EditorApp::on_actionMusicFile_triggered()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
diff --git a/editorapp.hh b/editorapp.hh
index 310f470..719df6e 100644
--- a/editorapp.hh
+++ b/editorapp.hh
@@ -37,6 +37,7 @@ public slots:
// Edit menu
void on_actionUndo_triggered();
+ void on_actionRedo_triggered();
// Insert menu
void on_actionMusicFile_triggered();
@@ -59,6 +60,7 @@ private:
Ui::EditorApp ui;
NoteGraphWidget* noteGraph;
OperationStack opStack;
+ OperationStack redoStack;
QScopedPointer<Song> song;
QString projectFileName;
};
|