|
From: Tapio V. <aa...@us...> - 2011-01-10 19:56:06
|
Module: editor
Branch: master
Commit: 55f37df2c1e428773252fd5eb8a009cfe23423d0
Author: Tapio Vierros <tap...@gm...>
Date: Mon Jan 10 21:55:17 2011 +0200
More notegraph tweaks.
---
notegraphwidget.cc | 63 +++++++++++++++++++++++++--------------------------
notelabel.cc | 5 +++-
2 files changed, 35 insertions(+), 33 deletions(-)
diff --git a/notegraphwidget.cc b/notegraphwidget.cc
index 0dec9bd..9c9f66d 100644
--- a/notegraphwidget.cc
+++ b/notegraphwidget.cc
@@ -87,43 +87,42 @@ void NoteGraphWidget::updateNotes()
NoteLabel *child = *it;
if (!child) continue;
- if (child->isFloating()) {
+ if (child->isFloating() && child != m_notes.back()) {
// Add floating note to gap
gap.addNote(child);
} else {
// Fixed note encountered, handle the gap (divide notes evenly into it)
- if (!gap.isEmpty()) {
- gap.end = child->x();
- int x = gap.begin;
-
- if (gap.width() >= gap.notesWidth()) {
- // Plenty of space - no resizing needed
- int step = (gap.width() - gap.notesWidth()) / (gap.notes.size() + 1);
- x += step;
- for (NoteLabels::iterator it2 = gap.notes.begin(); it2 != gap.notes.end(); ++it2) {
- (*it2)->move(x, (*it2)->y());
- x += step + (*it2)->width();
- }
-
- } else if (gap.width() <= gap.minWidth()) {
- // We are at minimum width, enforce it
- for (NoteLabels::iterator it2 = gap.notes.begin(); it2 != gap.notes.end(); ++it2) {
- (*it2)->move(x, (*it2)->y());
- (*it2)->resize(NoteLabel::min_width, (*it2)->height());
- x += NoteLabel::min_width;
- }
- // FIXME: Enforcing fixed note position doesn't work properly
- //child->move(gap.begin + gap.minWidth(), child->y());
-
- } else {
- // Make the notes smaller so that they fit
- float sf = gap.width() / float(gap.notesWidth());
- for (NoteLabels::iterator it2 = gap.notes.begin(); it2 != gap.notes.end(); ++it2) {
- (*it2)->move(x, (*it2)->y());
- (*it2)->resize((*it2)->width() * sf, (*it2)->height());
- x += (*it2)->width();
- }
+ gap.end = child->x();
+ int x = gap.begin;
+
+ if (gap.width() >= gap.notesWidth()) {
+ // Plenty of space - no resizing needed
+ int step = (gap.width() - gap.notesWidth()) / (gap.notes.size() + 1);
+ x += step;
+ for (NoteLabels::iterator it2 = gap.notes.begin(); it2 != gap.notes.end(); ++it2) {
+ (*it2)->move(x, (*it2)->y());
+ x += step + (*it2)->width();
+ }
+
+ } else if (gap.width() <= gap.minWidth()) {
+ // We are at minimum width, enforce it
+ for (NoteLabels::iterator it2 = gap.notes.begin(); it2 != gap.notes.end(); ++it2) {
+ (*it2)->move(x, (*it2)->y());
+ (*it2)->resize(NoteLabel::min_width, (*it2)->height());
+ x += NoteLabel::min_width;
+ }
+ // FIXME: Enforcing fixed note position can be cheated by rapid mouse movement
+ // Also, left & right side behaves differently
+ child->move(gap.begin + gap.minWidth(), child->y());
+
+ } else {
+ // Make the notes smaller so that they fit
+ float sf = gap.width() / float(gap.notesWidth());
+ for (NoteLabels::iterator it2 = gap.notes.begin(); it2 != gap.notes.end(); ++it2) {
+ (*it2)->move(x, (*it2)->y());
+ (*it2)->resize((*it2)->width() * sf, (*it2)->height());
+ x += (*it2)->width();
}
}
diff --git a/notelabel.cc b/notelabel.cc
index 75f3fad..8e0d512 100644
--- a/notelabel.cc
+++ b/notelabel.cc
@@ -104,8 +104,11 @@ void NoteLabel::mouseMoveEvent(QMouseEvent *event)
} else if (!m_hotspot.isNull()) {
// Moving
- move(pos() + event->pos() - m_hotspot);
+ QPoint newpos = pos() + event->pos() - m_hotspot;
+ move(newpos);
if (ngw) ngw->updateNotes();
+ // Check if we need a new hotspot, because the note was constrained
+ if (pos().x() != newpos.x()) m_hotspot.rx() = event->x();
} else {
// Hover cursors
|