Mercurial > hg > svgui
changeset 1354:40b9a495a0e0
Use zoom constraints more consistently, including the new RelativelyFine one
author | Chris Cannam |
---|---|
date | Wed, 10 Oct 2018 14:33:10 +0100 |
parents | 86429ff00f05 |
children | b9bfcb8cd5a1 |
files | view/Pane.cpp view/Pane.h view/View.cpp view/View.h |
diffstat | 4 files changed, 107 insertions(+), 148 deletions(-) [+] |
line wrap: on
line diff
--- a/view/Pane.cpp Wed Oct 10 08:44:27 2018 +0100 +++ b/view/Pane.cpp Wed Oct 10 14:33:10 2018 +0100 @@ -110,23 +110,6 @@ if (!isVisible()) return; -/* - int count = 0; - int currentLevel = 1; - int level = 1; - while (true) { - if (getZoomLevel() == level) currentLevel = count; - int newLevel = getZoomConstraintBlockSize(level + 1, - ZoomConstraint::RoundUp); - if (newLevel == level) break; - if (newLevel == 131072) break; //!!! just because - level = newLevel; - ++count; - } - - cerr << "Have " << count+1 << " zoom levels" << endl; -*/ - Layer *layer = 0; if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); @@ -199,70 +182,20 @@ connect(m_reset, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); } - int count = 0; - int current = 0; - ZoomLevel level; - - //!!! pull out into function (presumably in View) - bool haveConstraint = false; - for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); - ++i) { - if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) { - haveConstraint = true; - break; - } - } - - SVCERR << "haveConstraint = " << haveConstraint << endl; - - if (haveConstraint) { - while (true) { - //!!! this won't terminate if level is in the PixelsPerFrame zone - if (getZoomLevel() == level) current = count; - ZoomLevel newLevel = getZoomConstraintLevel(level.incremented(), - ZoomConstraint::RoundUp); - SVCERR << "newLevel = " << newLevel << endl; - if (newLevel == level) break; - level = newLevel; - if (++count == 50) break; - } - } else { - // if we have no particular constraints, we can really spread out - //!!! this is nonsense in PixelsPerFrame zone - while (true) { - using namespace std::rel_ops; - if (getZoomLevel() >= level) current = count; - int step = level.level / 10; - int pwr = 0; - while (step > 0) { - ++pwr; - step /= 2; - } - step = 1; - while (pwr > 0) { - step *= 2; - --pwr; - } - cerr << level.level << ", step " << step << endl; - level.level += step; - if (++count == 100 || level.level > 262144) break; - } - } - - //!!! - SVCERR << "Have " << count << " zoom levels" << endl; - - m_hthumb->setMinimumValue(0); + int count = countZoomLevels(); + int current = getZoomLevelIndex(getZoomLevel()); + + m_hthumb->setMinimumValue(1); m_hthumb->setMaximumValue(count); m_hthumb->setValue(count - current); -// cerr << "set value to " << count-current << endl; - -// cerr << "default value is " << m_hthumb->getDefaultValue() << endl; - - if (count != 50 && m_hthumb->getDefaultValue() == 0) { + cerr << "set value to " << count - 1 - current << endl; + + cerr << "default value is " << m_hthumb->getDefaultValue() << endl; + + if (m_hthumb->getDefaultValue() == 0) { m_hthumb->setDefaultValue(count - current); -// cerr << "set default value to " << m_hthumb->getDefaultValue() << endl; + cerr << "set default value to " << m_hthumb->getDefaultValue() << endl; } bool haveVThumb = false; @@ -2441,53 +2374,12 @@ void Pane::horizontalThumbwheelMoved(int value) { - //!!! dupe with updateHeadsUpDisplay - - int count = 0; - ZoomLevel level; - - //!!! pull out into function (presumably in View) - bool haveConstraint = false; - for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); - ++i) { - if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) { - haveConstraint = true; - break; - } - } - - if (haveConstraint) { - while (true) { - //!!! this won't terminate if level is in the PixelsPerFrame zone - if (m_hthumb->getMaximumValue() - value == count) break; - ZoomLevel newLevel = getZoomConstraintLevel(level.incremented(), - ZoomConstraint::RoundUp); - if (newLevel == level) break; - level = newLevel; - if (++count == 50) break; - } - } else { - //!!! this is nonsense in PixelsPerFrame zone - while (true) { - if (m_hthumb->getMaximumValue() - value == count) break; - int step = level.level / 10; - int pwr = 0; - while (step > 0) { - ++pwr; - step /= 2; - } - step = 1; - while (pwr > 0) { - step *= 2; - --pwr; - } -// cerr << level << endl; - level.level += step; - if (++count == 100 || level.level > 262144) break; - } - } + cerr << "horizontalThumbwheelMoved(" << value << ")" << endl; + + ZoomLevel level = getZoomLevelByIndex + (m_hthumb->getMaximumValue() - value); -// cerr << "new level is " << level << endl; + cerr << "new level is " << level << endl; setZoomLevel(level); }
--- a/view/Pane.h Wed Oct 10 08:44:27 2018 +0100 +++ b/view/Pane.h Wed Oct 10 14:33:10 2018 +0100 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _PANE_H_ -#define _PANE_H_ +#ifndef SV_PANE_H +#define SV_PANE_H #include <QFrame> #include <QPoint> @@ -212,7 +212,7 @@ bool m_playbackFrameMoveScheduled; sv_frame_t m_playbackFrameMoveTo; - + static QCursor *m_measureCursor1; static QCursor *m_measureCursor2; };
--- a/view/View.cpp Wed Oct 10 08:44:27 2018 +0100 +++ b/view/View.cpp Wed Oct 10 14:33:10 2018 +0100 @@ -26,7 +26,7 @@ #include "layer/SingleColourLayer.h" #include "layer/PaintAssistant.h" -#include "data/model/PowerOfSqrtTwoZoomConstraint.h" +#include "data/model/RelativelyFineZoomConstraint.h" #include "data/model/RangeSummarisableTimeValueModel.h" #include "widgets/IconLoader.h" @@ -1469,32 +1469,98 @@ { using namespace std::rel_ops; - ZoomLevel candidate = zoomLevel; - bool haveCandidate = false; - - PowerOfSqrtTwoZoomConstraint defaultZoomConstraint; - - for (auto i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { - - const ZoomConstraint *zoomConstraint = (*i)->getZoomConstraint(); - if (!zoomConstraint) zoomConstraint = &defaultZoomConstraint; - + ZoomLevel candidate = + RelativelyFineZoomConstraint().getNearestZoomLevel(zoomLevel, dir); + + for (auto i : m_layerStack) { + + if (i->supportsOtherZoomLevels() || !(i->getZoomConstraint())) { + continue; + } + ZoomLevel thisLevel = - zoomConstraint->getNearestZoomLevel(zoomLevel, dir); + i->getZoomConstraint()->getNearestZoomLevel(zoomLevel, dir); // Go for the block size that's furthest from the one // passed in. Most of the time, that's what we want. - if (!haveCandidate || - (thisLevel > zoomLevel && thisLevel > candidate) || + if ((thisLevel > zoomLevel && thisLevel > candidate) || (thisLevel < zoomLevel && thisLevel < candidate)) { candidate = thisLevel; - haveCandidate = true; } } return candidate; } +int +View::countZoomLevels() const +{ + int n = 0; + ZoomLevel min = ZoomConstraint().getMinZoomLevel(); + ZoomLevel max = ZoomConstraint().getMaxZoomLevel(); + ZoomLevel level = min; + while (true) { + ++n; + if (level == max) { + break; + } + level = getZoomConstraintLevel + (level.incremented(), ZoomConstraint::RoundUp); + } + cerr << "View::countZoomLevels: " << n << endl; + return n; +} + +ZoomLevel +View::getZoomLevelByIndex(int ix) const +{ + int n = 0; + ZoomLevel min = ZoomConstraint().getMinZoomLevel(); + ZoomLevel max = ZoomConstraint().getMaxZoomLevel(); + ZoomLevel level = min; + while (true) { + if (n == ix) { + cerr << "View::getZoomLevelByIndex: " << ix << " -> " << level + << endl; + return level; + } + ++n; + if (level == max) { + break; + } + level = getZoomConstraintLevel + (level.incremented(), ZoomConstraint::RoundUp); + } + cerr << "View::getZoomLevelByIndex: " << ix << " -> " << max << " (max)" + << endl; + return max; +} + +int +View::getZoomLevelIndex(ZoomLevel z) const +{ + int n = 0; + ZoomLevel min = ZoomConstraint().getMinZoomLevel(); + ZoomLevel max = ZoomConstraint().getMaxZoomLevel(); + ZoomLevel level = min; + while (true) { + if (z == level) { + cerr << "View::getZoomLevelIndex: " << z << " -> " << n + << endl; + return n; + } + ++n; + if (level == max) { + break; + } + level = getZoomConstraintLevel + (level.incremented(), ZoomConstraint::RoundUp); + } + cerr << "View::getZoomLevelIndex: " << z << " -> " << n << " (max)" + << endl; + return n; +} + bool View::areLayerColoursSignificant() const { @@ -1734,13 +1800,8 @@ } // ensure our constraints are met - -/*!!! Should we do this only if we have layers that can't support other - zoom levels? - - m_zoomLevel = getZoomConstraintBlockSize(m_zoomLevel, - ZoomConstraint::RoundUp); -*/ + m_zoomLevel = getZoomConstraintLevel + (m_zoomLevel, ZoomConstraint::RoundNearest); QPainter paint; bool repaintCache = false;
--- a/view/View.h Wed Oct 10 08:44:27 2018 +0100 +++ b/view/View.h Wed Oct 10 14:33:10 2018 +0100 @@ -457,10 +457,16 @@ bool areLayersScrollable() const; LayerList getScrollableBackLayers(bool testChanged, bool &changed) const; LayerList getNonScrollableFrontLayers(bool testChanged, bool &changed) const; + ZoomLevel getZoomConstraintLevel(ZoomLevel level, ZoomConstraint::RoundingDirection dir = ZoomConstraint::RoundNearest) const; + // These three are slow, intended for indexing GUI thumbwheel stuff + int countZoomLevels() const; + int getZoomLevelIndex(ZoomLevel level) const; + ZoomLevel getZoomLevelByIndex(int ix) const; + // True if the top layer(s) use colours for meaningful things. If // this is the case, selections will be shown using unfilled boxes // rather than with a translucent fill.