r23917 by jghali - Fix canvas positionning issue when going from page edit mode to masterpage edit mode then inline/symbol items edit mode and back

scribus-commit scribus-commit at lists.scribus.net
Tue Jul 14 21:50:28 UTC 2020


Author: jghali
Date: Tue Jul 14 21:50:28 2020
New Revision: 23917

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23917
Log:
Fix canvas positionning issue when going from page edit mode to masterpage edit mode then inline/symbol items edit mode and back

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

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23917&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Tue Jul 14 21:50:28 2020
@@ -7728,12 +7728,7 @@
 		doc->setAutoSave(false);
 	}
 	view->deselectItems(true);
-	m_storedPageNum = doc->currentPageNumber();
-	m_storedViewXCoor = view->contentsX();
-	m_storedViewYCoor = view->contentsY();
-	m_storedViewScale = view->scale();
-	doc->stored_minCanvasCoordinate = doc->minCanvasCoordinate;
-	doc->stored_maxCanvasCoordinate = doc->maxCanvasCoordinate;
+	view->saveViewState();
 	view->showSymbolPage(temp);
 	appModeHelper->setSymbolEditMode(true, doc);
 	pagePalette->enablePalette(false);
@@ -7761,9 +7756,6 @@
 
 void ScribusMainWindow::editSymbolEnd()
 {
-	doc->minCanvasCoordinate = doc->stored_minCanvasCoordinate;
-	doc->maxCanvasCoordinate = doc->stored_maxCanvasCoordinate;
-	view->setScale(m_storedViewScale);
 	view->hideSymbolPage();
 	if (m_WasAutoSave)
 	{
@@ -7776,16 +7768,10 @@
 	if ( ScCore->haveGS() || ScCore->isWinGUI() )
 		scrActions["PrintPreview"]->setEnabled(true);
 	if ( ScCore->haveGS() )
-		scrActions["OutputPrevewPDF"]->setEnabled(true);
+		scrActions["OutputPreviewPDF"]->setEnabled(true);
 	pagePalette->enablePalette(true);
 	pagePalette->rebuildMasters();
-	view->setScale(m_storedViewScale);
-	// #12857 : the number of pages may change when undoing/redoing
-	// page addition/deletion while in edit mode, so take some extra
-	// care so that storedPageNum is in appropriate range
-	m_storedPageNum = qMin(m_storedPageNum, doc->DocPages.count() - 1);
-	doc->setCurrentPage(doc->DocPages.at(m_storedPageNum));
-	view->setContentsPos(static_cast<int>(m_storedViewXCoor * m_storedViewScale), static_cast<int>(m_storedViewYCoor * m_storedViewScale));
+	view->restoreViewState();
 	view->DrawNew();
 	pagePalette->rebuild();
 	propertiesPalette->updateColorList();
@@ -7808,12 +7794,7 @@
 		doc->setAutoSave(false);
 	}
 	view->deselectItems(true);
-	m_storedPageNum = doc->currentPageNumber();
-	m_storedViewXCoor = view->contentsX();
-	m_storedViewYCoor = view->contentsY();
-	m_storedViewScale = view->scale();
-	doc->stored_minCanvasCoordinate = doc->minCanvasCoordinate;
-	doc->stored_maxCanvasCoordinate = doc->maxCanvasCoordinate;
+	view->saveViewState();
 	view->showInlinePage(id);
 	appModeHelper->setInlineEditMode(true, doc);
 	pagePalette->enablePalette(false);
@@ -7826,9 +7807,6 @@
 
 void ScribusMainWindow::editInlineEnd()
 {
-	doc->minCanvasCoordinate = doc->stored_minCanvasCoordinate;
-	doc->maxCanvasCoordinate = doc->stored_maxCanvasCoordinate;
-	view->setScale(m_storedViewScale);
 	view->hideInlinePage();
 	if (m_WasAutoSave)
 	{
@@ -7839,13 +7817,7 @@
 	appModeHelper->setInlineEditMode(false, doc);
 	pagePalette->enablePalette(true);
 	pagePalette->rebuildMasters();
-	view->setScale(m_storedViewScale);
-	// #12857 : the number of pages may change when undoing/redoing
-	// page addition/deletion while in edit mode, so take some extra
-	// care so that storedPageNum is in appropriate range
-	m_storedPageNum = qMin(m_storedPageNum, doc->DocPages.count() - 1);
-	doc->setCurrentPage(doc->DocPages.at(m_storedPageNum));
-	view->setContentsPos(static_cast<int>(m_storedViewXCoor * m_storedViewScale), static_cast<int>(m_storedViewYCoor * m_storedViewScale));
+	view->restoreViewState();
 	doc->invalidateAll();
 	view->DrawNew();
 	pagePalette->rebuild();
@@ -7889,12 +7861,7 @@
 		return;
 	}
 
-	m_storedPageNum = doc->currentPageNumber();
-	m_storedViewXCoor = view->horizontalScrollBar()->value();
-	m_storedViewYCoor = view->verticalScrollBar()->value();
-	m_storedViewScale = view->scale();
-	doc->stored_minCanvasCoordinate = doc->minCanvasCoordinate;
-	doc->stored_maxCanvasCoordinate = doc->maxCanvasCoordinate;
+	view->saveViewState();
 
 	pagePalette->startMasterPageMode(mpName);
 	if (!pagePalette->isVisible())
@@ -7907,9 +7874,6 @@
 
 void ScribusMainWindow::editMasterPagesEnd()
 {
-	doc->minCanvasCoordinate = doc->stored_minCanvasCoordinate;
-	doc->maxCanvasCoordinate = doc->stored_maxCanvasCoordinate;
-	view->setScale(m_storedViewScale);
 	view->hideMasterPage();
 	if (m_WasAutoSave)
 	{
@@ -7928,17 +7892,12 @@
 		pagePalette->setVisible(m_pagePalVisible);
 		scrActions["toolsPages"]->setChecked(m_pagePalVisible);
 	}
-	// #12857 : the number of pages may change when undoing/redoing
-	// page addition/deletion while in edit mode, so take some extra
-	// care so that storedPageNum is in appropriate range
-	m_storedPageNum = qMin(m_storedPageNum, doc->DocPages.count() - 1);
-	doc->setCurrentPage(doc->DocPages.at(m_storedPageNum));
-	doc->minCanvasCoordinate = doc->stored_minCanvasCoordinate;
-	doc->maxCanvasCoordinate = doc->stored_maxCanvasCoordinate;
-
+
+	ScribusView::ViewState viewState = view->topViewState();
 	doc->setLoading(true);
+	view->restoreViewState();
 	view->reformPages(false);
-	view->setContentsPos(m_storedViewXCoor, m_storedViewYCoor);
+	view->setContentsPos(viewState.contentX, viewState.contentY);
 	doc->setLoading(false);
 	view->DrawNew();
 }

Modified: trunk/Scribus/scribus/scribus.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23917&path=/trunk/Scribus/scribus/scribus.h
==============================================================================
--- trunk/Scribus/scribus/scribus.h	(original)
+++ trunk/Scribus/scribus/scribus.h	Tue Jul 14 21:50:28 2020
@@ -655,10 +655,7 @@
 					QString Command;
 				} PDef ;
 	TOCGenerator *m_tocGenerator {nullptr};
-	int m_storedPageNum;
-	int m_storedViewXCoor;
-	int m_storedViewYCoor;
-	double m_storedViewScale;
+
 	StyleManager *m_styleManager {nullptr};
 	UndoManager *m_undoManager {nullptr};
 	PrefsManager& m_prefsManager;

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23917&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h	(original)
+++ trunk/Scribus/scribus/scribusdoc.h	Tue Jul 14 21:50:28 2020
@@ -1307,8 +1307,6 @@
 	/** \brief Minimum and Maximum Points of Document */
 	FPoint minCanvasCoordinate;
 	FPoint maxCanvasCoordinate;
-	FPoint stored_minCanvasCoordinate;
-	FPoint stored_maxCanvasCoordinate;
 	double rulerXoffset {0.0};
 	double rulerYoffset {0.0};
 	/** \brief List of Pages */

Modified: trunk/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23917&path=/trunk/Scribus/scribus/scribusview.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusview.cpp	(original)
+++ trunk/Scribus/scribus/scribusview.cpp	Tue Jul 14 21:50:28 2020
@@ -3697,6 +3697,35 @@
 	undoManager->setUndoEnabled(true);
 }
 
