|
From: Tapio V. <aa...@us...> - 2011-02-07 19:02:05
|
Module: editor
Branch: master
Commit: 7b5642251b40fbfc6f32705888185377b2285a54
Author: Tapio Vierros <tap...@gm...>
Date: Mon Feb 7 20:45:47 2011 +0200
Note clearing now handled by the undo system.
---
notegraphwidget.cc | 23 ++++++++---------------
notegraphwidget.hh | 2 +-
notelabelmanager.cc | 13 +++++++++++++
3 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index f34e7b2..6c02428 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -43,23 +43,12 @@ NoteGraphWidget::NoteGraphWidget(QWidget *parent)
updateNotes();
}
-void NoteGraphWidget::clearNotes()
-{
- selectNote(NULL);
- // Clear NoteLabels
- const QObjectList &childlist = children();
- for (QObjectList::const_iterator it = childlist.begin(); it != childlist.end(); ++it) {
- NoteLabel *child = qobject_cast<NoteLabel*>(*it);
- if (child) child->close();
- }
- m_notes.clear();
-}
void NoteGraphWidget::setLyrics(QString lyrics)
{
QTextStream ts(&lyrics, QIODevice::ReadOnly);
- clearNotes();
+ doOperation(Operation("CLEAR"));
bool firstNote = true;
while (!ts.atEnd()) {
// We want to loop one line at the time to insert line breaks
@@ -84,7 +73,7 @@ void NoteGraphWidget::setLyrics(QString lyrics)
void NoteGraphWidget::setLyrics(const VocalTrack &track)
{
- clearNotes();
+ doOperation(Operation("CLEAR"));
m_duration = std::max(m_duration, track.endTime);
const Notes ¬es = track.notes;
for (Notes::const_iterator it = notes.begin(); it != notes.end(); ++it) {
@@ -92,13 +81,14 @@ void NoteGraphWidget::setLyrics(const VocalTrack &track)
doOperation(opFromNote(*it, m_notes.size(), false));
}
- updateNotes();
+ finalizeNewLyrics();
}
void NoteGraphWidget::finalizeNewLyrics()
{
+ int ops = m_notes.size();
// Set first and last to non-floating and put the last one to the end of the song
- if (m_notes.size() > 1) {
+ if (ops > 1 && m_notes[ops-1]->isFloating()) {
Operation floatop("FLOATING"); floatop << (int)m_notes.size()-1 << false;
doOperation(floatop);
Operation moveop("MOVE");
@@ -108,7 +98,10 @@ void NoteGraphWidget::finalizeNewLyrics()
doOperation(moveop);
// Make sure there is enough room
setFixedWidth(std::max<int>(width(), m_notes.size() * NoteLabel::min_width + m_notes.front()->width() * 2));
+ ops += 2; // Amount of extra Operations added here
}
+ // Combine the import into one undo action
+ doOperation(Operation("COMBINER", ops));
// Calculate floating note positions
updateNotes();
}
diff --git a/notegraphwidget.hh b/notegraphwidget.hh
index f091e02..71deb05 100644
--- a/notegraphwidget.hh
+++ b/notegraphwidget.hh
@@ -34,6 +34,7 @@ public:
virtual void updateNotes(bool leftToRight = true) {}
+ void clearNotes();
void selectNote(NoteLabel *note, bool clearPrevious = true);
void selectAll();
NoteLabel* selectedNote() const { return m_selectedNotes.isEmpty() ? NULL : m_selectedNotes.front(); }
@@ -84,7 +85,6 @@ public:
NoteGraphWidget(QWidget *parent = 0);
- void clearNotes();
void setLyrics(QString lyrics);
void setLyrics(const VocalTrack &track);
void analyzeMusic(QString filepath);
diff --git a/notelabelmanager.cc b/notelabelmanager.cc
index d3555df..540f4da 100644
--- a/notelabelmanager.cc
+++ b/notelabelmanager.cc
@@ -15,6 +15,17 @@ NoteLabelManager::NoteLabelManager(QWidget *parent)
templabel.close();
}
+void NoteLabelManager::clearNotes()
+{
+ selectNote(NULL);
+ // Clear NoteLabels
+ const QObjectList &childlist = children();
+ for (QObjectList::const_iterator it = childlist.begin(); it != childlist.end(); ++it) {
+ NoteLabel *child = qobject_cast<NoteLabel*>(*it);
+ if (child) child->close();
+ }
+ m_notes.clear();
+}
void NoteLabelManager::selectNote(NoteLabel* note, bool clearPrevious)
{
@@ -186,6 +197,8 @@ void NoteLabelManager::doOperation(const Operation& op, Operation::OperationFlag
QString action = op.op();
if (action == "BLOCK" || action == "COMBINER") {
; // No op
+ } else if (action == "CLEAR") {
+ clearNotes();
} else if (action == "NEW") {
Note newnote(op.s(2)); // lyric
newnote.lineBreak = op.b(7); // lineBreak
|