From: Soren Stoutner Date: Mon, 31 Jan 2022 20:48:58 +0000 (-0700) Subject: Add forward and back buttons. X-Git-Tag: v0.1~68 X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=commitdiff_plain;h=10c141f631ec7e341e45045b574661b644c7dbe9 Add forward and back buttons. --- diff --git a/src/com.stoutner.privacybrowser.desktop b/src/com.stoutner.privacybrowser.desktop index bdb64ed..a0e17f9 100644 --- a/src/com.stoutner.privacybrowser.desktop +++ b/src/com.stoutner.privacybrowser.desktop @@ -30,7 +30,7 @@ GenericName=Web Browser Categories=Network;WebBrowser; # Set the icon. -Icon=privacy_browser.svg +Icon=privacy-browser.svg # Set the executable. Exec=privacy-browser diff --git a/src/mainview.cpp b/src/mainview.cpp index 5c59662..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))); @@ -79,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()) @@ -88,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()); } diff --git a/src/mainview.h b/src/mainview.h index 47a9f27..a28565e 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -40,11 +40,14 @@ private Q_SLOTS: // Define the private slots. void loadUrl(const QString &urlFromUser); void pageLinkHovered(const QString &linkUrl); - void updateUrlLineEdit(); + void updateInterface(); private: // Define the private variables. + QPushButton *backButtonPointer; + QPushButton *forwardButtonPointer; KLineEdit *urlLineEditPointer; + QWebEngineHistory *webEngineHistoryPointer; QWebEngineView *webEngineViewPointer; }; #endif diff --git a/src/mainview.ui b/src/mainview.ui index 2174544..4865f6e 100644 --- a/src/mainview.ui +++ b/src/mainview.ui @@ -33,6 +33,11 @@ + + + 0 + + 0 @@ -51,7 +56,54 @@ - + + + + 0 + + + + + + + + + + + 24 + 24 + + + + + true + + + + + + + + + + + + + 24 + 24 + + + + + true + + + + + + + + diff --git a/src/settings.kcfg b/src/settings.kcfg index d4c5ffd..8497069 100644 --- a/src/settings.kcfg +++ b/src/settings.kcfg @@ -24,7 +24,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > - + +