r23568 by craig - Record screen and position in a better way to properly place the main window on opening in multi screen situation

scribus-commit scribus-commit at lists.scribus.net
Wed Apr 8 20:46:18 UTC 2020


Author: craig
Date: Wed Apr  8 20:46:18 2020
New Revision: 23568

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23568
Log:
Record screen and position in a better way to properly place the main window on opening in multi screen situation

Modified:
    trunk/Scribus/scribus/prefsmanager.cpp
    trunk/Scribus/scribus/prefsmanager.h
    trunk/Scribus/scribus/prefsstructs.h
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribus.h

Modified: trunk/Scribus/scribus/prefsmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23568&path=/trunk/Scribus/scribus/prefsmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/prefsmanager.cpp	(original)
+++ trunk/Scribus/scribus/prefsmanager.cpp	Wed Apr  8 20:46:18 2020
@@ -20,16 +20,17 @@
 
 #include <QColor>
 #include <QDebug>
-#include <QDesktopWidget>
 #include <QDir>
 #include <QDomDocument>
 #include <QFile>
 #include <QList>
 #include <QMessageBox>
+#include <QScreen>
 #include <QString>
 #include <QStringList>
 #include <QStyleFactory>
 #include <QTransform>
+#include <QWindow>
 
 #include "prefsmanager.h"
 
@@ -78,6 +79,11 @@
 	delete prefsFile;
 }
 
+bool PrefsManager::firstTimeIgnoreOldPrefs() const
+{
+	return m_firstTimeIgnoreOldPrefs;
+}
+
 PrefsManager& PrefsManager::instance()
 {
 	static PrefsManager m_instance;
@@ -164,9 +170,9 @@
 //	appPrefs.uiPrefs.mainWinSettings.yPosition = 0;
 	appPrefs.uiPrefs.mainWinSettings.width = 640;
 	appPrefs.uiPrefs.mainWinSettings.height = 480;
-	QDesktopWidget *d = QApplication::desktop();
-	appPrefs.uiPrefs.mainWinSettings.xPosition=(d->availableGeometry().width()-appPrefs.uiPrefs.mainWinSettings.width)/2;
-	appPrefs.uiPrefs.mainWinSettings.yPosition=(d->availableGeometry().height()-appPrefs.uiPrefs.mainWinSettings.height)/2;
+	QScreen* s=QGuiApplication::primaryScreen();
+	appPrefs.uiPrefs.mainWinSettings.xPosition=(s->availableGeometry().width()-appPrefs.uiPrefs.mainWinSettings.width)/2;
+	appPrefs.uiPrefs.mainWinSettings.yPosition=(s->availableGeometry().height()-appPrefs.uiPrefs.mainWinSettings.height)/2;
 	appPrefs.uiPrefs.mainWinSettings.maximized = false;
 	appPrefs.uiPrefs.mainWinState = QByteArray();
 	appPrefs.uiPrefs.RecentDocs.clear();
@@ -332,7 +338,7 @@
 	appPrefs.docSetupPrefs.AutoSaveLocation = true;
 	appPrefs.docSetupPrefs.AutoSaveDir = "";
 	appPrefs.miscPrefs.saveEmergencyFile = true;
-	int dpi = qApp->desktop()->logicalDpiX();
+	int dpi = s->logicalDotsPerInchX();
 	if ((dpi < 60) || (dpi > 200))
 		dpi = 72;
 	appPrefs.displayPrefs.displayScale = dpi / 72.0;
@@ -460,8 +466,8 @@
 	appPrefs.pdfPrefs.ImageProf = "";
 	appPrefs.pdfPrefs.PrintProf = "";
 	appPrefs.pdfPrefs.Info = "";
+	appPrefs.pdfPrefs.Intent2 = 0;
 	appPrefs.pdfPrefs.Intent = 0;
-	appPrefs.pdfPrefs.Intent2 = 0;
 	appPrefs.pdfPrefs.bleeds.set(0, 0, 0, 0);
 	appPrefs.pdfPrefs.useDocBleeds = true;
 	appPrefs.pdfPrefs.cropMarks = false;
@@ -904,37 +910,6 @@
 			return;
 		}
 	}
