From: Soren Stoutner Date: Tue, 12 Apr 2022 21:41:29 +0000 (-0700) Subject: Clear the URL line edit when navigating history. https://redmine.stoutner.com/issues/841 X-Git-Tag: v0.1~38 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=34816101e23ae2b489d64d540534125cf2c2e925;p=PrivacyBrowserPC.git Clear the URL line edit when navigating history. https://redmine.stoutner.com/issues/841 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8371822..4d33710 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 - MouseEventFilter.cpp ) # 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_subdirectory(filters) add_subdirectory(helpers) add_subdirectory(interceptors) add_subdirectory(ui.rc) diff --git a/src/MouseEventFilter.cpp b/src/MouseEventFilter.cpp deleted file mode 100644 index 3454d06..0000000 --- a/src/MouseEventFilter.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright © 2022 Soren Stoutner . - * - * This file is part of 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 . - */ - -// Application headers. -#include "MouseEventFilter.h" - -// Qt headers. -#include -#include - -// 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(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 index 92c015a..0000000 --- a/src/MouseEventFilter.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2022 Soren Stoutner . - * - * This file is part of 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 . - */ - -#ifndef MOUSEEVENTFILTER_H -#define MOUSEEVENTFILTER_H - -// Qt headers. -#include -#include - -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 index 0000000..c57b6ee --- /dev/null +++ b/src/filters/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright © 2022 Soren Stoutner . +# +# This file is part of 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 . + + +# 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 index 0000000..51bbb09 --- /dev/null +++ b/src/filters/MouseEventFilter.cpp @@ -0,0 +1,66 @@ +/* + * Copyright © 2022 Soren Stoutner . + * + * This file is part of 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 . + */ + +// Application headers. +#include "MouseEventFilter.h" + +// Qt headers. +#include +#include + +// 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(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 index 0000000..02e1b2d --- /dev/null +++ b/src/filters/MouseEventFilter.h @@ -0,0 +1,45 @@ +/* + * Copyright © 2022 Soren Stoutner . + * + * This file is part of 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 . + */ + +#ifndef MOUSEEVENTFILTER_H +#define MOUSEEVENTFILTER_H + +// Qt headers. +#include +#include + +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 diff --git a/src/ui.rc/browser_ui.rc b/src/ui.rc/browser_ui.rc index 0e1d60b..4c42e77 100644 --- a/src/ui.rc/browser_ui.rc +++ b/src/ui.rc/browser_ui.rc @@ -29,6 +29,7 @@ + On-The-Fly Settings User Agent @@ -56,6 +57,11 @@ + + + + + @@ -73,6 +79,5 @@ URL Toolbar - diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 2e29ea0..873b947 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -19,9 +19,9 @@ // Application headers. #include "BrowserView.h" -#include "MouseEventFilter.h" #include "Settings.h" #include "ui_BrowserView.h" +#include "filters/MouseEventFilter.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. - MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(webEngineViewPointer); + MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(); // 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))); @@ -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. diff --git a/src/views/BrowserView.h b/src/views/BrowserView.h index d61ceae..29ae93c 100644 --- a/src/views/BrowserView.h +++ b/src/views/BrowserView.h @@ -49,6 +49,7 @@ public: signals: // The signals. + void clearUrlLineEditFocus() 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 mouseBack() const; + void mouseForward() const; void refresh() const; private Q_SLOTS: diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index a29b503..3ddba02 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -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())); + // 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(); @@ -274,6 +277,12 @@ void BrowserWindow::back() const 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. diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 5be55f4..60dea63 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -47,6 +47,7 @@ private Q_SLOTS: // The private slots. void addOrEditDomainSettings() const; void back() const; + void clearUrlLineEditFocus() const; void fileNew() const; void forward() const; void getZoomFactorFromUser();