r24698 by jghali - #16619: File selection dialog box always reverts to small size

scribus-commit scribus-commit at lists.scribus.net
Sun Aug 22 22:56:03 UTC 2021


Author: jghali
Date: Sun Aug 22 22:56:03 2021
New Revision: 24698

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24698
Log:
#16619: File selection dialog box always reverts to small size

Modified:
    trunk/Scribus/scribus/ui/customfdialog.cpp
    trunk/Scribus/scribus/ui/customfdialog.h
    trunk/Scribus/scribus/ui/gtfiledialog.cpp
    trunk/Scribus/scribus/ui/gtfiledialog.h

Modified: trunk/Scribus/scribus/ui/customfdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24698&path=/trunk/Scribus/scribus/ui/customfdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/customfdialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/customfdialog.cpp	Sun Aug 22 22:56:03 2021
@@ -25,6 +25,7 @@
 #include <QApplication>
 #include <QCheckBox>
 #include <QComboBox>
+#include <QDesktopWidget>
 #include <QDir>
 #include <QFileInfo>
 #include <QFrame>
@@ -35,6 +36,7 @@
 #include <QPainter>
 #include <QPixmap>
 #include <QPushButton>
+#include <QScreen>
 #include <QTextCodec>
 #include <QVBoxLayout>
 
@@ -46,6 +48,8 @@
 #include "fileloader.h"
 #include "iconmanager.h"
 #include "loadsaveplugin.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
 #include "prefsmanager.h"
 #include "scfilewidget.h"
 #include "scimage.h"
@@ -56,9 +60,6 @@
 #include "util.h"
 #include "util_color.h"
 #include "util_formats.h"
-
-
-
 
 extern QString DocDir;
 
@@ -284,6 +285,8 @@
 CustomFDialog::CustomFDialog(QWidget *parent, const QString& wDir, const QString& caption, const QString& filter, int flags)
 			: QDialog(parent), m_optionFlags(flags)
 {
+	m_fileDialogPrefs = PrefsManager::instance().prefsFile->getContext("customfdialog", false);
+
 	setModal(true);
 	setWindowTitle(caption);
 	setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
@@ -491,6 +494,48 @@
 {
 }
 
+void CustomFDialog::closeEvent(QCloseEvent *closeEvent)
+{
+	storeSize();
+	QDialog::closeEvent(closeEvent);
+}
+
+void CustomFDialog::hideEvent(QHideEvent* hideEvent)
+{
+	storeSize();
+	QDialog::hideEvent(hideEvent);
+}
+
+void CustomFDialog::showEvent(QShowEvent *showEvent)
+{
+	QScreen* dialogScreen = this->screen();
+	if (m_fileDialogPrefs && dialogScreen && !showEvent->spontaneous())
+	{
+		if (m_fileDialogPrefs->contains("width"))
+		{
+			QRect scr = dialogScreen->availableGeometry();
+			int fdWidth  = qMax(0, qMin(m_fileDialogPrefs->getInt("width"), scr.width()));
+			int fdHeight = qMax(0, qMin(m_fileDialogPrefs->getInt("height"), scr.height()));
+			if (fdWidth > 0 && fdHeight > 0)
+			{
+				int newWidth = qMax(0, qMin(this->width() + fdWidth - fileDialog->width(), scr.width()));
+				int newHeight = qMax(0, qMin(this->height() + fdHeight - fileDialog->height(), scr.height()));
+				if (newWidth > 0 && newHeight > 0)
+					resize(newWidth, newHeight);
+			}
+		}
+	}
+	QDialog::showEvent(showEvent);
+}
+
+void CustomFDialog::storeSize()
+{
+	if (!m_fileDialogPrefs)
+		return;
+	m_fileDialogPrefs->set("width",  fileDialog->width());
+	m_fileDialogPrefs->set("height", fileDialog->height());
+}
+
 void CustomFDialog::fileClicked(const QString &path)
 {
 	if (m_optionFlags & fdDisableOk)

Modified: trunk/Scribus/scribus/ui/customfdialog.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24698&path=/trunk/Scribus/scribus/ui/customfdialog.h
==============================================================================
--- trunk/Scribus/scribus/ui/customfdialog.h	(original)
+++ trunk/Scribus/scribus/ui/customfdialog.h	Sun Aug 22 22:56:03 2021
@@ -27,14 +27,17 @@
 #include <QDialog>
 #include <QFileIconProvider>
 #include <QLabel>
+
 class QPushButton;
 class QComboBox;
 class QCheckBox;
+class QIcon;
 class QHBoxLayout;
 class QVBoxLayout;
 class QFrame;
+
+class PrefsContext;
 class ScFileWidget;
-class QIcon;
 
 #include "scribusapi.h"
 
@@ -171,13 +174,24 @@
 	QPushButton* okButton { nullptr };
 	QPushButton* cancelButton { nullptr };
 
+	PrefsContext* m_fileDialogPrefs { nullptr };
+
 	//! \brief Property with default extension
 	QString m_ext;
 	//! \brief Property with default compress extension
 	QString m_extZip;
 	//! \brief Option flags given by user in ctore
-	int  m_optionFlags;
-	bool m_previewIsShown;
+	int  m_optionFlags { 0 };
+	bool m_previewIsShown { false };
+
+	/** @brief Restore the geometry of the window when showing it. */
+	void showEvent(QShowEvent *showEvent) override;
+	/** @brief Captures the close event and changes it to hide */
+	void closeEvent(QCloseEvent *closeEvent) override;
+	/** @brief Stores the geometry of the window when hiding. */
+	void hideEvent(QHideEvent* hideEvent) override;
+
+	void storeSize();
 };
 
 #endif

Modified: trunk/Scribus/scribus/ui/gtfiledialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24698&path=/trunk/Scribus/scribus/ui/gtfiledialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/gtfiledialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/gtfiledialog.cpp	Sun Aug 22 22:56:03 2021
@@ -5,8 +5,10 @@
 for which a new license (GPL+exception) is in place.
 */
 #include <QPushButton>
+#include <QScreen>
 #include <QToolTip>
 #include <QTextCodec>
+
 #include "gtfiledialog.h"
 
 #include "prefsmanager.h"
@@ -15,6 +17,8 @@
 
 gtFileDialog::gtFileDialog(const QString& filters, const QStringList& importers, const QString& wdir)
 {
+	m_fileDialogPrefs = PrefsManager::instance().prefsFile->getContext("gtFileDialog", false);
+
 	setupUi(this);
 
 	fileWidget->setDirectory(wdir);
@@ -51,6 +55,40 @@
 	connect(fileWidget, SIGNAL(rejected()), this, SLOT(reject()));
 	connect(buttonBox, SIGNAL(accepted()), this, SLOT(okClicked()));
 	connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+}
+
+void gtFileDialog::closeEvent(QCloseEvent *closeEvent)
+{
+	storeSize();
+	QDialog::closeEvent(closeEvent);
+}
+
+void gtFileDialog::hideEvent(QHideEvent* hideEvent)
+{
+	storeSize();
+	QDialog::hideEvent(hideEvent);
+}
+
+void gtFileDialog::showEvent(QShowEvent *showEvent)
+{
+	QScreen* dialogScreen = this->screen();
+	if (m_fileDialogPrefs && dialogScreen && !showEvent->spontaneous())
+	{
+		if (m_fileDialogPrefs->contains("width"))
+		{
+			QRect scr = dialogScreen->availableGeometry();
+			int fdWidth  = qMax(0, qMin(m_fileDialogPrefs->getInt("width"), scr.width()));
+			int fdHeight = qMax(0, qMin(m_fileDialogPrefs->getInt("height"), scr.height()));
+			if (fdWidth > 0 && fdHeight > 0)
+			{
+				int newWidth = qMax(0, qMin(this->width() + fdWidth - fileWidget->width(), scr.width()));
+				int newHeight = qMax(0, qMin(this->height() + fdHeight - fileWidget->height(), scr.height()));
+				if (newWidth > 0 && newHeight > 0)
+					resize(newWidth, newHeight);
+			}
+		}
+	}
+	QDialog::showEvent(showEvent);
 }
 
 QString gtFileDialog::selectedFile()
@@ -129,6 +167,10 @@
 	context->set("prefix", prefixStylesCheckBox->isChecked());
 }
 
