# 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 subdirectories.
add_subdirectory(dialogs)
+add_subdirectory(filters)
add_subdirectory(helpers)
add_subdirectory(interceptors)
add_subdirectory(ui.rc)
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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
--- /dev/null
+# 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
+)
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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
<!-- 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" />
<Action name="search_engine_custom" />
</Menu>
</Menu>
+
+ <!-- Settings. -->
+ <Menu name="settings">
+ <Action name="domain_settings" />
+ </Menu>
</MenuBar>
<!-- The main toolbar is removed. -->
<ToolBar name="url_toolbar" iconText="icononly"> <text>URL Toolbar</text>
<Action name="javascript" />
<Action name="local_storage" />
- <Action name="domain_settings" />
</ToolBar>
</gui>
// 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"
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)));
}
}
+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.
signals:
// The signals.
+ void clearUrlLineEditFocus() const;
void hideProgressBar() const;
void linkHovered(const QString &linkUrl) const;
void showProgressBar(const int &progress) const;
void forward() const;
void home() const;
void loadUrlFromLineEdit(QString url) const;
+ void mouseBack() const;
+ void mouseForward() const;
void refresh() const;
private Q_SLOTS:
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();
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.
// The private slots.
void addOrEditDomainSettings() const;
void back() const;
+ void clearUrlLineEditFocus() const;
void fileNew() const;
void forward() const;
void getZoomFactorFromUser();