X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fmainview.cpp;h=b1adcbf2dc49f66c6796fb18a5e8a520c159e572;hp=e46f00d1d6660f68a6d9140a2ca61121668015f8;hb=8e2e267828a6fbd7ed9950204c50a100e3f413fa;hpb=aca3bbeca7fee2ff50918a9d09a41be4edf1140c diff --git a/src/mainview.cpp b/src/mainview.cpp index e46f00d..b1adcbf 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -18,6 +18,7 @@ */ // Application headers +#include "browserwindow.h" #include "mainview.h" #include "settings.h" @@ -39,6 +40,9 @@ MainView::MainView(QWidget *parent) : QWidget(parent) urlLineEditPointer = mainViewUi.urlLineEdit; webEngineViewPointer = mainViewUi.webEngineView; + // Get a handle for the webpage. + QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page(); + // Update the webengine view from the URL line edit. connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString))); @@ -47,9 +51,15 @@ MainView::MainView(QWidget *parent) : QWidget(parent) connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateUrlLineEdit())); connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateUrlLineEdit())); + // Listen for hovered link URLs. + connect(webEnginePagePointer, SIGNAL(linkHovered(QString)), this, SLOT(pageLinkHovered(QString))); + // Set the zoom factor. webEngineViewPointer->setZoomFactor(Settings::zoomFactor()); + // Set the focus on the WebEngine view. + webEngineViewPointer->setFocus(); + // Load a website. webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/"))); } @@ -60,10 +70,20 @@ void MainView::loadUrl(const QString &urlFromUser) webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser)); } +void MainView::pageLinkHovered(const QString &linkUrl) +{ + // Emit a signal so that the browser window can update the status bar. + emit linkHovered(linkUrl); +} + void MainView::updateUrlLineEdit() { - // Update the URL line edit. - urlLineEditPointer->setUrl(webEngineViewPointer->url().toString()); + // Update the URL line edit if it does not have focus. + if (!urlLineEditPointer->hasFocus()) + { + // Update the URL line edit. + urlLineEditPointer->setUrl(webEngineViewPointer->url().toString()); + } // Reapply the zoom factor. This is a bug in QWebEngineView that resets the zoom with every load. Hopefully it will be fixed in Qt6. webEngineViewPointer->setZoomFactor(Settings::zoomFactor());