X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=blobdiff_plain;f=src%2Fmainview.cpp;h=e46f00d1d6660f68a6d9140a2ca61121668015f8;hp=844f930971428834cd1bd747df6d028a5624b204;hb=aca3bbeca7fee2ff50918a9d09a41be4edf1140c;hpb=255215b082091aaadd5ef24cfc0880cd81e42272 diff --git a/src/mainview.cpp b/src/mainview.cpp index 844f930..e46f00d 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -21,17 +21,50 @@ #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; + + // 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())); + + // Set the zoom factor. + webEngineViewPointer->setZoomFactor(Settings::zoomFactor()); // Load a website. webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/"))); } + +void MainView::loadUrl(const QString &urlFromUser) +{ + // Load the URL, adding standard protocol sections if needed. TODO. Replace this with logic that prefers HTTPS. + webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser)); +} + +void MainView::updateUrlLineEdit() +{ + // 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()); +}