diff view/Pane.cpp @ 756:9cfcb2924ee3 tony_integration

Merge from branch tonioni
author Chris Cannam
date Wed, 02 Apr 2014 08:51:33 +0100
parents ad01e7d4a956 09e2677e34e7
children 410816717c2c
line wrap: on
line diff
--- a/view/Pane.cpp	Wed Apr 02 08:50:18 2014 +0100
+++ b/view/Pane.cpp	Wed Apr 02 08:51:33 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;
 }
@@ -1235,6 +1235,18 @@
                         tr("Show pane context menu"));
 }
 
+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)
 {
@@ -1346,8 +1358,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); 
         }
 
@@ -1461,11 +1473,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();
@@ -1476,19 +1499,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();
@@ -1539,10 +1549,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()) {
@@ -1651,8 +1663,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);
                     }