forked from pool/marble
800 lines
29 KiB
Diff
800 lines
29 KiB
Diff
|
From b42ee5c83d77761ef7d8bf8635662159bc2884bb Mon Sep 17 00:00:00 2001
|
||
|
From: Torsten Rahn <rahn@kde.org>
|
||
|
Date: Wed, 17 Oct 2018 15:21:28 +0200
|
||
|
Subject: Differential Revision: https://phabricator.kde.org/D698
|
||
|
|
||
|
Port to QtWebEngine (finally!)
|
||
|
---
|
||
|
CMakeLists.txt | 6 +-
|
||
|
src/apps/behaim/CMakeLists.txt | 2 +
|
||
|
src/apps/marble-maps/CMakeLists.txt | 2 +
|
||
|
src/lib/marble/CMakeLists.txt | 3 +-
|
||
|
src/lib/marble/LegendWidget.cpp | 2 -
|
||
|
src/lib/marble/LegendWidget.ui | 2 +-
|
||
|
src/lib/marble/MarbleLegendBrowser.cpp | 108 ++++++++++-----------
|
||
|
src/lib/marble/MarbleLegendBrowser.h | 31 ++++--
|
||
|
src/lib/marble/MarbleWebView.cpp | 4 +-
|
||
|
src/lib/marble/MarbleWebView.h | 25 ++++-
|
||
|
src/lib/marble/PopupItem.cpp | 47 ++++-----
|
||
|
src/lib/marble/PopupItem.h | 6 +-
|
||
|
src/lib/marble/TinyWebBrowser.cpp | 23 +++--
|
||
|
src/lib/marble/TinyWebBrowser.h | 10 +-
|
||
|
src/lib/marble/WebPopupWidget.ui | 14 ++-
|
||
|
src/lib/marble/cloudsync/RouteItemDelegate.cpp | 2 +-
|
||
|
.../geodata/handlers/dgml/DgmlIconTagHandler.cpp | 4 +-
|
||
|
17 files changed, 165 insertions(+), 126 deletions(-)
|
||
|
|
||
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||
|
index 2ea05eb..dd13e4c 100644
|
||
|
--- a/CMakeLists.txt
|
||
|
+++ b/CMakeLists.txt
|
||
|
@@ -130,11 +130,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL Android)
|
||
|
else()
|
||
|
find_package(Qt5 ${REQUIRED_QT_VERSION}
|
||
|
COMPONENTS
|
||
|
- WebKit
|
||
|
- WebKitWidgets
|
||
|
+ WebEngine
|
||
|
+ WebEngineWidgets
|
||
|
)
|
||
|
|
||
|
- if ( NOT Qt5WebKitWidgets_FOUND )
|
||
|
+ if ( NOT Qt5WebEngineWidgets_FOUND )
|
||
|
set ( MARBLE_NO_WEBKITWIDGETS TRUE )
|
||
|
endif()
|
||
|
endif()
|
||
|
diff --git a/src/apps/behaim/CMakeLists.txt b/src/apps/behaim/CMakeLists.txt
|
||
|
index b8ad26c..bbed8a9 100644
|
||
|
--- a/src/apps/behaim/CMakeLists.txt
|
||
|
+++ b/src/apps/behaim/CMakeLists.txt
|
||
|
@@ -25,6 +25,8 @@ if (CMAKE_SYSTEM_NAME STREQUAL Android)
|
||
|
Qt5::Positioning
|
||
|
Qt5::AndroidExtras
|
||
|
Qt5::Multimedia
|
||
|
+ Qt5::WebEngineWidgets
|
||
|
+ Qt5::WebEngine
|
||
|
)
|
||
|
else()
|
||
|
set(TARGET marble-behaim)
|
||
|
diff --git a/src/apps/marble-maps/CMakeLists.txt b/src/apps/marble-maps/CMakeLists.txt
|
||
|
index 14be2c0..a52818c 100644
|
||
|
--- a/src/apps/marble-maps/CMakeLists.txt
|
||
|
+++ b/src/apps/marble-maps/CMakeLists.txt
|
||
|
@@ -30,6 +30,8 @@ if (CMAKE_SYSTEM_NAME STREQUAL Android)
|
||
|
Qt5::AndroidExtras
|
||
|
Qt5::Multimedia
|
||
|
Qt5::QuickControls2
|
||
|
+ Qt5::WebEngineWidgets
|
||
|
+ Qt5::WebEngine
|
||
|
)
|
||
|
else()
|
||
|
set(TARGET marble-maps)
|
||
|
diff --git a/src/lib/marble/CMakeLists.txt b/src/lib/marble/CMakeLists.txt
|
||
|
index 3f1afa7..64d0cec 100644
|
||
|
--- a/src/lib/marble/CMakeLists.txt
|
||
|
+++ b/src/lib/marble/CMakeLists.txt
|
||
|
@@ -394,7 +394,8 @@ target_link_libraries(marblewidget
|
||
|
if (NOT MARBLE_NO_WEBKITWIDGETS)
|
||
|
target_link_libraries(marblewidget
|
||
|
LINK_PUBLIC
|
||
|
- Qt5::WebKitWidgets
|
||
|
+ Qt5::WebEngineWidgets
|
||
|
+ Qt5::WebEngine
|
||
|
)
|
||
|
endif ()
|
||
|
if (NOT MARBLE_NO_DBUS)
|
||
|
diff --git a/src/lib/marble/LegendWidget.cpp b/src/lib/marble/LegendWidget.cpp
|
||
|
index c6949ae..8f9c237 100644
|
||
|
--- a/src/lib/marble/LegendWidget.cpp
|
||
|
+++ b/src/lib/marble/LegendWidget.cpp
|
||
|
@@ -22,8 +22,6 @@ using namespace Marble;
|
||
|
#include "ui_LegendWidget.h"
|
||
|
#endif
|
||
|
|
||
|
-#include "MarbleLegendBrowser.h"
|
||
|
-
|
||
|
namespace Marble
|
||
|
{
|
||
|
|
||
|
diff --git a/src/lib/marble/LegendWidget.ui b/src/lib/marble/LegendWidget.ui
|
||
|
index 5a41ffd..14c7633 100644
|
||
|
--- a/src/lib/marble/LegendWidget.ui
|
||
|
+++ b/src/lib/marble/LegendWidget.ui
|
||
|
@@ -28,7 +28,7 @@
|
||
|
<customwidgets>
|
||
|
<customwidget>
|
||
|
<class>MarbleLegendBrowser</class>
|
||
|
- <extends>QWebView</extends>
|
||
|
+ <extends>QWebEngineView</extends>
|
||
|
<header>MarbleLegendBrowser.h</header>
|
||
|
</customwidget>
|
||
|
</customwidgets>
|
||
|
diff --git a/src/lib/marble/MarbleLegendBrowser.cpp b/src/lib/marble/MarbleLegendBrowser.cpp
|
||
|
index c06fe9a..d5a4a87 100644
|
||
|
--- a/src/lib/marble/MarbleLegendBrowser.cpp
|
||
|
+++ b/src/lib/marble/MarbleLegendBrowser.cpp
|
||
|
@@ -24,8 +24,9 @@
|
||
|
#include <QRegExp>
|
||
|
|
||
|
#ifndef MARBLE_NO_WEBKITWIDGETS
|
||
|
-#include <QWebFrame>
|
||
|
-#include <QWebElement>
|
||
|
+#include <QWebEnginePage>
|
||
|
+#include <QWebChannel>
|
||
|
+#include "MarbleWebView.h"
|
||
|
#endif
|
||
|
|
||
|
#include <QTextDocument>
|
||
|
@@ -49,10 +50,11 @@ namespace Marble
|
||
|
class MarbleLegendBrowserPrivate
|
||
|
{
|
||
|
public:
|
||
|
- MarbleModel *m_marbleModel;
|
||
|
+ MarbleModel *m_marbleModel;
|
||
|
QMap<QString, bool> m_checkBoxMap;
|
||
|
QMap<QString, QPixmap> m_symbolMap;
|
||
|
QString m_currentThemeId;
|
||
|
+ MarbleJsWrapper *m_jsWrapper;
|
||
|
};
|
||
|
|
||
|
|
||
|
@@ -64,14 +66,7 @@ MarbleLegendBrowser::MarbleLegendBrowser( QWidget *parent )
|
||
|
d( new MarbleLegendBrowserPrivate )
|
||
|
{
|
||
|
d->m_marbleModel = nullptr;
|
||
|
-
|
||
|
-#ifndef MARBLE_NO_WEBKITWIDGETS
|
||
|
- QWebFrame *frame = page()->mainFrame();
|
||
|
- connect(frame, SIGNAL(javaScriptWindowObjectCleared()),
|
||
|
- this, SLOT(injectCheckBoxChecker()));
|
||
|
- page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
|
||
|
- connect( this, SIGNAL(linkClicked(QUrl)), this, SLOT(openLinkExternally(QUrl)) );
|
||
|
-#endif
|
||
|
+ d->m_jsWrapper = new MarbleJsWrapper(this);
|
||
|
}
|
||
|
|
||
|
MarbleLegendBrowser::~MarbleLegendBrowser()
|
||
|
@@ -92,7 +87,7 @@ void MarbleLegendBrowser::setMarbleModel( MarbleModel *marbleModel )
|
||
|
|
||
|
QSize MarbleLegendBrowser::sizeHint() const
|
||
|
{
|
||
|
- return QSize( 180, 320 );
|
||
|
+ return QSize( 320, 320 );
|
||
|
}
|
||
|
|
||
|
void MarbleLegendBrowser::initTheme()
|
||
|
@@ -153,6 +148,7 @@ void MarbleLegendBrowser::loadLegend()
|
||
|
TemplateDocument doc(finalHtml);
|
||
|
finalHtml = doc.finalText();
|
||
|
|
||
|
+ injectWebChannel(finalHtml);
|
||
|
reverseSupportCheckboxes(finalHtml);
|
||
|
|
||
|
// Generate some parts of the html from the MapTheme <Legend> tag.
|
||
|
@@ -166,18 +162,20 @@ void MarbleLegendBrowser::loadLegend()
|
||
|
QUrl baseUrl = QUrl::fromLocalFile( legendPath );
|
||
|
|
||
|
// Set the html string in the QTextBrowser.
|
||
|
- setHtml(finalHtml, baseUrl);
|
||
|
+ MarbleWebPage * page = new MarbleWebPage(this);
|
||
|
+ connect( page, SIGNAL(linkClicked(QUrl)), this, SLOT(openLinkExternally(QUrl)) );
|
||
|
+ page->setHtml(finalHtml, baseUrl);
|
||
|
+ setPage(page);
|
||
|
|
||
|
- QTextDocument *document = new QTextDocument(page()->mainFrame()->toHtml());
|
||
|
- d->m_marbleModel->setLegend( document );
|
||
|
-#endif
|
||
|
-}
|
||
|
+ QWebChannel *channel = new QWebChannel(page);
|
||
|
+ channel->registerObject(QStringLiteral("Marble"), d->m_jsWrapper);
|
||
|
+ page->setWebChannel(channel);
|
||
|
|
||
|
-void MarbleLegendBrowser::injectCheckBoxChecker()
|
||
|
-{
|
||
|
-#ifndef MARBLE_NO_WEBKITWIDGETS
|
||
|
- QWebFrame *frame = page()->mainFrame();
|
||
|
- frame->addToJavaScriptWindowObject( "Marble", this );
|
||
|
+ if ( d->m_marbleModel ) {
|
||
|
+ page->toHtml([=]( QString document ) {
|
||
|
+ d->m_marbleModel->setLegend( new QTextDocument(document) );
|
||
|
+ });
|
||
|
+ }
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
@@ -194,6 +192,7 @@ bool MarbleLegendBrowser::event( QEvent * event )
|
||
|
{
|
||
|
// "Delayed initialization": legend gets created only
|
||
|
if ( event->type() == QEvent::Show ) {
|
||
|
+ setVisible(true);
|
||
|
loadLegend();
|
||
|
return true;
|
||
|
}
|
||
|
@@ -218,8 +217,7 @@ QString MarbleLegendBrowser::readHtml( const QUrl & name )
|
||
|
void MarbleLegendBrowser::translateHtml( QString & html )
|
||
|
{
|
||
|
// must match string extraction in Messages.sh
|
||
|
- // TODO: html.remove also changes html, is that intended?
|
||
|
- QString s = html.remove(0, html.indexOf(QLatin1String("<body>")));
|
||
|
+ QString s = html;
|
||
|
QRegExp rx( "</?\\w+((\\s+\\w+(\\s*=\\s*(?:\".*\"|'.*'|[^'\">\\s]+))?)+\\s*|\\s*)/?>" );
|
||
|
rx.setMinimal( true );
|
||
|
s.replace( rx, "\n" );
|
||
|
@@ -232,6 +230,18 @@ void MarbleLegendBrowser::translateHtml( QString & html )
|
||
|
html.replace(*i, QCoreApplication::translate("Legends", (*i).toUtf8().constData()));
|
||
|
}
|
||
|
|
||
|
+void MarbleLegendBrowser::injectWebChannel(QString &html)
|
||
|
+{
|
||
|
+ QString webChannelCode = "<script type=\"text/javascript\" src=\"qrc:///qtwebchannel/qwebchannel.js\"></script>";
|
||
|
+ webChannelCode += "<script> document.addEventListener(\"DOMContentLoaded\", function() {"
|
||
|
+ "new QWebChannel(qt.webChannelTransport, function (channel) {"
|
||
|
+ "Marble = channel.objects.Marble;"
|
||
|
+ "});"
|
||
|
+ "}); </script>"
|
||
|
+ "</head>";
|
||
|
+ html.replace("</head>", webChannelCode);
|
||
|
+}
|
||
|
+
|
||
|
void MarbleLegendBrowser::reverseSupportCheckboxes(QString &html)
|
||
|
{
|
||
|
const QString old = "<a href=\"checkbox:cities\"/>";
|
||
|
@@ -241,7 +251,7 @@ void MarbleLegendBrowser::reverseSupportCheckboxes(QString &html)
|
||
|
checked = "checked";
|
||
|
|
||
|
const QString repair = QLatin1String(
|
||
|
- "<input type=\"checkbox\" "
|
||
|
+ "<input style=\"position: relative; top: -4px;\" type=\"checkbox\" "
|
||
|
"onchange=\"Marble.setCheckedProperty(this.name, this.checked);\" ") + checked + QLatin1String(" name=\"cities\"/>");
|
||
|
|
||
|
html.replace(old, repair);
|
||
|
@@ -283,7 +293,7 @@ QString MarbleLegendBrowser::generateSectionsHtml()
|
||
|
if(!section->radio().isEmpty()) {
|
||
|
checkBoxString = QLatin1String(
|
||
|
"<label class=\"section-head\">"
|
||
|
- "<input type=\"radio\" "
|
||
|
+ "<input style=\"position: relative; top: -4px;\" type=\"radio\" "
|
||
|
"onchange=\"Marble.setRadioCheckedProperty(this.value, this.name ,this.checked);\" ") +
|
||
|
checked + QLatin1String(" value=\"") + section->connectTo() + QLatin1String("\" name=\"") + section->radio() + QLatin1String("\" /><span>")
|
||
|
+ heading +
|
||
|
@@ -292,7 +302,7 @@ QString MarbleLegendBrowser::generateSectionsHtml()
|
||
|
} else {
|
||
|
checkBoxString = QLatin1String(
|
||
|
"<label class=\"section-head\">"
|
||
|
- "<input type=\"checkbox\" "
|
||
|
+ "<input style=\"position: relative; top: -4px;\" type=\"checkbox\" "
|
||
|
"onchange=\"Marble.setCheckedProperty(this.name, this.checked);\" ") + checked + QLatin1String(" name=\"") + section->connectTo() + QLatin1String("\" /><span>")
|
||
|
+ heading +
|
||
|
QLatin1String("</span></label>");
|
||
|
@@ -330,20 +340,24 @@ QString MarbleLegendBrowser::generateSectionsHtml()
|
||
|
src = QUrl::fromLocalFile( path ).toString();
|
||
|
styleDiv = QLatin1String("width: ") + QString::number(pixmapWidth) + QLatin1String("px; height: ") +
|
||
|
QString::number(pixmapHeight) + QLatin1String("px;");
|
||
|
+ } else {
|
||
|
+ // Workaround for rendered border around empty images in webkit
|
||
|
+ src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
||
|
}
|
||
|
// NOTICE. There are some pixmaps without image, so we should
|
||
|
// create just a plain rectangle with set color
|
||
|
- else if (item->icon()->color().isValid()) {
|
||
|
+ if (QColor(item->icon()->color()).isValid()) {
|
||
|
const QColor color = item->icon()->color();
|
||
|
styleDiv = QLatin1String("width: ") + QString::number(pixmapWidth) + QLatin1String("px; height: ") +
|
||
|
QString::number(pixmapHeight) + QLatin1String("px; background-color: ") + color.name() + QLatin1Char(';');
|
||
|
}
|
||
|
+ styleDiv += " position: relative; top: -3px;";
|
||
|
const QString text = QCoreApplication::translate("DGML", item->text().toUtf8().constData());
|
||
|
QString html = QLatin1String(
|
||
|
"<div class=\"legend-entry\">"
|
||
|
" <label>") + checkBoxString + QLatin1String(
|
||
|
" <img class=\"image-pic\" src=\"") + src + QLatin1String("\" style=\"") + styleDiv + QLatin1String("\"/>"
|
||
|
- " <span class=\"notation\">") + text + QLatin1String("</span>"
|
||
|
+ " <span class=\"kotation\" >") + text + QLatin1String("</span>"
|
||
|
" </label>"
|
||
|
"</div>");
|
||
|
customLegendString += html;
|
||
|
@@ -356,39 +370,19 @@ QString MarbleLegendBrowser::generateSectionsHtml()
|
||
|
|
||
|
void MarbleLegendBrowser::setCheckedProperty( const QString& name, bool checked )
|
||
|
{
|
||
|
-#ifndef MARBLE_NO_WEBKITWIDGETS
|
||
|
- QWebElement box = page()->mainFrame()->findFirstElement(QLatin1String("input[name=") + name + QLatin1Char(']'));
|
||
|
- if (!box.isNull()) {
|
||
|
- if (checked != d->m_checkBoxMap[name]) {
|
||
|
- d->m_checkBoxMap[name] = checked;
|
||
|
- emit toggledShowProperty( name, checked );
|
||
|
- }
|
||
|
+ if (checked != d->m_checkBoxMap[name]) {
|
||
|
+ d->m_checkBoxMap[name] = checked;
|
||
|
+ emit toggledShowProperty( name, checked );
|
||
|
}
|
||
|
-
|
||
|
- update();
|
||
|
-#endif
|
||
|
}
|
||
|
|
||
|
void MarbleLegendBrowser::setRadioCheckedProperty( const QString& value, const QString& name , bool checked )
|
||
|
{
|
||
|
-#ifndef MARBLE_NO_WEBKITWIDGETS
|
||
|
- QWebElement box = page()->mainFrame()->findFirstElement(QLatin1String("input[value=") + value + QLatin1Char(']'));
|
||
|
- QWebElementCollection boxes = page()->mainFrame()->findAllElements(QLatin1String("input[name=") + name + QLatin1Char(']'));
|
||
|
- QString currentValue;
|
||
|
- for(int i=0; i<boxes.count(); ++i) {
|
||
|
- currentValue = boxes.at(i).attribute("value");
|
||
|
- d->m_checkBoxMap[currentValue]=false;
|
||
|
- emit toggledShowProperty( currentValue, false );
|
||
|
- }
|
||
|
- if (!box.isNull()) {
|
||
|
- if (checked != d->m_checkBoxMap[value]) {
|
||
|
- d->m_checkBoxMap[value] = checked;
|
||
|
- emit toggledShowProperty( value, checked );
|
||
|
- }
|
||
|
- }
|
||
|
-
|
||
|
- update();
|
||
|
-#endif
|
||
|
+ Q_UNUSED(value)
|
||
|
+ if (checked != d->m_checkBoxMap[name]) {
|
||
|
+ d->m_checkBoxMap[name] = checked;
|
||
|
+ emit toggledShowProperty( name, checked );
|
||
|
+ }
|
||
|
}
|
||
|
|
||
|
}
|
||
|
diff --git a/src/lib/marble/MarbleLegendBrowser.h b/src/lib/marble/MarbleLegendBrowser.h
|
||
|
index b77b035..6f568e9 100644
|
||
|
--- a/src/lib/marble/MarbleLegendBrowser.h
|
||
|
+++ b/src/lib/marble/MarbleLegendBrowser.h
|
||
|
@@ -46,19 +46,17 @@ class MARBLE_EXPORT MarbleLegendBrowser : public MarbleWebView
|
||
|
void setMarbleModel( MarbleModel *marbleModel );
|
||
|
QSize sizeHint() const override;
|
||
|
|
||
|
- public Q_SLOTS:
|
||
|
- void setCheckedProperty( const QString& name, bool checked );
|
||
|
- void setRadioCheckedProperty( const QString& value,const QString& name, bool checked );
|
||
|
-
|
||
|
-
|
||
|
Q_SIGNALS:
|
||
|
void toggledShowProperty( const QString&, bool );
|
||
|
void tourLinkClicked( const QString &url );
|
||
|
|
||
|
+ public Q_SLOTS:
|
||
|
+ void setCheckedProperty( const QString& name, bool checked );
|
||
|
+ void setRadioCheckedProperty( const QString& value,const QString& name, bool checked );
|
||
|
+
|
||
|
private Q_SLOTS:
|
||
|
void initTheme();
|
||
|
void loadLegend();
|
||
|
- void injectCheckBoxChecker();
|
||
|
void openLinkExternally( const QUrl &url );
|
||
|
|
||
|
protected:
|
||
|
@@ -68,13 +66,32 @@ class MARBLE_EXPORT MarbleLegendBrowser : public MarbleWebView
|
||
|
static void translateHtml(QString &html);
|
||
|
|
||
|
private:
|
||
|
+ void injectWebChannel( QString &html );
|
||
|
void reverseSupportCheckboxes( QString &html );
|
||
|
-
|
||
|
private:
|
||
|
Q_DISABLE_COPY( MarbleLegendBrowser )
|
||
|
MarbleLegendBrowserPrivate * const d;
|
||
|
};
|
||
|
|
||
|
+class MarbleJsWrapper : public QObject
|
||
|
+{
|
||
|
+ Q_OBJECT
|
||
|
+public:
|
||
|
+ explicit MarbleJsWrapper( MarbleLegendBrowser* parent ) : m_parent(parent) {}
|
||
|
+
|
||
|
+public Q_SLOTS:
|
||
|
+ void setCheckedProperty( const QString& name, bool checked )
|
||
|
+ {
|
||
|
+ m_parent->setCheckedProperty(name, checked);
|
||
|
+ }
|
||
|
+ void setRadioCheckedProperty( const QString& value,const QString& name, bool checked )
|
||
|
+ {
|
||
|
+ m_parent->setRadioCheckedProperty(value, name, checked);
|
||
|
+ }
|
||
|
+private:
|
||
|
+ MarbleLegendBrowser * m_parent;
|
||
|
+};
|
||
|
+
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
diff --git a/src/lib/marble/MarbleWebView.cpp b/src/lib/marble/MarbleWebView.cpp
|
||
|
index 16ec4ea..a4982f0 100644
|
||
|
--- a/src/lib/marble/MarbleWebView.cpp
|
||
|
+++ b/src/lib/marble/MarbleWebView.cpp
|
||
|
@@ -16,7 +16,7 @@
|
||
|
#include <QClipboard>
|
||
|
|
||
|
MarbleWebView::MarbleWebView(QWidget *parent) :
|
||
|
- QWebView(parent),
|
||
|
+ QWebEngineView(parent),
|
||
|
m_contextMenu(new QMenu(this)),
|
||
|
m_copyAction(new QAction(this))
|
||
|
{
|
||
|
@@ -52,7 +52,7 @@ void MarbleWebView::keyPressEvent(QKeyEvent *event)
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
- QWebView::keyPressEvent(event);
|
||
|
+ QWebEngineView::keyPressEvent(event);
|
||
|
}
|
||
|
|
||
|
#include "moc_MarbleWebView.cpp"
|
||
|
diff --git a/src/lib/marble/MarbleWebView.h b/src/lib/marble/MarbleWebView.h
|
||
|
index 8c84b7b..7ae71fc 100644
|
||
|
--- a/src/lib/marble/MarbleWebView.h
|
||
|
+++ b/src/lib/marble/MarbleWebView.h
|
||
|
@@ -11,11 +11,32 @@
|
||
|
#ifndef MARBLEWEBVIEW_H
|
||
|
#define MARBLEWEBVIEW_H
|
||
|
|
||
|
-#include <QWebView>
|
||
|
+#include <QWebEngineView>
|
||
|
+#include <QWebEnginePage>
|
||
|
+#include <QPaintEvent>
|
||
|
|
||
|
#include "marble_export.h"
|
||
|
|
||
|
-class MARBLE_EXPORT MarbleWebView : public QWebView
|
||
|
+class MARBLE_EXPORT MarbleWebPage : public QWebEnginePage
|
||
|
+{
|
||
|
+ Q_OBJECT
|
||
|
+public:
|
||
|
+ explicit MarbleWebPage(QObject *parent = nullptr) : QWebEnginePage(parent){}
|
||
|
+
|
||
|
+Q_SIGNALS:
|
||
|
+ void linkClicked(const QUrl & url);
|
||
|
+protected:
|
||
|
+ bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override {
|
||
|
+ Q_UNUSED(isMainFrame)
|
||
|
+ if (type == QWebEnginePage::NavigationTypeLinkClicked) {
|
||
|
+ emit linkClicked(url);
|
||
|
+ return false;
|
||
|
+ }
|
||
|
+ return true;
|
||
|
+ }
|
||
|
+};
|
||
|
+
|
||
|
+class MARBLE_EXPORT MarbleWebView : public QWebEngineView
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
public:
|
||
|
diff --git a/src/lib/marble/PopupItem.cpp b/src/lib/marble/PopupItem.cpp
|
||
|
index 2415f88..16b6949 100644
|
||
|
--- a/src/lib/marble/PopupItem.cpp
|
||
|
+++ b/src/lib/marble/PopupItem.cpp
|
||
|
@@ -17,11 +17,13 @@
|
||
|
#ifdef MARBLE_NO_WEBKITWIDGETS
|
||
|
#include "NullMarbleWebView.h"
|
||
|
#else
|
||
|
-#include <QWebView>
|
||
|
-#include <QWebHistory>
|
||
|
+#include <QWebEngineView>
|
||
|
+#include <QWebEngineHistory>
|
||
|
+#include <QWebEngineSettings>
|
||
|
#include "MarbleWebView.h"
|
||
|
#endif
|
||
|
|
||
|
+#include <QDebug>
|
||
|
#include <QPointer>
|
||
|
#include <QPrinter>
|
||
|
#include <QPrintDialog>
|
||
|
@@ -38,17 +40,16 @@ namespace Marble
|
||
|
PopupItem::PopupItem( QObject* parent ) :
|
||
|
QObject( parent ),
|
||
|
BillboardGraphicsItem(),
|
||
|
- m_widget( new QWidget ),
|
||
|
+ m_widget( new QWidget() ),
|
||
|
m_textColor( QColor(Qt::black) ),
|
||
|
m_backColor( QColor(Qt::white) ),
|
||
|
m_needMouseRelease(false)
|
||
|
{
|
||
|
- setCacheMode( ItemCoordinateCache );
|
||
|
+// setCacheMode( ItemCoordinateCache );
|
||
|
setVisible( false );
|
||
|
setSize( QSizeF( 300.0, 320.0 ) );
|
||
|
|
||
|
m_ui.setupUi( m_widget );
|
||
|
-
|
||
|
m_ui.goBackButton->setVisible( false );
|
||
|
connect( m_ui.goBackButton, SIGNAL(clicked()), this, SLOT(goBack()) );
|
||
|
|
||
|
@@ -59,13 +60,15 @@ PopupItem::PopupItem( QObject* parent ) :
|
||
|
connect( m_ui.printButton, SIGNAL(clicked()), this, SLOT(printContent()) );
|
||
|
#endif
|
||
|
|
||
|
+ m_widget->setVisible(true);
|
||
|
+ m_widget->setAttribute(Qt::WA_DontShowOnScreen);
|
||
|
m_widget->setAttribute( Qt::WA_NoSystemBackground, true );
|
||
|
QPalette palette = m_ui.webView->palette();
|
||
|
palette.setBrush(QPalette::Base, Qt::transparent);
|
||
|
- m_ui.webView->setPalette(palette);
|
||
|
#ifndef MARBLE_NO_WEBKITWIDGETS
|
||
|
- m_ui.webView->page()->setPalette(palette);
|
||
|
- m_ui.webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
|
||
|
+ m_ui.webView->setPalette(palette);
|
||
|
+ m_ui.webView->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
|
||
|
+ m_ui.webView->page()->settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
|
||
|
#endif
|
||
|
m_ui.webView->setAttribute(Qt::WA_OpaquePaintEvent, false);
|
||
|
m_ui.webView->setUrl( QUrl( "about:blank" ) );
|
||
|
@@ -73,11 +76,10 @@ PopupItem::PopupItem( QObject* parent ) :
|
||
|
connect( m_ui.hideButton, SIGNAL(clicked()), this, SIGNAL(hide()) );
|
||
|
|
||
|
#ifndef MARBLE_NO_WEBKITWIDGETS
|
||
|
- connect( m_ui.webView, SIGNAL(titleChanged(QString)), m_ui.titleText, SLOT(setText(QString)) );
|
||
|
- connect( m_ui.webView, SIGNAL(urlChanged(QUrl)), this, SLOT(updateBackButton()) );
|
||
|
+ connect( m_ui.webView->page(), SIGNAL(titleChanged(QString)), m_ui.titleText, SLOT(setText(QString)) );
|
||
|
+ connect( m_ui.webView->page(), SIGNAL(urlChanged(QUrl)), this, SLOT(updateBackButton()) );
|
||
|
// Update the popupitem on changes while loading the webpage
|
||
|
- connect( m_ui.webView->page(), SIGNAL(repaintRequested(QRect)), this, SLOT(requestUpdate()) );
|
||
|
- connect(m_ui.webView->page(), SIGNAL(linkClicked(QUrl)), this, SLOT(openUrl(QUrl)));
|
||
|
+ connect(m_ui.webView, SIGNAL(loadFinished(bool)), this, SLOT(requestUpdate()));
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
@@ -99,13 +101,11 @@ void PopupItem::setPrintButtonVisible( bool display )
|
||
|
void PopupItem::setUrl( const QUrl &url )
|
||
|
{
|
||
|
m_ui.webView->setUrl( url );
|
||
|
- setVisible( true );
|
||
|
|
||
|
QPalette palette = m_ui.webView->palette();
|
||
|
palette.setBrush(QPalette::Base, Qt::transparent);
|
||
|
- m_ui.webView->setPalette(palette);
|
||
|
#ifndef MARBLE_NO_WEBKITWIDGETS
|
||
|
- m_ui.webView->page()->setPalette(palette);
|
||
|
+ m_ui.webView->setPalette(palette);
|
||
|
#endif
|
||
|
m_ui.webView->setAttribute(Qt::WA_OpaquePaintEvent, false);
|
||
|
|
||
|
@@ -181,7 +181,7 @@ void PopupItem::paint( QPainter *painter )
|
||
|
image = pixmap("marble/webpopup/arrow2_topleft");
|
||
|
painter->drawPixmap( 0, size().height() / 2, image );
|
||
|
}
|
||
|
- m_widget->render( painter, QPoint( image.width() - 3, 0 ), QRegion() );
|
||
|
+ m_widget->render( painter, QPoint( image.width() - 3, 0 ) );
|
||
|
} else if ( alignment() & Qt::AlignLeft ) {
|
||
|
popupRect.setRect( -10, -10,
|
||
|
size().width() - ( image.width() - 3 ),
|
||
|
@@ -359,7 +359,7 @@ void PopupItem::printContent() const
|
||
|
QPrinter printer;
|
||
|
QPointer<QPrintDialog> dialog = new QPrintDialog(&printer);
|
||
|
if (dialog->exec() == QPrintDialog::Accepted) {
|
||
|
- m_ui.webView->print(&printer);
|
||
|
+ m_ui.webView->page()->print(&printer, [=](bool){});
|
||
|
}
|
||
|
delete dialog;
|
||
|
#endif
|
||
|
@@ -369,10 +369,11 @@ void PopupItem::printContent() const
|
||
|
void PopupItem::updateBackButton()
|
||
|
{
|
||
|
#ifndef MARBLE_NO_WEBKITWIDGETS
|
||
|
- bool const hasHistory = m_ui.webView->history()->count() > 1;
|
||
|
- bool const previousIsHtml = !m_content.isEmpty() && m_ui.webView->history()->currentItemIndex() == 1;
|
||
|
- bool const atStart = m_ui.webView->history()->currentItemIndex() <= 1;
|
||
|
- bool const currentIsHtml = m_ui.webView->url() == QUrl( "about:blank" );
|
||
|
+ bool const hasHistory = m_ui.webView->page()->history()->count() > 1;
|
||
|
+ bool const previousIsHtml = !m_content.isEmpty() && m_ui.webView->page()->history()->currentItemIndex() == 1;
|
||
|
+ bool const atStart = m_ui.webView->page()->history()->currentItemIndex() <= 1;
|
||
|
+ bool const currentIsHtml = m_ui.webView->page()->url() == QUrl( "about:blank" );
|
||
|
+
|
||
|
m_ui.goBackButton->setVisible( hasHistory && !currentIsHtml && ( previousIsHtml || !atStart ) );
|
||
|
#endif
|
||
|
}
|
||
|
@@ -380,8 +381,8 @@ void PopupItem::updateBackButton()
|
||
|
void PopupItem::goBack()
|
||
|
{
|
||
|
#ifndef MARBLE_NO_WEBKITWIDGETS
|
||
|
- if ( m_ui.webView->history()->currentItemIndex() == 1 && !m_content.isEmpty() ) {
|
||
|
- m_ui.webView->setHtml( m_content, m_baseUrl );
|
||
|
+ if ( m_ui.webView->page()->history()->currentItemIndex() == 1 && !m_content.isEmpty() ) {
|
||
|
+ m_ui.webView->page()->setHtml( m_content, m_baseUrl );
|
||
|
} else {
|
||
|
m_ui.webView->back();
|
||
|
}
|
||
|
diff --git a/src/lib/marble/PopupItem.h b/src/lib/marble/PopupItem.h
|
||
|
index bf2f209..220dd3d 100644
|
||
|
--- a/src/lib/marble/PopupItem.h
|
||
|
+++ b/src/lib/marble/PopupItem.h
|
||
|
@@ -35,7 +35,7 @@ namespace Marble
|
||
|
* This class represents graphics item for information bubble.
|
||
|
* Mostly used by @see MapInfoDialog.
|
||
|
*
|
||
|
- * It has nice API for QWebView and methods for styling it.
|
||
|
+ * It has nice API for QWebEngineView and methods for styling it.
|
||
|
*
|
||
|
*/
|
||
|
class PopupItem : public QObject, public BillboardGraphicsItem
|
||
|
@@ -49,7 +49,7 @@ public:
|
||
|
* @brief Print button visibility indicator
|
||
|
*
|
||
|
* There is a button in the header of item with print icon.
|
||
|
- * It used to print the content of QWebView inside.
|
||
|
+ * It used to print the content of QWebEngineView inside.
|
||
|
* This method indicates visibility of this button.
|
||
|
*
|
||
|
* @see setPrintButtonVisible();
|
||
|
@@ -62,7 +62,7 @@ public:
|
||
|
* @brief Sets visibility of the print button
|
||
|
*
|
||
|
* There is a button in the header of item with print icon.
|
||
|
- * It used to print the content of QWebView inside
|
||
|
+ * It used to print the content of QWebEngineView inside
|
||
|
*
|
||
|
* This method sets visibility of this button.
|
||
|
*
|
||
|
diff --git a/src/lib/marble/TinyWebBrowser.cpp b/src/lib/marble/TinyWebBrowser.cpp
|
||
|
index dbce339..0220f38 100644
|
||
|
--- a/src/lib/marble/TinyWebBrowser.cpp
|
||
|
+++ b/src/lib/marble/TinyWebBrowser.cpp
|
||
|
@@ -26,6 +26,7 @@
|
||
|
#include "MarbleDebug.h"
|
||
|
#include "MarbleDirs.h"
|
||
|
#include "MarbleLocale.h"
|
||
|
+#include "MarbleWebView.h"
|
||
|
|
||
|
namespace Marble
|
||
|
{
|
||
|
@@ -42,20 +43,22 @@ static QString guessWikipediaDomain()
|
||
|
}
|
||
|
|
||
|
TinyWebBrowser::TinyWebBrowser( QWidget* parent )
|
||
|
- : QWebView( parent ),
|
||
|
+ : QWebEngineView( parent ),
|
||
|
d( nullptr )
|
||
|
{
|
||
|
+ MarbleWebPage * page = new MarbleWebPage();
|
||
|
+ setPage(page);
|
||
|
+
|
||
|
connect( this, SIGNAL(statusBarMessage(QString)),
|
||
|
this, SIGNAL(statusMessage(QString)) );
|
||
|
|
||
|
- page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
|
||
|
- connect( this, SIGNAL(linkClicked(QUrl)),
|
||
|
+ connect( page, SIGNAL(linkClicked(QUrl)),
|
||
|
this, SLOT(openExternalLink(QUrl)) );
|
||
|
connect( this, SIGNAL(titleChanged(QString)),
|
||
|
this, SLOT(setWindowTitle(QString)) );
|
||
|
|
||
|
- pageAction( QWebPage::OpenLinkInNewWindow )->setEnabled( false );
|
||
|
- pageAction( QWebPage::OpenLinkInNewWindow )->setVisible( false );
|
||
|
+ pageAction( QWebEnginePage::OpenLinkInNewWindow )->setEnabled( false );
|
||
|
+ pageAction( QWebEnginePage::OpenLinkInNewWindow )->setVisible( false );
|
||
|
}
|
||
|
|
||
|
TinyWebBrowser::~TinyWebBrowser()
|
||
|
@@ -79,19 +82,15 @@ void TinyWebBrowser::print()
|
||
|
|
||
|
QPointer<QPrintDialog> dlg = new QPrintDialog( &printer, this );
|
||
|
if ( dlg->exec() )
|
||
|
- QWebView::print( &printer );
|
||
|
+ page()->print( &printer, [=](bool){} );
|
||
|
delete dlg;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
-QWebView *TinyWebBrowser::createWindow( QWebPage::WebWindowType type )
|
||
|
+QWebEngineView *TinyWebBrowser::createWindow( QWebEnginePage::WebWindowType type )
|
||
|
{
|
||
|
+ Q_UNUSED(type)
|
||
|
TinyWebBrowser *view = new TinyWebBrowser( this );
|
||
|
-
|
||
|
- if ( type == QWebPage::WebModalDialog ) {
|
||
|
- view->setWindowModality( Qt::WindowModal );
|
||
|
- }
|
||
|
-
|
||
|
return view;
|
||
|
}
|
||
|
|
||
|
diff --git a/src/lib/marble/TinyWebBrowser.h b/src/lib/marble/TinyWebBrowser.h
|
||
|
index c6103b2..0475b23 100644
|
||
|
--- a/src/lib/marble/TinyWebBrowser.h
|
||
|
+++ b/src/lib/marble/TinyWebBrowser.h
|
||
|
@@ -13,7 +13,7 @@
|
||
|
#define MARBLE_TINYWEBBROWSER_H
|
||
|
|
||
|
// Qt
|
||
|
-#include <QWebView>
|
||
|
+#include <QWebEngineView>
|
||
|
|
||
|
// Marble
|
||
|
#include "marble_export.h"
|
||
|
@@ -27,12 +27,12 @@ namespace Marble
|
||
|
class TinyWebBrowserPrivate;
|
||
|
|
||
|
/**
|
||
|
- * This class provides a tiny web browser based on QWebView (WebKit).
|
||
|
- * It is different from QWebView as it has the button "Open in new Window"
|
||
|
+ * This class provides a tiny web browser based on QWebEngineView (WebKit).
|
||
|
+ * It is different from QWebEngineView as it has the button "Open in new Window"
|
||
|
* disabled per default and instead opens every link in the default web
|
||
|
* browser of the user.
|
||
|
*/
|
||
|
-class MARBLE_EXPORT TinyWebBrowser : public QWebView
|
||
|
+class MARBLE_EXPORT TinyWebBrowser : public QWebEngineView
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
|
||
|
@@ -48,7 +48,7 @@ class MARBLE_EXPORT TinyWebBrowser : public QWebView
|
||
|
void statusMessage( const QString& );
|
||
|
|
||
|
protected:
|
||
|
- QWebView *createWindow( QWebPage::WebWindowType type ) override;
|
||
|
+ QWebEngineView *createWindow( QWebEnginePage::WebWindowType type ) override;
|
||
|
|
||
|
private Q_SLOTS:
|
||
|
void openExternalLink( const QUrl& );
|
||
|
diff --git a/src/lib/marble/WebPopupWidget.ui b/src/lib/marble/WebPopupWidget.ui
|
||
|
index 8cf7103..e129b73 100644
|
||
|
--- a/src/lib/marble/WebPopupWidget.ui
|
||
|
+++ b/src/lib/marble/WebPopupWidget.ui
|
||
|
@@ -18,9 +18,6 @@
|
||
|
</property>
|
||
|
</widget>
|
||
|
</item>
|
||
|
- <item row="1" column="0" colspan="4">
|
||
|
- <widget class="MarbleWebView" name="webView" native="true"/>
|
||
|
- </item>
|
||
|
<item row="0" column="0">
|
||
|
<widget class="QToolButton" name="goBackButton">
|
||
|
<property name="text">
|
||
|
@@ -58,11 +55,20 @@
|
||
|
<iconset resource="libmarble.qrc">
|
||
|
<normaloff>:/marble/webpopup/icon-remove.png</normaloff>:/marble/webpopup/icon-remove.png</iconset>
|
||
|
</property>
|
||
|
+ <property name="popupMode">
|
||
|
+ <enum>QToolButton::DelayedPopup</enum>
|
||
|
+ </property>
|
||
|
<property name="autoRaise">
|
||
|
<bool>true</bool>
|
||
|
</property>
|
||
|
- </widget>
|
||
|
+ <property name="arrowType">
|
||
|
+ <enum>Qt::NoArrow</enum>
|
||
|
+ </property>
|
||
|
+ </widget>
|
||
|
</item>
|
||
|
+ <item row="1" column="0" colspan="4">
|
||
|
+ <widget class="MarbleWebView" name="webView" native="true"/>
|
||
|
+ </item>
|
||
|
</layout>
|
||
|
</widget>
|
||
|
<customwidgets>
|
||
|
diff --git a/src/lib/marble/cloudsync/RouteItemDelegate.cpp b/src/lib/marble/cloudsync/RouteItemDelegate.cpp
|
||
|
index 98ad8bb..586ba22 100644
|
||
|
--- a/src/lib/marble/cloudsync/RouteItemDelegate.cpp
|
||
|
+++ b/src/lib/marble/cloudsync/RouteItemDelegate.cpp
|
||
|
@@ -5,7 +5,7 @@
|
||
|
#ifdef MARBLE_NO_WEBKITWIDGETS
|
||
|
#include <QWidget>
|
||
|
#else
|
||
|
-#include <QWebView>
|
||
|
+#include <QWebEngineView>
|
||
|
#endif
|
||
|
|
||
|
#include <QApplication>
|
||
|
diff --git a/src/lib/marble/geodata/handlers/dgml/DgmlIconTagHandler.cpp b/src/lib/marble/geodata/handlers/dgml/DgmlIconTagHandler.cpp
|
||
|
index d0c49ec..e26bf72 100644
|
||
|
--- a/src/lib/marble/geodata/handlers/dgml/DgmlIconTagHandler.cpp
|
||
|
+++ b/src/lib/marble/geodata/handlers/dgml/DgmlIconTagHandler.cpp
|
||
|
@@ -47,9 +47,7 @@ GeoNode* DgmlIconTagHandler::parse(GeoParser& parser) const
|
||
|
QString pixmapRelativePath = parser.attribute(dgmlAttr_pixmap).trimmed();
|
||
|
|
||
|
QColor color;
|
||
|
- if (pixmapRelativePath.isEmpty()) {
|
||
|
- color.setNamedColor(parser.attribute(dgmlAttr_color).trimmed());
|
||
|
- }
|
||
|
+ color.setNamedColor(parser.attribute(dgmlAttr_color).trimmed());
|
||
|
|
||
|
GeoSceneIcon *icon = nullptr;
|
||
|
|
||
|
--
|
||
|
cgit v0.11.2
|
||
|
|