r20227 by craig - Related to #13194. Replace the Qt WebKit / QWebView parts of ScTextBrowser with QTextBrowser. Bookmark setting disabled for now

scribus-commit scribus-commit at lists.scribus.net
Wed Jul 1 23:01:34 UTC 2015


Author: craig
Date: Wed Jul  1 23:01:34 2015
New Revision: 20227

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20227
Log:
Related to #13194. Replace the Qt WebKit / QWebView parts of ScTextBrowser with QTextBrowser. Bookmark setting disabled for now

Modified:
    trunk/Scribus/CMakeLists.txt
    trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
    trunk/Scribus/scribus/ui/about.cpp
    trunk/Scribus/scribus/ui/helpbrowser.cpp
    trunk/Scribus/scribus/ui/helpbrowser.h
    trunk/Scribus/scribus/ui/sctextbrowser.cpp
    trunk/Scribus/scribus/ui/sctextbrowser.h

Modified: trunk/Scribus/CMakeLists.txt
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20227&path=/trunk/Scribus/CMakeLists.txt
==============================================================================
--- trunk/Scribus/CMakeLists.txt (original)
+++ trunk/Scribus/CMakeLists.txt Wed Jul  1 23:01:34 2015
@@ -554,18 +554,18 @@
 ELSE(Qt5Xml_FOUND)
 	MESSAGE(FATAL_ERROR "ERROR: No QT 5 XML found")
 ENDIF(Qt5Xml_FOUND)
-FIND_PACKAGE(Qt5WebKit REQUIRED)
-IF(Qt5WebKit_FOUND)
-	MESSAGE(STATUS "----- USE Qt5WebKit -----")
-ELSE(Qt5WebKit_FOUND)
-	MESSAGE(FATAL_ERROR "ERROR: No Qt5WebKit found")
-ENDIF(Qt5WebKit_FOUND)
-FIND_PACKAGE(Qt5WebKitWidgets REQUIRED)
-IF(Qt5WebKitWidgets_FOUND)
-	MESSAGE(STATUS "----- USE Qt5WebKitWidgets -----")
-ELSE(Qt5WebKitWidgets_FOUND)
-	MESSAGE(FATAL_ERROR "ERROR: No Qt5WebKitWidgets found")
-ENDIF(Qt5WebKitWidgets_FOUND)
+#FIND_PACKAGE(Qt5WebKit REQUIRED)
+#IF(Qt5WebKit_FOUND)
+#	MESSAGE(STATUS "----- USE Qt5WebKit -----")
+#ELSE(Qt5WebKit_FOUND)
+#	MESSAGE(FATAL_ERROR "ERROR: No Qt5WebKit found")
+#ENDIF(Qt5WebKit_FOUND)
+#FIND_PACKAGE(Qt5WebKitWidgets REQUIRED)
+#IF(Qt5WebKitWidgets_FOUND)
+#	MESSAGE(STATUS "----- USE Qt5WebKitWidgets -----")
+#ELSE(Qt5WebKitWidgets_FOUND)
+#	MESSAGE(FATAL_ERROR "ERROR: No Qt5WebKitWidgets found")
+#ENDIF(Qt5WebKitWidgets_FOUND)
 FIND_PACKAGE(Qt5Network REQUIRED)
 IF(Qt5Network_FOUND)
 	MESSAGE(STATUS "----- USE Qt5Network -----")
@@ -604,10 +604,10 @@
 ADD_DEFINITIONS(${Qt5Gui_DEFINITIONS})
 INCLUDE_DIRECTORIES(${Qt5Xml_INCLUDE_DIRS})
 ADD_DEFINITIONS(${Qt5Xml_DEFINITIONS})
