Fixed issue #591. Control scene max and min scale factor.
--HG-- branch : develop
This commit is contained in:
parent
0685654c87
commit
2377373a89
|
@ -45,6 +45,7 @@
|
||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
|
||||||
#include "../vmisc/def.h"
|
#include "../vmisc/def.h"
|
||||||
#include "../vmisc/vmath.h"
|
#include "../vmisc/vmath.h"
|
||||||
|
@ -57,8 +58,7 @@ 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 maxSceneSize = ((50 * 100.0) / 25.4) * PrintDPI; // 50 meters in pixels
|
||||||
const qreal minScale = 0.004; // for zoom out
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
GraphicsViewZoom::GraphicsViewZoom(QGraphicsView* view)
|
GraphicsViewZoom::GraphicsViewZoom(QGraphicsView* view)
|
||||||
|
@ -91,8 +91,8 @@ 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.
|
// 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.
|
// See issue #532: Unexpected error occurs when zoom out image.
|
||||||
// factor > 1 for zoomIn and factor < 1 for zoomOut.
|
// factor > 1 for zoomIn and factor < 1 for zoomOut.
|
||||||
if ((_view->transform().m11() < maxScale && factor > 1) ||
|
if ((_view->transform().m11() < VMainGraphicsView::MaxScale() && factor > 1) ||
|
||||||
(_view->transform().m11() > minScale && factor < 1))
|
(_view->transform().m11() > VMainGraphicsView::MinScale() && factor < 1))
|
||||||
{
|
{
|
||||||
_view->scale(factor, factor);
|
_view->scale(factor, factor);
|
||||||
if (factor < 1)
|
if (factor < 1)
|
||||||
|
@ -360,7 +360,7 @@ 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.
|
// 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.
|
// See issue #532: Unexpected error occurs when zoom out image.
|
||||||
if (this->transform().m11() < maxScale)
|
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);
|
||||||
|
@ -373,7 +373,7 @@ 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.
|
// 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.
|
// See issue #532: Unexpected error occurs when zoom out image.
|
||||||
if (this->transform().m11() > minScale)
|
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);
|
||||||
|
@ -406,8 +406,19 @@ void VMainGraphicsView::ZoomFitBest()
|
||||||
}
|
}
|
||||||
|
|
||||||
this->fitInView(rect, Qt::KeepAspectRatio);
|
this->fitInView(rect, Qt::KeepAspectRatio);
|
||||||
|
QTransform transform = this->transform();
|
||||||
|
|
||||||
|
qreal factor = transform.m11();
|
||||||
|
factor = qMax(factor, MinScale());
|
||||||
|
factor = qMin(factor, MaxScale());
|
||||||
|
|
||||||
|
transform.setMatrix(factor, transform.m12(), transform.m13(), transform.m21(), factor, transform.m23(),
|
||||||
|
transform.m31(), transform.m32(), transform.m33());
|
||||||
|
this->setTransform(transform);
|
||||||
|
|
||||||
VMainGraphicsView::NewSceneRect(scene(), this);
|
VMainGraphicsView::NewSceneRect(scene(), this);
|
||||||
emit NewFactor(this->transform().m11());
|
|
||||||
|
emit NewFactor(factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -482,6 +493,24 @@ void VMainGraphicsView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qreal VMainGraphicsView::MinScale()
|
||||||
|
{
|
||||||
|
const QRect screenRect = QApplication::desktop()->availableGeometry();
|
||||||
|
const qreal screenSize = qMax(screenRect.width(), screenRect.height());
|
||||||
|
|
||||||
|
return screenSize / maxSceneSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
qreal VMainGraphicsView::MaxScale()
|
||||||
|
{
|
||||||
|
const QRect screenRect = QApplication::desktop()->availableGeometry();
|
||||||
|
const qreal screenSize = qMax(screenRect.width(), screenRect.height());
|
||||||
|
|
||||||
|
return maxSceneSize / screenSize;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VMainGraphicsView::setShowToolOptions(bool value)
|
void VMainGraphicsView::setShowToolOptions(bool value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -129,6 +129,9 @@ public:
|
||||||
static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view);
|
static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view);
|
||||||
static QRectF SceneVisibleArea(QGraphicsView *view);
|
static QRectF SceneVisibleArea(QGraphicsView *view);
|
||||||
|
|
||||||
|
static qreal MinScale();
|
||||||
|
static qreal MaxScale();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* @brief NewFactor send new scale factor.
|
* @brief NewFactor send new scale factor.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user