changeset 649:2ad082c5a090 tonioni

boundary actions and note delete consolidated
author gyorgyf
date Sun, 16 Jun 2013 20:40:05 +0100
parents f61a54364d1d
children 76c5dfe333ee
files layer/FlexiNoteLayer.cpp layer/FlexiNoteLayer.h view/Pane.cpp
diffstat 3 files changed, 115 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/layer/FlexiNoteLayer.cpp	Sat Jun 15 19:52:06 2013 +0100
+++ b/layer/FlexiNoteLayer.cpp	Sun Jun 16 20:40:05 2013 +0100
@@ -944,8 +944,12 @@
 
     if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
     m_originalPoint = m_editingPoint;
-
-    m_dragPointX = v->getXForFrame(m_editingPoint.frame);
+    
+    if (m_editMode == rightBoundary) {
+        m_dragPointX = v->getXForFrame(m_editingPoint.frame + m_editingPoint.duration);
+    } else {
+        m_dragPointX = v->getXForFrame(m_editingPoint.frame);
+    }
     m_dragPointY = getYForValue(v, m_editingPoint.value);
 
     if (m_editingCommand) {
@@ -983,9 +987,17 @@
     }
 
     m_editingCommand->deletePoint(m_editingPoint);
-    m_editingPoint.frame = frame;
+    if (m_editMode == leftBoundary) 
+        m_editingPoint.duration = m_editingPoint.duration + (m_editingPoint.frame - frame); // GF: left boundary change
+    if (m_editMode == rightBoundary) {
+        m_editingPoint.duration = frame - m_editingPoint.frame; // GF: right boundary change
+    } else {
+        m_editingPoint.frame = frame;
+    }
     m_editingPoint.value = value;
     m_editingCommand->addPoint(m_editingPoint);
+    std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl;
+    
 }
 
 void
@@ -1047,7 +1059,7 @@
 {
     // GF: note splitting ends. (!! remove printing soon)
     std::cerr << "splitEnd" << std::endl;
-    if (!m_model || !m_editing) return;
+    if (!m_model || !m_editing || m_editMode != splitNote) return;
 
     int xdist = e->x() - m_dragStartX;
     int ydist = e->y() - m_dragStartY;
@@ -1056,7 +1068,7 @@
         return; 
     }
 
-    // MM simpler declaration
+    // MM: simpler declaration 
     FlexiNote note(0);
     if (!getPointToDrag(v, e->x(), e->y(), note)) return;
 
@@ -1064,7 +1076,7 @@
 
     int gap = 0; // MM: I prefer a gap of 0, but we can decide later
     
-    // MM: changed this a bit, to make it slightly clearer
+    // MM: changed this a bit, to make it slightly clearer (// GF: nice changes!)
     FlexiNote newNote1(note.frame, note.value, 
                        frame - note.frame - gap, 
                        note.level, note.label);
@@ -1076,6 +1088,10 @@
     FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
         (m_model, tr("Edit Point"));
     command->deletePoint(note);
+    if ((e->modifiers() & Qt::ShiftModifier)) {
+        finish(command);
+        return;
+    }
     command->addPoint(newNote1);
     command->addPoint(newNote2);
     finish(command);
@@ -1096,14 +1112,16 @@
     bool closeToLeft = false, closeToRight = false, closeToTop = false, closeToBottom = false;
     getRelativeMousePosition(v, note, e->x(), e->y(), closeToLeft, closeToRight, closeToTop, closeToBottom);
     // if (!closeToLeft) return;
-    if (closeToLeft || closeToRight) { v->setCursor(Qt::SizeHorCursor); return; }
     // if (closeToTop) v->setCursor(Qt::SizeVerCursor);
-    if (closeToTop) { v->setCursor(Qt::CrossCursor); return; }
-    if (closeToBottom) { v->setCursor(Qt::UpArrowCursor); return; }
+    
+    if (closeToLeft) { v->setCursor(Qt::SizeHorCursor); m_editMode = leftBoundary; return; }
+    if (closeToRight) { v->setCursor(Qt::SizeHorCursor); m_editMode = rightBoundary; return; }
+    if (closeToTop) { v->setCursor(Qt::CrossCursor);  m_editMode = dragNote; return; }
+    if (closeToBottom) { v->setCursor(Qt::UpArrowCursor); m_editMode = splitNote; return; }
+
     v->setCursor(Qt::ArrowCursor);
 
-
-    std::cerr << "Mouse moved in edit mode over FlexiNoteLayer" << std::endl;
+    // std::cerr << "Mouse moved in edit mode over FlexiNoteLayer" << std::endl;
     // v->setCursor(Qt::SizeHorCursor);
 
 }
