]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/mainview.cpp
Add a homepage setting.
[PrivacyBrowserPC.git] / src / mainview.cpp
index a1e018b400734422350bbf1b8cf3c46d5ef88685..5c596624d3a130192f6aae13eea3363d07ac2c07 100644 (file)
@@ -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,18 +51,43 @@ MainView::MainView(QWidget *parent) : QWidget(parent)
     connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateUrlLineEdit()));
     connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateUrlLineEdit()));
 
-    // Load a website.
-    webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/")));
+    // 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.
-    urlLineEditPointer->setText(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.  <https://bugreports.qt.io/browse/QTBUG-51992>
+    webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
 }