]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Clear the URL line edit when navigating history. https://redmine.stoutner.com/issues/841
authorSoren Stoutner <soren@stoutner.com>
Tue, 12 Apr 2022 21:41:29 +0000 (14:41 -0700)
committerSoren Stoutner <soren@stoutner.com>
Tue, 12 Apr 2022 21:41:29 +0000 (14:41 -0700)
src/CMakeLists.txt
src/MouseEventFilter.cpp [deleted file]
src/MouseEventFilter.h [deleted file]
src/filters/CMakeLists.txt [new file with mode: 0644]
src/filters/MouseEventFilter.cpp [new file with mode: 0644]
src/filters/MouseEventFilter.h [new file with mode: 0644]
src/ui.rc/browser_ui.rc
src/views/BrowserView.cpp
src/views/BrowserView.h
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

index 83718228956d13b1c920a0c0fd69ba3845ffe3a5..4d33710bb035c2c688fd4caef84aa632a7d67d23 100644 (file)
@@ -21,7 +21,6 @@ add_executable(privacy-browser resources.qrc)
 # List the sources to include in the executable.
 target_sources(privacy-browser PRIVATE
     main.cpp
 # List the sources to include in the executable.
 target_sources(privacy-browser PRIVATE
     main.cpp
-    MouseEventFilter.cpp
 )
 
 # Add the Qt logging category.  This will create the `debug.h` header file.
 )
 
 # Add the Qt logging category.  This will create the `debug.h` header file.
