diff view/Pane.cpp @ 753:09e2677e34e7 tonioni

Fix fancy note-editing mode (was not working in new multi-layer world, and shift-click delete was broken)
author Chris Cannam
date Tue, 01 Apr 2014 21:18:31 +0100
parents f831ca41d4a5
children 9cfcb2924ee3 785c6f175ccc
line wrap: on
line diff
--- a/view/Pane.cpp	Tue Apr 01 16:20:55 2014 +0100
+++ b/view/Pane.cpp	Tue Apr 01 21:18:31 2014 +0100
@@ -344,10 +344,10 @@
     }
 
     if (layer == getSelectedLayer() &&
-    !shouldIlluminateLocalSelection(discard, b0, b1)) {
-
-    pos = m_identifyPoint;
-    return m_identifyFeatures;
+        !shouldIlluminateLocalSelection(discard, b0, b1)) {
+
+        pos = m_identifyPoint;
+        return m_identifyFeatures;
     }
 
     return false;
@@ -364,17 +364,17 @@
         !m_manager->getSelections().empty() &&
         !selectionIsBeingEdited()) {
 
-    Selection s(getSelectionAt(m_identifyPoint.x(),
-                   closeToLeft, closeToRight));
-
-    if (!s.isEmpty()) {
-        if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) {
-        
-        pos = m_identifyPoint;
-        return true;
+        Selection s(getSelectionAt(m_identifyPoint.x(),
+                                   closeToLeft, closeToRight));
+
+        if (!s.isEmpty()) {
+            if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) {
+            
+                pos = m_identifyPoint;
+                return true;
+            }
         }
     }
-    }
 
     return false;
 }
@@ -1276,6 +1276,18 @@
                         tr("Shift-click left button and drag to zoom to a rectangular area"));
 }
 
+Layer *
+Pane::getTopFlexiNoteLayer()
+{
+    for (int i = int(m_layers.size()) - 1; i >= 0; --i) {
+        if (LayerFactory::getInstance()->getLayerType(m_layers[i]) ==
+            LayerFactory::FlexiNotes) {
+            return m_layers[i];
+        }
+    }
+    return 0;
+}
+
 void
 Pane::mousePressEvent(QMouseEvent *e)
 {
@@ -1387,8 +1399,8 @@
     } else if (mode == ViewManager::NoteEditMode) {
 
         std::cerr << "mouse pressed in note edit mode" << std::endl;
-        Layer *layer = getSelectedLayer();
-        if (layer && layer->isLayerEditable()) {
+        Layer *layer = getTopFlexiNoteLayer();
+        if (layer) {
             layer->splitStart(this, e); 
         }
 
@@ -1502,11 +1514,22 @@
     } else if (mode == ViewManager::NoteEditMode) {
     
         //GF: handle mouse release for NoteEditMode (note: works but will need to re-think this a bit later)
-        Layer *layer = getSelectedLayer();
-        if (layer && layer->isLayerEditable()) {
+        Layer *layer = getTopFlexiNoteLayer();
+
+        if (layer) {
             layer->splitEnd(this, e);
-            update(); }
-
+            update();
+
+            if (m_editing) {
+                if (!editSelectionEnd(e)) {
+                    layer->editEnd(this, e);
+                    update();
+                }
+            }
+        } 
+
+    } else if (mode == ViewManager::EditMode) {
+        
         if (m_editing) {
             if (!editSelectionEnd(e)) {
                 Layer *layer = getSelectedLayer();
@@ -1517,19 +1540,6 @@
             }
         } 
 
-    } else if (mode == ViewManager::EditMode) {
-        
-        // GF: edited this previously, but restored to original state
-        if (m_editing) {
-            if (!editSelectionEnd(e)) {
-                Layer *layer = getSelectedLayer();
-                if (layer && layer->isLayerEditable()) {
-                    layer->editEnd(this, e);
-                    update();
-                }
-            }
-        } 
-
     } else if (mode == ViewManager::MeasureMode) {
 
         Layer *layer = getTopLayer();
@@ -1580,10 +1590,12 @@
     
         // GF: handle mouse move for context sensitive cursor switching in NoteEditMode.
         // GF: Propagate the event to FlexiNoteLayer. I somehow feel it's best handeled there rather than here, but perhaps not if this will be needed elsewhere too.
-        if (mode == ViewManager::NoteEditMode && LayerFactory::getInstance()->getLayerType(getTopLayer()) == LayerFactory::FlexiNotes) {
-        
-            dynamic_cast<FlexiNoteLayer *>(getTopLayer())->mouseMoveEvent(this, e);
-
+        if (mode == ViewManager::NoteEditMode) {
+            FlexiNoteLayer *layer = qobject_cast<FlexiNoteLayer *>(getTopFlexiNoteLayer());
+            if (layer) {
+                layer->mouseMoveEvent(this, e); //!!! ew
+                return;
+            }
         }   
     
         if (mode == ViewManager::SelectMode && hasTopLayerTimeXAxis()) {
@@ -1692,8 +1704,8 @@
                                        e->modifiers());
 
                 if (!editSelectionStart(&clickEvent)) {
-                    Layer *layer = getSelectedLayer();
-                    if (layer && layer->isLayerEditable()) {
+                    Layer *layer = getTopFlexiNoteLayer();
+                    if (layer) {
                         std::cerr << "calling edit start" << std::endl;
                         layer->editStart(this, &clickEvent);
                     }