X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=src%2Fmainview.cpp;h=75767bb587d7ad876f49f4a8498f0ed19dac16aa;hb=10c141f631ec7e341e45045b574661b644c7dbe9;hp=b1adcbf2dc49f66c6796fb18a5e8a520c159e572;hpb=8e2e267828a6fbd7ed9950204c50a100e3f413fa;p=PrivacyBrowserPC.git diff --git a/src/mainview.cpp b/src/mainview.cpp index b1adcbf..75767bb 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -26,6 +26,7 @@ #include // Qt framework headers. +#include #include MainView::MainView(QWidget *parent) : QWidget(parent) @@ -37,19 +38,26 @@ MainView::MainView(QWidget *parent) : QWidget(parent) mainViewUi.setupUi(this); // Get handles for the views. + backButtonPointer = mainViewUi.backButton; + forwardButtonPointer = mainViewUi.forwardButton; urlLineEditPointer = mainViewUi.urlLineEdit; webEngineViewPointer = mainViewUi.webEngineView; - // Get a handle for the webpage. + // Get handles for the webpage and history. QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page(); + webEngineHistoryPointer = webEnginePagePointer->history(); // 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())); + connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateInterface())); + connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateInterface())); + connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateInterface())); + + // Setup the forward and back buttons. + connect(backButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(back())); + connect(forwardButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(forward())); // Listen for hovered link URLs. connect(webEnginePagePointer, SIGNAL(linkHovered(QString)), this, SLOT(pageLinkHovered(QString))); @@ -60,12 +68,15 @@ MainView::MainView(QWidget *parent) : QWidget(parent) // Set the focus on the WebEngine view. webEngineViewPointer->setFocus(); - // Load a website. - webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/"))); + // 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)); } @@ -76,7 +87,7 @@ void MainView::pageLinkHovered(const QString &linkUrl) emit linkHovered(linkUrl); } -void MainView::updateUrlLineEdit() +void MainView::updateInterface() { // Update the URL line edit if it does not have focus. if (!urlLineEditPointer->hasFocus()) @@ -85,6 +96,9 @@ void MainView::updateUrlLineEdit() urlLineEditPointer->setUrl(webEngineViewPointer->url().toString()); } + backButtonPointer->setEnabled(webEngineHistoryPointer->canGoBack()); + forwardButtonPointer->setEnabled(webEngineHistoryPointer->canGoForward()); + // 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()); }