Mercurial > hg > svgui
diff layer/SliceLayer.cpp @ 1389:1eb560b363e7 spectrogramparam
Make "zoom to region" work sensibly for slice/spectrum layers; ensure that min/max bin are remapped properly when changing fft size
author | Chris Cannam |
---|---|
date | Tue, 13 Nov 2018 14:06:48 +0000 |
parents | bca9870301b7 |
children | 4a36f6130056 |
line wrap: on
line diff
--- a/layer/SliceLayer.cpp Tue Nov 13 13:39:01 2018 +0000 +++ b/layer/SliceLayer.cpp Tue Nov 13 14:06:48 2018 +0000 @@ -74,8 +74,10 @@ connectSignals(m_sliceableModel); - m_minbin = 0; - m_maxbin = m_sliceableModel->getHeight(); + if (m_minbin == 0 && m_maxbin == 0) { + m_minbin = 0; + m_maxbin = m_sliceableModel->getHeight(); + } emit modelReplaced(); emit layerParametersChanged(); @@ -403,18 +405,23 @@ } int mh = m_sliceableModel->getHeight(); + int bin0 = 0; + if (m_maxbin > m_minbin) { + mh = m_maxbin - m_minbin; + bin0 = m_minbin; + } if (m_plotStyle == PlotBlocks) { // Must use actual zero-width pen, too slow otherwise paint.setPen(QPen(getBaseQColor(), 0)); } else { - // Similarly, if there are very many bins here, let's drop to - // a precise 1-pixel-width pen - if (mh > 10000) { - paint.setPen(QPen(getBaseQColor(), 1)); - } else { - paint.setPen(PaintAssistant::scalePen(getBaseQColor())); + // Similarly, if there are very many bins here, we use a + // thinner pen + QPen pen(getBaseQColor(), 1); + if (mh < 10000) { + pen = PaintAssistant::scalePen(pen); } + paint.setPen(pen); } int xorigin = getVerticalScaleWidth(v, true, paint) + 1; @@ -430,13 +437,6 @@ if (h <= 0) return; QPainterPath path; - - int bin0 = 0; - - if (m_maxbin > m_minbin) { - mh = m_maxbin - m_minbin; - bin0 = m_minbin; - } int divisor = 0; @@ -1210,3 +1210,18 @@ return new LinearRangeMapper(0, m_sliceableModel->getHeight(), 0, m_sliceableModel->getHeight(), ""); } + +void +SliceLayer::zoomToRegion(const LayerGeometryProvider *v, QRect rect) +{ + double bin0 = getBinForX(v, rect.x()); + double bin1 = getBinForX(v, rect.x() + rect.width()); + + // ignore y for now... + + SVDEBUG << "SliceLayer::zoomToRegion: zooming to bin range " + << bin0 << " -> " << bin1 << endl; + + setDisplayExtents(floor(bin0), ceil(bin1)); +} +