-INCLUDE_DIRECTORIES(${Qt5WebKit_INCLUDE_DIRS})
-ADD_DEFINITIONS(${Qt5WebKit_DEFINITIONS})
-INCLUDE_DIRECTORIES(${Qt5WebKitWidgets_INCLUDE_DIRS})
-ADD_DEFINITIONS(${Qt5WebKitWidgets_DEFINITIONS})
+#INCLUDE_DIRECTORIES(${Qt5WebKit_INCLUDE_DIRS})
+#ADD_DEFINITIONS(${Qt5WebKit_DEFINITIONS})
+#INCLUDE_DIRECTORIES(${Qt5WebKitWidgets_INCLUDE_DIRS})
+#ADD_DEFINITIONS(${Qt5WebKitWidgets_DEFINITIONS})
 INCLUDE_DIRECTORIES(${Qt5Network_INCLUDE_DIRS})
 ADD_DEFINITIONS(${Qt5Network_DEFINITIONS})
 INCLUDE_DIRECTORIES(${Qt5OpenGL_INCLUDE_DIRS})

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20227&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp Wed Jul  1 23:01:34 2015
@@ -535,7 +535,7 @@
 	html += "</body></html>";
 	input.close();
 	HelpBrowser *dia = new HelpBrowser(0, QObject::tr("About Script") + " " + fi.fileName(), "en");
-	dia->setText(html);
+	dia->setHtml(html);
 	dia->show();
 }
 

Modified: trunk/Scribus/scribus/ui/about.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20227&path=/trunk/Scribus/scribus/ui/about.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/about.cpp (original)
+++ trunk/Scribus/scribus/ui/about.cpp Wed Jul  1 23:01:34 2015
@@ -114,8 +114,8 @@
 	buildID = new QLabel( tab );
 	buildID->setAlignment(Qt::AlignCenter);
 	buildID->setTextInteractionFlags(Qt::TextSelectableByMouse);
-	QString BUILD_DAY = "22";
-	QString BUILD_MONTH = CommonStrings::june;
+	QString BUILD_DAY = "02";
+	QString BUILD_MONTH = CommonStrings::july;
 	QString BUILD_YEAR = "2015";
 	QString BUILD_TIME = "";
 	QString BUILD_TZ = "";

Modified: trunk/Scribus/scribus/ui/helpbrowser.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20227&path=/trunk/Scribus/scribus/ui/helpbrowser.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/helpbrowser.cpp (original)
+++ trunk/Scribus/scribus/ui/helpbrowser.cpp Wed Jul  1 23:01:34 2015
@@ -59,6 +59,7 @@
 #include "scribuscore.h"
 #include "util_debug.h"
 #include "iconmanager.h"
