Mercurial > hg > svgui
comparison layer/TimeValueLayer.cpp @ 68:193b569a975f
* Add scale lines to waveform layer
* Various fixes to vertical scale drawing for waveform and time-value layers
* Make log/linear scale have an effect for time-value layer segmentation mode
author | Chris Cannam |
---|---|
date | Wed, 29 Mar 2006 16:24:25 +0000 |
parents | c4fff27cd651 |
children | bf306158803d |
comparison
equal
deleted
inserted
replaced
67:c4fff27cd651 | 68:193b569a975f |
---|---|
415 int h = v->height(); | 415 int h = v->height(); |
416 | 416 |
417 return min + (float(h - y) * float(max - min)) / h; | 417 return min + (float(h - y) * float(max - min)) / h; |
418 } | 418 } |
419 | 419 |
420 QColor | |
421 TimeValueLayer::getColourForValue(float val) const | |
422 { | |
423 float min = m_model->getValueMinimum(); | |
424 float max = m_model->getValueMaximum(); | |
425 if (max == min) max = min + 1.0; | |
426 | |
427 if (m_verticalScale == FrequencyScale || m_verticalScale == LogScale) { | |
428 min = (min < 0.0) ? -log10(-min) : (min == 0.0) ? 0.0 : log10(min); | |
429 max = (max < 0.0) ? -log10(-max) : (max == 0.0) ? 0.0 : log10(max); | |
430 val = (val < 0.0) ? -log10(-val) : (val == 0.0) ? 0.0 : log10(val); | |
431 } else if (m_verticalScale == PlusMinusOneScale) { | |
432 min = -1.0; | |
433 max = 1.0; | |
434 } | |
435 | |
436 int iv = ((val - min) / (max - min)) * 255.999; | |
437 | |
438 QColor colour = QColor::fromHsv(256 - iv, iv / 2 + 128, iv); | |
439 return QColor(colour.red(), colour.green(), colour.blue(), 120); | |
440 } | |
441 | |
420 void | 442 void |
421 TimeValueLayer::paint(View *v, QPainter &paint, QRect rect) const | 443 TimeValueLayer::paint(View *v, QPainter &paint, QRect rect) const |
422 { | 444 { |
423 if (!m_model || !m_model->isOK()) return; | 445 if (!m_model || !m_model->isOK()) return; |
424 | 446 |
495 | 517 |
496 if (w < 1) w = 1; | 518 if (w < 1) w = 1; |
497 paint.setPen(m_colour); | 519 paint.setPen(m_colour); |
498 | 520 |
499 if (m_plotStyle == PlotSegmentation) { | 521 if (m_plotStyle == PlotSegmentation) { |
500 int value = ((p.value - min) / (max - min)) * 255.999; | 522 paint.setBrush(getColourForValue(p.value)); |
501 QColor colour = QColor::fromHsv(256 - value, value / 2 + 128, value); | |
502 paint.setBrush(QColor(colour.red(), colour.green(), colour.blue(), | |
503 120)); | |
504 labelY = v->height(); | 523 labelY = v->height(); |
505 } else if (m_plotStyle == PlotLines || | 524 } else if (m_plotStyle == PlotLines || |
506 m_plotStyle == PlotCurve) { | 525 m_plotStyle == PlotCurve) { |
507 paint.setBrush(Qt::NoBrush); | 526 paint.setBrush(Qt::NoBrush); |
508 } else { | 527 } else { |
615 } | 634 } |
616 | 635 |
617 int | 636 int |
618 TimeValueLayer::getVerticalScaleWidth(View *v, QPainter &paint) const | 637 TimeValueLayer::getVerticalScaleWidth(View *v, QPainter &paint) const |
619 { | 638 { |
620 if (m_plotStyle == PlotSegmentation) return 0; | 639 int w = paint.fontMetrics().width("-000.000"); |
621 return paint.fontMetrics().width("+0.000e+00") + 15; | 640 if (m_plotStyle == PlotSegmentation) return w + 20; |
641 else return w + 10; | |
622 } | 642 } |
623 | 643 |
624 void | 644 void |
625 TimeValueLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const | 645 TimeValueLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const |
626 { | 646 { |
627 if (!m_model) return; | 647 if (!m_model) return; |
628 if (m_plotStyle == PlotSegmentation) return; | 648 |
629 | 649 int h = v->height(); |
630 float val = m_model->getValueMinimum(); | 650 |
631 float inc = (m_model->getValueMaximum() - val) / 10; | 651 int n = 10; |
652 | |
653 float max = m_model->getValueMaximum(); | |
654 float min = m_model->getValueMinimum(); | |
655 float val = min; | |
656 float inc = (max - val) / n; | |
632 | 657 |
633 char buffer[40]; | 658 char buffer[40]; |
634 | 659 |
635 int w = getVerticalScaleWidth(v, paint); | 660 int w = getVerticalScaleWidth(v, paint); |
636 | 661 |
637 while (val < m_model->getValueMaximum()) { | 662 int tx = 5; |
638 int y = getYForValue(v, val); | 663 |
639 // QString label = QString("%1").arg(val); | 664 int boxx = 5, boxy = 5; |
640 sprintf(buffer, "%+.3e", val); | 665 if (m_model->getScaleUnits() != "") { |
666 boxy += paint.fontMetrics().height(); | |
667 } | |
668 int boxw = 10, boxh = h - boxy - 5; | |
669 | |
670 if (m_plotStyle == PlotSegmentation) { | |
671 tx += boxx + boxw; | |
672 paint.drawRect(boxx, boxy, boxw, boxh); | |
673 } | |
674 | |
675 if (m_plotStyle == PlotSegmentation) { | |
676 paint.save(); | |
677 for (int y = 0; y < boxh; ++y) { | |
678 float val = ((boxh - y) * (max - min)) / boxh + min; | |
679 paint.setPen(getColourForValue(val)); | |
680 paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1); | |
681 } | |
682 paint.restore(); | |
683 } | |
684 | |
685 for (int i = 0; i < n; ++i) { | |
686 | |
687 int y, ty; | |
688 bool drawText = true; | |
689 | |
690 if (m_plotStyle == PlotSegmentation) { | |
691 y = boxy + int(boxh - ((val - min) * boxh) / (max - min)); | |
692 ty = y; | |
693 } else { | |
694 if (i == n-1) { | |
695 if (m_model->getScaleUnits() != "") drawText = false; | |
696 } | |
697 y = getYForValue(v, val); | |
698 ty = y - paint.fontMetrics().height() + | |
699 paint.fontMetrics().ascent(); | |
700 } | |
701 | |
702 sprintf(buffer, "%.3f", val); | |
641 QString label = QString(buffer); | 703 QString label = QString(buffer); |
642 paint.drawLine(w - 5, y, w, y);// 100 - 10, y, 100, y); | 704 |
643 paint.drawText(5, // 100 - 15 - paint.fontMetrics().width(label), | 705 if (m_plotStyle != PlotSegmentation) { |
644 y - paint.fontMetrics().height() + paint.fontMetrics().ascent(), | 706 paint.drawLine(w - 5, y, w, y); |
645 label); | 707 } else { |
708 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y); | |
709 } | |
710 | |
711 if (drawText) paint.drawText(tx, ty, label); | |
646 val += inc; | 712 val += inc; |
647 } | 713 } |
648 | 714 |
649 if (m_model->getScaleUnits() != "") { | 715 if (m_model->getScaleUnits() != "") { |
650 paint.drawText(5, 5 + paint.fontMetrics().ascent(), | 716 paint.drawText(5, 5 + paint.fontMetrics().ascent(), |
651 m_model->getScaleUnits()); | 717 m_model->getScaleUnits()); |
652 } | 718 } |
653 } | 719 } |