r23003 by jghali - Do a better job at preserving clicked point when zooming out

scribus-commit scribus-commit at lists.scribus.net
Fri Jun 7 01:09:22 UTC 2019


Author: jghali
Date: Fri Jun  7 01:09:21 2019
New Revision: 23003

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23003
Log:
Do a better job at preserving clicked point when zooming out

Modified:
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h
    trunk/Scribus/scribus/scribusview.cpp

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23003&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Fri Jun  7 01:09:21 2019
@@ -5822,9 +5822,9 @@
 	int docItemsCount=Items->count();
 	if (docItemsCount != 0)
 	{
-		for (int ic = 0; ic < docItemsCount; ++ic)
-		{
-			currItem = Items->at(ic);
+		for (int i = 0; i < docItemsCount; ++i)
+		{
+			currItem = Items->at(i);
 			if (currItem->rotation() != 0.0)
 			{
 				FPointArray pb;
@@ -5855,23 +5855,58 @@
 	}
 	else
 	{
-		ScPage* Seite;
-		int docPageCount=Pages->count();
+		ScPage* page;
 		MarginStruct pageBleeds;
-		for (int a = 0; a < docPageCount; ++a)
-		{
-			Seite = Pages->at(a);
-			getBleeds(Seite, pageBleeds);
-			minx = qMin(minx, Seite->xOffset() - pageBleeds.left());
-			miny = qMin(miny, Seite->yOffset() - pageBleeds.top());
-			maxx = qMax(maxx, Seite->xOffset() + Seite->width() + pageBleeds.left() + pageBleeds.right());
-			maxy = qMax(maxy, Seite->yOffset() + Seite->height() + pageBleeds.top() + pageBleeds.bottom());
+		int docPageCount = Pages->count();
+		for (int i = 0; i < docPageCount; ++i)
+		{
+			page = Pages->at(i);
+			getBleeds(page, pageBleeds);
+			minx = qMin(minx, page->xOffset() - pageBleeds.left());
+			miny = qMin(miny, page->yOffset() - pageBleeds.top());
+			maxx = qMax(maxx, page->xOffset() + page->width() + pageBleeds.left() + pageBleeds.right());
+			maxy = qMax(maxy, page->yOffset() + page->height() + pageBleeds.top() + pageBleeds.bottom());
 		}
 	}
 	minPoint.setX(minx);
 	minPoint.setY(miny);
 	maxPoint.setX(maxx);
 	maxPoint.setY(maxy);
+}
+
+QRectF ScribusDoc::canvasOptimalRect()
+{
+	double x, y, width, height;
+	QRectF canvasRect;
+	QRectF pageRect;
+	MarginStruct pageBleeds;
+	PageItem *currItem;
+	ScPage* page;
+
+	int pageCount = Pages->count();
+	for (int i = 0; i < pageCount; ++i)
+	{
+		page = Pages->at(i);
+		getBleeds(page, pageBleeds);
+		x = page->xOffset() - pageBleeds.left();
+		y = page->yOffset() - pageBleeds.top();
+		width  = page->width() + pageBleeds.left() + pageBleeds.right();
+		height = page->height() + pageBleeds.top() + pageBleeds.bottom();
+		canvasRect = canvasRect.united(QRectF(x, y, width, height));
+	}
+
+	int itemsCount = Items->count();
+	for (int i = 0; i < itemsCount; ++i)
+	{
+		currItem = Items->at(i);
+		QRectF itemRect = currItem->getBoundingRect();
+		canvasRect = canvasRect.united(itemRect);
+	}
+
+	const MarginStruct& scratch = m_docPrefsData.displayPrefs.scratch;
+	canvasRect.adjust(-scratch.left(), -scratch.top(), scratch.right(), scratch.bottom());
+
+	return canvasRect;
 }
 
 
@@ -6252,11 +6287,12 @@
 		return;
 	if (!isLoading())
 	{
+		FPoint minPoint, maxPoint;
+		const MarginStruct& scratch = m_docPrefsData.displayPrefs.scratch;
 		updateMarks(true);
-		FPoint minPoint, maxPoint;
 		canvasMinMax(minPoint, maxPoint);
-		FPoint maxSize(qMax(maxXPos, maxPoint.x()+m_docPrefsData.displayPrefs.scratch.right()), qMax(maxYPos, maxPoint.y()+m_docPrefsData.displayPrefs.scratch.bottom()));
-		adjustCanvas(FPoint(qMin(0.0, minPoint.x()-m_docPrefsData.displayPrefs.scratch.left()),qMin(0.0, minPoint.y()-m_docPrefsData.displayPrefs.scratch.top())), maxSize, true);
+		FPoint maxSize(qMax(maxXPos, maxPoint.x() + scratch.right()), qMax(maxYPos, maxPoint.y() + scratch.bottom()));
+		adjustCanvas(FPoint(qMin(0.0, minPoint.x() - scratch.left()), qMin(0.0, minPoint.y() - scratch.top())), maxSize, true);
 		changed();
 	}
 	else

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23003&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h	(original)
+++ trunk/Scribus/scribus/scribusdoc.h	Fri Jun  7 01:09:21 2019
@@ -858,11 +858,16 @@
 	 * @param dia optional progress widget
 	 */
 	void RecalcPictures(QList<PageItem*>* items, ProfilesL *Pr, ProfilesL *PrCMYK, QProgressBar *dia = nullptr);
-	/**
-	 *
+
+	/**
 	 * @brief Find the minX,MinY and maxX,maxY for the canvas required for the doc
 	 */
 	void canvasMinMax(FPoint&, FPoint&);
+
+	/**
+	 * @brief Find the optimal area for canvas
+	 */
+	QRectF canvasOptimalRect();
 	
 	int  OnPage(double x2, double  y2);
 	int  OnPage(PageItem *currItem);

Modified: trunk/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23003&path=/trunk/Scribus/scribus/scribusview.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusview.cpp	(original)
+++ trunk/Scribus/scribus/scribusview.cpp	Fri Jun  7 01:09:21 2019
@@ -3617,20 +3617,73 @@
 void ScribusView::zoom(int canvasX, int canvasY, double scale, bool preservePoint)
 {
 	QPoint globalPoint = m_canvas->canvasToGlobal(QPointF(canvasX, canvasY));
+	double oldScale = m_canvas->scale();
 	double newScale = (scale > (Prefs->opToolPrefs.magMax / 100) * Prefs->displayPrefs.displayScale) ? ((Prefs->opToolPrefs.magMax / 100) * Prefs->displayPrefs.displayScale) : scale;
 	undoManager->setUndoEnabled(false);
 	updatesOn(false);
 	setScale(newScale);
+
+	FPoint minPos = Doc->minCanvasCoordinate;
+	FPoint maxPos = Doc->maxCanvasCoordinate;
+	if (newScale > oldScale)
+	{
+		// Try to set scrollBars values in a reasonable way after important zoom out 
+		QRectF optimalRect = Doc->canvasOptimalRect();
+		double minX = qMax(minPos.x(), optimalRect.left());
+		double minY = qMax(minPos.y(), optimalRect.top());
+		double maxX = qMin(maxPos.x(), optimalRect.right());
+		double maxY = qMin(maxPos.y(), optimalRect.bottom());
+		minPos.setXY(minX, minY);
+		maxPos.setXY(maxX, maxY);
+	}
+
+	// FIXME : find a way to avoid adjustCanvas/resizeContents, cause unnecessary paintEvents despite updates disabled
+	if (minPos != Doc->minCanvasCoordinate || maxPos != Doc->maxCanvasCoordinate)
+		Doc->adjustCanvas(minPos, maxPos, true);
+	else
+	{
+		int nw = qMax(qRound((Doc->maxCanvasCoordinate.x() - Doc->minCanvasCoordinate.x()) * m_canvas->scale()), visibleWidth());
+		int nh = qMax(qRound((Doc->maxCanvasCoordinate.y() - Doc->minCanvasCoordinate.y()) * m_canvas->scale()), visibleHeight());
+		resizeContents(nw, nh);
+	}
+
 	QPoint localPoint = m_canvas->canvasToLocal( QPointF(canvasX, canvasY) );
-	int nw = qMax(qRound((Doc->maxCanvasCoordinate.x() - Doc->minCanvasCoordinate.x()) * m_canvas->scale()), visibleWidth());
-	int nh = qMax(qRound((Doc->maxCanvasCoordinate.y() - Doc->minCanvasCoordinate.y()) * m_canvas->scale()), visibleHeight());
-	resizeContents(nw, nh); // FIXME : should be avoided here, cause an unnecessary paintEvent despite updates disabled
+
 	QPoint canvasPoint;
 	if (preservePoint)
 		canvasPoint = viewport()->mapFromGlobal(globalPoint);
 	else
 		canvasPoint = QPoint(viewport()->width() / 2, viewport()->height() / 2);
-	setContentsPos(localPoint.x() - canvasPoint.x(), localPoint.y() - canvasPoint.y());
+
+	int contentPosX = localPoint.x() - canvasPoint.x();
+	int contentPosY = localPoint.y() - canvasPoint.y();
+
+	QSize maxViewport = maximumViewportSize();
+	minPos = m_canvas->localToCanvas(QPoint(horizontalScrollBar()->minimum(), verticalScrollBar()->minimum()));
+	maxPos = m_canvas->localToCanvas(QPoint(horizontalScrollBar()->maximum() + maxViewport.width(), verticalScrollBar()->maximum() + maxViewport.height()));
+
+	int hMin = qMin(contentPosX, horizontalScrollBar()->minimum());
+	int hMax = qMax(contentPosX, horizontalScrollBar()->maximum());
+	int vMin = qMin(contentPosY, verticalScrollBar()->minimum());
+	int vMax = qMax(contentPosY, verticalScrollBar()->maximum());
+	if ((hMin < horizontalScrollBar()->minimum()) || (hMax > horizontalScrollBar()->maximum()) ||
+		(vMin < verticalScrollBar()->minimum())   || (vMax > verticalScrollBar()->maximum()))
+	{
+		QSize maxViewport = maximumViewportSize();
+		minPos = m_canvas->localToCanvas(QPoint(hMin, vMin));
+		maxPos = m_canvas->localToCanvas(QPoint(hMax + maxViewport.width(), vMax + maxViewport.height()));
+	}
+
+	Doc->adjustCanvas(minPos, maxPos);
+	localPoint = m_canvas->canvasToLocal(QPointF(canvasX, canvasY));
+	if (preservePoint)
+		canvasPoint = viewport()->mapFromGlobal(globalPoint);
+	else
+		canvasPoint = QPoint(viewport()->width() / 2, viewport()->height() / 2);
+	contentPosX = localPoint.x() - canvasPoint.x();
+	contentPosY = localPoint.y() - canvasPoint.y();
+	setContentsPos(contentPosX, contentPosY);
+	
 	updatesOn(true);
 	undoManager->setUndoEnabled(true);
 }




More information about the scribus-commit mailing list