+#include "util.h"
 
 /*! \brief XML parsef for documantation history.
 This is small helper class which reads saved bookmarks configuration
@@ -160,6 +161,7 @@
 	setupLocalUI();
 	language = guiLanguage.isEmpty() ? QString("en") : guiLanguage.left(2);
 	finalBaseDir = ScPaths::instance().docDir() + "en/"; //Sane default for help location
+	textBrowser->setSearchPaths(QStringList(finalBaseDir));
 	menuModel=NULL;
 	loadMenu();
 	if (menuModel!=NULL)
@@ -249,7 +251,7 @@
 
 	//Add Toolbar items
 	goHome=toolBar->addAction(IconManager::instance()->loadIcon("16/go-home.png"), "", textBrowser, SLOT(home()));
-	goBack=toolBar->addAction(IconManager::instance()->loadIcon("16/go-previous.png"), "", textBrowser, SLOT(back()));
+	goBack=toolBar->addAction(IconManager::instance()->loadIcon("16/go-previous.png"), "", textBrowser, SLOT(backward()));
 	goFwd=toolBar->addAction(IconManager::instance()->loadIcon("16/go-next.png"), "", textBrowser, SLOT(forward()));
 	goBack->setMenu(histMenu);
 	
@@ -280,10 +282,7 @@
 //	connect(textBrowser, SIGNAL(overLink(const QString &)), this, SLOT(showLinkContents(const QString &)));
 
 	// status bar
-	connect( textBrowser, SIGNAL(statusBarMessage(QString)), this->statusBar(), SLOT(showMessage(QString)));
-	connect(textBrowser,SIGNAL(loadStarted()), this, SLOT(loadStart()));
-	connect(textBrowser,SIGNAL(loadProgress(int)), this, SLOT(loadProcess(int)));
-	connect(textBrowser,SIGNAL(loadFinished(bool)), this, SLOT(loadEnd(bool)));
+//	connect(textBrowser,SIGNAL(statusBarMessage(QString)), this->statusBar(), SLOT(showMessage(QString)));
 	
 	languageChange();
 }
@@ -293,26 +292,6 @@
 //	statusBar()->showMessage(link);
 //}
 
-void HelpBrowser::loadStart()
-{
-	progressBar->setValue(0);
-	progressBar->setVisible(true);
-}
-
-void HelpBrowser::loadProcess(int p)
-{
-	progressBar->setValue(p);
-}
-
-void HelpBrowser::loadEnd(bool e)
-{
-	progressBar->setVisible(false);
-	if(e)
-		statusBar()->showMessage( textBrowser->title() );
-	else
-		statusBar()->showMessage( tr("Loading Failed") );
-}
-
 void HelpBrowser::changeEvent(QEvent *e)
 {
 	if (e->type() == QEvent::LanguageChange)
@@ -321,6 +300,11 @@
 	}
 	else
 		QWidget::changeEvent(e);
+}
+
+void HelpBrowser::setHtml(const QString& str)
+{
+	textBrowser->setHtml(str);
 }
 
 void HelpBrowser::languageChange()
@@ -342,7 +326,7 @@
 	Ui::HelpBrowser::retranslateUi(this);
 	if (!firstRun)
 	{
-		QString fname(QDir::cleanPath(textBrowser->url().toLocalFile()));
+		QString fname(QDir::cleanPath(textBrowser->source().toLocalFile()));
 		QFileInfo fi(fname);
 		QString filename(fi.fileName());
 		if (ScCore->getGuiLanguage().isEmpty())
@@ -446,12 +430,12 @@
 
 void HelpBrowser::bookmarkButton_clicked()
 {
-	QString title = textBrowser->title();
-	QString fname(QDir::cleanPath(textBrowser->url().toLocalFile()));
- 	title = QInputDialog::getText(this, tr("New Bookmark"), tr("New Bookmark's Title:"), QLineEdit::Normal, title, 0);
+/*	QString title = textBrowser->title();
+	QString fname(QDir::cleanPath(textBrowser->source().toLocalFile()));
+	title = QInputDialog::getText(this, tr("New Bookmark"), tr("New Bookmark's Title:"), QLineEdit::Normal, title, 0);
 	// user cancel
- 	if (title.isNull())
- 		return;
+	if (title.isNull())
+		return;
 	//TODO: start storing full paths
  	QString toFind(fname.remove(QDir::toNativeSeparators(finalBaseDir)));
 	toFind=toFind.mid(1, toFind.length()-1);
@@ -465,6 +449,7 @@
 			helpNav->bookmarksView->addTopLevelItem(new QTreeWidgetItem(helpNav->bookmarksView, QStringList() << title));
 		}
 	}
+*/
 }
 
 void HelpBrowser::deleteBookmarkButton_clicked()
@@ -487,7 +472,8 @@
 void HelpBrowser::histChosen(QAction* i)
 {
 	if (mHistory.contains(i))
-		textBrowser->setUrl( QUrl::fromLocalFile(mHistory[i].url) );
+		textBrowser->setSource( QUrl::fromLocalFile(mHistory[i].url) );
+
 }
 
 void HelpBrowser::jumpToHelpSection(const QString& jumpToSection, const QString& jumpToFile, bool dontChangeIfAlreadyLoaded)
@@ -515,7 +501,7 @@
 	}
 	else
 	{
-		toLoad=ScPaths::instance().docDir() + language + "/" + jumpToFile;
+		toLoad=finalBaseDir + "/" + jumpToFile;
 	}
 	if (!noDocs)
 		loadHelp(toLoad);
