r24706 by jghali - Code cleanup

scribus-commit scribus-commit at lists.scribus.net
Tue Aug 24 21:48:12 UTC 2021


Author: jghali
Date: Tue Aug 24 21:48:11 2021
New Revision: 24706

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24706
Log:
Code cleanup

Modified:
    trunk/Scribus/scribus/ui/scfilewidget.cpp
    trunk/Scribus/scribus/ui/scfilewidget.h

Modified: trunk/Scribus/scribus/ui/scfilewidget.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24706&path=/trunk/Scribus/scribus/ui/scfilewidget.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/scfilewidget.cpp	(original)
+++ trunk/Scribus/scribus/ui/scfilewidget.cpp	Tue Aug 24 21:48:11 2021
@@ -1,72 +1,68 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#include <cstdlib>
-
-#include <QDebug>
-#include <QStandardPaths>
-#include <QLayout>
-#include <QLineEdit>
-#include <QListView>
-#include <QPushButton>
-#include <QStringList>
-#include <QUrl>
-
-#include "filedialogeventcatcher.h"
-#include "scfilewidget.h"
-
-
-ScFileWidget::ScFileWidget(QWidget * parent) : QFileDialog(parent, Qt::Widget)
-{
-	m_forceDoubleClickActivation = false;
-
-	setOption(QFileDialog::DontUseNativeDialog);
-	setSizeGripEnabled(false);
-	setModal(false);
-	setViewMode(QFileDialog::List);
-	setWindowFlags(Qt::Widget);
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#include <cstdlib>
+
+#include <QDebug>
+#include <QStandardPaths>
+#include <QLayout>
+#include <QLineEdit>
+#include <QListView>
+#include <QPushButton>
+#include <QStringList>
+#include <QUrl>
+
+#include "filedialogeventcatcher.h"
+#include "scfilewidget.h"
+
+
+ScFileWidget::ScFileWidget(QWidget * parent) : QFileDialog(parent, Qt::Widget)
+{
+	setOption(QFileDialog::DontUseNativeDialog);
+	setSizeGripEnabled(false);
+	setModal(false);
+	setViewMode(QFileDialog::List);
+	setWindowFlags(Qt::Widget);
 
 	// The margins' content should be set both on the widget and its layout.
 	setContentsMargins(0, 0, 0, 0);
-	layout()->setContentsMargins(0, 0, 0, 0);
-
-#ifdef Q_OS_MAC
-	QList<QUrl> urls;
-	QUrl computer(QUrl::fromLocalFile(QLatin1String("")));
-	if (!urls.contains(computer))
-		urls << computer;
-	QUrl volumes(QUrl::fromLocalFile("/Volumes"));
-	if (!urls.contains(volumes))
-		urls << volumes;
-	QUrl dt(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)));
-	if (!urls.contains(dt))
-		urls << dt;
-	setSidebarUrls(urls);
-#endif
-
-	FileDialogEventCatcher* keyCatcher = new FileDialogEventCatcher(this);
-	QList<QListView *> lv = findChildren<QListView *>();
-	QListIterator<QListView *> lvi(lv);
-	while (lvi.hasNext())
-		lvi.next()->installEventFilter(keyCatcher);
-	connect(keyCatcher, SIGNAL(escapePressed()), this, SLOT(reject()));
-	connect(keyCatcher, SIGNAL(dropLocation(QString)), this, SLOT(locationDropped(QString)));
-	connect(keyCatcher, SIGNAL(desktopPressed()), this, SLOT(gotoDesktopDirectory()));
-	connect(keyCatcher, SIGNAL(homePressed()), this, SLOT(gotoHomeDirectory()));
-	connect(keyCatcher, SIGNAL(parentPressed()), this, SLOT(gotoParentDirectory()));
-	connect(keyCatcher, SIGNAL(enterSelectedPressed()), this, SLOT(gotoSelectedDirectory()));
-
-	QList<QPushButton *> b = findChildren<QPushButton *>();
-	QListIterator<QPushButton *> i(b);
-	while (i.hasNext())
-		i.next()->setVisible(false);
-	setMinimumSize(QSize(480, 310));
-	setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
-}
+	layout()->setContentsMargins(0, 0, 0, 0);
+
+#ifdef Q_OS_MAC
+	QList<QUrl> urls;
+	QUrl computer(QUrl::fromLocalFile(QLatin1String("")));
+	if (!urls.contains(computer))
+		urls << computer;
+	QUrl volumes(QUrl::fromLocalFile("/Volumes"));
+	if (!urls.contains(volumes))
+		urls << volumes;
+	QUrl dt(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)));
+	if (!urls.contains(dt))
+		urls << dt;
+	setSidebarUrls(urls);
+#endif
+
+	FileDialogEventCatcher* keyCatcher = new FileDialogEventCatcher(this);
+	QList<QListView *> childListViews = findChildren<QListView *>();
+	for (QListView * lvi : childListViews)
+		lvi->installEventFilter(keyCatcher);
+	connect(keyCatcher, SIGNAL(escapePressed()), this, SLOT(reject()));
+	connect(keyCatcher, SIGNAL(dropLocation(QString)), this, SLOT(locationDropped(QString)));
+	connect(keyCatcher, SIGNAL(desktopPressed()), this, SLOT(gotoDesktopDirectory()));
+	connect(keyCatcher, SIGNAL(homePressed()), this, SLOT(gotoHomeDirectory()));
+	connect(keyCatcher, SIGNAL(parentPressed()), this, SLOT(gotoParentDirectory()));
+	connect(keyCatcher, SIGNAL(enterSelectedPressed()), this, SLOT(gotoSelectedDirectory()));
+
+	QList<QPushButton *> childPushButtons = findChildren<QPushButton *>();
+	for (QPushButton* pb : childPushButtons)
+		pb->setVisible(false);
+	setMinimumSize(QSize(480, 310));
+	setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+}
 
 void ScFileWidget::forceDoubleClickActivation(bool force)
 {
@@ -74,71 +70,71 @@
 	// needed e.g on OpenSuse KDE. Otherwise file would open on first
 	// click, leaving user no time to see preview.
 	if (m_forceDoubleClickActivation == force)
-		return;
-
-	if (force)
-		setStyleSheet(QStringLiteral("QAbstractItemView { activate-on-singleclick: 0; }"));
-	else
-		setStyleSheet(QString());
-	m_forceDoubleClickActivation = force;
-}
-
-QString ScFileWidget::selectedFile()
-{
-	QStringList l(selectedFiles());
-	if (l.count() == 0)
-		return QString();
-	return l.at(0);
-}
-
-void ScFileWidget::locationDropped(const QString& fileUrl)
-{
-	QFileInfo fi(fileUrl);
-	if (fi.isDir())
-	{
-		setDirectory(fi.absoluteFilePath());
-		return;
-	}
-
-	QString absFilePath = fi.absolutePath();
-	QString fileName = fi.fileName();
-		
-	setDirectory(absFilePath);
-	selectFile(fileName);
-}
-
-void ScFileWidget::gotoParentDirectory()
-{
-	QDir d(directory());
-	d.cdUp();
-	setDirectory(d);
-}
-
-void ScFileWidget::gotoSelectedDirectory()
-{
-	QStringList s(selectedFiles());
-	if (!s.isEmpty())
-	{
-		QFileInfo fi(s.first());
-//		qDebug()<<s.first()<<fi.absoluteFilePath();
-		if (fi.isDir())
-			setDirectory(fi.absoluteFilePath());
-	}
-}
-
-void ScFileWidget::gotoDesktopDirectory()
-{
-	QString dp=QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
-	QFileInfo fi(dp);
-	if (fi.exists())
-		setDirectory(dp);
-}
-
-void ScFileWidget::gotoHomeDirectory()
-{
-	QString dp=QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
-	QFileInfo fi(dp);
-	if (fi.exists())
-		setDirectory(dp);
-}
-
+		return;
+
+	if (force)
+		setStyleSheet(QStringLiteral("QAbstractItemView { activate-on-singleclick: 0; }"));
+	else
+		setStyleSheet(QString());
+	m_forceDoubleClickActivation = force;
+}
+
+QString ScFileWidget::selectedFile()
+{
+	QStringList l(selectedFiles());
+	if (l.count() == 0)
+		return QString();
+	return l.at(0);
+}
+
+void ScFileWidget::locationDropped(const QString& fileUrl)
+{
+	QFileInfo fi(fileUrl);
+	if (fi.isDir())
+	{
+		setDirectory(fi.absoluteFilePath());
+		return;
+	}
+
+	QString absFilePath = fi.absolutePath();
+	QString fileName = fi.fileName();
+		
+	setDirectory(absFilePath);
+	selectFile(fileName);
+}
+
+void ScFileWidget::gotoParentDirectory()
+{
+	QDir d(directory());
+	d.cdUp();
+	setDirectory(d);
+}
+
+void ScFileWidget::gotoSelectedDirectory()
+{
+	QStringList s(selectedFiles());
+	if (!s.isEmpty())
+	{
+		QFileInfo fi(s.first());
+//		qDebug()<<s.first()<<fi.absoluteFilePath();
+		if (fi.isDir())
+			setDirectory(fi.absoluteFilePath());
+	}
+}
+
+void ScFileWidget::gotoDesktopDirectory()
+{
+	QString dp=QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
+	QFileInfo fi(dp);
+	if (fi.exists())
+		setDirectory(dp);
+}
+
+void ScFileWidget::gotoHomeDirectory()
+{
+	QString dp=QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
+	QFileInfo fi(dp);
+	if (fi.exists())
+		setDirectory(dp);
+}
+

