Fixed: #1301 Added max and min zooming.
This commit is contained in:
parent
b37b0b8d60
commit
974c5a0c52
2 changed files with 13 additions and 28 deletions
|
@ -33,17 +33,15 @@ namespace LandscapeEditor
|
||||||
LandscapeView::LandscapeView(QWidget *parent)
|
LandscapeView::LandscapeView(QWidget *parent)
|
||||||
: QGraphicsView(parent),
|
: QGraphicsView(parent),
|
||||||
m_visibleGrid(true),
|
m_visibleGrid(true),
|
||||||
m_visibleText(false)
|
m_visibleText(true)
|
||||||
{
|
{
|
||||||
//setDragMode(ScrollHandDrag);
|
|
||||||
setTransformationAnchor(AnchorUnderMouse);
|
setTransformationAnchor(AnchorUnderMouse);
|
||||||
setBackgroundBrush(QBrush(Qt::lightGray));
|
setBackgroundBrush(QBrush(Qt::lightGray));
|
||||||
//setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
|
||||||
//setRenderHints(QPainter::Antialiasing);
|
|
||||||
//setCacheMode(QGraphicsView::CacheBackground);
|
|
||||||
m_cellSize = 160;
|
m_cellSize = 160;
|
||||||
m_numSteps = 0;
|
m_maxView = 0.06;
|
||||||
m_maxSteps = 20;
|
m_minView = 32.0;
|
||||||
|
m_maxViewText = 0.6;
|
||||||
|
|
||||||
//A modified version of centerOn(), handles special cases
|
//A modified version of centerOn(), handles special cases
|
||||||
setCenter(QPointF(500.0, 500.0));
|
setCenter(QPointF(500.0, 500.0));
|
||||||
|
@ -72,25 +70,7 @@ void LandscapeView::setVisibleText(bool visible)
|
||||||
|
|
||||||
void LandscapeView::wheelEvent(QWheelEvent *event)
|
void LandscapeView::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
/* double numDegrees = event->delta() / 8.0;
|
//nlinfo(QString("%1").arg(transform().m11()).toStdString().c_str());
|
||||||
double numSteps = numDegrees / 15.0;
|
|
||||||
double factor = std::pow(1.125, numSteps);
|
|
||||||
if (factor > 1.0)
|
|
||||||
{
|
|
||||||
// check max scale view
|
|
||||||
if (m_numSteps > m_maxSteps)
|
|
||||||
return;
|
|
||||||
++m_numSteps;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// check min scale view
|
|
||||||
if (m_numSteps < -m_maxSteps)
|
|
||||||
return;
|
|
||||||
--m_numSteps;
|
|
||||||
}
|
|
||||||
scale(factor, factor);
|
|
||||||
QGraphicsView::wheelEvent(event);*/
|
|
||||||
|
|
||||||
//Get the position of the mouse before scaling, in scene coords
|
//Get the position of the mouse before scaling, in scene coords
|
||||||
QPointF pointBeforeScale(mapToScene(event->pos()));
|
QPointF pointBeforeScale(mapToScene(event->pos()));
|
||||||
|
@ -102,11 +82,16 @@ void LandscapeView::wheelEvent(QWheelEvent *event)
|
||||||
double scaleFactor = 1.15; //How fast we zoom
|
double scaleFactor = 1.15; //How fast we zoom
|
||||||
if(event->delta() > 0)
|
if(event->delta() > 0)
|
||||||
{
|
{
|
||||||
|
if (transform().m11() > m_minView )
|
||||||
|
return;
|
||||||
//Zoom in
|
//Zoom in
|
||||||
scale(scaleFactor, scaleFactor);
|
scale(scaleFactor, scaleFactor);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (transform().m11() < m_maxView )
|
||||||
|
return;
|
||||||
|
|
||||||
//Zooming out
|
//Zooming out
|
||||||
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
|
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
|
||||||
}
|
}
|
||||||
|
@ -242,7 +227,7 @@ void LandscapeView::drawForeground(QPainter *painter, const QRectF &rect)
|
||||||
if (!m_visibleText)
|
if (!m_visibleText)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_numSteps > -m_maxSteps / 4)
|
if (transform().m11() > m_maxViewText)
|
||||||
{
|
{
|
||||||
painter->setPen(QPen(Qt::white, 0.5, Qt::SolidLine));
|
painter->setPen(QPen(Qt::white, 0.5, Qt::SolidLine));
|
||||||
//painter->setFont(QFont("Helvetica [Cronyx]", 12));
|
//painter->setFont(QFont("Helvetica [Cronyx]", 12));
|
||||||
|
|
|
@ -59,7 +59,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool m_visibleGrid, m_visibleText;
|
bool m_visibleGrid, m_visibleText;
|
||||||
int m_numSteps, m_maxSteps;
|
qreal m_maxView, m_minView, m_maxViewText;
|
||||||
int m_cellSize;
|
int m_cellSize;
|
||||||
|
|
||||||
//Holds the current centerpoint for the view, used for panning and zooming
|
//Holds the current centerpoint for the view, used for panning and zooming
|
||||||
|
|
Loading…
Reference in a new issue