@@ -537,7 +523,7 @@
 			toLoad=filename;
 		else
 		{
-			toLoad = QDir::toNativeSeparators(ScPaths::instance().docDir() + "en/index.html");
+			toLoad = QDir::toNativeSeparators(finalBaseDir + "/index.html");
 // 			language="en";
 			fi = QFileInfo(toLoad);
 			if (!fi.exists())
@@ -551,9 +537,9 @@
 		Avail=false;
 	if (Avail)
 	{
-		textBrowser->setUrl( QUrl::fromLocalFile(toLoad) );
+		textBrowser->setSource(toLoad);
 		
-		his.title = textBrowser->title();
+//		his.title = textBrowser->title();
 		if (his.title.isEmpty())
 			his.title = toLoad;
 		his.url = toLoad;
@@ -621,6 +607,7 @@
 	}
 	//Set our final location for loading the help files
 	finalBaseDir=baseFi.path();
+	textBrowser->setSearchPaths(QStringList(finalBaseDir));
 	if (baseFi.exists())
 	{
 		if (menuModel!=NULL)
@@ -663,11 +650,6 @@
  	reader.parse(source);
 }
 
-void HelpBrowser::setText(const QString& str)
-{
-	textBrowser->setSimpleText(str);
-}
-
 void HelpBrowser::itemSelected(const QItemSelection & selected, const QItemSelection & deselected)
 {
 	Q_UNUSED(deselected);
@@ -757,7 +739,7 @@
 	QString noHelpMsg=tr("<h2><p>Sorry, no manual is installed!</p><p>Please see:</p><ul><li>http://docs.scribus.net for updated documentation</li><li>http://www.scribus.net for downloads</li></ul></h2>",
 						 "HTML message for no documentation available to show");
 
-	textBrowser->setSimpleText(noHelpMsg);
+	textBrowser->setPlainText(noHelpMsg);
 	
 	filePrint->setEnabled(false);
 	editFind->setEnabled(false);

Modified: trunk/Scribus/scribus/ui/helpbrowser.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20227&path=/trunk/Scribus/scribus/ui/helpbrowser.h
==============================================================================
--- trunk/Scribus/scribus/ui/helpbrowser.h (original)
+++ trunk/Scribus/scribus/ui/helpbrowser.h Wed Jul  1 23:01:34 2015
@@ -80,8 +80,8 @@
 	QMap<QAction*, histd2> mHistory;
 	/*! \brief Set text to the browser
 	\param str a QString with text (html) */
-	void setText(const QString& str);
-	
+	void setHtml(const QString& str);
+
 	static bool firstRun;
 
 public slots:
@@ -145,10 +145,6 @@
 	QString bookmarkFile();
 	QString historyFile();
 
-	void loadStart();
-	void loadProcess(int);
-	void loadEnd(bool);
-
 	/*! \brief Load doc file when user select filename in content view. */
 	void itemSelected(const QItemSelection & selected, const QItemSelection & deselected);
 

Modified: trunk/Scribus/scribus/ui/sctextbrowser.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20227&path=/trunk/Scribus/scribus/ui/sctextbrowser.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/sctextbrowser.cpp (original)
+++ trunk/Scribus/scribus/ui/sctextbrowser.cpp Wed Jul  1 23:01:34 2015
@@ -5,27 +5,20 @@
 for which a new license (GPL+exception) is in place.
 */
 
+#include <QDebug>
+#include <QPixmap>
+
+#include "iconmanager.h"
 #include "sctextbrowser.h"
-
-#include <QWebFrame>
-#include <QEvent>
-#include <QDebug>
-
-#if defined(_WIN32)
-#include <windows.h>
-#include <shellapi.h>
-#endif
-
 #include "urllauncher.h"
+#include "util.h"
 
 ScTextBrowser::ScTextBrowser( QWidget * parent )
-	 : QWebView(parent)
+	 : QTextBrowser(parent)
 {
-	hideContextMenus=false;
-	// Questionable - e.g. I would like to browse only through help browser (a pref?)
-	page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
-	connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(catchHome(QUrl)));
-	connect(this, SIGNAL(linkClicked(QUrl)), this, SLOT(externalLinkClick(QUrl)));
+	setOpenExternalLinks(true);
+	connect(this, SIGNAL(sourceChanged(QUrl)), this, SLOT(catchHome(QUrl)));
+	connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(externalLinkClick(QUrl)));
 }
 
 void ScTextBrowser::clear()
