mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-04 03:08:04 +01:00
multiple fixes
This commit is contained in:
parent
1787368ee1
commit
982a3dc004
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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<QPair<LabelButton*, QAction*>>()) {
|
||||
m_txtMessage = new WebBrowser(this);
|
||||
m_txtMessage = new WebBrowser(nullptr, this);
|
||||
|
||||
m_toolBar->setOrientation(Qt::Orientation::Vertical);
|
||||
|
||||
|
@ -186,7 +186,7 @@ void TabWidget::closeCurrentTab() {
|
||||
}
|
||||
|
||||
int TabWidget::addNewspaperView(RootItem* root, const QList<Message>& 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);
|
||||
|
@ -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();
|
||||
|
@ -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 <QToolTip>
|
||||
#include <QWidgetAction>
|
||||
|
||||
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());
|
||||
|
@ -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);
|
||||
|
||||
|
@ -52,10 +52,6 @@ WebEnginePage* WebEngineViewer::page() const {
|
||||
return qobject_cast<WebEnginePage*>(QWebEngineView::page());
|
||||
}
|
||||
|
||||
void WebEngineViewer::displayMessage() {
|
||||
setHtml(m_messageContents, m_messageBaseUrl /*, QUrl::fromUserInput(INTERNAL_URL_MESSAGE)*/);
|
||||
}
|
||||
|
||||
void WebEngineViewer::loadMessages(const QList<Message>& messages, RootItem* root) {
|
||||
Skin skin = qApp->skins()->currentSkin();
|
||||
QString messages_layout;
|
||||
@ -134,7 +130,7 @@ void WebEngineViewer::loadMessages(const QList<Message>& 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<QWebEngineView*>(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);
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user