Mercurial > hg > svgui
comparison layer/SpectrumLayer.cpp @ 1398:f228bee4981c
We need to draw illumination label *after* the spectrum...
author | Chris Cannam |
---|---|
date | Wed, 14 Nov 2018 15:14:21 +0000 |
parents | 9ea551137329 |
children | ba1f0234efa7 |
comparison
equal
deleted
inserted
replaced
1397:9ea551137329 | 1398:f228bee4981c |
---|---|
731 int scaleHeight = getHorizontalScaleHeight(v, paint); | 731 int scaleHeight = getHorizontalScaleHeight(v, paint); |
732 | 732 |
733 QPoint localPos; | 733 QPoint localPos; |
734 bool shouldIlluminate = v->shouldIlluminateLocalFeatures(this, localPos); | 734 bool shouldIlluminate = v->shouldIlluminateLocalFeatures(this, localPos); |
735 | 735 |
736 int illuminateX = 0; | |
737 double illuminateFreq = 0.0; | |
738 double illuminateLevel = 0.0; | |
739 | |
740 ColourMapper mapper = | |
741 hasLightBackground() ? | |
742 ColourMapper(ColourMapper::BlackOnWhite, m_colourInverted, 0, 1) : | |
743 ColourMapper(ColourMapper::WhiteOnBlack, m_colourInverted, 0, 1); | |
744 | |
736 // cerr << "shouldIlluminate = " << shouldIlluminate << ", localPos = " << localPos.x() << "," << localPos.y() << endl; | 745 // cerr << "shouldIlluminate = " << shouldIlluminate << ", localPos = " << localPos.x() << "," << localPos.y() << endl; |
737 | 746 |
738 if (fft && m_showPeaks) { | 747 if (fft && m_showPeaks) { |
739 | 748 |
740 // draw peak lines | 749 // draw peak lines |
741 | 750 |
742 int col = int(v->getCentreFrame() / fft->getResolution()); | 751 int col = int(v->getCentreFrame() / fft->getResolution()); |
743 | 752 |
744 paint.save(); | 753 paint.save(); |
745 paint.setRenderHint(QPainter::Antialiasing, false); | 754 paint.setRenderHint(QPainter::Antialiasing, false); |
746 | |
747 ColourMapper mapper = | |
748 hasLightBackground() ? | |
749 ColourMapper(ColourMapper::BlackOnWhite, m_colourInverted, 0, 1) : | |
750 ColourMapper(ColourMapper::WhiteOnBlack, m_colourInverted, 0, 1); | |
751 | 755 |
752 int peakminbin = 0; | 756 int peakminbin = 0; |
753 int peakmaxbin = fft->getHeight() - 1; | 757 int peakmaxbin = fft->getHeight() - 1; |
754 double peakmaxfreq = Pitch::getFrequencyForPitch(128); | 758 double peakmaxfreq = Pitch::getFrequencyForPitch(128); |
755 peakmaxbin = int(((peakmaxfreq * fft->getHeight() * 2) / | 759 peakmaxbin = int(((peakmaxfreq * fft->getHeight() * 2) / |
763 int cs = int(curve.size()); | 767 int cs = int(curve.size()); |
764 | 768 |
765 int px = -1; | 769 int px = -1; |
766 | 770 |
767 int fuzz = ViewManager::scalePixelSize(3); | 771 int fuzz = ViewManager::scalePixelSize(3); |
768 bool illuminatedSomething = false; | |
769 | 772 |
770 for (FFTModel::PeakSet::iterator i = peaks.begin(); | 773 for (FFTModel::PeakSet::iterator i = peaks.begin(); |
771 i != peaks.end(); ++i) { | 774 i != peaks.end(); ++i) { |
772 | 775 |
773 double freq = i->second; | 776 double freq = i->second; |
791 QColor colour = mapper.map(norm); | 794 QColor colour = mapper.map(norm); |
792 | 795 |
793 paint.setPen(QPen(colour, 1)); | 796 paint.setPen(QPen(colour, 1)); |
794 paint.drawLine(x, 0, x, v->getPaintHeight() - scaleHeight - 1); | 797 paint.drawLine(x, 0, x, v->getPaintHeight() - scaleHeight - 1); |
795 | 798 |
796 bool illuminateThis = false; | 799 if (shouldIlluminate && std::abs(localPos.x() - x) <= fuzz) { |
797 if (shouldIlluminate && !illuminatedSomething && | 800 illuminateX = x; |
798 std::abs(localPos.x() - x) <= fuzz) { | 801 illuminateFreq = freq; |
799 illuminateThis = true; | 802 illuminateLevel = norm; |
800 } | |
801 | |
802 if (illuminateThis) { | |
803 int labelY = v->getPaintHeight() - | |
804 getHorizontalScaleHeight(v, paint) - | |
805 paint.fontMetrics().height() * 4; | |
806 QString text = tr("%1 Hz").arg(freq); | |
807 int lw = paint.fontMetrics().width(text); | |
808 int gap = ViewManager::scalePixelSize(v->getXForViewX(3)); | |
809 double half = double(gap)/2.0; | |
810 int labelX = x - lw - gap; | |
811 if (labelX < getVerticalScaleWidth(v, false, paint)) { | |
812 labelX = x + gap; | |
813 } | |
814 PaintAssistant::drawVisibleText | |
815 (v, paint, labelX, labelY, | |
816 text, PaintAssistant::OutlinedText); | |
817 if (Pitch::isFrequencyInMidiRange(freq)) { | |
818 QString pitchLabel = Pitch::getPitchLabelForFrequency(freq); | |
819 PaintAssistant::drawVisibleText | |
820 (v, paint, | |
821 labelX, labelY + paint.fontMetrics().ascent() + gap, | |
822 pitchLabel, PaintAssistant::OutlinedText); | |
823 } | |
824 paint.fillRect(QRectF(x - half, labelY + gap, gap, gap), | |
825 colour); | |
826 illuminatedSomething = true; | |
827 } | 803 } |
828 | 804 |
829 px = x; | 805 px = x; |
830 } | 806 } |
831 | 807 |
837 SliceLayer::paint(v, paint, rect); | 813 SliceLayer::paint(v, paint, rect); |
838 | 814 |
839 paintHorizontalScale(v, paint, xorigin); | 815 paintHorizontalScale(v, paint, xorigin); |
840 | 816 |
841 paint.restore(); | 817 paint.restore(); |
818 | |
819 if (illuminateFreq > 0.0) { | |
820 | |
821 QColor colour = mapper.map(illuminateLevel); | |
822 paint.setPen(QPen(colour, 1)); | |
823 | |
824 int labelY = v->getPaintHeight() - | |
825 getHorizontalScaleHeight(v, paint) - | |
826 paint.fontMetrics().height() * 4; | |
827 | |
828 QString text = tr("%1 Hz").arg(illuminateFreq); | |
829 int lw = paint.fontMetrics().width(text); | |
830 | |
831 int gap = ViewManager::scalePixelSize(v->getXForViewX(3)); | |
832 double half = double(gap)/2.0; | |
833 | |
834 int labelX = illuminateX - lw - gap; | |
835 if (labelX < getVerticalScaleWidth(v, false, paint)) { | |
836 labelX = illuminateX + gap; | |
837 } | |
838 | |
839 PaintAssistant::drawVisibleText | |
840 (v, paint, labelX, labelY, | |
841 text, PaintAssistant::OutlinedText); | |
842 | |
843 if (Pitch::isFrequencyInMidiRange(illuminateFreq)) { | |
844 QString pitchLabel = Pitch::getPitchLabelForFrequency | |
845 (illuminateFreq); | |
846 PaintAssistant::drawVisibleText | |
847 (v, paint, | |
848 labelX, labelY + paint.fontMetrics().ascent() + gap, | |
849 pitchLabel, PaintAssistant::OutlinedText); | |
850 } | |
851 paint.fillRect(QRectF(illuminateX - half, labelY + gap, gap, gap), | |
852 colour); | |
853 } | |
842 } | 854 } |
843 | 855 |
844 int | 856 int |
845 SpectrumLayer::getHorizontalScaleHeight(LayerGeometryProvider *v, | 857 SpectrumLayer::getHorizontalScaleHeight(LayerGeometryProvider *v, |
846 QPainter &paint) const | 858 QPainter &paint) const |