Fixed issue #532. Unexpected error occurs when zoom out image.
--HG-- branch : feature
This commit is contained in:
parent
08c80f6a3d
commit
e985ce26ad
|
@ -39,6 +39,9 @@
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
|
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), _view(view), _modifiers(Qt::ControlModifier), _zoom_factor_base(1.0015),
|
: QObject(view), _view(view), _modifiers(Qt::ControlModifier), _zoom_factor_base(1.0015),
|
||||||
|
@ -54,13 +57,19 @@ GraphicsViewZoom::GraphicsViewZoom(QGraphicsView* view)
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void GraphicsViewZoom::gentle_zoom(double factor)
|
void GraphicsViewZoom::gentle_zoom(double factor)
|
||||||
|
{
|
||||||
|
// We need to check current scale factor because in Windows we have an error when we zoom in or zoom out to much.
|
||||||
|
// See issue #532: Unexpected error occurs when zoom out image.
|
||||||
|
// factor > 1 for zoomIn and factor < 1 for zoomOut.
|
||||||
|
if ((_view->transform().m11() < maxScale && factor > 1) ||
|
||||||
|
(_view->transform().m11() > minScale && factor < 1))
|
||||||
{
|
{
|
||||||
_view->scale(factor, factor);
|
_view->scale(factor, factor);
|
||||||
if (factor < 1)
|
if (factor < 1)
|
||||||
{
|
{
|
||||||
// Because QGraphicsView centers the picture when it's smaller than the view. And QGraphicsView's scrolls
|
// Because QGraphicsView centers the picture when it's smaller than the view. And QGraphicsView's scrolls
|
||||||
// boundaries don't allow to put any picture point at any viewport position we will provide fictive scene size.
|
// boundaries don't allow to put any picture point at any viewport position we will provide fictive scene
|
||||||
// Temporary and bigger than view, scene size will help position an image under cursor.
|
// size. Temporary and bigger than view, scene size will help position an image under cursor.
|
||||||
FictiveSceneRect(_view->scene(), _view);
|
FictiveSceneRect(_view->scene(), _view);
|
||||||
}
|
}
|
||||||
_view->centerOn(target_scene_pos);
|
_view->centerOn(target_scene_pos);
|
||||||
|
@ -72,6 +81,7 @@ void GraphicsViewZoom::gentle_zoom(double factor)
|
||||||
VMainGraphicsView::NewSceneRect(_view->scene(), _view);
|
VMainGraphicsView::NewSceneRect(_view->scene(), _view);
|
||||||
emit zoomed();
|
emit zoomed();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
|
@ -236,19 +246,29 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent)
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VMainGraphicsView::ZoomIn()
|
void VMainGraphicsView::ZoomIn()
|
||||||
|
{
|
||||||
|
// We need to check current scale factor because in Windows we have an error when we zoom in or zoom out to much.
|
||||||
|
// See issue #532: Unexpected error occurs when zoom out image.
|
||||||
|
if (this->transform().m11() < maxScale)
|
||||||
{
|
{
|
||||||
scale(1.1, 1.1);
|
scale(1.1, 1.1);
|
||||||
VMainGraphicsView::NewSceneRect(this->scene(), this);
|
VMainGraphicsView::NewSceneRect(this->scene(), this);
|
||||||
emit NewFactor(1.1);
|
emit NewFactor(1.1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VMainGraphicsView::ZoomOut()
|
void VMainGraphicsView::ZoomOut()
|
||||||
|
{
|
||||||
|
// We need to check current scale factor because in Windows we have an error when we zoom in or zoom out to much.
|
||||||
|
// See issue #532: Unexpected error occurs when zoom out image.
|
||||||
|
if (this->transform().m11() > minScale)
|
||||||
{
|
{
|
||||||
scale(1.0/1.1, 1.0/1.1);
|
scale(1.0/1.1, 1.0/1.1);
|
||||||
VMainGraphicsView::NewSceneRect(this->scene(), this);
|
VMainGraphicsView::NewSceneRect(this->scene(), this);
|
||||||
emit NewFactor(1.0/1.1);
|
emit NewFactor(1.0/1.1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VMainGraphicsView::ZoomOriginal()
|
void VMainGraphicsView::ZoomOriginal()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user