Modified: trunk/Scribus/scribus/ui/scfilewidget.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24706&path=/trunk/Scribus/scribus/ui/scfilewidget.h
==============================================================================
--- trunk/Scribus/scribus/ui/scfilewidget.h	(original)
+++ trunk/Scribus/scribus/ui/scfilewidget.h	Tue Aug 24 21:48:11 2021
@@ -1,19 +1,19 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-#ifndef SCFILEWIDGET_H
-#define SCFILEWIDGET_H
-
-#include <QFileDialog>
-
-#include "scribusapi.h"
-
-/*! \brief Simple wrapper simulating the QFileDialog as a common widget.
-Usage is simple - everything is like in QFileDialog except it is not
-a dialog, it's a widget. It can be used for extension features etc.
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+#ifndef SCFILEWIDGET_H
+#define SCFILEWIDGET_H
+
+#include <QFileDialog>
+
+#include "scribusapi.h"
+
+/*! \brief Simple wrapper simulating the QFileDialog as a common widget.
+Usage is simple - everything is like in QFileDialog except it is not
+a dialog, it's a widget. It can be used for extension features etc.
 \note Original QFileDialog OK/Cancel buttons are hidden. You must
 write your own dialog accept/reject handling.
 There is one good idea - it's quite good to handle original dialog
@@ -21,26 +21,26 @@
 user e.g. doubleclicks the "open" file (in the parent (new) dialog):
 connect(fileWidget, SIGNAL(accepted()), this, SLOT(accept()));
 \author Petr Vanek <petr at scribus.info>
-*/
-class SCRIBUS_API ScFileWidget : public QFileDialog
-{
-	Q_OBJECT
-
-public:
-	ScFileWidget(QWidget * parent);
-
-	QString selectedFile();
-	void forceDoubleClickActivation(bool force);
-
-public slots:
-	void locationDropped(const QString& fileUrl);
-	void gotoParentDirectory();
-	void gotoSelectedDirectory();
-	void gotoDesktopDirectory();
-	void gotoHomeDirectory();
-
-private:
-	bool m_forceDoubleClickActivation;
-};
-
-#endif
+*/
+class SCRIBUS_API ScFileWidget : public QFileDialog
+{
+	Q_OBJECT
+
+public:
+	ScFileWidget(QWidget * parent);
+
+	QString selectedFile();
+	void forceDoubleClickActivation(bool force);
+
+public slots:
+	void locationDropped(const QString& fileUrl);
+	void gotoParentDirectory();
+	void gotoSelectedDirectory();
+	void gotoDesktopDirectory();
+	void gotoHomeDirectory();
+
+private:
+	bool m_forceDoubleClickActivation { false };
+};
+
+#endif




More information about the scribus-commit mailing list