-}
-
-void PrefsManager::setupMainWindow(ScribusMainWindow* mw)
-{
-	mw->setDefaultPrinter(appPrefs.printerPrefs.PrinterName, appPrefs.printerPrefs.PrinterFile, appPrefs.printerPrefs.PrinterCommand);
-
-	uint max = qMin(appPrefs.uiPrefs.recentDocCount, appPrefs.uiPrefs.RecentDocs.count());
-	for (uint m = 0; m < max; ++m)
-	{
-		QFileInfo fd(appPrefs.uiPrefs.RecentDocs[m]);
-		if (fd.exists())
-		{
-			mw->m_recentDocsList.append(appPrefs.uiPrefs.RecentDocs[m]);
-			//#9845: ScCore->fileWatcher->addFile(appPrefs.uiPrefs.RecentDocs[m]);
-		}
-	}
-	mw->rebuildRecentFileMenu();
-	mw->move(appPrefs.uiPrefs.mainWinSettings.xPosition, appPrefs.uiPrefs.mainWinSettings.yPosition);
-	mw->resize(appPrefs.uiPrefs.mainWinSettings.width, appPrefs.uiPrefs.mainWinSettings.height);
-	if (appPrefs.uiPrefs.mainWinSettings.maximized)
-		mw->setWindowState((ScCore->primaryMainWindow()->windowState() & ~Qt::WindowMinimized) | Qt::WindowMaximized);
-	//For 1.3.5, we dump prefs first time around.
-	if (!m_firstTimeIgnoreOldPrefs)
-		ReadPrefsXML();
-	if (appPrefs.verifierPrefs.checkerPrefsList.count() == 0)
-	{
-		initDefaultCheckerPrefs(appPrefs.verifierPrefs.checkerPrefsList);
-		appPrefs.verifierPrefs.curCheckProfile = CommonStrings::PDF_1_4;
-	}
-	if (!appPrefs.uiPrefs.mainWinState.isEmpty())
-		mw->restoreState(appPrefs.uiPrefs.mainWinState);
 }
 
 void PrefsManager::ReadPrefsXML()
@@ -1002,11 +977,25 @@
 	// The caller is responsible for ensuring we aren't called under those
 	// conditions.
 	Q_ASSERT(!emergencyActivated);
-	appPrefs.uiPrefs.mainWinSettings.xPosition = abs(ScCore->primaryMainWindow()->pos().x());
-	appPrefs.uiPrefs.mainWinSettings.yPosition = abs(ScCore->primaryMainWindow()->pos().y());
+	int currentScreen=0;
+	int currentScreenXPos=0;
+	int currentScreenYPos=0;
+	ScCore->primaryMainWindow()->getScreenData(currentScreen, currentScreenXPos, currentScreenYPos);
+	appPrefs.uiPrefs.mainWinSettings.xPosition = ScCore->primaryMainWindow()->pos().x() - currentScreenXPos;
+	appPrefs.uiPrefs.mainWinSettings.yPosition = ScCore->primaryMainWindow()->pos().y();
 	appPrefs.uiPrefs.mainWinSettings.width = ScCore->primaryMainWindow()->size().width();
 	appPrefs.uiPrefs.mainWinSettings.height = ScCore->primaryMainWindow()->size().height();
 	appPrefs.uiPrefs.mainWinSettings.maximized = ScCore->primaryMainWindow()->isMaximized();
+	QList<QScreen*> screens = QGuiApplication::screens();
+#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
+	QWindow* w = ScCore->primaryMainWindow()->windowHandle();
+	if (w != nullptr)
+		currentScreen=screens.indexOf(w->screen());
+#else
+	QScreen* s = ScCore->primaryMainWindow()->screen();
+	currentScreen=screens.indexOf(s);
+#endif
+	appPrefs.uiPrefs.mainWinSettings.screenNumber = currentScreen;
 	appPrefs.uiPrefs.mainWinState = ScCore->primaryMainWindow()->saveState();
 	appPrefs.uiPrefs.RecentDocs.clear();
 	uint max = qMin(appPrefs.uiPrefs.recentDocCount, ScCore->primaryMainWindow()->m_recentDocsList.count());
@@ -1628,6 +1617,7 @@
 	dcMainWindow.setAttribute("Width",appPrefs.uiPrefs.mainWinSettings.width);
 	dcMainWindow.setAttribute("Height",appPrefs.uiPrefs.mainWinSettings.height);
 	dcMainWindow.setAttribute("Maximized",static_cast<int>(appPrefs.uiPrefs.mainWinSettings.maximized));
+	dcMainWindow.setAttribute("ScreenNumber",appPrefs.uiPrefs.mainWinSettings.screenNumber);
 	elem.appendChild(dcMainWindow);
 
 	QDomElement dcScrapbook=docu.createElement("ScrapBook");
