comparison 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
comparison
equal deleted inserted replaced
27:38fe0ea9e46e 28:202d1dca67d2
208 } else if (nextPoints.begin()->frame - frame < 208 } else if (nextPoints.begin()->frame - frame <
209 frame - prevPoints.begin()->frame) { 209 frame - prevPoints.begin()->frame) {
210 usePoints = nextPoints; 210 usePoints = nextPoints;
211 } 211 }
212 212
213 if (!usePoints.empty()) {
214 int fuzz = 2;
215 int px = getXForFrame(usePoints.begin()->frame);
216 if ((px > x && px - x > fuzz) ||
217 (px < x && x - px > fuzz + 1)) {
218 usePoints.clear();
219 }
220 }
221
213 return usePoints; 222 return usePoints;
214 } 223 }
215 224
216 QString 225 QString
217 TimeValueLayer::getFeatureDescription(QPoint &pos) const 226 TimeValueLayer::getFeatureDescription(QPoint &pos) const
249 258
250 pos = QPoint(getXForFrame(useFrame), getYForValue(points.begin()->value)); 259 pos = QPoint(getXForFrame(useFrame), getYForValue(points.begin()->value));
251 return text; 260 return text;
252 } 261 }
253 262
254 int 263 bool
255 TimeValueLayer::getNearestFeatureFrame(int frame, 264 TimeValueLayer::snapToFeatureFrame(int &frame,
256 size_t &resolution, 265 size_t &resolution,
257 bool snapRight) const 266 SnapType snap) const
258 { 267 {
259 if (!m_model) { 268 if (!m_model) {
260 return Layer::getNearestFeatureFrame(frame, resolution, snapRight); 269 return Layer::snapToFeatureFrame(frame, resolution, snap);
261 } 270 }
262 271
263 resolution = m_model->getResolution(); 272 resolution = m_model->getResolution();
264 SparseTimeValueModel::PointList points(m_model->getPoints(frame, frame)); 273 SparseTimeValueModel::PointList points;
265 274
266 int returnFrame = frame; 275 if (snap == SnapNeighbouring) {
276
277 points = getLocalPoints(getXForFrame(frame));
278 if (points.empty()) return false;
279 frame = points.begin()->frame;
280 return true;
281 }
282
283 points = m_model->getPoints(frame, frame);
284 int snapped = frame;
285 bool found = false;
267 286
268 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); 287 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
269 i != points.end(); ++i) { 288 i != points.end(); ++i) {
270 289
271 if (snapRight) { 290 if (snap == SnapRight) {
291
272 if (i->frame > frame) { 292 if (i->frame > frame) {
273 returnFrame = i->frame; 293 snapped = i->frame;
294 found = true;
274 break; 295 break;
275 } 296 }
276 } else { 297
298 } else if (snap == SnapLeft) {
299
277 if (i->frame <= frame) { 300 if (i->frame <= frame) {
278 returnFrame = i->frame; 301 snapped = i->frame;
302 found = true; // don't break, as the next may be better
303 } else {
304 break;
279 } 305 }
280 } 306
281 } 307 } else { // nearest
282 308
283 return returnFrame; 309 SparseTimeValueModel::PointList::const_iterator j = i;
310 ++j;
311
312 if (j == points.end()) {
313
314 snapped = i->frame;
315 found = true;
316 break;
317
318 } else if (j->frame >= frame) {
319
320 if (j->frame - frame < frame - i->frame) {
321 snapped = j->frame;
322 } else {
323 snapped = i->frame;
324 }
325 found = true;
326 break;
327 }
328 }
329 }
330
331 frame = snapped;
332 return found;
284 } 333 }
285 334
286 int 335 int
287 TimeValueLayer::getYForValue(float value) const 336 TimeValueLayer::getYForValue(float value) const
288 { 337 {
471 nx = getXForFrame(m_model->getEndFrame()); 520 nx = getXForFrame(m_model->getEndFrame());
472 } 521 }
473 522
474 if (nx <= x) continue; 523 if (nx <= x) continue;
475 524
476 if (nx < x + 5 && illuminateFrame != p.frame) { 525 if (illuminateFrame != p.frame &&
526 (nx < x + 5 || x >= m_view->width() - 1)) {
477 paint.setPen(Qt::NoPen); 527 paint.setPen(Qt::NoPen);
478 } 528 }
479 529
480 paint.drawRect(x, -1, nx - x, m_view->height() + 1); 530 paint.drawRect(x, -1, nx - x, m_view->height() + 1);
481 } 531 }