Mercurial > hg > svgui
comparison view/View.cpp @ 278:a078aa2932cc
* Fix piano keyboard in spectrum, add pitch labels to frequency displays in
measurement rect (clunkily done) and harmonic cursor in spectrum
author | Chris Cannam |
---|---|
date | Tue, 03 Jul 2007 18:47:39 +0000 |
parents | b9380f679f70 |
children | 47fe0352861e |
comparison
equal
deleted
inserted
replaced
277:8acd30ed735c | 278:a078aa2932cc |
---|---|
16 #include "View.h" | 16 #include "View.h" |
17 #include "layer/Layer.h" | 17 #include "layer/Layer.h" |
18 #include "data/model/Model.h" | 18 #include "data/model/Model.h" |
19 #include "base/ZoomConstraint.h" | 19 #include "base/ZoomConstraint.h" |
20 #include "base/Profiler.h" | 20 #include "base/Profiler.h" |
21 #include "base/Pitch.h" | |
21 | 22 |
22 #include "layer/TimeRulerLayer.h" //!!! damn, shouldn't be including that here | 23 #include "layer/TimeRulerLayer.h" //!!! damn, shouldn't be including that here |
23 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" //!!! likewise | 24 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" //!!! likewise |
24 | 25 |
25 #include <QPainter> | 26 #include <QPainter> |
1677 paint.restore(); | 1678 paint.restore(); |
1678 } | 1679 } |
1679 | 1680 |
1680 if (!focus) return; | 1681 if (!focus) return; |
1681 | 1682 |
1683 paint.save(); | |
1684 QFont fn = paint.font(); | |
1685 if (fn.pointSize() > 8) { | |
1686 fn.setPointSize(fn.pointSize() - 1); | |
1687 paint.setFont(fn); | |
1688 } | |
1689 | |
1682 int fontHeight = paint.fontMetrics().height(); | 1690 int fontHeight = paint.fontMetrics().height(); |
1683 int fontAscent = paint.fontMetrics().ascent(); | 1691 int fontAscent = paint.fontMetrics().ascent(); |
1684 | 1692 |
1685 float v0, v1; | 1693 float v0, v1; |
1686 QString u0, u1; | 1694 QString u0, u1; |
1693 | 1701 |
1694 int labelCount = 0; | 1702 int labelCount = 0; |
1695 | 1703 |
1696 if ((b0 = topLayer->getXScaleValue(this, r.x(), v0, u0))) { | 1704 if ((b0 = topLayer->getXScaleValue(this, r.x(), v0, u0))) { |
1697 axs = QString("%1 %2").arg(v0).arg(u0); | 1705 axs = QString("%1 %2").arg(v0).arg(u0); |
1706 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) { | |
1707 axs = QString("%1 (%2)").arg(axs) | |
1708 .arg(Pitch::getPitchLabelForFrequency(v0)); | |
1709 } | |
1698 aw = paint.fontMetrics().width(axs); | 1710 aw = paint.fontMetrics().width(axs); |
1699 ++labelCount; | 1711 ++labelCount; |
1700 } | 1712 } |
1701 | 1713 |
1702 if (r.width() > 0) { | 1714 if (r.width() > 0) { |
1703 if ((b1 = topLayer->getXScaleValue(this, r.x() + r.width(), v1, u1))) { | 1715 if ((b1 = topLayer->getXScaleValue(this, r.x() + r.width(), v1, u1))) { |
1704 bxs = QString("%1 %2").arg(v1).arg(u1); | 1716 bxs = QString("%1 %2").arg(v1).arg(u1); |
1717 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) { | |
1718 bxs = QString("%1 (%2)").arg(bxs) | |
1719 .arg(Pitch::getPitchLabelForFrequency(v1)); | |
1720 } | |
1705 bw = paint.fontMetrics().width(bxs); | 1721 bw = paint.fontMetrics().width(bxs); |
1706 } | 1722 } |
1707 } | 1723 } |
1708 | 1724 |
1709 if (b0 && b1 && u0 == u1) { | 1725 if (b0 && b1 && u0 == u1) { |
1714 b0 = false; | 1730 b0 = false; |
1715 b1 = false; | 1731 b1 = false; |
1716 | 1732 |
1717 if ((b0 = topLayer->getYScaleValue(this, r.y(), v0, u0))) { | 1733 if ((b0 = topLayer->getYScaleValue(this, r.y(), v0, u0))) { |
1718 ays = QString("%1 %2").arg(v0).arg(u0); | 1734 ays = QString("%1 %2").arg(v0).arg(u0); |
1735 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) { | |
1736 ays = QString("%1 (%2)").arg(ays) | |
1737 .arg(Pitch::getPitchLabelForFrequency(v0)); | |
1738 } | |
1719 aw = std::max(aw, paint.fontMetrics().width(ays)); | 1739 aw = std::max(aw, paint.fontMetrics().width(ays)); |
1720 ++labelCount; | 1740 ++labelCount; |
1721 } | 1741 } |
1722 | 1742 |
1723 if (r.height() > 0) { | 1743 if (r.height() > 0) { |
1724 if ((b1 = topLayer->getYScaleValue(this, r.y() + r.height(), v1, u1))) { | 1744 if ((b1 = topLayer->getYScaleValue(this, r.y() + r.height(), v1, u1))) { |
1725 bys = QString("%1 %2").arg(v1).arg(u1); | 1745 bys = QString("%1 %2").arg(v1).arg(u1); |
1746 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) { | |
1747 bys = QString("%1 (%2)").arg(bys) | |
1748 .arg(Pitch::getPitchLabelForFrequency(v1)); | |
1749 } | |
1726 bw = std::max(bw, paint.fontMetrics().width(bys)); | 1750 bw = std::max(bw, paint.fontMetrics().width(bys)); |
1727 } | 1751 } |
1728 } | 1752 } |
1729 | 1753 |
1730 bool bd = false; | 1754 bool bd = false; |
1825 | 1849 |
1826 if (dys != "") { | 1850 if (dys != "") { |
1827 drawVisibleText(paint, dxx, dxy, dys, OutlinedText); | 1851 drawVisibleText(paint, dxx, dxy, dys, OutlinedText); |
1828 dxy += fontHeight; | 1852 dxy += fontHeight; |
1829 } | 1853 } |
1854 | |
1855 paint.restore(); | |
1830 } | 1856 } |
1831 | 1857 |
1832 bool | 1858 bool |
1833 View::render(QPainter &paint, int xorigin, size_t f0, size_t f1) | 1859 View::render(QPainter &paint, int xorigin, size_t f0, size_t f1) |
1834 { | 1860 { |