@@ -2258,7 +2248,7 @@
 			appPrefs.uiPrefs.mainWinSettings.width = dc.attribute("Width", "640").toInt();
 			appPrefs.uiPrefs.mainWinSettings.height = dc.attribute("Height", "480").toInt();
 			appPrefs.uiPrefs.mainWinSettings.maximized = static_cast<bool>(dc.attribute("Maximized", "0").toInt());
-			QDesktopWidget *d = QApplication::desktop();
+			appPrefs.uiPrefs.mainWinSettings.screenNumber = dc.attribute("ScreenNumber", "0").toInt();
 			QSize gStrut = QApplication::globalStrut();
 			int minX = 0;
 			int minY = 0;
@@ -2266,14 +2256,18 @@
 			// on Mac you're dead if the titlebar is not on screen
 			minY = 22;
 #endif
-			if (appPrefs.uiPrefs.mainWinSettings.xPosition < minX )
-				appPrefs.uiPrefs.mainWinSettings.xPosition = minX;
-			if (appPrefs.uiPrefs.mainWinSettings.yPosition <  minY)
-				appPrefs.uiPrefs.mainWinSettings.yPosition = minY;
+			if (QGuiApplication::screens().count()==1)
+			{
+				if (appPrefs.uiPrefs.mainWinSettings.xPosition < minX )
+					appPrefs.uiPrefs.mainWinSettings.xPosition = minX;
+				if (appPrefs.uiPrefs.mainWinSettings.yPosition <  minY)
+					appPrefs.uiPrefs.mainWinSettings.yPosition = minY;
+			}
 			int minWidth = 5*gStrut.width();
 			int minHeight = 5*gStrut.width();
-			int maxWidth = d->width();
-			int maxHeight = d->height();
+			QScreen* s=QGuiApplication::screens().at(qMin(appPrefs.uiPrefs.mainWinSettings.screenNumber, QGuiApplication::screens().count()-1));
+			int maxWidth = s->availableSize().width();
+			int maxHeight = s->availableSize().height();
 			if (appPrefs.uiPrefs.mainWinSettings.width > maxWidth)
 				appPrefs.uiPrefs.mainWinSettings.width = maxWidth;
 			if (appPrefs.uiPrefs.mainWinSettings.width < minWidth)
@@ -2282,8 +2276,8 @@
 				appPrefs.uiPrefs.mainWinSettings.height = maxHeight;
 			if (appPrefs.uiPrefs.mainWinSettings.height < minHeight)
 				appPrefs.uiPrefs.mainWinSettings.height = minHeight;
-			int maxX = d->width() - minWidth;
-			int maxY = d->height() - minHeight;
+			int maxX = s->availableSize().width() - minWidth;
+			int maxY = s->availableSize().height() - minHeight;
 			if (appPrefs.uiPrefs.mainWinSettings.xPosition >= maxX)
 				appPrefs.uiPrefs.mainWinSettings.xPosition = maxX;
 			if (appPrefs.uiPrefs.mainWinSettings.yPosition >= maxY)

Modified: trunk/Scribus/scribus/prefsmanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23568&path=/trunk/Scribus/scribus/prefsmanager.h
==============================================================================
--- trunk/Scribus/scribus/prefsmanager.h	(original)
+++ trunk/Scribus/scribus/prefsmanager.h	Wed Apr  8 20:46:18 2020
@@ -120,8 +120,6 @@
 	\param ho a file name to write
 	\retval bool true on success, false on write error */
 	bool ReadPref(const QString& ho);
-	//! \brief Set up the main window with prefs values, recent files list, main window size etc
-	void setupMainWindow(ScribusMainWindow* mw);
 	void setGhostscriptExecutable(const QString&);
 	void setImageEditorExecutable(const QString&);
 	void setExtBrowserExecutable(const QString&);
@@ -203,18 +201,20 @@
 
 	//! \brief Temporarily public while this class takes shape so progress can happen and cvs can build
 	struct ApplicationPrefs appPrefs;
-	PrefsFile* prefsFile;
+	PrefsFile* prefsFile {nullptr};
+	bool firstTimeIgnoreOldPrefs() const;
 
 public slots:
 	void languageChange();
 
-private:
+
+	private:
 	PrefsManager(QObject *parent = nullptr);
 	~PrefsManager();
 
 	QString m_prefsLocation;
-	bool m_importingFrom12;
-	bool m_firstTimeIgnoreOldPrefs;
+	bool m_importingFrom12 {false};
+	bool m_firstTimeIgnoreOldPrefs {false};
 
 	/*! \brief The last error message generated by a method of this class.
 	Do not write "success" messages to this. */

