diff --git a/src/librssguard/gui/litehtml/litehtmlviewer.cpp b/src/librssguard/gui/litehtml/litehtmlviewer.cpp
index a277e1e58..540f3a623 100755
--- a/src/librssguard/gui/litehtml/litehtmlviewer.cpp
+++ b/src/librssguard/gui/litehtml/litehtmlviewer.cpp
@@ -29,7 +29,7 @@ LiteHtmlViewer::LiteHtmlViewer(QWidget* parent) : QLiteHtmlWidget(parent), m_dow
return handleResource(url);
});
- connect(this, &LiteHtmlViewer::linkClicked, this, &LiteHtmlViewer::setUrl);
+ connect(this, &LiteHtmlViewer::linkClicked, this, &LiteHtmlViewer::onLinkClicked);
connect(this, &LiteHtmlViewer::copyAvailable, this, &LiteHtmlViewer::selectedTextChanged);
connect(this, &LiteHtmlViewer::contextMenuRequested, this, &LiteHtmlViewer::showContextMenu);
}
@@ -50,8 +50,6 @@ void LiteHtmlViewer::bindToBrowser(WebBrowser* browser) {
// right away.
browser->m_actionStop->setEnabled(false);
- connect(this, &LiteHtmlViewer::zoomFactorChanged, browser, &WebBrowser::onZoomFactorChanged);
-
connect(this, &LiteHtmlViewer::linkHighlighted, browser, [browser](const QUrl& url) {
browser->onLinkHovered(url.toString());
});
@@ -60,6 +58,11 @@ void LiteHtmlViewer::bindToBrowser(WebBrowser* browser) {
connect(this, &LiteHtmlViewer::loadStarted, browser, &WebBrowser::onLoadingStarted);
connect(this, &LiteHtmlViewer::loadProgress, browser, &WebBrowser::onLoadingProgress);
connect(this, &LiteHtmlViewer::loadFinished, browser, &WebBrowser::onLoadingFinished);
+ connect(this, &LiteHtmlViewer::newWindowRequested, browser, &WebBrowser::newWindowRequested);
+
+ // TODO: add "Open in new tab" to context menu.
+ //
+ //connect(page(), &WebEnginePage::windowCloseRequested, browser, &WebBrowser::windowCloseRequested);
}
void LiteHtmlViewer::findText(const QString& text, bool backwards) {
@@ -255,6 +258,18 @@ void LiteHtmlViewer::selectedTextChanged(bool available) {
}
}
+void LiteHtmlViewer::onLinkClicked(const QUrl& link) {
+ if ((QApplication::queryKeyboardModifiers() & Qt::KeyboardModifier::ControlModifier) > 0) {
+ LiteHtmlViewer* viewer = new LiteHtmlViewer(this);
+ emit newWindowRequested(viewer);
+
+ viewer->setUrl(link);
+ }
+ else {
+ setUrl(link);
+ }
+}
+
void LiteHtmlViewer::showContextMenu(const QPoint& pos, const QUrl& url) {
if (m_contextMenu.isNull()) {
m_contextMenu.reset(new QMenu("Context menu for web browser", this));
diff --git a/src/librssguard/gui/litehtml/litehtmlviewer.h b/src/librssguard/gui/litehtml/litehtmlviewer.h
index ad62568ab..d22b52e1a 100755
--- a/src/librssguard/gui/litehtml/litehtmlviewer.h
+++ b/src/librssguard/gui/litehtml/litehtmlviewer.h
@@ -39,15 +39,16 @@ class LiteHtmlViewer : public QLiteHtmlWidget, public WebViewer {
private slots:
void selectedTextChanged(bool available);
+ void onLinkClicked(const QUrl& link);
void showContextMenu(const QPoint& pos, const QUrl& url);
signals:
- void zoomFactorChanged();
void titleChanged(const QString& new_title);
void urlChanged(const QUrl& url);
void loadStarted();
void loadProgress(int progress);
void loadFinished(bool success);
+ void newWindowRequested(WebViewer* viewer);
protected:
virtual void keyPressEvent(QKeyEvent* event);
diff --git a/src/librssguard/gui/messagepreviewer.cpp b/src/librssguard/gui/messagepreviewer.cpp
index a5fa07e59..341244d6c 100644
--- a/src/librssguard/gui/messagepreviewer.cpp
+++ b/src/librssguard/gui/messagepreviewer.cpp
@@ -42,7 +42,7 @@ void MessagePreviewer::createConnections() {
MessagePreviewer::MessagePreviewer(QWidget* parent)
: QWidget(parent), m_layout(new QGridLayout(this)), m_toolBar(new QToolBar(this)),
m_separator(nullptr), m_btnLabels(QList>()) {
- m_txtMessage = new WebBrowser(this);
+ m_txtMessage = new WebBrowser(nullptr, this);
m_toolBar->setOrientation(Qt::Orientation::Vertical);
diff --git a/src/librssguard/gui/tabwidget.cpp b/src/librssguard/gui/tabwidget.cpp
index e31b7b5e1..89c975399 100644
--- a/src/librssguard/gui/tabwidget.cpp
+++ b/src/librssguard/gui/tabwidget.cpp
@@ -186,7 +186,7 @@ void TabWidget::closeCurrentTab() {
}
int TabWidget::addNewspaperView(RootItem* root, const QList& messages) {
- WebBrowser* browser = new WebBrowser(this);
+ WebBrowser* browser = new WebBrowser(nullptr, this);
int index = addTab(browser,
qApp->icons()->fromTheme(QSL("format-justify-fill")),
tr("Newspaper view"),
@@ -211,12 +211,10 @@ int TabWidget::addLinkedBrowser(const QUrl& initial_url) {
}
int TabWidget::addLinkedBrowser(const QString& initial_url) {
- return addLinkedBrowser(QUrl(initial_url));
+ return addLinkedBrowser(QUrl::fromUserInput(initial_url));
}
-int TabWidget::addBrowser(bool move_after_current, bool make_active, const QUrl& initial_url) {
- // Create new WebBrowser.
- WebBrowser* browser = new WebBrowser(this);
+int TabWidget::addBrowser(bool move_after_current, bool make_active, WebBrowser* browser) {
int final_index;
QString browser_tab_name = tr("Web browser");
@@ -243,11 +241,6 @@ int TabWidget::addBrowser(bool move_after_current, bool make_active, const QUrl&
// Setup the tab index.
browser->setIndex(final_index);
- // Load initial web page if desired.
- if (initial_url.isValid()) {
- browser->loadUrl(initial_url);
- }
-
// Make new web browser active if desired.
if (make_active) {
setCurrentIndex(final_index);
@@ -257,6 +250,19 @@ int TabWidget::addBrowser(bool move_after_current, bool make_active, const QUrl&
return final_index;
}
+int TabWidget::addBrowser(bool move_after_current, bool make_active, const QUrl& initial_url) {
+ // Create new WebBrowser.
+ WebBrowser* browser = new WebBrowser(nullptr, this);
+ int index = addBrowser(move_after_current, make_active, browser);
+
+ // Load initial web page if desired.
+ if (initial_url.isValid()) {
+ browser->loadUrl(initial_url);
+ }
+
+ return index;
+}
+
void TabWidget::gotoNextTab() {
if (currentIndex() == count() - 1) {
setCurrentIndex(0);
diff --git a/src/librssguard/gui/tabwidget.h b/src/librssguard/gui/tabwidget.h
index 6daa61201..c4e1a5529 100644
--- a/src/librssguard/gui/tabwidget.h
+++ b/src/librssguard/gui/tabwidget.h
@@ -80,6 +80,7 @@ class TabWidget : public QTabWidget {
// General method for adding WebBrowsers.
int addBrowser(bool move_after_current, bool make_active, const QUrl& initial_url = QUrl());
+ int addBrowser(bool move_after_current, bool make_active, WebBrowser* browser);
void gotoNextTab();
void gotoPreviousTab();
diff --git a/src/librssguard/gui/webbrowser.cpp b/src/librssguard/gui/webbrowser.cpp
index 4f7310816..7b925ebdd 100644
--- a/src/librssguard/gui/webbrowser.cpp
+++ b/src/librssguard/gui/webbrowser.cpp
@@ -3,11 +3,13 @@
#include "gui/webbrowser.h"
#include "database/databasequeries.h"
+#include "gui/dialogs/formmain.h"
#include "gui/litehtml/litehtmlviewer.h" // QLiteHtml-based web browsing.
#include "gui/messagebox.h"
#include "gui/reusable/discoverfeedsbutton.h"
#include "gui/reusable/locationlineedit.h"
#include "gui/reusable/searchtextwidget.h"
+#include "gui/tabwidget.h"
#include "gui/webviewer.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
@@ -27,9 +29,10 @@
#include
#include
-WebBrowser::WebBrowser(QWidget* parent) : TabContent(parent),
+WebBrowser::WebBrowser(WebViewer* viewer, QWidget* parent) : TabContent(parent),
m_layout(new QVBoxLayout(this)),
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
+ m_webView(viewer),
m_searchWidget(new SearchTextWidget(this)),
m_txtLocation(new LocationLineEdit(this)),
m_btnDiscoverFeeds(new DiscoverFeedsButton(this)),
@@ -39,17 +42,18 @@ WebBrowser::WebBrowser(QWidget* parent) : TabContent(parent),
m_actionReadabilePage(new QAction(qApp->icons()->fromTheme(QSL("text-html")),
tr("View website in reader mode"),
this)) {
-
+ if (m_webView == nullptr) {
#if !defined(USE_WEBENGINE)
- m_webView = new LiteHtmlViewer(this),
+ m_webView = new LiteHtmlViewer(this),
#else
- if (qApp->forcedNoWebEngine()) {
- m_webView = new LiteHtmlViewer(this);
- }
- else {
- m_webView = new WebEngineViewer(this);
- }
+ if (qApp->forcedNoWebEngine()) {
+ m_webView = new LiteHtmlViewer(this);
+ }
+ else {
+ m_webView = new WebEngineViewer(this);
+ }
#endif
+ }
// Initialize the components and layout.
m_webView->bindToBrowser(this);
@@ -229,7 +233,7 @@ void WebBrowser::onTitleChanged(const QString& new_title) {
emit titleChanged(m_index, tr("No title"));
}
else {
- emit titleChanged(m_index, new_title);
+ emit titleChanged(m_index, new_title.simplified());
}
}
@@ -245,6 +249,12 @@ void WebBrowser::onLinkHovered(const QString& url) {
{ false, false, true });
}
+void WebBrowser::newWindowRequested(WebViewer* viewer) {
+ WebBrowser* browser = new WebBrowser(viewer, this);
+
+ qApp->mainForm()->tabWidget()->addBrowser(false, false, browser);
+}
+
void WebBrowser::setReadabledHtml(const QString& better_html) {
if (!better_html.isEmpty()) {
m_webView->setHtml(better_html, m_webView->url());
diff --git a/src/librssguard/gui/webbrowser.h b/src/librssguard/gui/webbrowser.h
index b6e402846..81a294129 100644
--- a/src/librssguard/gui/webbrowser.h
+++ b/src/librssguard/gui/webbrowser.h
@@ -30,19 +30,19 @@ class WebBrowser : public TabContent {
friend class LiteHtmlViewer;
public:
- explicit WebBrowser(QWidget* parent = nullptr);
+ explicit WebBrowser(WebViewer* viewer = nullptr, QWidget* parent = nullptr);
virtual ~WebBrowser();
virtual WebBrowser* webBrowser() const;
WebViewer* viewer() const;
+ void reloadFontSettings();
+
double verticalScrollBarPosition() const;
void setVerticalScrollBarPosition(double pos);
public slots:
- void reloadFontSettings();
-
void clear(bool also_hide);
void loadUrl(const QString& url);
void loadUrl(const QUrl& url);
@@ -62,13 +62,14 @@ class WebBrowser : public TabContent {
void onTitleChanged(const QString& new_title);
void onIconChanged(const QIcon& icon);
void onLinkHovered(const QString& url);
+ void newWindowRequested(WebViewer* viewer);
void readabilePage();
void setReadabledHtml(const QString& better_html);
void readabilityFailed(const QString& error);
signals:
- void closeRequested();
+ void windowCloseRequested();
void iconChanged(int index, const QIcon& icon);
void titleChanged(int index, const QString& title);
diff --git a/src/librssguard/gui/webengine/webengineviewer.cpp b/src/librssguard/gui/webengine/webengineviewer.cpp
index 4022400ee..d4b6fdd77 100644
--- a/src/librssguard/gui/webengine/webengineviewer.cpp
+++ b/src/librssguard/gui/webengine/webengineviewer.cpp
@@ -52,10 +52,6 @@ WebEnginePage* WebEngineViewer::page() const {
return qobject_cast(QWebEngineView::page());
}
-void WebEngineViewer::displayMessage() {
- setHtml(m_messageContents, m_messageBaseUrl /*, QUrl::fromUserInput(INTERNAL_URL_MESSAGE)*/);
-}
-
void WebEngineViewer::loadMessages(const QList& messages, RootItem* root) {
Skin skin = qApp->skins()->currentSkin();
QString messages_layout;
@@ -134,7 +130,7 @@ void WebEngineViewer::loadMessages(const QList& messages, RootItem* roo
bool previously_enabled = isEnabled();
setEnabled(false);
- displayMessage();
+ setHtml(m_messageContents, m_messageBaseUrl /*, QUrl::fromUserInput(INTERNAL_URL_MESSAGE)*/);
setEnabled(previously_enabled);
page()->runJavaScript(QSL("window.scrollTo(0, 0);"));
@@ -216,15 +212,10 @@ void WebEngineViewer::contextMenuEvent(QContextMenuEvent* event) {
}
QWebEngineView* WebEngineViewer::createWindow(QWebEnginePage::WebWindowType type) {
- Q_UNUSED(type)
- int index = qApp->mainForm()->tabWidget()->addBrowser(false, false);
+ auto* viewer = new WebEngineViewer(this);
+ emit newWindowRequested(viewer);
- if (index >= 0) {
- return dynamic_cast(qApp->mainForm()->tabWidget()->widget(index)->webBrowser()->viewer());
- }
- else {
- return nullptr;
- }
+ return viewer;
}
void WebEngineViewer::openUrlWithExternalTool(ExternalTool tool, const QString& target_url) {
@@ -243,16 +234,15 @@ void WebEngineViewer::bindToBrowser(WebBrowser* browser) {
browser->m_actionReload = pageAction(QWebEnginePage::WebAction::Reload);
browser->m_actionStop = pageAction(QWebEnginePage::WebAction::Stop);
- connect(this, &WebEngineViewer::zoomFactorChanged, browser, &WebBrowser::onZoomFactorChanged);
-
connect(this, &WebEngineViewer::loadStarted, browser, &WebBrowser::onLoadingStarted);
connect(this, &WebEngineViewer::loadProgress, browser, &WebBrowser::onLoadingProgress);
connect(this, &WebEngineViewer::loadFinished, browser, &WebBrowser::onLoadingFinished);
connect(this, &WebEngineViewer::titleChanged, browser, &WebBrowser::onTitleChanged);
connect(this, &WebEngineViewer::iconChanged, browser, &WebBrowser::onIconChanged);
connect(this, &WebEngineViewer::urlChanged, browser, &WebBrowser::updateUrl);
+ connect(this, &WebEngineViewer::newWindowRequested, browser, &WebBrowser::newWindowRequested);
- connect(page(), &WebEnginePage::windowCloseRequested, browser, &WebBrowser::closeRequested);
+ connect(page(), &WebEnginePage::windowCloseRequested, browser, &WebBrowser::windowCloseRequested);
connect(page(), &WebEnginePage::linkHovered, browser, &WebBrowser::onLinkHovered);
}
diff --git a/src/librssguard/gui/webengine/webengineviewer.h b/src/librssguard/gui/webengine/webengineviewer.h
index d4bab908b..f018b691a 100644
--- a/src/librssguard/gui/webengine/webengineviewer.h
+++ b/src/librssguard/gui/webengine/webengineviewer.h
@@ -42,7 +42,7 @@ class WebEngineViewer : public QWebEngineView, public WebViewer {
virtual QUrl url() const;
signals:
- void zoomFactorChanged();
+ void newWindowRequested(WebViewer* viewer);
protected:
virtual QWebEngineView* createWindow(QWebEnginePage::WebWindowType type);
@@ -50,7 +50,6 @@ class WebEngineViewer : public QWebEngineView, public WebViewer {
virtual bool event(QEvent* event);
private slots:
- void displayMessage();
void openUrlWithExternalTool(ExternalTool tool, const QString& target_url);
private: