# HG changeset patch # User Chris Cannam # Date 1156177595 0 # Node ID a859b87162cad7ea40c3ca5d4796dc2593e9f3ea # Parent e981307646354b7cecdf780858e00e739d074ff6 * beginnings of drag up/down in layers as appropriate diff -r e98130764635 -r a859b87162ca layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Mon Aug 21 13:18:50 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Mon Aug 21 16:26:35 2006 +0000 @@ -2787,10 +2787,12 @@ int n = 0; defaultStep = 0; + bool haveDefault = false; float s2 = sqrtf(sqrtf(2)); while (dist > min) { - if (max >= m_initialMaxFrequency) { + if (!haveDefault && max <= m_initialMaxFrequency) { defaultStep = n; + haveDefault = true; } ++n; dist /= s2; diff -r e98130764635 -r a859b87162ca view/Pane.cpp --- a/view/Pane.cpp Mon Aug 21 13:18:50 2006 +0000 +++ b/view/Pane.cpp Mon Aug 21 16:26:35 2006 +0000 @@ -652,6 +652,20 @@ m_navigating = true; m_dragCentreFrame = m_centreFrame; + //!!! pull out into function to go with mouse move code + + m_dragStartMinValue = 0; + + Layer *layer = 0; + if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); + + if (layer) { + float min = 0.f, max = 0.f; + if (layer->getDisplayExtents(min, max)) { + m_dragStartMinValue = min; + } + } + } else if (mode == ViewManager::SelectMode) { bool closeToLeft = false, closeToRight = false; @@ -926,6 +940,52 @@ if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) { setCentreFrame(newCentreFrame); } + + //!!! For drag up/down, we need to: call getValueExtents + //and getDisplayExtents and see whether both return true + //(we can only drag up/down if they do); and check whether + //the ranges returned differ (likewise). Then, we know + //the height of the layer, so... + + //!!! this should have its own function + + Layer *layer = 0; + if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); + + if (layer) { + + float vmin = 0.f, vmax = 0.f; + bool vlog = false; + QString vunit; + + float dmin = 0.f, dmax = 0.f; + + if (layer->getValueExtents(vmin, vmax, vlog, vunit) && + layer->getDisplayExtents(dmin, dmax) && + (dmin > vmin || dmax < vmax)) { + + int ydiff = e->y() - m_clickPos.y(); + std::cerr << "ydiff = " << ydiff << std::endl; + + float perpix = (dmax - dmin) / height(); + float valdiff = ydiff * perpix; + std::cerr << "valdiff = " << valdiff << std::endl; + + float newmin = m_dragStartMinValue + valdiff; + float newmax = m_dragStartMinValue + (dmax - dmin) + valdiff; + if (newmin < vmin) { + newmax += vmin - newmin; + newmin += vmin - newmin; + } + if (newmax > vmax) { + newmin -= newmax - vmax; + newmax -= newmax - vmax; + } + std::cerr << "(" << dmin << ", " << dmax << ") -> (" + << newmin << ", " << newmax << ") (drag start " << m_dragStartMinValue << ")" << std::endl; + layer->setDisplayExtents(newmin, newmax); + } + } } } else if (mode == ViewManager::SelectMode) { diff -r e98130764635 -r a859b87162ca view/Pane.h --- a/view/Pane.h Mon Aug 21 13:18:50 2006 +0000 +++ b/view/Pane.h Mon Aug 21 16:26:35 2006 +0000 @@ -93,6 +93,7 @@ bool m_navigating; bool m_resizing; size_t m_dragCentreFrame; + float m_dragStartMinValue; bool m_centreLineVisible; size_t m_selectionStartFrame; Selection m_editingSelection;