resolve relative URLs when navigating in nwe

This commit is contained in:
Martin Rotter 2022-04-21 08:25:28 +02:00
parent e0174e9ddc
commit 3ccce27dd5
2 changed files with 9 additions and 13 deletions

View File

@ -26,7 +26,7 @@
<url type="donation">https://github.com/sponsors/martinrotter</url>
<content_rating type="oars-1.1" />
<releases>
<release version="4.2.1" date="2022-04-20"/>
<release version="4.2.1" date="2022-04-21"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -364,11 +364,11 @@ void TextBrowserViewer::reloadWithImages() {
}
}
auto scrolled = verticalScrollBar()->value();
auto scrolled = verticalScrollBarPosition();
setHtmlPrivate(html(), m_currentUrl);
verticalScrollBar()->setValue(scrolled);
setVerticalScrollBarPosition(scrolled);
}
void TextBrowserViewer::openLinkInExternalBrowser() {
@ -397,22 +397,18 @@ void TextBrowserViewer::downloadLink() {
void TextBrowserViewer::onAnchorClicked(const QUrl& url) {
if (!url.isEmpty()) {
const QUrl resolved_url = (m_currentUrl.isValid() && url.isRelative()) ? m_currentUrl.resolved(url) : url;
bool open_externally_now =
qApp->settings()->value(GROUP(Browser), SETTING(Browser::OpenLinksInExternalBrowserRightAway)).toBool();
if (open_externally_now) {
qApp->web()->openUrlInExternalBrowser(url.toString());
qApp->web()->openUrlInExternalBrowser(resolved_url.toString());
}
else {
setUrl(url);
setUrl(resolved_url);
}
}
else {
MsgBox::show(qApp->mainFormWidget(),
QMessageBox::Warning,
tr("Incorrect link"),
tr("Selected hyperlink is invalid."));
}
}
void TextBrowserViewer::setHtml(const QString& html, const QUrl& base_url) {
@ -456,12 +452,12 @@ QVariant TextBrowserDocument::loadResource(int type, const QUrl& name) {
m_resourcesForHtml.append(name);
}
return QTextDocument::loadResource(type, name);
return {};
}
else if (m_loadedResources.contains(name)) {
return QImage::fromData(m_loadedResources.value(name));
}
else {
return QTextDocument::loadResource(type, name);
return {};
}
}