@@ -33,68 +26,29 @@
 	setHtml(QString::fromLatin1("<html></html>"));
 }
 
-void ScTextBrowser::setSimpleText(const QString& str)
-{
-	if(!str.isEmpty())
-		setContent(str.toUtf8(), QLatin1String("text/plain; charset=utf-8"));
-	else
-		clear();
-}
-
 void ScTextBrowser::find(const QString& txt, const int& options)
 {
-	findText(txt, QWebPage::FindFlag(options));
-}
-
-void ScTextBrowser::swallowContextMenus(bool b)
-{
-	hideContextMenus=b;
-}
-
-
-QString ScTextBrowser::toPlainText()
-{
-	if(page())
-	{
-		if(page()->mainFrame())
-		{
-			return page()->mainFrame()->toPlainText();
-		}
-	}
-	return QString();
+	find(txt, QTextDocument::FindFlag(options));
 }
 
 void ScTextBrowser::home()
 {
-	setUrl(homeUrl);
+	setSource(homeUrl);
 }
+
 
 void ScTextBrowser::catchHome(QUrl url)
 {
 	if(homeUrl.isEmpty())
 	{
 		homeUrl = url;
-		disconnect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(catchHome(QUrl)));
+		disconnect(this, SIGNAL(sourceChanged(QUrl)), this, SLOT(catchHome(QUrl)));
 	}
 }
 
 void ScTextBrowser::externalLinkClick(QUrl url)
 {
-	UrlLauncher::instance()->launchUrlExt(url, parentWidget());
+	if (url.scheme()=="http")
+		UrlLauncher::instance()->launchUrlExt(url, parentWidget());
 }
 
-bool ScTextBrowser::event(QEvent * e)
-{
-//	bool ret(QWebView::event(e));
-//	qDebug()<<"ScTextBrowser::event"<<e->type()<<ret;
-//	return ret;
-	return QWebView::event(e);
-}
-
-void ScTextBrowser::contextMenuEvent(QContextMenuEvent* e)
-{
-	if (hideContextMenus)
-		page()->swallowContextMenuEvent(e);
-	else
-		QWebView::contextMenuEvent(e);
-}

Modified: trunk/Scribus/scribus/ui/sctextbrowser.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20227&path=/trunk/Scribus/scribus/ui/sctextbrowser.h
==============================================================================
--- trunk/Scribus/scribus/ui/sctextbrowser.h (original)
+++ trunk/Scribus/scribus/ui/sctextbrowser.h Wed Jul  1 23:01:34 2015
@@ -8,10 +8,13 @@
 #define SCTEXTBROWSER_H
 
 #include "scribusapi.h"
+
+#include <QString>
+#include <QTextBrowser>
 #include <QUrl>
-#include <QWebView>
 
-class SCRIBUS_API ScTextBrowser : public QWebView
+
+class SCRIBUS_API ScTextBrowser : public QTextBrowser
 {
 	Q_OBJECT
 
@@ -21,15 +24,7 @@
 		ScTextBrowser( QWidget * parent = 0 );
 
 		void clear();
-		void setSimpleText(const QString& str);
 		void find(const QString& txt, const int& options = 0);
-		void swallowContextMenus(bool b);
-		QString toPlainText();
-
-	protected:
-		bool event(QEvent *e);
-		void contextMenuEvent(QContextMenuEvent *e);
-		bool hideContextMenus;
 
 	public slots:
 		void home();
@@ -38,6 +33,9 @@
 		void catchHome(QUrl url);
 		void externalLinkClick(QUrl url);
 
+	protected:
+		QString m_baseDir;
+
 };
 
 #endif




More information about the scribus-commit mailing list