]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/mainview.cpp
Add a zoom factor setting.
[PrivacyBrowserPC.git] / src / mainview.cpp
index 844f930971428834cd1bd747df6d028a5624b204..e46f00d1d6660f68a6d9140a2ca61121668015f8 100644 (file)
 #include "mainview.h"
 #include "settings.h"
 
+// KDE Framework headers.
+#include <KLineEdit>
+
 // Qt framework headers.
 #include <QWebEngineView>
 
 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.  <https://bugreports.qt.io/browse/QTBUG-51992>
+    webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
+}