diff layer/RegionLayer.cpp @ 559:5bcfc5606528

* Add option to import time+duration (or time+endtime) from CSV files (importing to Region layers) * Fix ffwd/rwd in Region layers so as to behave like time-value layers
author Chris Cannam
date Thu, 08 Jul 2010 14:22:28 +0000
parents 2e8194a30f40
children f4960f8ce798
line wrap: on
line diff
--- a/layer/RegionLayer.cpp	Tue Jun 22 09:45:42 2010 +0000
+++ b/layer/RegionLayer.cpp	Thu Jul 08 14:22:28 2010 +0000
@@ -517,6 +517,79 @@
     return found;
 }
 
+bool
+RegionLayer::snapToSimilarFeature(View *v, int &frame,
+                                  size_t &resolution,
+                                  SnapType snap) const
+{
+    if (!m_model) {
+	return Layer::snapToSimilarFeature(v, frame, resolution, snap);
+    }
+
+    resolution = m_model->getResolution();
+
+    const RegionModel::PointList &points = m_model->getPoints();
+    RegionModel::PointList close = m_model->getPoints(frame, frame);
+
+    RegionModel::PointList::const_iterator i;
+
+    int matchframe = frame;
+    float matchvalue = 0.f;
+
+    for (i = close.begin(); i != close.end(); ++i) {
+        if (i->frame > frame) break;
+        matchvalue = i->value;
+        matchframe = i->frame;
+    }
+
+    int snapped = frame;
+    bool found = false;
+    bool distant = false;
+    float epsilon = 0.0001;
+
+    i = close.begin();
+
+    // Scan through the close points first, then the more distant ones
+    // if no suitable close one is found
+
+    while (i != points.end()) {
+
+        if (i == close.end()) {
+            i = points.begin();
+            distant = true;
+        }
+
+	if (snap == SnapRight) {
+
+	    if (i->frame > matchframe &&
+                fabsf(i->value - matchvalue) < epsilon) {
+		snapped = i->frame;
+		found = true;
+		break;
+	    }
+
+	} else if (snap == SnapLeft) {
+
+	    if (i->frame < matchframe) {
+                if (fabsf(i->value - matchvalue) < epsilon) {
+                    snapped = i->frame;
+                    found = true; // don't break, as the next may be better
+                }
+	    } else if (found || distant) {
+		break;
+	    }
+
+	} else { 
+            // no other snap types supported
+	}
+
+        ++i;
+    }
+
+    frame = snapped;
+    return found;
+}
+
 void
 RegionLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const
 {
@@ -847,6 +920,7 @@
                 RegionModel::Point::Comparator()(illuminatePoint, p) ||
                 RegionModel::Point::Comparator()(p, illuminatePoint)) {
 
+                paint.setPen(QPen(getForegroundQColor(v), 1));
                 paint.drawLine(x, 0, x, v->height());
                 paint.setPen(Qt::NoPen);
 
@@ -854,7 +928,7 @@
                 paint.setPen(QPen(getForegroundQColor(v), 2));
             }
 
-	    paint.drawRect(x, 0, ex - x, v->height() + 1);
+	    paint.drawRect(x, -1, ex - x, v->height() + 2);
 
 	} else {