@@ -1111,6 +1129,7 @@
 void
 FlexiNoteLayer::getRelativeMousePosition(View *v, FlexiNoteModel::Point &note, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const
 {
+    // GF: TODO: consoloidate the tolerance values
     if (!m_model) return;
 
     int ctol = 2;
--- a/layer/FlexiNoteLayer.h	Sat Jun 15 19:52:06 2013 +0100
+++ b/layer/FlexiNoteLayer.h	Sun Jun 16 20:40:05 2013 +0100
@@ -88,6 +88,14 @@
         LogScale,
         MIDIRangeScale
     };
+    
+    //GF: Tonioni: context sensitive note edit actions (denoted clockwise from top).
+    enum EditMode {
+        dragNote,
+        rightBoundary,
+        splitNote,
+        leftBoundary
+    };
 
     void setVerticalScale(VerticalScale scale);
     VerticalScale getVerticalScale() const { return m_verticalScale; }
@@ -158,6 +166,7 @@
     FlexiNoteModel::Point m_editingPoint;
     FlexiNoteModel::EditCommand *m_editingCommand;
     VerticalScale m_verticalScale;
+    EditMode m_editMode;
 
     typedef std::set<FlexiNoteModel::Point, FlexiNoteModel::Point::Comparator> FlexiNoteSet;
     FlexiNoteSet m_pendingNoteOns;
--- a/view/Pane.cpp	Sat Jun 15 19:52:06 2013 +0100
+++ b/view/Pane.cpp	Sun Jun 16 20:40:05 2013 +0100
@@ -1627,23 +1627,88 @@
 
     } else if (mode == ViewManager::SelectMode) {
 
-        if (!hasTopLayerTimeXAxis()) return;
-
-        dragExtendSelection(e);
+            if (!hasTopLayerTimeXAxis()) return;
+
+            dragExtendSelection(e);
 
     } else if (mode == ViewManager::DrawMode) {
 
-    Layer *layer = getSelectedLayer();
-    if (layer && layer->isLayerEditable()) {
-        layer->drawDrag(this, e);
-    }
+        Layer *layer = getSelectedLayer();
+        if (layer && layer->isLayerEditable()) {
+            layer->drawDrag(this, e);
+        }
 
     } else if (mode == ViewManager::EraseMode) {
 
-    Layer *layer = getSelectedLayer();
-    if (layer && layer->isLayerEditable()) {
-        layer->eraseDrag(this, e);
-    }
+        Layer *layer = getSelectedLayer();
+        if (layer && layer->isLayerEditable()) {
+            layer->eraseDrag(this, e);
+        }
+
+    // GF: handling NoteEditMode dragging and boundary actions for mouseMoveEvent
+    } else if (mode == ViewManager::NoteEditMode) {
+
+        bool resist = true;
+
+        if ((e->modifiers() & Qt::ShiftModifier)) {
+            m_shiftPressed = true;
+        }
+
+        if (m_shiftPressed) resist = false;
+
+        m_dragMode = updateDragMode
+            (m_dragMode,
+             m_clickPos,
+             e->pos(),
+             true,    // can move horiz
+             true,    // can move vert
+             resist,  // resist horiz
+             resist); // resist vert
+
+        if (!m_editing) {
+
+            if (m_dragMode != UnresolvedDrag) {
+
+                m_editing = true;
+
+                QMouseEvent clickEvent(QEvent::MouseButtonPress,
+                                       m_clickPos,
+                                       Qt::NoButton,
+                                       e->buttons(),
+                                       e->modifiers());
+
+                if (!editSelectionStart(&clickEvent)) {
+                    Layer *layer = getSelectedLayer();
+                    if (layer && layer->isLayerEditable()) {
+                        std::cerr << "calling edit start" << std::endl;
+                        layer->editStart(this, &clickEvent);
+                    }
+                }
+            }
+
+        } else {
+
+            if (!editSelectionDrag(e)) {
+
+                Layer *layer = getSelectedLayer();
+
+                if (layer && layer->isLayerEditable()) {
+
+                    int x = e->x();
+                    int y = e->y();
+                    if (m_dragMode == VerticalDrag) x = m_clickPos.x();
+                    else if (m_dragMode == HorizontalDrag) y = m_clickPos.y();
+
+                    QMouseEvent moveEvent(QEvent::MouseMove,
+                                          QPoint(x, y),
+                                          Qt::NoButton,
+                                          e->buttons(),
+                                          e->modifiers());
+                    std::cerr << "calling editDrag" << std::endl;
+                    layer->editDrag(this, &moveEvent);
+                }
+            }
+        }
 
     } else if (mode == ViewManager::EditMode) {