diff layer/TextLayer.cpp @ 125:999ae0f7d10c

* Change preferences dialog to ok/apply/cancel model * Make preferences persist in a config file * Change instance() to getInstance() for all singleton types * Make pasting to time-value layer with no values in clipboard ask you how to generate the values * Fix bad behaviour caused by importing "data"-type (i.e. 3d dense) model from annotation file without a fixed window size available
author Chris Cannam
date Thu, 27 Jul 2006 16:06:32 +0000
parents 0f36cdf407a6
children 33929e0c3c6b
line wrap: on
line diff
--- a/layer/TextLayer.cpp	Wed Jul 26 16:48:07 2006 +0000
+++ b/layer/TextLayer.cpp	Thu Jul 27 16:06:32 2006 +0000
@@ -705,16 +705,26 @@
     }
 }
 
-void
-TextLayer::paste(const Clipboard &from, int frameOffset)
+bool
+TextLayer::paste(const Clipboard &from, int frameOffset, bool interactive)
 {
-    if (!m_model) return;
+    if (!m_model) return false;
 
     const Clipboard::PointList &points = from.getPoints();
 
     TextModel::EditCommand *command =
 	new TextModel::EditCommand(m_model, tr("Paste"));
 
+    float valueMin = 0.0, valueMax = 1.0;
+    for (Clipboard::PointList::const_iterator i = points.begin();
+         i != points.end(); ++i) {
+        if (i->haveValue()) {
+            if (i->getValue() < valueMin) valueMin = i->getValue();
+            if (i->getValue() > valueMax) valueMax = i->getValue();
+        }
+    }
+    if (valueMax < valueMin + 1.0) valueMax = valueMin + 1.0;
+
     for (Clipboard::PointList::const_iterator i = points.begin();
          i != points.end(); ++i) {
         
@@ -724,14 +734,26 @@
             frame = i->getFrame() + frameOffset;
         }
         TextModel::Point newPoint(frame);
-        if (i->haveValue()) newPoint.height = i->haveValue();
-        if (i->haveLabel()) newPoint.label = i->getLabel();
-        else newPoint.label = tr("New Point");
+
+        if (i->haveValue()) {
+            newPoint.height = (i->getValue() - valueMin) / (valueMax - valueMin);
+        } else {
+            newPoint.height = 0.5;
+        }
+
+        if (i->haveLabel()) {
+            newPoint.label = i->getLabel();
+        } else if (i->haveValue()) {
+            newPoint.label = QString("%1").arg(i->getValue());
+        } else {
+            newPoint.label = tr("New Point");
+        }
         
         command->addPoint(newPoint);
     }
 
     command->finish();
+    return true;
 }
 
 QString