comparison layer/RegionLayer.cpp @ 413:f71752646f97

* tweaks
author Chris Cannam
date Fri, 19 Sep 2008 14:05:34 +0000
parents d332ad1ca66b
children fc19435ac0f5
comparison
equal deleted inserted replaced
412:d332ad1ca66b 413:f71752646f97
288 } 288 }
289 289
290 RegionRec region(0); 290 RegionRec region(0);
291 RegionModel::PointList::iterator i; 291 RegionModel::PointList::iterator i;
292 292
293 //!!! harmonise with whatever decision is made about point y
294 //!!! coords in paint method
295
293 for (i = points.begin(); i != points.end(); ++i) { 296 for (i = points.begin(); i != points.end(); ++i) {
294 297
295 int y = getYForValue(v, i->value); 298 int y = getYForValue(v, i->value);
296 int h = 3; 299 int h = 3;
297 300
454 RegionLayer::getYForValue(View *v, float val) const 457 RegionLayer::getYForValue(View *v, float val) const
455 { 458 {
456 float min = 0.0, max = 0.0; 459 float min = 0.0, max = 0.0;
457 bool logarithmic = false; 460 bool logarithmic = false;
458 int h = v->height(); 461 int h = v->height();
462 int margin = 8;
463 if (h < margin * 8) margin = h / 8;
459 464
460 getScaleExtents(v, min, max, logarithmic); 465 getScaleExtents(v, min, max, logarithmic);
461 466
462 // std::cerr << "RegionLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl; 467 std::cerr << "RegionLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl;
468 std::cerr << "h = " << h << ", margin = " << margin << std::endl;
463 469
464 if (logarithmic) { 470 if (logarithmic) {
465 val = LogRange::map(val); 471 val = LogRange::map(val);
466 // std::cerr << "logarithmic true, val now = " << val << std::endl; 472 std::cerr << "logarithmic true, val now = " << val << std::endl;
467 } 473 }
468 474
469 int y = int(h - ((val - min) * h) / (max - min)) - 1; 475 h -= margin * 2;
470 // std::cerr << "y = " << y << std::endl; 476 int y = margin + int(h - ((val - min) * h) / (max - min)) - 1;
477 std::cerr << "y = " << y << std::endl;
471 return y; 478 return y;
472 } 479 }
473 480
474 float 481 float
475 RegionLayer::getValueForY(View *v, int y) const 482 RegionLayer::getValueForY(View *v, int y) const
528 } 535 }
529 536
530 paint.save(); 537 paint.save();
531 paint.setRenderHint(QPainter::Antialiasing, false); 538 paint.setRenderHint(QPainter::Antialiasing, false);
532 539
540 //!!! point y coords if model does not haveDistinctValues() should
541 //!!! be assigned to avoid overlaps
542
543 //!!! if it does have distinct values, we should still ensure y
544 //!!! coord is never completely flat on the top or bottom
545
533 for (RegionModel::PointList::const_iterator i = points.begin(); 546 for (RegionModel::PointList::const_iterator i = points.begin();
534 i != points.end(); ++i) { 547 i != points.end(); ++i) {
535 548
536 const RegionModel::Point &p(*i); 549 const RegionModel::Point &p(*i);
537 550
538 int x = v->getXForFrame(p.frame); 551 int x = v->getXForFrame(p.frame);
539 int y = getYForValue(v, p.value); 552 int y = getYForValue(v, p.value);
540 int w = v->getXForFrame(p.frame + p.duration) - x; 553 int w = v->getXForFrame(p.frame + p.duration) - x;
541 int h = 3; 554 int h = 9;
542 555
543 if (m_model->getValueQuantization() != 0.0) { 556 if (m_model->getValueQuantization() != 0.0) {
544 h = y - getYForValue(v, p.value + m_model->getValueQuantization()); 557 h = y - getYForValue(v, p.value + m_model->getValueQuantization());
545 if (h < 3) h = 3; 558 if (h < 3) h = 3;
546 } 559 }
554 paint.setPen(v->getForeground()); 567 paint.setPen(v->getForeground());
555 paint.setBrush(v->getForeground()); 568 paint.setBrush(v->getForeground());
556 } 569 }
557 } 570 }
558 571
559 paint.drawLine(x, y, x + w, y); 572 paint.drawLine(x, y-1, x + w, y-1);
573 paint.drawLine(x, y+1, x + w, y+1);
560 paint.drawLine(x, y - h/2, x, y + h/2); 574 paint.drawLine(x, y - h/2, x, y + h/2);
561 paint.drawLine(x + w, y - h/2, x + w, y + h/2); 575 paint.drawLine(x+w, y - h/2, x + w, y + h/2);
562 576
563 /// if (p.label != "") { 577 /// if (p.label != "") {
564 /// paint.drawText(x + 5, y - paint.fontMetrics().height() + paint.fontMetrics().ascent(), p.label); 578 /// paint.drawText(x + 5, y - paint.fontMetrics().height() + paint.fontMetrics().ascent(), p.label);
565 /// } 579 /// }
566 } 580 }