Mercurial > hg > svgui
comparison layer/RegionLayer.cpp @ 433:ac349afdb23f
* somewhat clearer layout in region layer
author | Chris Cannam |
---|---|
date | Thu, 16 Oct 2008 13:38:33 +0000 |
parents | 8b2b497d302c |
children | 5930f2b0b1d2 |
comparison
equal
deleted
inserted
replaced
432:8b2b497d302c | 433:ac349afdb23f |
---|---|
41 m_model(0), | 41 m_model(0), |
42 m_editing(false), | 42 m_editing(false), |
43 m_originalPoint(0, 0.0, 0, tr("New Point")), | 43 m_originalPoint(0, 0.0, 0, tr("New Point")), |
44 m_editingPoint(0, 0.0, 0, tr("New Point")), | 44 m_editingPoint(0, 0.0, 0, tr("New Point")), |
45 m_editingCommand(0), | 45 m_editingCommand(0), |
46 m_verticalScale(AutoAlignScale), | 46 m_verticalScale(EqualSpaced), |
47 m_colourMap(0), | 47 m_colourMap(0), |
48 m_plotStyle(PlotLines) | 48 m_plotStyle(PlotLines) |
49 { | 49 { |
50 | 50 |
51 } | 51 } |
55 { | 55 { |
56 if (m_model == model) return; | 56 if (m_model == model) return; |
57 m_model = model; | 57 m_model = model; |
58 | 58 |
59 connectSignals(m_model); | 59 connectSignals(m_model); |
60 | |
61 connect(m_model, SIGNAL(modelChanged()), this, SLOT(recalcSpacing())); | |
62 recalcSpacing(); | |
60 | 63 |
61 // std::cerr << "RegionLayer::setModel(" << model << ")" << std::endl; | 64 // std::cerr << "RegionLayer::setModel(" << model << ")" << std::endl; |
62 | 65 |
63 emit modelReplaced(); | 66 emit modelReplaced(); |
64 } | 67 } |
125 | 128 |
126 } else if (name == "Vertical Scale") { | 129 } else if (name == "Vertical Scale") { |
127 | 130 |
128 if (min) *min = 0; | 131 if (min) *min = 0; |
129 if (max) *max = 3; | 132 if (max) *max = 3; |
130 if (deflt) *deflt = int(AutoAlignScale); | 133 if (deflt) *deflt = int(EqualSpaced); |
131 | 134 |
132 val = int(m_verticalScale); | 135 val = int(m_verticalScale); |
133 | 136 |
134 } else if (name == "Scale Units") { | 137 } else if (name == "Scale Units") { |
135 | 138 |
163 | 166 |
164 } else if (name == "Vertical Scale") { | 167 } else if (name == "Vertical Scale") { |
165 switch (value) { | 168 switch (value) { |
166 default: | 169 default: |
167 case 0: return tr("Auto-Align"); | 170 case 0: return tr("Auto-Align"); |
168 case 1: return tr("Linear"); | 171 case 1: return tr("Equal Spaced"); |
169 case 2: return tr("Log"); | 172 case 2: return tr("Linear"); |
173 case 3: return tr("Log"); | |
170 } | 174 } |
171 } | 175 } |
172 return SingleColourLayer::getPropertyValueLabel(name, value); | 176 return SingleColourLayer::getPropertyValueLabel(name, value); |
173 } | 177 } |
174 | 178 |
226 { | 230 { |
227 QPoint discard; | 231 QPoint discard; |
228 return !v->shouldIlluminateLocalFeatures(this, discard); | 232 return !v->shouldIlluminateLocalFeatures(this, discard); |
229 } | 233 } |
230 | 234 |
235 void | |
236 RegionLayer::recalcSpacing() | |
237 { | |
238 m_spacingMap.clear(); | |
239 if (!m_model) return; | |
240 | |
241 std::set<float> values; | |
242 | |
243 for (RegionModel::PointList::const_iterator i = m_model->getPoints().begin(); | |
244 i != m_model->getPoints().end(); ++i) { | |
245 values.insert(i->value); | |
246 } | |
247 | |
248 int n = 0; | |
249 | |
250 for (std::set<float>::const_iterator i = values.begin(); | |
251 i != values.end(); ++i) { | |
252 m_spacingMap[*i] = n++; | |
253 } | |
254 } | |
255 | |
231 bool | 256 bool |
232 RegionLayer::getValueExtents(float &min, float &max, | 257 RegionLayer::getValueExtents(float &min, float &max, |
233 bool &logarithmic, QString &unit) const | 258 bool &logarithmic, QString &unit) const |
234 { | 259 { |
235 if (!m_model) return false; | 260 if (!m_model) return false; |
243 } | 268 } |
244 | 269 |
245 bool | 270 bool |
246 RegionLayer::getDisplayExtents(float &min, float &max) const | 271 RegionLayer::getDisplayExtents(float &min, float &max) const |
247 { | 272 { |
248 if (!m_model || m_verticalScale == AutoAlignScale) return false; | 273 if (!m_model || |
274 m_verticalScale == AutoAlignScale || | |
275 m_verticalScale == EqualSpaced) return false; | |
249 | 276 |
250 min = m_model->getValueMinimum(); | 277 min = m_model->getValueMinimum(); |
251 max = m_model->getValueMaximum(); | 278 max = m_model->getValueMaximum(); |
252 | 279 |
253 return true; | 280 return true; |
474 | 501 |
475 std::cerr << "RegionLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; | 502 std::cerr << "RegionLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; |
476 | 503 |
477 } | 504 } |
478 | 505 |
506 } else if (m_verticalScale == EqualSpaced) { | |
507 | |
508 if (!m_spacingMap.empty()) { | |
509 SpacingMap::const_iterator i = m_spacingMap.begin(); | |
510 min = i->second; | |
511 i = m_spacingMap.end(); | |
512 --i; | |
513 max = i->second; | |
514 std::cerr << "RegionLayer[" << this << "]::getScaleExtents: equal spaced; min = " << min << ", max = " << max << ", log = " << log << std::endl; | |
515 } | |
516 | |
479 } else { | 517 } else { |
480 | 518 |
481 min = m_model->getValueMinimum(); | 519 min = m_model->getValueMinimum(); |
482 max = m_model->getValueMaximum(); | 520 max = m_model->getValueMaximum(); |
483 | 521 |
494 RegionLayer::getYForValue(View *v, float val) const | 532 RegionLayer::getYForValue(View *v, float val) const |
495 { | 533 { |
496 float min = 0.0, max = 0.0; | 534 float min = 0.0, max = 0.0; |
497 bool logarithmic = false; | 535 bool logarithmic = false; |
498 int h = v->height(); | 536 int h = v->height(); |
499 int margin = 8; | 537 |
500 if (h < margin * 8) margin = h / 8; | 538 if (m_verticalScale == EqualSpaced) { |
501 | 539 |
502 getScaleExtents(v, min, max, logarithmic); | 540 if (m_spacingMap.empty()) return h/2; |
541 | |
542 SpacingMap::const_iterator i = m_spacingMap.lower_bound(val); | |
543 //!!! what now, if i->first != v? | |
544 | |
545 int vh = i->second; | |
546 | |
547 SpacingMap::const_iterator j = m_spacingMap.end(); | |
548 --j; | |
549 | |
550 return h - (((h * vh) / (j->second + 1)) + (h / (2 * (j->second + 1)))); | |
551 | |
552 } else { | |
553 | |
554 getScaleExtents(v, min, max, logarithmic); | |
503 | 555 |
504 // std::cerr << "RegionLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl; | 556 // std::cerr << "RegionLayer[" << this << "]::getYForValue(" << val << "): min = " << min << ", max = " << max << ", log = " << logarithmic << std::endl; |
505 // std::cerr << "h = " << h << ", margin = " << margin << std::endl; | 557 // std::cerr << "h = " << h << ", margin = " << margin << std::endl; |
506 | 558 |
507 if (logarithmic) { | 559 if (logarithmic) { |
508 val = LogRange::map(val); | 560 val = LogRange::map(val); |
509 std::cerr << "logarithmic true, val now = " << val << std::endl; | 561 } |
510 } | 562 |
511 | 563 return int(h - ((val - min) * h) / (max - min)); |
512 h -= margin * 2; | 564 } |
513 int y = margin + int(h - ((val - min) * h) / (max - min)) - 1; | |
514 // std::cerr << "y = " << y << std::endl; | |
515 return y; | |
516 } | 565 } |
517 | 566 |
518 QColor | 567 QColor |
519 RegionLayer::getColourForValue(View *v, float val) const | 568 RegionLayer::getColourForValue(View *v, float val) const |
520 { | 569 { |
622 | 671 |
623 int x = v->getXForFrame(p.frame); | 672 int x = v->getXForFrame(p.frame); |
624 int y = getYForValue(v, p.value); | 673 int y = getYForValue(v, p.value); |
625 int w = v->getXForFrame(p.frame + p.duration) - x; | 674 int w = v->getXForFrame(p.frame + p.duration) - x; |
626 int h = 9; | 675 int h = 9; |
627 | 676 int ex = x + w; |
628 bool haveNext = false; | |
629 int nx = v->getXForFrame(v->getModelsEndFrame()); | |
630 | 677 |
631 RegionModel::PointList::const_iterator j = i; | 678 RegionModel::PointList::const_iterator j = i; |
632 ++j; | 679 ++j; |
633 | 680 |
634 if (j != points.end()) { | 681 if (j != points.end()) { |
635 const RegionModel::Point &q(*j); | 682 const RegionModel::Point &q(*j); |
636 nx = v->getXForFrame(q.frame); | 683 int nx = v->getXForFrame(q.frame); |
637 haveNext = true; | 684 if (nx < ex) ex = nx; |
638 } | 685 } |
639 | 686 |
640 if (m_plotStyle != PlotSegmentation) { | 687 if (m_plotStyle != PlotSegmentation) { |
641 textY = y - paint.fontMetrics().height() | 688 textY = y - paint.fontMetrics().height() |
642 + paint.fontMetrics().ascent(); | 689 + paint.fontMetrics().ascent(); |
660 paint.setBrush(brushColour); | 707 paint.setBrush(brushColour); |
661 } | 708 } |
662 | 709 |
663 if (m_plotStyle == PlotSegmentation) { | 710 if (m_plotStyle == PlotSegmentation) { |
664 | 711 |
665 if (nx <= x) continue; | 712 if (ex <= x) continue; |
666 | 713 |
667 if (illuminateFrame != p.frame && | 714 if (illuminateFrame != p.frame && |
668 (nx < x + 5 || x >= v->width() - 1)) { | 715 (ex < x + 5 || x >= v->width() - 1)) { |
669 paint.setPen(Qt::NoPen); | 716 paint.setPen(Qt::NoPen); |
670 } | 717 } |
671 | 718 |
672 paint.drawRect(x, -1, nx - x, v->height() + 1); | 719 paint.drawRect(x, -1, ex - x, v->height() + 1); |
673 | 720 |
674 } else { | 721 } else { |
675 | 722 |
676 if (illuminateFrame == p.frame) { | 723 if (illuminateFrame == p.frame) { |
677 if (localPos.y() >= y - h && localPos.y() < y) { | 724 if (localPos.y() >= y - h && localPos.y() < y) { |
685 paint.drawLine(x, y - h/2, x, y + h/2); | 732 paint.drawLine(x, y - h/2, x, y + h/2); |
686 paint.drawLine(x+w, y - h/2, x + w, y + h/2); | 733 paint.drawLine(x+w, y - h/2, x + w, y + h/2); |
687 } | 734 } |
688 | 735 |
689 if (p.label != "") { | 736 if (p.label != "") { |
690 if (!haveNext || nx > x + 6 + paint.fontMetrics().width(p.label)) { | 737 // if (ex > x + 6 + paint.fontMetrics().width(p.label)) { |
691 paint.drawText(x + 5, textY, p.label); | 738 paint.drawText(x + 5, textY, p.label); |
692 } | 739 // } |
693 } | 740 } |
694 } | 741 } |
695 | 742 |
696 paint.restore(); | 743 paint.restore(); |
697 } | 744 } |