Fixed issue #532. Unexpected error occurs when zoom out image.
(grafted from c9e825b2ba62707e063700cea95ded566f158d6a) --HG-- branch : develop
This commit is contained in:
parent
3f75727b6a
commit
3ee6faf124
|
@ -57,6 +57,9 @@ class QWheelEvent;
|
||||||
const int GraphicsViewZoom::duration = 300;
|
const int GraphicsViewZoom::duration = 300;
|
||||||
const int GraphicsViewZoom::updateInterval = 40;
|
const int GraphicsViewZoom::updateInterval = 40;
|
||||||
|
|
||||||
|
const qreal maxScale = 50.0; // for zoom in
|
||||||
|
const qreal minScale = 0.004; // for zoom out
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
GraphicsViewZoom::GraphicsViewZoom(QGraphicsView* view)
|
GraphicsViewZoom::GraphicsViewZoom(QGraphicsView* view)
|
||||||
: QObject(view),
|
: QObject(view),
|
||||||
|
@ -85,22 +88,29 @@ GraphicsViewZoom::GraphicsViewZoom(QGraphicsView* view)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void GraphicsViewZoom::gentle_zoom(double factor)
|
void GraphicsViewZoom::gentle_zoom(double factor)
|
||||||
{
|
{
|
||||||
_view->scale(factor, factor);
|
// We need to check current scale factor because in Windows we have an error when we zoom in or zoom out to much.
|
||||||
if (factor < 1)
|
// See issue #532: Unexpected error occurs when zoom out image.
|
||||||
{
|
// factor > 1 for zoomIn and factor < 1 for zoomOut.
|
||||||
// Because QGraphicsView centers the picture when it's smaller than the view. And QGraphicsView's scrolls
|
if ((_view->transform().m11() < maxScale && factor > 1) ||
|
||||||
// boundaries don't allow to put any picture point at any viewport position we will provide fictive scene size.
|
(_view->transform().m11() > minScale && factor < 1))
|
||||||
// Temporary and bigger than view, scene size will help position an image under cursor.
|
{
|
||||||
FictiveSceneRect(_view->scene(), _view);
|
_view->scale(factor, factor);
|
||||||
}
|
if (factor < 1)
|
||||||
_view->centerOn(target_scene_pos);
|
{
|
||||||
QPointF delta_viewport_pos = target_viewport_pos - QPointF(_view->viewport()->width() / 2.0,
|
// Because QGraphicsView centers the picture when it's smaller than the view. And QGraphicsView's scrolls
|
||||||
_view->viewport()->height() / 2.0);
|
// boundaries don't allow to put any picture point at any viewport position we will provide fictive scene
|
||||||
QPointF viewport_center = _view->mapFromScene(target_scene_pos) - delta_viewport_pos;
|
// size. Temporary and bigger than view, scene size will help position an image under cursor.
|
||||||
_view->centerOn(_view->mapToScene(viewport_center.toPoint()));
|
FictiveSceneRect(_view->scene(), _view);
|
||||||
// In the end we just set correct scene size
|
}
|
||||||
VMainGraphicsView::NewSceneRect(_view->scene(), _view);
|
_view->centerOn(target_scene_pos);
|
||||||
emit zoomed();
|
QPointF delta_viewport_pos = target_viewport_pos - QPointF(_view->viewport()->width() / 2.0,
|
||||||
|
_view->viewport()->height() / 2.0);
|
||||||
|
QPointF viewport_center = _view->mapFromScene(target_scene_pos) - delta_viewport_pos;
|
||||||
|
_view->centerOn(_view->mapToScene(viewport_center.toPoint()));
|
||||||
|
// In the end we just set correct scene size
|
||||||
|
VMainGraphicsView::NewSceneRect(_view->scene(), _view);
|
||||||
|
emit zoomed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -348,17 +358,27 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VMainGraphicsView::ZoomIn()
|
void VMainGraphicsView::ZoomIn()
|
||||||
{
|
{
|
||||||
scale(1.1, 1.1);
|
// We need to check current scale factor because in Windows we have an error when we zoom in or zoom out to much.
|
||||||
VMainGraphicsView::NewSceneRect(this->scene(), this);
|
// See issue #532: Unexpected error occurs when zoom out image.
|
||||||
emit NewFactor(1.1);
|
if (this->transform().m11() < maxScale)
|
||||||
|
{
|
||||||
|
scale(1.1, 1.1);
|
||||||
|
VMainGraphicsView::NewSceneRect(this->scene(), this);
|
||||||
|
emit NewFactor(1.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VMainGraphicsView::ZoomOut()
|
void VMainGraphicsView::ZoomOut()
|
||||||
{
|
{
|
||||||
scale(1.0/1.1, 1.0/1.1);
|
// We need to check current scale factor because in Windows we have an error when we zoom in or zoom out to much.
|
||||||
VMainGraphicsView::NewSceneRect(this->scene(), this);
|
// See issue #532: Unexpected error occurs when zoom out image.
|
||||||
emit NewFactor(1.0/1.1);
|
if (this->transform().m11() > minScale)
|
||||||
|
{
|
||||||
|
scale(1.0/1.1, 1.0/1.1);
|
||||||
|
VMainGraphicsView::NewSceneRect(this->scene(), this);
|
||||||
|
emit NewFactor(1.0/1.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user