@@ -62,6 +61,7 @@ target_link_libraries(privacy-browser
 
 # Add the subdirectories.
 add_subdirectory(dialogs)
 
 # Add the subdirectories.
 add_subdirectory(dialogs)
+add_subdirectory(filters)
 add_subdirectory(helpers)
 add_subdirectory(interceptors)
 add_subdirectory(ui.rc)
 add_subdirectory(helpers)
 add_subdirectory(interceptors)
 add_subdirectory(ui.rc)
diff --git a/src/MouseEventFilter.cpp b/src/MouseEventFilter.cpp
deleted file mode 100644 (file)
index 3454d06..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
- *
- * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
- *
- * Privacy Browser PC is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Privacy Browser PC is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-// Application headers.
-#include "MouseEventFilter.h"
-
-// Qt headers.
-#include <QEvent>
-#include <QMouseEvent>
-
-// The primary constructor.
-MouseEventFilter::MouseEventFilter(QWebEngineView *webEngineView) : QObject()
-{
-    // Save a handle to the WebEngine view.
-    webEngineViewPointer = webEngineView;
-};
-
-bool MouseEventFilter::eventFilter(QObject *objectPointer, QEvent *eventPointer)
-{
-    // Only process mouse button press events.
-    if (eventPointer->type() == QEvent::MouseButtonPress)
-    {
-        // Tell the compiler to ignore the unused object pointer.
-        (void)objectPointer;
-
-        // Cast the event to a mouse event.
-        QMouseEvent *mouseEventPointer = static_cast<QMouseEvent *>(eventPointer);
-
-        // Run the command according to the button that was pushed.
-        switch (mouseEventPointer->button())
-        {
-            case (Qt::BackButton):
-                // Tell the WebEngine to go back.
-                webEngineViewPointer->back();
-
-                // Consume the event.
-                return true;
-
-            case (Qt::ForwardButton):
-                // Tell the WebEngine to go forward.
-                webEngineViewPointer->forward();
-
-                // Consume the event.
-                return true;
-
-            default:
-                // Do not consume the event.
-                return false;
-        }
-    }
-
-    // Do not consume the event.
-    return false;
-}
diff --git a/src/MouseEventFilter.h b/src/MouseEventFilter.h
deleted file mode 100644 (file)
index 92c015a..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
- *
- * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
- *
- * Privacy Browser PC is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Privacy Browser PC is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef MOUSEEVENTFILTER_H
-#define MOUSEEVENTFILTER_H
-
-// Qt headers.
-#include <QObject>
-#include <QWebEngineView>
-
-class MouseEventFilter : public QObject
-{
-    // Include the Q_OBJECT macro.
-    Q_OBJECT
-
-public:
-    // The primary constructor.
-    MouseEventFilter(QWebEngineView *webEngineView);
-
-protected:
-    // The protected functions.
-    bool eventFilter(QObject *objectPointer, QEvent *eventPointer) override;
-
-private:
-    // The private variables.
-    QWebEngineView *webEngineViewPointer;
-};
-#endif
diff --git a/src/filters/CMakeLists.txt b/src/filters/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c57b6ee
--- /dev/null
@@ -0,0 +1,22 @@
+# Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+#
+# This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+#
+# Privacy Browser PC is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Privacy Browser PC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
+
+
+# List the sources to include in the executable.
+target_sources(privacy-browser PRIVATE
+    MouseEventFilter.cpp
+)
diff --git a/src/filters/MouseEventFilter.cpp b/src/filters/MouseEventFilter.cpp
new file mode 100644 (file)
index 0000000..51bbb09
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Application headers.
+#include "MouseEventFilter.h"
+
+// Qt headers.
+#include <QEvent>
+#include <QMouseEvent>
+
+// The primary constructor.
+MouseEventFilter::MouseEventFilter() : QObject() {};
+
+bool MouseEventFilter::eventFilter(QObject *objectPointer, QEvent *eventPointer)
+{
+    // Only process mouse button press events.
+    if (eventPointer->type() == QEvent::MouseButtonPress)
+    {
+        // Tell the compiler to ignore the unused object pointer.
+        (void)objectPointer;
+
+        // Cast the event to a mouse event.
+        QMouseEvent *mouseEventPointer = static_cast<QMouseEvent *>(eventPointer);
+
+        // Run the command according to the button that was pushed.
+        switch (mouseEventPointer->button())
+        {
+            case (Qt::BackButton):
+                // Tell the WebEngine to go back.
+                emit mouseBack();
+
+                // Consume the event.
+                return true;
+
+            case (Qt::ForwardButton):
+                // Tell the WebEngine to go forward.
+                emit mouseForward();
+
+                // Consume the event.
+                return true;
+
+            default:
+                // Do not consume the event.
+                return false;
+        }
+    }
+
+    // Do not consume the event.
+    return false;
+}
diff --git a/src/filters/MouseEventFilter.h b/src/filters/MouseEventFilter.h
new file mode 100644 (file)
index 0000000..02e1b2d
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MOUSEEVENTFILTER_H
+#define MOUSEEVENTFILTER_H
+
+// Qt headers.
+#include <QObject>
+#include <QWebEngineView>
+
+class MouseEventFilter : public QObject
+{
+    // Include the Q_OBJECT macro.
+    Q_OBJECT
+
+public:
+    // The primary constructor.
+    MouseEventFilter();
+
+signals:
+    // The signals.
+    void mouseBack() const;
+    void mouseForward() const;
+
+protected:
+    // The protected functions.
+    bool eventFilter(QObject *objectPointer, QEvent *eventPointer) override;
+};
+#endif
index 0e1d60b2ddd2c9c451c1f7f2b4fa42c2c44540b9..4c42e77146e9625599a0af95f3ce677da184d346 100644 (file)
@@ -29,6 +29,7 @@
 
     <!-- The menu bar. -->
     <MenuBar>
 
     <!-- The menu bar. -->
     <MenuBar>
+        <!-- On-the-fly Settings. -->
         <Menu name="on_the_fly_settings"> <text>On-The-Fly Settings</text>
             <Menu name="user_agent" icon="user-group-properties"> <text>User Agent</text>
                 <Action name="user_agent_privacy_browser" />
         <Menu name="on_the_fly_settings"> <text>On-The-Fly Settings</text>
             <Menu name="user_agent" icon="user-group-properties"> <text>User Agent</text>
                 <Action name="user_agent_privacy_browser" />
                 <Action name="search_engine_custom" />
             </Menu>
         </Menu>
                 <Action name="search_engine_custom" />
             </Menu>
         </Menu>
+
+        <!-- Settings. -->
+        <Menu name="settings">
+            <Action name="domain_settings" />
+        </Menu>
     </MenuBar>
 
     <!-- The main toolbar is removed. -->
     </MenuBar>
 
     <!-- The main toolbar is removed. -->
@@ -73,6 +79,5 @@
     <ToolBar name="url_toolbar" iconText="icononly"> <text>URL Toolbar</text>
         <Action name="javascript" />
         <Action name="local_storage" />
     <ToolBar name="url_toolbar" iconText="icononly"> <text>URL Toolbar</text>
         <Action name="javascript" />
         <Action name="local_storage" />
-        <Action name="domain_settings" />
     </ToolBar>
 </gui>
     </ToolBar>
 </gui>
index 2e29ea0caf9fd515690e9205f498cdd621659c20..873b9476da8bd0cce0bd441e742e0f79d7febb05 100644 (file)
@@ -19,9 +19,9 @@
 
 // Application headers.
 #include "BrowserView.h"
 
 // Application headers.
 #include "BrowserView.h"
-#include "MouseEventFilter.h"
 #include "Settings.h"
 #include "ui_BrowserView.h"
 #include "Settings.h"
 #include "ui_BrowserView.h"
+#include "filters/MouseEventFilter.h"
 #include "helpers/DomainsDatabaseHelper.h"
 #include "helpers/SearchEngineHelper.h"
 #include "helpers/UserAgentHelper.h"
 #include "helpers/DomainsDatabaseHelper.h"
 #include "helpers/SearchEngineHelper.h"
 #include "helpers/UserAgentHelper.h"
@@ -71,11 +71,15 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
     connect(webEngineViewPointer, SIGNAL(loadFinished(const bool)), this, SLOT(loadFinished()));
 
     // Instantiate the mouse event filter pointer.
     connect(webEngineViewPointer, SIGNAL(loadFinished(const bool)), this, SLOT(loadFinished()));
 
     // Instantiate the mouse event filter pointer.
-    MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(webEngineViewPointer);
+    MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter();
 
     // Install the mouse event filter.
     qApp->installEventFilter(mouseEventFilterPointer);
 
 
     // Install the mouse event filter.
     qApp->installEventFilter(mouseEventFilterPointer);
 
+    // Process mouse forward and back commands.
+    connect(mouseEventFilterPointer, SIGNAL(mouseBack()), this, SLOT(mouseBack()));
+    connect(mouseEventFilterPointer, SIGNAL(mouseForward()), this, SLOT(mouseForward()));
+
     // Listen for hovered link URLs.
     connect(webEnginePagePointer, SIGNAL(linkHovered(const QString)), this, SLOT(pageLinkHovered(const QString)));
 
     // Listen for hovered link URLs.
     connect(webEnginePagePointer, SIGNAL(linkHovered(const QString)), this, SLOT(pageLinkHovered(const QString)));
 
@@ -376,6 +380,32 @@ void BrowserView::loadUrlFromLineEdit(QString url) const
     }
 }
 
     }
 }
 
