fix sig/slot warning in webviewer

This commit is contained in:
Martin Rotter 2022-04-09 15:54:05 +02:00
parent a38d3fb9af
commit 9fb922f785
6 changed files with 117 additions and 117 deletions

View File

@ -24,19 +24,16 @@
#include <QToolTip>
#include <QWidgetAction>
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)),
m_actionOpenInSystemBrowser(new QAction(qApp->icons()->fromTheme(QSL("document-open")),
tr("Open this website in system web browser"),
this)),
m_actionReadabilePage(new QAction(qApp->icons()->fromTheme(QSL("text-html")),
tr("View website in reader mode"),
this)) {
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)),
m_actionOpenInSystemBrowser(new QAction(qApp->icons()->fromTheme(QSL("document-open")),
tr("Open this website in system web browser"),
this)),
m_actionReadabilePage(new QAction(qApp->icons()->fromTheme(QSL("text-html")),
tr("View website in reader mode"),
this)) {
if (m_webView == nullptr) {
m_webView = qApp->createWebView();
dynamic_cast<QWidget*>(m_webView)->setParent(this);
@ -62,13 +59,13 @@ void WebBrowser::bindWebView() {
auto* qobj_viewer = dynamic_cast<QObject*>(m_webView);
connect(qobj_viewer, SIGNAL(linkHighlighted(QUrl)), this, SLOT(onLinkHovered(QUrl)));
connect(qobj_viewer, SIGNAL(titleChanged(QString)), this, SLOT(onTitleChanged(QString)));
connect(qobj_viewer, SIGNAL(urlChanged(QUrl)), this, SLOT(updateUrl(QUrl)));
connect(qobj_viewer, SIGNAL(iconChanged(QIcon)), this, SLOT(onIconChanged(QIcon)));
connect(qobj_viewer, SIGNAL(loadStarted()), this, SLOT(onLoadingStarted()));
connect(qobj_viewer, SIGNAL(loadProgress(int)), this, SLOT(onLoadingProgress(int)));
connect(qobj_viewer, SIGNAL(loadFinished(bool)), this, SLOT(onLoadingFinished(bool)));
connect(qobj_viewer, SIGNAL(linkMouseHighlighted(QUrl)), this, SLOT(onLinkHovered(QUrl)));
connect(qobj_viewer, SIGNAL(pageTitleChanged(QString)), this, SLOT(onTitleChanged(QString)));
connect(qobj_viewer, SIGNAL(pageUrlChanged(QUrl)), this, SLOT(updateUrl(QUrl)));
connect(qobj_viewer, SIGNAL(pageIconChanged(QIcon)), this, SLOT(onIconChanged(QIcon)));
connect(qobj_viewer, SIGNAL(loadingStarted()), this, SLOT(onLoadingStarted()));
connect(qobj_viewer, SIGNAL(loadingProgress(int)), this, SLOT(onLoadingProgress(int)));
connect(qobj_viewer, SIGNAL(loadingFinished(bool)), this, SLOT(onLoadingFinished(bool)));
connect(qobj_viewer, SIGNAL(newWindowRequested(WebViewer*)), this, SLOT(newWindowRequested(WebViewer*)));
connect(qobj_viewer, SIGNAL(closeWindowRequested()), this, SIGNAL(windowCloseRequested()));
}
@ -87,8 +84,10 @@ void WebBrowser::createConnections() {
connect(m_actionOpenInSystemBrowser, &QAction::triggered, this, &WebBrowser::openCurrentSiteInSystemBrowser);
connect(m_actionReadabilePage, &QAction::triggered, this, &WebBrowser::readabilePage);
connect(m_txtLocation, &LocationLineEdit::submitted,
this, static_cast<void (WebBrowser::*)(const QString&)>(&WebBrowser::loadUrl));
connect(m_txtLocation,
&LocationLineEdit::submitted,
this,
static_cast<void (WebBrowser::*)(const QString&)>(&WebBrowser::loadUrl));
connect(qApp->web()->readability(), &Readability::htmlReadabled, this, &WebBrowser::setReadabledHtml);
connect(qApp->web()->readability(), &Readability::errorOnHtmlReadabiliting, this, &WebBrowser::readabilityFailed);
@ -121,8 +120,7 @@ void WebBrowser::setVerticalScrollBarPosition(double pos) {
void WebBrowser::reloadFontSettings() {
QFont fon;
fon.fromString(qApp->settings()->value(GROUP(Messages),
SETTING(Messages::PreviewerFontStandard)).toString());
fon.fromString(qApp->settings()->value(GROUP(Messages), SETTING(Messages::PreviewerFontStandard)).toString());
m_webView->applyFont(fon);
}
@ -250,8 +248,8 @@ void WebBrowser::onLinkHovered(const QUrl& url) {
qDebugNN << LOGSEC_GUI << "Hovered link:" << QUOTE_W_SPACE_DOT(url);
qApp->showGuiMessage(Notification::Event::GeneralEvent,
{ url.toString(), url.toString(), QSystemTrayIcon::MessageIcon::NoIcon },
{ false, false, true });
{url.toString(), url.toString(), QSystemTrayIcon::MessageIcon::NoIcon},
{false, false, true});
}
void WebBrowser::newWindowRequested(WebViewer* viewer) {
@ -267,7 +265,8 @@ void WebBrowser::setReadabledHtml(const QString& better_html) {
}
void WebBrowser::readabilityFailed(const QString& error) {
MsgBox::show({}, QMessageBox::Icon::Critical,
MsgBox::show({},
QMessageBox::Icon::Critical,
tr("Reader mode failed for this website"),
tr("Reader mode cannot be applied to current page."),
{},
@ -295,7 +294,7 @@ void WebBrowser::initializeLayout() {
m_actionOpenInSystemBrowser->setEnabled(false);
m_actionReadabilePage->setEnabled(false);
//m_btnDiscoverFeedsAction->setDefaultWidget(new QWidget(this));
// m_btnDiscoverFeedsAction->setDefaultWidget(new QWidget(this));
m_btnDiscoverFeedsAction->setDefaultWidget(m_btnDiscoverFeeds);
@ -322,7 +321,7 @@ void WebBrowser::initializeLayout() {
m_layout->addWidget(dynamic_cast<QWidget*>(m_webView));
m_layout->addWidget(m_loadingProgress);
m_layout->addWidget(m_searchWidget);
m_layout->setContentsMargins({ 0, 0, 0, 0 });
m_layout->setContentsMargins({0, 0, 0, 0});
m_layout->setSpacing(0);
m_searchWidget->hide();
@ -355,7 +354,8 @@ void WebBrowser::onLoadingFinished(bool success) {
// Let's check if there are any feeds defined on the web and eventually
// display "Add feeds" button.
m_btnDiscoverFeeds->setFeedAddresses(NetworkFactory::extractFeedLinksFromHtmlPage(m_webView->url(), m_webView->html()));
m_btnDiscoverFeeds->setFeedAddresses(NetworkFactory::extractFeedLinksFromHtmlPage(m_webView->url(),
m_webView->html()));
}
else {
m_btnDiscoverFeeds->clearFeedAddresses();

View File

@ -23,11 +23,13 @@
#include <QTimer>
#include <QWheelEvent>
LiteHtmlViewer::LiteHtmlViewer(QWidget* parent) : QLiteHtmlWidget(parent), m_downloader(new Downloader(this)),
m_reloadingWithImages(false),
m_useSimpleArticleLayout(qApp->settings()->value(GROUP(Messages), SETTING(Messages::SimpleArticleLayout)).toBool()) {
LiteHtmlViewer::LiteHtmlViewer(QWidget* parent)
: QLiteHtmlWidget(parent), m_downloader(new Downloader(this)), m_reloadingWithImages(false),
m_useSimpleArticleLayout(qApp->settings()
->value(GROUP(Messages), SETTING(Messages::SimpleArticleLayout))
.toBool()) {
setResourceHandler([this](const QUrl& url) {
emit loadProgress(-1);
emit loadingProgress(-1);
return m_reloadingWithImages ? handleResource(url) : QByteArray{};
});
@ -58,13 +60,13 @@ void LiteHtmlViewer::bindToBrowser(WebBrowser* browser) {
}
void LiteHtmlViewer::findText(const QString& text, bool backwards) {
QLiteHtmlWidget::findText(text, backwards
? QTextDocument::FindFlag::FindBackward
: QTextDocument::FindFlag(0x0), false);
QLiteHtmlWidget::findText(text,
backwards ? QTextDocument::FindFlag::FindBackward : QTextDocument::FindFlag(0x0),
false);
}
void LiteHtmlViewer::setUrl(const QUrl& url) {
emit loadStarted();
emit loadingStarted();
QString html_str;
QUrl nonconst_url = url;
bool is_error = false;
@ -79,10 +81,7 @@ void LiteHtmlViewer::setUrl(const QUrl& url) {
QEventLoop loop;
connect(m_downloader.data(), &Downloader::completed, &loop, &QEventLoop::quit);
m_downloader->manipulateData(url.toString(),
QNetworkAccessManager::Operation::GetOperation,
{},
5000);
m_downloader->manipulateData(url.toString(), QNetworkAccessManager::Operation::GetOperation, {}, 5000);
loop.exec();
@ -95,8 +94,8 @@ void LiteHtmlViewer::setUrl(const QUrl& url) {
}
else {
if (content_type.startsWith(QSL("image/"))) {
html_str = QSL("<img src=\"data:%1;base64,%2\">").arg(content_type,
QString::fromLocal8Bit(m_downloader->lastOutputData().toBase64()));
html_str = QSL("<img src=\"data:%1;base64,%2\">")
.arg(content_type, QString::fromLocal8Bit(m_downloader->lastOutputData().toBase64()));
}
else {
html_str = QString::fromUtf8(m_downloader->lastOutputData());
@ -106,15 +105,15 @@ void LiteHtmlViewer::setUrl(const QUrl& url) {
setHtml(html_str, nonconst_url);
emit loadFinished(is_error);
emit loadingFinished(is_error);
}
void LiteHtmlViewer::setHtml(const QString& html, const QUrl& base_url) {
QLiteHtmlWidget::setUrl(base_url);
QLiteHtmlWidget::setHtml(html);
emit titleChanged(title());
emit urlChanged(base_url);
emit pageTitleChanged(title());
emit pageUrlChanged(base_url);
}
QString LiteHtmlViewer::html() const {
@ -129,7 +128,8 @@ void LiteHtmlViewer::clear() {
setHtml({});
}
QPair<QString, QUrl> LiteHtmlViewer::prepareHtmlForMessage(const QList<Message>& messages, RootItem* selected_item) const {
QPair<QString, QUrl> LiteHtmlViewer::prepareHtmlForMessage(const QList<Message>& messages,
RootItem* selected_item) const {
QString html;
for (const Message& message : messages) {
@ -145,7 +145,7 @@ QPair<QString, QUrl> LiteHtmlViewer::prepareHtmlForMessage(const QList<Message>&
QRegularExpression imgTagRegex("\\<img[^\\>]*src\\s*=\\s*[\"\']([^\"\']*)[\"\'][^\\>]*\\>",
QRegularExpression::PatternOption::CaseInsensitiveOption |
QRegularExpression::PatternOption::InvertedGreedinessOption);
QRegularExpression::PatternOption::InvertedGreedinessOption);
QRegularExpressionMatchIterator i = imgTagRegex.globalMatch(message.m_contents);
QString pictures_html;
@ -170,25 +170,24 @@ QPair<QString, QUrl> LiteHtmlViewer::prepareHtmlForMessage(const QList<Message>&
// TODO: If FgInteresting not defined by the skin
// use current pallette/Highlight color perhaps.
return { QSL("<html>"
"<head><style>"
"a { color: %2; }"
"</style></head>"
"<body>%1</body>"
"</html>").arg(html,
qApp->skins()->currentSkin()
.colorForModel(SkinEnums::PaletteColors::FgInteresting)
.value<QColor>().name()),
QUrl() };
return {
QSL("<html>"
"<head><style>"
"a { color: %2; }"
"</style></head>"
"<body>%1</body>"
"</html>")
.arg(html,
qApp->skins()->currentSkin().colorForModel(SkinEnums::PaletteColors::FgInteresting).value<QColor>().name()),
QUrl()};
}
void LiteHtmlViewer::loadMessages(const QList<Message>& messages, RootItem* root) {
auto html_messages = m_useSimpleArticleLayout
? prepareHtmlForMessage(messages, root)
: qApp->skins()->generateHtmlOfArticles(messages, root);
auto html_messages = m_useSimpleArticleLayout ? prepareHtmlForMessage(messages, root)
: qApp->skins()->generateHtmlOfArticles(messages, root);
setHtml(html_messages.first, html_messages.second);
emit loadFinished(true);
emit loadingFinished(true);
}
double LiteHtmlViewer::verticalScrollBarPosition() const {
@ -264,17 +263,13 @@ void LiteHtmlViewer::showContextMenu(const QPoint& pos, const QUrl& url) {
if (m_contextMenu.isNull()) {
m_contextMenu.reset(new QMenu("Context menu for web browser", this));
m_actionCopyUrl.reset(new QAction(qApp->icons()->fromTheme(QSL("edit-copy")),
tr("Copy URL"),
this));
m_actionCopyUrl.reset(new QAction(qApp->icons()->fromTheme(QSL("edit-copy")), tr("Copy URL"), this));
connect(m_actionCopyUrl.data(), &QAction::triggered, this, [url]() {
QGuiApplication::clipboard()->setText(url.toString(), QClipboard::Mode::Clipboard);
});
m_actionCopyText.reset(new QAction(qApp->icons()->fromTheme(QSL("edit-copy")),
tr("Copy selection"),
this));
m_actionCopyText.reset(new QAction(qApp->icons()->fromTheme(QSL("edit-copy")), tr("Copy selection"), this));
connect(m_actionCopyText.data(), &QAction::triggered, this, [this]() {
QGuiApplication::clipboard()->setText(QLiteHtmlWidget::selectedText(), QClipboard::Mode::Clipboard);
@ -288,7 +283,9 @@ void LiteHtmlViewer::showContextMenu(const QPoint& pos, const QUrl& url) {
connect(m_actionOpenLinkExternally.data(), &QAction::triggered, this, [url]() {
qApp->web()->openUrlInExternalBrowser(url.toString());
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::BringAppToFrontAfterMessageOpenedExternally)).toBool()) {
if (qApp->settings()
->value(GROUP(Messages), SETTING(Messages::BringAppToFrontAfterMessageOpenedExternally))
.toBool()) {
QTimer::singleShot(1000, qApp, []() {
qApp->mainForm()->display();
});
@ -314,11 +311,11 @@ void LiteHtmlViewer::showContextMenu(const QPoint& pos, const QUrl& url) {
m_actionOpenLinkExternally->setEnabled(url.isValid());
m_contextMenu->clear();
m_contextMenu->addActions({ m_actionCopyUrl.data(),
m_actionCopyText.data(),
m_actionOpenLinkExternally.data(),
m_actionSimpleLayout.data(),
m_actionReloadWithImages.data() });
m_contextMenu->addActions({m_actionCopyUrl.data(),
m_actionCopyText.data(),
m_actionOpenLinkExternally.data(),
m_actionSimpleLayout.data(),
m_actionReloadWithImages.data()});
if (url.isValid()) {
QFileIconProvider icon_provider;
@ -383,10 +380,7 @@ QByteArray LiteHtmlViewer::handleResource(const QUrl& url) {
QEventLoop loop;
connect(m_downloader.data(), &Downloader::completed, &loop, &QEventLoop::quit);
m_downloader->manipulateData(url.toString(),
QNetworkAccessManager::Operation::GetOperation,
{},
5000);
m_downloader->manipulateData(url.toString(), QNetworkAccessManager::Operation::GetOperation, {}, 5000);
loop.exec();
return m_downloader->lastOutputData();

View File

@ -13,8 +13,8 @@ class QWheelEvent;
class QMenu;
class LiteHtmlViewer : public QLiteHtmlWidget, public WebViewer {
Q_OBJECT
Q_INTERFACES(WebViewer)
Q_OBJECT
Q_INTERFACES(WebViewer)
public:
explicit LiteHtmlViewer(QWidget* parent = nullptr);
@ -42,13 +42,13 @@ class LiteHtmlViewer : public QLiteHtmlWidget, public WebViewer {
void showContextMenu(const QPoint& pos, const QUrl& url);
signals:
void titleChanged(const QString& new_title);
void urlChanged(const QUrl& url);
void iconChanged(const QIcon&);
void linkHighlighted(const QUrl& url);
void loadStarted();
void loadProgress(int progress);
void loadFinished(bool success);
void pageTitleChanged(const QString& new_title);
void pageUrlChanged(const QUrl& url);
void pageIconChanged(const QIcon&);
void linkMouseHighlighted(const QUrl& url);
void loadingStarted();
void loadingProgress(int progress);
void loadingFinished(bool success);
void newWindowRequested(WebViewer* viewer);
void closeWindowRequested();

View File

@ -95,7 +95,9 @@ void WebEngineViewer::contextMenuEvent(QContextMenuEvent* event) {
menu->addAction(qApp->icons()->fromTheme(QSL("document-open")), tr("Open link in external browser"), [link_url]() {
qApp->web()->openUrlInExternalBrowser(link_url);
if (qApp->settings()->value(GROUP(Messages), SETTING(Messages::BringAppToFrontAfterMessageOpenedExternally)).toBool()) {
if (qApp->settings()
->value(GROUP(Messages), SETTING(Messages::BringAppToFrontAfterMessageOpenedExternally))
.toBool()) {
QTimer::singleShot(1000, qApp, []() {
qApp->mainForm()->display();
});
@ -104,7 +106,8 @@ void WebEngineViewer::contextMenuEvent(QContextMenuEvent* event) {
}
if (menu_data.mediaUrl().isValid() || menu_data.linkUrl().isValid()) {
QString media_link = menu_data.mediaUrl().isValid() ? menu_data.mediaUrl().toString() : menu_data.linkUrl().toString();
QString media_link =
menu_data.mediaUrl().isValid() ? menu_data.mediaUrl().toString() : menu_data.linkUrl().toString();
QFileIconProvider icon_provider;
QMenu* menu_ext_tools = new QMenu(tr("Open with external tool"), menu);
auto tools = ExternalTool::toolsFromSettings();
@ -166,16 +169,16 @@ void WebEngineViewer::bindToBrowser(WebBrowser* browser) {
browser->m_actionReload = pageAction(QWebEnginePage::WebAction::Reload);
browser->m_actionStop = pageAction(QWebEnginePage::WebAction::Stop);
// NOTE: Just forwar QtWebEngine signals, it's all there.
connect(this, &QWebEngineView::loadStarted, this, &WebEngineViewer::loadStarted);
connect(this, &QWebEngineView::loadProgress, this, &WebEngineViewer::loadProgress);
connect(this, &QWebEngineView::loadFinished, this, &WebEngineViewer::loadFinished);
connect(this, &QWebEngineView::titleChanged, this, &WebEngineViewer::titleChanged);
connect(this, &QWebEngineView::iconChanged, this, &WebEngineViewer::iconChanged);
connect(this, &QWebEngineView::urlChanged, this, &WebEngineViewer::urlChanged);
// NOTE: Just forward QtWebEngine signals, it's all there.
connect(this, &QWebEngineView::loadStarted, this, &WebEngineViewer::loadingStarted);
connect(this, &QWebEngineView::loadProgress, this, &WebEngineViewer::loadingProgress);
connect(this, &QWebEngineView::loadFinished, this, &WebEngineViewer::loadingFinished);
connect(this, &QWebEngineView::titleChanged, this, &WebEngineViewer::pageTitleChanged);
connect(this, &QWebEngineView::iconChanged, this, &WebEngineViewer::pageIconChanged);
connect(this, &QWebEngineView::urlChanged, this, &WebEngineViewer::pageUrlChanged);
connect(page(), &QWebEnginePage::windowCloseRequested, this, &WebEngineViewer::closeWindowRequested);
connect(page(), &QWebEnginePage::linkHovered, this, &WebEngineViewer::linkHighlighted);
connect(page(), &QWebEnginePage::linkHovered, this, &WebEngineViewer::linkMouseHighlighted);
}
void WebEngineViewer::findText(const QString& text, bool backwards) {
@ -215,9 +218,12 @@ void WebEngineViewer::setVerticalScrollBarPosition(double pos) {
void WebEngineViewer::applyFont(const QFont& fon) {
auto pixel_size = QFontMetrics(fon).ascent();
QWebEngineProfile::defaultProfile()->settings()->setFontFamily(QWebEngineSettings::FontFamily::StandardFont, fon.family());
QWebEngineProfile::defaultProfile()->settings()->setFontFamily(QWebEngineSettings::FontFamily::SerifFont, fon.family());
QWebEngineProfile::defaultProfile()->settings()->setFontFamily(QWebEngineSettings::FontFamily::SansSerifFont, fon.family());
QWebEngineProfile::defaultProfile()->settings()->setFontFamily(QWebEngineSettings::FontFamily::StandardFont,
fon.family());
QWebEngineProfile::defaultProfile()->settings()->setFontFamily(QWebEngineSettings::FontFamily::SerifFont,
fon.family());
QWebEngineProfile::defaultProfile()->settings()->setFontFamily(QWebEngineSettings::FontFamily::SansSerifFont,
fon.family());
QWebEngineProfile::defaultProfile()->settings()->setFontSize(QWebEngineSettings::DefaultFontSize, pixel_size);
}

View File

@ -15,8 +15,8 @@ class RootItem;
class WebBrowser;
class WebEngineViewer : public QWebEngineView, public WebViewer {
Q_OBJECT
Q_INTERFACES(WebViewer)
Q_OBJECT
Q_INTERFACES(WebViewer)
public:
explicit WebEngineViewer(QWidget* parent = nullptr);
@ -39,13 +39,13 @@ class WebEngineViewer : public QWebEngineView, public WebViewer {
virtual QUrl url() const;
signals:
void titleChanged(const QString& new_title);
void urlChanged(const QUrl& url);
void iconChanged(const QIcon&);
void linkHighlighted(const QUrl& url);
void loadStarted();
void loadProgress(int progress);
void loadFinished(bool success);
void pageTitleChanged(const QString& new_title);
void pageUrlChanged(const QUrl& url);
void pageIconChanged(const QIcon&);
void linkMouseHighlighted(const QUrl& url);
void loadingStarted();
void loadingProgress(int progress);
void loadingFinished(bool success);
void newWindowRequested(WebViewer* viewer);
void closeWindowRequested();

View File

@ -59,13 +59,13 @@ class WebViewer {
virtual void setZoomFactor(qreal zoom_factor) = 0;
signals:
virtual void titleChanged(const QString& new_title) = 0;
virtual void urlChanged(const QUrl& url) = 0;
virtual void iconChanged(const QIcon&) = 0;
virtual void linkHighlighted(const QUrl& url) = 0;
virtual void loadStarted() = 0;
virtual void loadProgress(int progress) = 0;
virtual void loadFinished(bool success) = 0;
virtual void pageTitleChanged(const QString& new_title) = 0;
virtual void pageUrlChanged(const QUrl& url) = 0;
virtual void pageIconChanged(const QIcon&) = 0;
virtual void linkMouseHighlighted(const QUrl& url) = 0;
virtual void loadingStarted() = 0;
virtual void loadingProgress(int progress) = 0;
virtual void loadingFinished(bool success) = 0;
virtual void newWindowRequested(WebViewer* viewer) = 0;
virtual void closeWindowRequested() = 0;
};