Modified: trunk/Scribus/scribus/prefsstructs.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23568&path=/trunk/Scribus/scribus/prefsstructs.h
==============================================================================
--- trunk/Scribus/scribus/prefsstructs.h	(original)
+++ trunk/Scribus/scribus/prefsstructs.h	Wed Apr  8 20:46:18 2020
@@ -92,23 +92,14 @@
 
 struct WindowPrefs
 {
-	WindowPrefs() {
-		xPosition = 0;
-		yPosition = 0;
-		width   = 640;
-		height  = 480;
-		visible = true;
-		docked  = false;
-		maximized = false;
-	}
-
-	int xPosition;
-	int yPosition;
-	int width;
-	int height;
-	bool visible;
-	bool docked;
-	bool maximized;
+	int xPosition {0};
+	int yPosition {0};
+	int width {640};
+	int height {480};
+	bool visible {true};
+	bool docked {false};
+	bool maximized {false};
+	int screenNumber {0};
 };
 
 struct tabPrefs
@@ -120,34 +111,20 @@
 //User Interface
 struct UIPrefs
 {
-	UIPrefs() {
-		mouseMoveTimeout = 150;
-		wheelJump = 40;
-		applicationFontSize = 12;
-		paletteFontSize = 10;
-		recentDocCount = 5;
-		useSmallWidgets = false;
-		useTabs = false;
-		showStartupDialog = true;
-		showSplashOnStartup = true;
-		stickyTools = false;
-		grayscaleIcons = false;
-	}
-
-	int mouseMoveTimeout; //! Mouse move timeout for move/resize operations
-	int wheelJump; //! Distance to jump with mouse wheel scrolling
-	int applicationFontSize; //! Font size to use in the application, apart from pßalettes
-	int paletteFontSize; //! Font size to use in the palettes
+	int mouseMoveTimeout {150}; //! Mouse move timeout for move/resize operations
+	int wheelJump {40}; //! Distance to jump with mouse wheel scrolling
+	int applicationFontSize {12}; //! Font size to use in the application, apart from pßalettes
+	int paletteFontSize {10}; //! Font size to use in the palettes
 	QString style; 	//! Currently used QStyle name
-	int recentDocCount; //! Number of recent documents to remember
+	int recentDocCount {5}; //! Number of recent documents to remember
 	QStringList RecentDocs; //! List of recent documents
 	QString language; //! Language of the user interface
-	bool useSmallWidgets; //! Use small widgets in the palettes
-	bool useTabs;		 //! Use a tabbed MainWidget a la FireFox 
-	bool showStartupDialog; //! Whether to show the startup dialog or not
-	bool showSplashOnStartup; //! Whether to show the splashscreen or not
-	bool stickyTools; //! Whether a user's tool section remains after use or the normal tool is reselected
-	bool grayscaleIcons; //! Show icons in toolbars as grayscale
+	bool useSmallWidgets {false}; //! Use small widgets in the palettes
+	bool useTabs {false}; //! Use a tabbed MainWidget a la FireFox
+	bool showStartupDialog {true}; //! Whether to show the startup dialog or not
+	bool showSplashOnStartup {true}; //! Whether to show the splashscreen or not
+	bool stickyTools {false}; //! Whether a user's tool section remains after use or the normal tool is reselected
+	bool grayscaleIcons {false}; //! Show icons in toolbars as grayscale
 	QString iconSet; //! Icon set name
 	WindowPrefs mainWinSettings;
 	QByteArray mainWinState;

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23568&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Wed Apr  8 20:46:18 2020
@@ -28,7 +28,6 @@
 #include <QColor>
 #include <QColorDialog>
 #include <QCursor>
-#include <QDesktopWidget>
 #include <QDrag>
 #include <QDragEnterEvent>
 #include <QDropEvent>
@@ -62,10 +61,12 @@
 //>>
 #include <QRegExp>
 #include <QScopedPointer>
+#include <QScreen>
 #include <QStyleFactory>
 #include <QTableWidget>
 #include <QTextCodec>
 #include <QTranslator>
+#include <QWindow>
 #include <QWheelEvent>
 
 #ifdef DEBUG_LOAD_TIMES
@@ -393,7 +394,7 @@
 	connect( scrActions["windowsTile"], SIGNAL(triggered()) , mdiArea, SLOT(tileSubWindows()) );
 	initPalettes();
 
-	m_prefsManager.setupMainWindow(this);
+	setupMainWindow();
 
 	viewToolBar->previewQualitySwitcher->setCurrentIndex(m_prefsManager.appPrefs.itemToolPrefs.imageLowResType);
 	if (primaryMainWindow)
@@ -457,6 +458,62 @@
 	setStyleSheet();
 
 	return retVal;
+}
+
+void ScribusMainWindow::setupMainWindow()
+{
+	setDefaultPrinter(m_prefsManager.appPrefs.printerPrefs.PrinterName, m_prefsManager.appPrefs.printerPrefs.PrinterFile, m_prefsManager.appPrefs.printerPrefs.PrinterCommand);
+
+	uint max = qMin(m_prefsManager.appPrefs.uiPrefs.recentDocCount, m_prefsManager.appPrefs.uiPrefs.RecentDocs.count());
+	for (uint m = 0; m < max; ++m)
+	{
+		QFileInfo fd(m_prefsManager.appPrefs.uiPrefs.RecentDocs[m]);
+		if (fd.exists())
+		{
+			m_recentDocsList.append(m_prefsManager.appPrefs.uiPrefs.RecentDocs[m]);
+			//#9845: ScCore->fileWatcher->addFile(appPrefs.uiPrefs.RecentDocs[m]);
+		}
+	}
+	rebuildRecentFileMenu();
+	//For 1.3.5, we dump prefs first time around.
+	if (!m_prefsManager.firstTimeIgnoreOldPrefs())
+		m_prefsManager.ReadPrefsXML();
+	if (m_prefsManager.appPrefs.verifierPrefs.checkerPrefsList.count() == 0)
+	{
+		m_prefsManager.initDefaultCheckerPrefs(m_prefsManager.appPrefs.verifierPrefs.checkerPrefsList);
+		m_prefsManager.appPrefs.verifierPrefs.curCheckProfile = CommonStrings::PDF_1_4;
+	}
+
+	QWindow* w = ScCore->primaryMainWindow()->windowHandle();
+	QList<QScreen*> screens = QGuiApplication::screens();
+	QScreen* s=nullptr;
+	if (w != nullptr)
+	{
+		s=screens.at(qMin(m_prefsManager.appPrefs.uiPrefs.mainWinSettings.screenNumber, QGuiApplication::screens().count()-1));
+		windowHandle()->setScreen(s);
+	}
+	else
+		s=QGuiApplication::primaryScreen();
+	QRect r(0,0,0,0);
+	if (s!=nullptr)
+		r=s->geometry();
+	move(r.left()+abs(m_prefsManager.appPrefs.uiPrefs.mainWinSettings.xPosition), r.top()+m_prefsManager.appPrefs.uiPrefs.mainWinSettings.yPosition);
+	resize(m_prefsManager.appPrefs.uiPrefs.mainWinSettings.width, m_prefsManager.appPrefs.uiPrefs.mainWinSettings.height);
+}
+
+void ScribusMainWindow::getScreenData(int& screenNumber, int& xPos, int& yPos)
+{
+	QList<QScreen*> screens = QGuiApplication::screens();
+#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
+	QWindow* w = ScCore->primaryMainWindow()->windowHandle();
+	if (w != nullptr)
+		screenNumber=screens.indexOf(w->screen());
+#else
+	QScreen* s = ScCore->primaryMainWindow()->screen();
+	screenNumber = screens.indexOf(s);
+#endif
+	xPos = screens.at(screenNumber)->geometry().left();
+	yPos = screens.at(screenNumber)->geometry().top();
 }
 
 
@@ -6862,9 +6919,6 @@
 		}
 	}
 
-	move(m_prefsManager.appPrefs.uiPrefs.mainWinSettings.xPosition, m_prefsManager.appPrefs.uiPrefs.mainWinSettings.yPosition);
-	resize(m_prefsManager.appPrefs.uiPrefs.mainWinSettings.width, m_prefsManager.appPrefs.uiPrefs.mainWinSettings.height);
-
 	// init the toolbars
 	fileToolBar->initVisibility();
 	editToolBar->initVisibility();

Modified: trunk/Scribus/scribus/scribus.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23568&path=/trunk/Scribus/scribus/scribus.h
==============================================================================
--- trunk/Scribus/scribus/scribus.h	(original)
+++ trunk/Scribus/scribus/scribus.h	Wed Apr  8 20:46:18 2020
@@ -134,6 +134,8 @@
 	* \retval 0 - ok, 1 - no fonts, ...
 	*/
 	int initScMW(bool primaryMainwWindow);
+	void setupMainWindow();
+	void getScreenData(int& screenNumber, int& xPos, int& yPos);
 	void addScToolBar(ScToolBar *tb, const QString& name);
 	bool warningVersion(QWidget *parent);
 	void SetShortCut();




More information about the scribus-commit mailing list