+void BrowserView::mouseBack() const
+{
+    // Go back if possible.
+    if (webEngineHistoryPointer->canGoBack())
+    {
+        // Clear the URL line edit focus.
+        emit clearUrlLineEditFocus();
+
+        // Go back.
+        webEngineViewPointer->back();
+    }
+}
+
+void BrowserView::mouseForward() const
+{
+    // Go forward if possible.
+    if (webEngineHistoryPointer->canGoForward())
+    {
+        // Clear the URL line edit focus.
+        emit clearUrlLineEditFocus();
+
+        // Go forward.
+        webEngineViewPointer->forward();
+    }
+}
+
 void BrowserView::pageLinkHovered(const QString &linkUrl) const
 {
     // Emit a signal so that the browser window can update the status bar.
 void BrowserView::pageLinkHovered(const QString &linkUrl) const
 {
     // Emit a signal so that the browser window can update the status bar.
index d61ceaefd8b371694561e3d887e442b4730e9a56..29ae93c04ebe91221b00f923e9a6d243c3d6ad1b 100644 (file)
@@ -49,6 +49,7 @@ public:
 
 signals:
     // The signals.
 
 signals:
     // The signals.
+    void clearUrlLineEditFocus() const;
     void hideProgressBar() const;
     void linkHovered(const QString &linkUrl) const;
     void showProgressBar(const int &progress) const;
     void hideProgressBar() const;
     void linkHovered(const QString &linkUrl) const;
     void showProgressBar(const int &progress) const;
@@ -73,6 +74,8 @@ public Q_SLOTS:
     void forward() const;
     void home() const;
     void loadUrlFromLineEdit(QString url) const;
     void forward() const;
     void home() const;
     void loadUrlFromLineEdit(QString url) const;
+    void mouseBack() const;
+    void mouseForward() const;
     void refresh() const;
 
 private Q_SLOTS:
     void refresh() const;
 
 private Q_SLOTS:
index a29b5037c83af5ae69dcfd9f146228fc96f0e251..3ddba02c9e3809475a6d7393354b5cbc5eae33fb 100644 (file)
@@ -218,6 +218,9 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     connect(browserViewPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
     connect(browserViewPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
 
     connect(browserViewPointer, SIGNAL(showProgressBar(const int)), this, SLOT(showProgressBar(const int)));
     connect(browserViewPointer, SIGNAL(hideProgressBar()), progressBarPointer, SLOT(hide()));
 
+    // Clear the URL line edit focus when requested.
+    connect(browserViewPointer, SIGNAL(clearUrlLineEditFocus()), this, SLOT(clearUrlLineEditFocus()));
+
     // Get the URL line edit palettes.
     noDomainSettingsPalette = urlLineEditPointer->palette();
     domainSettingsPalette = urlLineEditPointer->palette();
     // Get the URL line edit palettes.
     noDomainSettingsPalette = urlLineEditPointer->palette();
     domainSettingsPalette = urlLineEditPointer->palette();
@@ -274,6 +277,12 @@ void BrowserWindow::back() const
     browserViewPointer->back();
 }
 
     browserViewPointer->back();
 }
 
+void BrowserWindow::clearUrlLineEditFocus() const
+{
+    // Remove the focus from the URL line edit.
+    urlLineEditPointer->clearFocus();
+}
+
 void BrowserWindow::fileNew() const
 {
     // Display a new instance of Privacy Browser.
 void BrowserWindow::fileNew() const
 {
     // Display a new instance of Privacy Browser.
index 5be55f489ed6dda00f38bc2e1c7b093ff0eb0ced..60dea63b7aa5604c936aad11badd9c30a6f71ebb 100644 (file)
@@ -47,6 +47,7 @@ private Q_SLOTS:
     // The private slots.
     void addOrEditDomainSettings() const;
     void back() const;
     // The private slots.
     void addOrEditDomainSettings() const;
     void back() const;
+    void clearUrlLineEditFocus() const;
     void fileNew() const;
     void forward() const;
     void getZoomFactorFromUser();
     void fileNew() const;
     void forward() const;
     void getZoomFactorFromUser();