Mercurial > hg > svgui
changeset 1183:57d192e26331 zoom
Some hackery toward having a zoomlevel type
author | Chris Cannam |
---|---|
date | Mon, 12 Dec 2016 15:18:52 +0000 |
parents | 6605984fa98f |
children | 13d9b422f7fe |
files | layer/LayerGeometryProvider.h view/AlignmentView.cpp view/AlignmentView.h view/Overview.cpp view/View.cpp view/View.h |
diffstat | 6 files changed, 42 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/LayerGeometryProvider.h Fri Dec 09 18:01:55 2016 +0000 +++ b/layer/LayerGeometryProvider.h Mon Dec 12 15:18:52 2016 +0000 @@ -147,9 +147,10 @@ bool &log) const = 0; /** - * Return the zoom level, i.e. the number of frames per pixel + * Return the zoom level, i.e. the number of frames per pixel or + * pixels per frame */ - virtual int getZoomLevel() const = 0; + virtual ZoomLevel getZoomLevel() const = 0; /** * To be called from a layer, to obtain the extent of the surface
--- a/view/AlignmentView.cpp Fri Dec 09 18:01:55 2016 +0000 +++ b/view/AlignmentView.cpp Mon Dec 12 15:18:52 2016 +0000 @@ -57,14 +57,14 @@ } void -AlignmentView::viewAboveZoomLevelChanged(int level, bool) +AlignmentView::viewAboveZoomLevelChanged(ZoomLevel level, bool) { m_zoomLevel = level; update(); } void -AlignmentView::viewBelowZoomLevelChanged(int, bool) +AlignmentView::viewBelowZoomLevelChanged(ZoomLevel, bool) { update(); } @@ -80,9 +80,9 @@ if (m_above) { connect(m_above, - SIGNAL(zoomLevelChanged(int, bool)), + SIGNAL(zoomLevelChanged(ZoomLevel, bool)), this, - SLOT(viewAboveZoomLevelChanged(int, bool))); + SLOT(viewAboveZoomLevelChanged(ZoomLevel, bool))); } } @@ -97,9 +97,9 @@ if (m_below) { connect(m_below, - SIGNAL(zoomLevelChanged(int, bool)), + SIGNAL(zoomLevelChanged(ZoomLevel, bool)), this, - SLOT(viewBelowZoomLevelChanged(int, bool))); + SLOT(viewBelowZoomLevelChanged(ZoomLevel, bool))); } }
--- a/view/AlignmentView.h Fri Dec 09 18:01:55 2016 +0000 +++ b/view/AlignmentView.h Mon Dec 12 15:18:52 2016 +0000 @@ -32,8 +32,8 @@ public slots: virtual void globalCentreFrameChanged(sv_frame_t); virtual void viewCentreFrameChanged(View *, sv_frame_t); - virtual void viewAboveZoomLevelChanged(int, bool); - virtual void viewBelowZoomLevelChanged(int, bool); + virtual void viewAboveZoomLevelChanged(ZoomLevel, bool); + virtual void viewBelowZoomLevelChanged(ZoomLevel, bool); virtual void viewManagerPlaybackFrameChanged(sv_frame_t); protected:
--- a/view/Overview.cpp Fri Dec 09 18:01:55 2016 +0000 +++ b/view/Overview.cpp Mon Dec 12 15:18:52 2016 +0000 @@ -47,10 +47,9 @@ bool zoomChanged = false; sv_frame_t frameCount = getModelsEndFrame() - getModelsStartFrame(); - int zoomLevel = int(frameCount / width()); - if (zoomLevel < 1) zoomLevel = 1; - zoomLevel = getZoomConstraintBlockSize(zoomLevel, - ZoomConstraint::RoundUp); + ZoomLevel zoomLevel { ZoomLevel::FramesPerPixel, int(frameCount / width()) }; + if (zoomLevel.level < 1) zoomLevel.level = 1; + zoomLevel = getZoomConstraintBlockSize(zoomLevel, ZoomConstraint::RoundUp); if (zoomLevel != m_zoomLevel) { zoomChanged = true; }
--- a/view/View.cpp Fri Dec 09 18:01:55 2016 +0000 +++ b/view/View.cpp Mon Dec 12 15:18:52 2016 +0000 @@ -444,7 +444,7 @@ } } -int +ZoomLevel View::getZoomLevel() const { #ifdef DEBUG_VIEW_WIDGET_PAINT @@ -473,7 +473,7 @@ } void -View::setZoomLevel(int z) +View::setZoomLevel(ZoomLevel z) { int dpratio = effectiveDevicePixelRatio(); if (z < dpratio) return; @@ -721,13 +721,13 @@ m_manager->disconnect(this, SLOT(globalCentreFrameChanged(sv_frame_t))); m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, sv_frame_t))); m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t))); - m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, int, bool))); + m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, ZoomLevel, bool))); m_manager->disconnect(this, SLOT(toolModeChanged())); m_manager->disconnect(this, SLOT(selectionChanged())); m_manager->disconnect(this, SLOT(overlayModeChanged())); m_manager->disconnect(this, SLOT(zoomWheelsEnabledChanged())); disconnect(m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode))); - disconnect(m_manager, SLOT(zoomLevelChanged(int, bool))); + disconnect(m_manager, SLOT(zoomLevelChanged(ZoomLevel, bool))); } m_manager = manager; @@ -739,8 +739,8 @@ connect(m_manager, SIGNAL(playbackFrameChanged(sv_frame_t)), this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t))); - connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, int, bool)), - this, SLOT(viewZoomLevelChanged(View *, int, bool))); + connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, ZoomLevel, bool)), + this, SLOT(viewZoomLevelChanged(View *, ZoomLevel, bool))); connect(m_manager, SIGNAL(toolModeChanged()), this, SLOT(toolModeChanged())); @@ -760,8 +760,8 @@ m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode))); - connect(this, SIGNAL(zoomLevelChanged(int, bool)), - m_manager, SLOT(viewZoomLevelChanged(int, bool))); + connect(this, SIGNAL(zoomLevelChanged(ZoomLevel, bool)), + m_manager, SLOT(viewZoomLevelChanged(ZoomLevel, bool))); switch (m_followPlay) { @@ -1123,7 +1123,7 @@ } void -View::viewZoomLevelChanged(View *p, int z, bool locked) +View::viewZoomLevelChanged(View *p, ZoomLevel z, bool locked) { #ifdef DEBUG_VIEW_WIDGET_PAINT cerr << "View[" << this << "]: viewZoomLevelChanged(" << p << ", " << z << ", " << locked << ")" << endl; @@ -1450,14 +1450,14 @@ void View::zoom(bool in) { - int newZoomLevel = m_zoomLevel; + ZoomLevel newZoomLevel = m_zoomLevel; if (in) { - newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1, - ZoomConstraint::RoundDown); + newZoomLevel = getZoomConstraintLevel(m_zoomLevel.decremented(), + ZoomConstraint::RoundDown); } else { - newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1, - ZoomConstraint::RoundUp); + newZoomLevel = getZoomConstraintLevel(m_zoomLevel.incremented(), + ZoomConstraint::RoundUp); } if (newZoomLevel != m_zoomLevel) {
--- a/view/View.h Fri Dec 09 18:01:55 2016 +0000 +++ b/view/View.h Mon Dec 12 15:18:52 2016 +0000 @@ -148,16 +148,17 @@ bool logarithmic) const; /** - * Return the zoom level, i.e. the number of frames per pixel + * Return the zoom level, i.e. the number of frames per pixel or + * pixels per frame */ - int getZoomLevel() const; + ZoomLevel getZoomLevel() const; /** - * Set the zoom level, i.e. the number of frames per pixel. The - * centre frame will be unchanged; the start and end frames will - * change. + * Set the zoom level, i.e. the number of frames per pixel or + * pixels per frame. The centre frame will be unchanged; the + * start and end frames will change. */ - virtual void setZoomLevel(int z); + virtual void setZoomLevel(ZoomLevel z); /** * Zoom in or out. @@ -370,7 +371,7 @@ bool globalScroll, PlaybackFollowMode followMode); - void zoomLevelChanged(int level, bool locked); + void zoomLevelChanged(ZoomLevel level, bool locked); void contextHelpChanged(const QString &); @@ -388,7 +389,7 @@ virtual void globalCentreFrameChanged(sv_frame_t); virtual void viewCentreFrameChanged(View *, sv_frame_t); virtual void viewManagerPlaybackFrameChanged(sv_frame_t); - virtual void viewZoomLevelChanged(View *, int, bool); + virtual void viewZoomLevelChanged(View *, ZoomLevel, bool); virtual void propertyContainerSelected(View *, PropertyContainer *pc); @@ -426,9 +427,9 @@ bool areLayersScrollable() const; LayerList getScrollableBackLayers(bool testChanged, bool &changed) const; LayerList getNonScrollableFrontLayers(bool testChanged, bool &changed) const; - int getZoomConstraintBlockSize(int blockSize, - ZoomConstraint::RoundingDirection dir = - ZoomConstraint::RoundNearest) const; + ZoomLevel getZoomConstraintLevel(ZoomLevel level, + ZoomConstraint::RoundingDirection dir = + ZoomConstraint::RoundNearest) const; // True if the top layer(s) use colours for meaningful things. If // this is the case, selections will be shown using unfilled boxes @@ -451,7 +452,7 @@ int effectiveDevicePixelRatio() const; sv_frame_t m_centreFrame; - int m_zoomLevel; + ZoomLevel m_zoomLevel; bool m_followPan; bool m_followZoom; PlaybackFollowMode m_followPlay; @@ -463,7 +464,7 @@ QPixmap *m_cache; QPixmap *m_buffer; sv_frame_t m_cacheCentreFrame; - int m_cacheZoomLevel; + ZoomLevel m_cacheZoomLevel; bool m_selectionCached; bool m_deleting;