+void ScribusView::saveViewState()
+{
+	ViewState viewState;
+	viewState.currentPage = m_doc->currentPageNumber();
+	viewState.contentX = horizontalScrollBar()->value();
+	viewState.contentY = verticalScrollBar()->value();
+	viewState.canvasScale = m_canvas->scale();
+	viewState.minCanvasCoordinate = m_doc->minCanvasCoordinate;
+	viewState.maxCanvasCoordinate = m_doc->maxCanvasCoordinate;
+	m_viewStates.push(viewState);
+}
+
+void ScribusView::restoreViewState()
+{
+	if (m_viewStates.isEmpty())
+		return;
+
+	ViewState viewState = m_viewStates.pop();
+	m_doc->minCanvasCoordinate = viewState.minCanvasCoordinate;
+	m_doc->maxCanvasCoordinate = viewState.maxCanvasCoordinate;
+	setScale(viewState.canvasScale);
+
+	// #12857 : the number of pages may change when undoing/redoing
+	// page addition/deletion while in edit mode, so take some extra
+	// care so that storedPageNum is in appropriate range
+	int currentPage = qMin(viewState.currentPage, m_doc->DocPages.count() - 1);
+	m_doc->setCurrentPage(m_doc->DocPages.at(currentPage));
+	setContentsPos(viewState.contentX, viewState.contentY);
+}
 
 void ScribusView::stopAllDrags() // deprecated
 {

Modified: trunk/Scribus/scribus/scribusview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23917&path=/trunk/Scribus/scribus/scribusview.h
==============================================================================
--- trunk/Scribus/scribus/scribusview.h	(original)
+++ trunk/Scribus/scribus/scribusview.h	Tue Jul 14 21:50:28 2020
@@ -42,6 +42,7 @@
 #include <QRect>
 #include <QRectF>
 #include <QSize>
+#include <QStack>
 #include <QTimer>
 #include <QScrollArea>
 #include <QScrollBar>
@@ -52,6 +53,7 @@
 class QMimeData;
 
 // application specific includes
+#include "fpoint.h"
 #include "observable.h"
 #include "scribusapi.h"
 #include "scribusdoc.h"
@@ -105,6 +107,16 @@
 	friend class CanvasMode_Normal;
 	friend class CanvasMode_ObjImport;
 	friend class CanvasMode_Rotate;
+
+	struct ViewState
+	{
+		int currentPage { 0 };
+		int contentX { 0 };
+		int contentY { 0 };
+		double canvasScale { 1.0 };
+		FPoint minCanvasCoordinate;
+		FPoint maxCanvasCoordinate;
+	};
 	
 	void requestMode(int appMode);
 //	void setCursorBasedOnAppMode(int appMode);
@@ -228,6 +240,10 @@
 	void zoom(double scale = 0.0);
 	void zoom(int canvasX, int canvasY, double scale, bool preservePoint);
 
+	void saveViewState();
+	void restoreViewState();
+	const ViewState& topViewState() const { return m_viewStates.top(); }
+
 public slots: // Public slots
 	void iconSetChange();
 	void languageChange();
@@ -282,6 +298,7 @@
 	bool _isGlobalMode {true};
 	bool linkAfterDraw {false};
 	bool ImageAfterDraw {false};
+	QStack<ViewState> m_viewStates;
 
 private slots:
 	void setZoom();




More information about the scribus-commit mailing list