Mercurial > hg > svgui
changeset 264:7e9e533f1863
* few more measurement mode bits
author | Chris Cannam |
---|---|
date | Fri, 15 Jun 2007 12:55:16 +0000 |
parents | 16fffa24da02 |
children | a3a54632cd4c |
files | layer/SpectrogramLayer.cpp layer/SpectrumLayer.cpp view/Pane.cpp |
diffstat | 3 files changed, 127 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Thu Jun 14 20:57:01 2007 +0000 +++ b/layer/SpectrogramLayer.cpp Fri Jun 15 12:55:16 2007 +0000 @@ -2500,7 +2500,7 @@ } bool -SpectrogramLayer::getCrosshairExtents(View *v, QPainter &, +SpectrogramLayer::getCrosshairExtents(View *v, QPainter &paint, QPoint cursorPos, std::vector<QRect> &extents) const { @@ -2510,6 +2510,13 @@ QRect horizontal(0, cursorPos.y(), cursorPos.x(), 1); extents.push_back(horizontal); + int sw = getVerticalScaleWidth(v, paint); + + QRect label(sw, cursorPos.y() - paint.fontMetrics().ascent() - 2, + paint.fontMetrics().width("123456 Hz") + sw + 2, + paint.fontMetrics().height()); + extents.push_back(label); + return true; } @@ -2525,6 +2532,9 @@ float fundamental = getFrequencyForY(v, cursorPos.y()); + int sw = getVerticalScaleWidth(v, paint); + paint.drawText(sw + 2, cursorPos.y() - 2, QString("%1 Hz").arg(fundamental)); + int harmonic = 2; while (harmonic < 100) {
--- a/layer/SpectrumLayer.cpp Thu Jun 14 20:57:01 2007 +0000 +++ b/layer/SpectrumLayer.cpp Fri Jun 15 12:55:16 2007 +0000 @@ -255,20 +255,6 @@ return false; } -bool -SpectrumLayer::getCrosshairExtents(View *v, QPainter &, - QPoint cursorPos, - std::vector<QRect> &extents) const -{ - QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->height() - cursorPos.y()); - extents.push_back(vertical); - - QRect horizontal(0, cursorPos.y(), v->width(), 12); - extents.push_back(horizontal); - - return true; -} - float SpectrumLayer::getFrequencyForX(float x, float w) const { @@ -327,11 +313,30 @@ SpectrumLayer::getXScaleValue(View *v, int x, float &value, QString &unit) const { - value = getFrequencyForX(x, v->width() - m_xorigins[v]); + value = getFrequencyForX(x - m_xorigins[v], v->width() - m_xorigins[v] - 1); unit = "Hz"; return true; } +bool +SpectrumLayer::getCrosshairExtents(View *v, QPainter &paint, + QPoint cursorPos, + std::vector<QRect> &extents) const +{ + QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->height() - cursorPos.y()); + extents.push_back(vertical); + + QRect horizontal(0, cursorPos.y(), v->width(), 12); + extents.push_back(horizontal); + + QRect label(cursorPos.x(), v->height() - paint.fontMetrics().height(), + paint.fontMetrics().width("123456 Hz") + 2, + paint.fontMetrics().height()); + extents.push_back(label); + + return true; +} + void SpectrumLayer::paintCrosshairs(View *v, QPainter &paint, QPoint cursorPos) const @@ -349,6 +354,9 @@ float fundamental = getFrequencyForX(cursorPos.x() - xorigin, w); + paint.drawText(cursorPos.x() + 2, v->height() - 2, + QString("%1 Hz").arg(fundamental)); + int harmonic = 2; while (harmonic < 100) {
--- a/view/Pane.cpp Thu Jun 14 20:57:01 2007 +0000 +++ b/view/Pane.cpp Fri Jun 15 12:55:16 2007 +0000 @@ -4,7 +4,7 @@ Sonic Visualiser An audio file viewer and annotation editor. Centre for Digital Music, Queen Mary, University of London. - This file copyright 2006 Chris Cannam and QMUL. + This file copyright 2006-2007 Chris Cannam and QMUL. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -760,19 +760,28 @@ bool b0 = false, b1 = false; QString axs, ays, bxs, bys, dxs, dys; + + int axx, axy, bxx, bxy, dxx, dxy; + int aw = 0, bw = 0, dw = 0; + int labelCount = 0; + if ((b0 = topLayer->getXScaleValue(this, m_measureStart.x(), v0, u0))) { axs = QString("%1 %2").arg(v0).arg(u0); + aw = paint.fontMetrics().width(axs); + ++labelCount; } if (m_measureStart != m_measureEnd) { if ((b1 = topLayer->getXScaleValue(this, m_measureEnd.x(), v1, u1))) { bxs = QString("%1 %2").arg(v1).arg(u1); + bw = paint.fontMetrics().width(bxs); } } if (b0 && b1 && u0 == u1) { - dxs = QString("(%1 %2)").arg(v1 - v0).arg(u1); + dxs = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); + dw = paint.fontMetrics().width(dxs); } b0 = false; @@ -780,46 +789,109 @@ if ((b0 = topLayer->getYScaleValue(this, m_measureStart.y(), v0, u0))) { ays = QString("%1 %2").arg(v0).arg(u0); + aw = std::max(aw, paint.fontMetrics().width(ays)); + ++labelCount; } if (m_measureStart != m_measureEnd) { if ((b1 = topLayer->getYScaleValue(this, m_measureEnd.y(), v1, u1))) { bys = QString("%1 %2").arg(v1).arg(u1); + bw = std::max(bw, paint.fontMetrics().width(bys)); } } if (b0 && b1 && u0 == u1) { - dys = QString("(%1 %2)").arg(v1 - v0).arg(u1); + dys = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); + dw = std::max(dw, paint.fontMetrics().width(dys)); + } + + int mw = abs(m_measureEnd.x() - m_measureStart.x()); + int mh = abs(m_measureEnd.y() - m_measureStart.y()); + + bool edgeLabelsInside = false; + bool sizeLabelsInside = false; + + if (mw < std::max(aw, std::max(bw, dw)) + 4) { + // defaults stand + } else if (mw < aw + bw + 4) { + if (mh > fontHeight * labelCount * 3 + 4) { + edgeLabelsInside = true; + sizeLabelsInside = true; + } else if (mh > fontHeight * labelCount * 2 + 4) { + edgeLabelsInside = true; + } + } else if (mw < aw + bw + dw + 4) { + if (mh > fontHeight * labelCount * 3 + 4) { + edgeLabelsInside = true; + sizeLabelsInside = true; + } else if (mh > fontHeight * labelCount + 4) { + edgeLabelsInside = true; + } + } else { + if (mh > fontHeight * labelCount + 4) { + edgeLabelsInside = true; + sizeLabelsInside = true; + } + } + + if (edgeLabelsInside) { + + axx = m_measureStart.x() + 2; + axy = m_measureStart.y() + fontAscent + 2; + + bxx = m_measureEnd.x() - bw - 2; + bxy = m_measureEnd.y() - (labelCount-1) * fontHeight - 2; + + } else { + + axx = m_measureStart.x() - aw - 2; + axy = m_measureStart.y() + fontAscent; + + bxx = m_measureEnd.x() + 2; + bxy = m_measureEnd.y() - (labelCount-1) * fontHeight; + } + + dxx = (m_measureEnd.x() - m_measureStart.x()) + / 2 + m_measureStart.x() - dw/2; + + if (sizeLabelsInside) { + + dxy = (m_measureEnd.y() - m_measureStart.y()) + / 2 + m_measureStart.y() - (labelCount * fontHeight)/2 + fontAscent; + + } else { + + dxy = std::max(m_measureEnd.y(), m_measureStart.y()) + fontAscent + 2; } - int x = m_measureStart.x() + 2; - int y = m_measureStart.y() + fontAscent + 2; - if (axs != "") { - drawVisibleText(paint, x, y, axs, OutlinedText); - y += fontHeight; + drawVisibleText(paint, axx, axy, axs, OutlinedText); + axy += fontHeight; } if (ays != "") { - drawVisibleText(paint, x, y, ays, OutlinedText); - y += fontHeight; + drawVisibleText(paint, axx, axy, ays, OutlinedText); + axy += fontHeight; } - x = m_measureEnd.x() - paint.fontMetrics().width(bxs) - 2; - y = m_measureEnd.y() - 2; - - if (bys != "" && bxs != "") y -= fontHeight; - if (bxs != "") { - drawVisibleText(paint, x, y, bxs, OutlinedText); - y += fontHeight; + drawVisibleText(paint, bxx, bxy, bxs, OutlinedText); + bxy += fontHeight; } - x = m_measureEnd.x() - paint.fontMetrics().width(bys) - 2; + if (bys != "") { + drawVisibleText(paint, bxx, bxy, bys, OutlinedText); + bxy += fontHeight; + } - if (bys != "") { - drawVisibleText(paint, x, y, bys, OutlinedText); - y += fontHeight; + if (dxs != "") { + drawVisibleText(paint, dxx, dxy, dxs, OutlinedText); + dxy += fontHeight; + } + + if (dys != "") { + drawVisibleText(paint, dxx, dxy, dys, OutlinedText); + dxy += fontHeight; } if (m_measureStart != m_measureEnd) {