X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fmainview.cpp;h=5c596624d3a130192f6aae13eea3363d07ac2c07;hp=844f930971428834cd1bd747df6d028a5624b204;hb=5452b388e3fcfc1c86a234f8354edab04354aa3a;hpb=255215b082091aaadd5ef24cfc0880cd81e42272 diff --git a/src/mainview.cpp b/src/mainview.cpp index 844f930..5c59662 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -18,20 +18,76 @@ */ // Application headers +#include "browserwindow.h" #include "mainview.h" #include "settings.h" +// KDE Framework headers. +#include + // Qt framework headers. #include MainView::MainView(QWidget *parent) : QWidget(parent) { + // Instantiate the mainview UI. + Ui::MainView mainViewUi; + // Setup the UI. mainViewUi.setupUi(this); - // Get a handle for the web engine view. - QWebEngineView *webEngineViewPointer = mainViewUi.webEngineView; + // Get handles for the views. + 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))); + + // Update the URL line edit form the webengine view. + connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateUrlLineEdit())); + 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 the homepage. TODO. Consider sanitizing the homepage input and adding things like protocols if they are missing. + webEngineViewPointer->setUrl(Settings::homepage()); +} + +void MainView::loadUrl(const QString &urlFromUser) +{ + // Remove the focus from the URL line edit. + urlLineEditPointer->clearFocus(); + + // Load the URL, adding standard protocol sections if needed. TODO. Replace this with logic that prefers HTTPS. + 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 if it does not have focus. + if (!urlLineEditPointer->hasFocus()) + { + // Update the URL line edit. + urlLineEditPointer->setUrl(webEngineViewPointer->url().toString()); + } - // Load a website. - webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/"))); + // 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()); }