Mercurial > hg > svgui
diff layer/TimeValueLayer.cpp @ 28:202d1dca67d2
* Rationalise the local feature identification API in Layer subclasses
* Add segmentation mode to TimeInstantLayer
author | Chris Cannam |
---|---|
date | Mon, 06 Feb 2006 17:24:52 +0000 |
parents | 38fe0ea9e46e |
children | c43f2c4f66f2 |
line wrap: on
line diff
--- a/layer/TimeValueLayer.cpp Fri Feb 03 17:30:47 2006 +0000 +++ b/layer/TimeValueLayer.cpp Mon Feb 06 17:24:52 2006 +0000 @@ -210,6 +210,15 @@ usePoints = nextPoints; } + if (!usePoints.empty()) { + int fuzz = 2; + int px = getXForFrame(usePoints.begin()->frame); + if ((px > x && px - x > fuzz) || + (px < x && x - px > fuzz + 1)) { + usePoints.clear(); + } + } + return usePoints; } @@ -251,36 +260,76 @@ return text; } -int -TimeValueLayer::getNearestFeatureFrame(int frame, - size_t &resolution, - bool snapRight) const +bool +TimeValueLayer::snapToFeatureFrame(int &frame, + size_t &resolution, + SnapType snap) const { if (!m_model) { - return Layer::getNearestFeatureFrame(frame, resolution, snapRight); + return Layer::snapToFeatureFrame(frame, resolution, snap); } resolution = m_model->getResolution(); - SparseTimeValueModel::PointList points(m_model->getPoints(frame, frame)); + SparseTimeValueModel::PointList points; - int returnFrame = frame; + if (snap == SnapNeighbouring) { + + points = getLocalPoints(getXForFrame(frame)); + if (points.empty()) return false; + frame = points.begin()->frame; + return true; + } + + points = m_model->getPoints(frame, frame); + int snapped = frame; + bool found = false; for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); i != points.end(); ++i) { - if (snapRight) { + if (snap == SnapRight) { + if (i->frame > frame) { - returnFrame = i->frame; + snapped = i->frame; + found = true; break; } - } else { + + } else if (snap == SnapLeft) { + if (i->frame <= frame) { - returnFrame = i->frame; + snapped = i->frame; + found = true; // don't break, as the next may be better + } else { + break; + } + + } else { // nearest + + SparseTimeValueModel::PointList::const_iterator j = i; + ++j; + + if (j == points.end()) { + + snapped = i->frame; + found = true; + break; + + } else if (j->frame >= frame) { + + if (j->frame - frame < frame - i->frame) { + snapped = j->frame; + } else { + snapped = i->frame; + } + found = true; + break; } } } - return returnFrame; + frame = snapped; + return found; } int @@ -473,7 +522,8 @@ if (nx <= x) continue; - if (nx < x + 5 && illuminateFrame != p.frame) { + if (illuminateFrame != p.frame && + (nx < x + 5 || x >= m_view->width() - 1)) { paint.setPen(Qt::NoPen); }