comparison layer/TimeValueLayer.cpp @ 79:19bf27e4fb29

* Replace crash with warning when a transform could not be automatically re-run * More sensible default paths for Vamp plugin lookup (at least on Linux and OS/X) * A start to making the y coords for time value layers etc align * Set sensible y coords for text labels in time instant and value layers
author Chris Cannam
date Thu, 13 Apr 2006 18:29:10 +0000
parents 45ba0b381c5d
children 01f27a282c90
comparison
equal deleted inserted replaced
78:967193b6c7aa 79:19bf27e4fb29
214 214
215 QPoint discard; 215 QPoint discard;
216 return !v->shouldIlluminateLocalFeatures(this, discard); 216 return !v->shouldIlluminateLocalFeatures(this, discard);
217 } 217 }
218 218
219 bool
220 TimeValueLayer::getValueExtents(float &min, float &max, QString &unit) const
221 {
222 min = m_model->getValueMinimum();
223 max = m_model->getValueMaximum();
224 unit = m_model->getScaleUnits();
225 return true;
226 }
227
219 SparseTimeValueModel::PointList 228 SparseTimeValueModel::PointList
220 TimeValueLayer::getLocalPoints(View *v, int x) const 229 TimeValueLayer::getLocalPoints(View *v, int x) const
221 { 230 {
222 if (!m_model) return SparseTimeValueModel::PointList(); 231 if (!m_model) return SparseTimeValueModel::PointList();
223 232
371 } 380 }
372 381
373 int 382 int
374 TimeValueLayer::getYForValue(View *v, float val) const 383 TimeValueLayer::getYForValue(View *v, float val) const
375 { 384 {
385 float min = 0.0, max = 0.0;
386 int h = v->height();
387
388 if (!v->getValueExtents(m_model->getScaleUnits(), min, max)) {
389 min = m_model->getValueMinimum();
390 max = m_model->getValueMaximum();
391 }
392
393 if (max == min) max = min + 1.0;
394
395 /*!!!
376 float min = m_model->getValueMinimum(); 396 float min = m_model->getValueMinimum();
377 float max = m_model->getValueMaximum(); 397 float max = m_model->getValueMaximum();
378 if (max == min) max = min + 1.0; 398 if (max == min) max = min + 1.0;
379 399
380 int h = v->height(); 400 int h = v->height();
399 419
400 } else if (m_verticalScale == PlusMinusOneScale) { 420 } else if (m_verticalScale == PlusMinusOneScale) {
401 min = -1.0; 421 min = -1.0;
402 max = 1.0; 422 max = 1.0;
403 } 423 }
424 */
404 425
405 return int(h - ((val - min) * h) / (max - min)); 426 return int(h - ((val - min) * h) / (max - min));
406 } 427 }
407 428
408 float 429 float
490 511
491 paint.save(); 512 paint.save();
492 513
493 QPainterPath path; 514 QPainterPath path;
494 int pointCount = 0; 515 int pointCount = 0;
516
517 int textY = 0;
518 if (m_plotStyle == PlotSegmentation) {
519 textY = v->getTextLabelHeight(this, paint);
520 }
495 521
496 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); 522 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
497 i != points.end(); ++i) { 523 i != points.end(); ++i) {
498 524
499 const SparseTimeValueModel::Point &p(*i); 525 const SparseTimeValueModel::Point &p(*i);
500 526
501 int x = v->getXForFrame(p.frame); 527 int x = v->getXForFrame(p.frame);
502 int y = getYForValue(v, p.value); 528 int y = getYForValue(v, p.value);
529
530 if (m_plotStyle != PlotSegmentation) {
531 textY = y - paint.fontMetrics().height()
532 + paint.fontMetrics().ascent();
533 }
503 534
504 bool haveNext = false; 535 bool haveNext = false;
505 int nx = v->getXForFrame(v->getModelsEndFrame()); 536 int nx = v->getXForFrame(v->getModelsEndFrame());
506 // m_model->getEndFrame()); 537 // m_model->getEndFrame());
507 int ny = y; 538 int ny = y;
574 605
575 if (haveNext) { 606 if (haveNext) {
576 607
577 if (m_plotStyle == PlotConnectedPoints) { 608 if (m_plotStyle == PlotConnectedPoints) {
578 609
610 paint.save();
579 paint.setPen(brushColour); 611 paint.setPen(brushColour);
580 paint.drawLine(x + w, y, nx, ny); 612 paint.drawLine(x + w, y, nx, ny);
613 paint.restore();
581 614
582 } else if (m_plotStyle == PlotLines) { 615 } else if (m_plotStyle == PlotLines) {
583 616
584 paint.drawLine(x + w/2, y, nx + w/2, ny); 617 paint.drawLine(x + w/2, y, nx + w/2, ny);
585 618
624 657
625 paint.drawRect(x, -1, nx - x, v->height() + 1); 658 paint.drawRect(x, -1, nx - x, v->height() + 1);
626 } 659 }
627 660
628 if (p.label != "") { 661 if (p.label != "") {
629 paint.drawText(x + 5, y - paint.fontMetrics().height() + paint.fontMetrics().ascent(), p.label); 662 if (!haveNext || nx > x + 6 + paint.fontMetrics().width(p.label)) {
663 paint.drawText(x + 5, textY, p.label);
664 }
630 } 665 }
631 } 666 }
632 667
633 if (m_plotStyle == PlotCurve && !path.isEmpty()) { 668 if (m_plotStyle == PlotCurve && !path.isEmpty()) {
634 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width()); 669 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width());