-gtFileDialog::~gtFileDialog()
+void gtFileDialog::storeSize()
 {
+	if (!m_fileDialogPrefs)
+		return;
+	m_fileDialogPrefs->set("width",  fileWidget->width());
+	m_fileDialogPrefs->set("height", fileWidget->height());
 }

Modified: trunk/Scribus/scribus/ui/gtfiledialog.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24698&path=/trunk/Scribus/scribus/ui/gtfiledialog.h
==============================================================================
--- trunk/Scribus/scribus/ui/gtfiledialog.h	(original)
+++ trunk/Scribus/scribus/ui/gtfiledialog.h	Sun Aug 22 22:56:03 2021
@@ -11,6 +11,7 @@
 #include "ui_gtfiledialog.h"
 #include "scribusapi.h"
 
+class PrefsContext;
 
 /*! \brief Enhanced file dialog for get-text plugins
 This class is separated from gtdialogs.h file due the huge
@@ -23,7 +24,7 @@
 	Q_OBJECT
 public:
 	gtFileDialog(const QString& filters, const QStringList& importers, const QString& wdir);
-	~gtFileDialog();
+	~gtFileDialog() {};
 
 	QString selectedFile();
 
@@ -33,6 +34,17 @@
 	void okClicked();
 
 protected:
+	PrefsContext* m_fileDialogPrefs { nullptr };
+
+	/** @brief Restore the geometry of the window when showing it. */
+	void showEvent(QShowEvent *showEvent) override;
+	/** @brief Captures the close event and changes it to hide */
+	void closeEvent(QCloseEvent *closeEvent) override;
+	/** @brief Stores the geometry of the window when hiding. */
+	void hideEvent(QHideEvent* hideEvent) override;
+
+	void storeSize();
+
 	void loadSettings();
 	void saveSettings();
 };




More information about the scribus-commit mailing list