]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Display hovered link URLs in the status bar.
authorSoren Stoutner <soren@stoutner.com>
Sat, 29 Jan 2022 20:01:40 +0000 (13:01 -0700)
committerSoren Stoutner <soren@stoutner.com>
Sat, 29 Jan 2022 20:01:40 +0000 (13:01 -0700)
src/CMakeLists.txt
src/browserwindow.cpp [new file with mode: 0644]
src/browserwindow.h [new file with mode: 0644]
src/main.cpp
src/mainview.cpp
src/mainview.h
src/mainwindow.cpp [deleted file]
src/mainwindow.h [deleted file]

index 2b5beb12619e52cb0ea1ea4a435e451ec7d96c5f..320ae9dd5fb569090398d14f287dfaeb837ac2c0 100644 (file)
@@ -21,8 +21,8 @@ add_executable(privacy-browser resources.qrc)
 
 # List the sources to include in the executable.
 target_sources(privacy-browser PRIVATE
 
 # List the sources to include in the executable.
 target_sources(privacy-browser PRIVATE
+    browserwindow.cpp
     main.cpp
     main.cpp
-    mainwindow.cpp
     mainview.cpp
 )
 
     mainview.cpp
 )
 
diff --git a/src/browserwindow.cpp b/src/browserwindow.cpp
new file mode 100644 (file)
index 0000000..d539fed
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * 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 "browserwindow.h"
+#include "mainview.h"
+#include "settings.h"
+#include "ui_settings.h"
+
+// KDE Frameworks headers.
+#include <KActionCollection>
+#include <KConfigDialog>
+
+// Qt framework headers.
+#include <QStatusBar>
+
+BrowserWindow::BrowserWindow() : KXmlGuiWindow()
+{
+    // Instantiate the main view pointer.
+    MainView *mainViewPointer = new MainView(this);
+
+    // Set the main view as the central widget.
+    setCentralWidget(mainViewPointer);
+
+    // Get a handle for the action collectoin.
+    KActionCollection *actionCollectionPointer = this->actionCollection();
+
+    // Add the standard actions.
+    KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
+    KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
+    KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
+
+    // Update the status bar with the URL when a link is hovered.
+    connect(mainViewPointer, SIGNAL(linkHovered(QString)), this, SLOT(updateStatusBar(QString)));
+
+    // Setup the GUI based on the privacybrowserui.rc file.
+    setupGUI();
+}
+
+void BrowserWindow::fileNew()
+{
+    // Display a new instance of Privacy Browser.
+    (new BrowserWindow)->show();
+}
+
+void BrowserWindow::settingsConfigure()
+{
+    // Check to make sure the dialog box isn't already displayed.
+    if (!KConfigDialog::exists(QStringLiteral("settings")))
+    {
+        // Create a general settings page.
+        QWidget *generalSettingsWidgetPointer = new QWidget;
+
+        // Instantiate the settings UI.
+        Ui::Settings settingsUi;
+
+        // Setup the UI to display the general settings widget.
+        settingsUi.setupUi(generalSettingsWidgetPointer);
+
+        // Instantiate a settings config dialog from the settings.kcfg file.
+        KConfigDialog *configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
+
+        // Add the general settings widget page.
+        configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
+
+        // Delete the config dialog when it is closed.
+        configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
+
+        // Make it so.
+        configDialogPointer->show();
+    }
+}
+
+void BrowserWindow::updateStatusBar(const QString &statusBarMessage)
+{
+    // Display the status bar message.
+    statusBar()->showMessage(statusBarMessage);
+}
diff --git a/src/browserwindow.h b/src/browserwindow.h
new file mode 100644 (file)
index 0000000..613f210
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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 BROWSERWINDOW_H
+#define BROWSERWINDOW_H
+
+// KDE Frameworks headers.
+#include <KXmlGuiWindow>
+
+class BrowserWindow : public KXmlGuiWindow
+{
+    // Include the Q_OBJECT macro.
+    Q_OBJECT
+
+public:
+    // The default constructor.
+    BrowserWindow();
+
+private Q_SLOTS:
+    // Define the private slots.
+    void fileNew();
+    void settingsConfigure();
+    void updateStatusBar(const QString &statusBarMessage);
+};
+#endif
index 6bf5e74b642466face091a50d80a2acbc9969fe8..80909e284a603b7b28904abe08118db25cd1a3bc 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 // Application headers.
  */
 
 // Application headers.
-#include "mainwindow.h"
+#include "browserwindow.h"
 
 // KDE Frameworks headers.
 #include <KAboutData>
 
 // KDE Frameworks headers.
 #include <KAboutData>
@@ -79,10 +79,10 @@ int main(int argc, char *argv[])
     KDBusService appDBusService(KDBusService::Multiple | KDBusService::NoExitOnFailure);
 
     // Create the main window.
     KDBusService appDBusService(KDBusService::Multiple | KDBusService::NoExitOnFailure);
 
     // Create the main window.
-    MainWindow *mainWindowPointer = new MainWindow;
+    BrowserWindow *browserWindowPointer = new BrowserWindow;
 
     // Show the main window.
 
     // Show the main window.
-    mainWindowPointer->show();
+    browserWindowPointer->show();
 
     // Return the application.
     return application.exec();
 
     // Return the application.
     return application.exec();
index e46f00d1d6660f68a6d9140a2ca61121668015f8..b1adcbf2dc49f66c6796fb18a5e8a520c159e572 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 // Application headers
  */
 
 // Application headers
+#include "browserwindow.h"
 #include "mainview.h"
 #include "settings.h"
 
 #include "mainview.h"
 #include "settings.h"
 
@@ -39,6 +40,9 @@ MainView::MainView(QWidget *parent) : QWidget(parent)
     urlLineEditPointer = mainViewUi.urlLineEdit;
     webEngineViewPointer = mainViewUi.webEngineView;
 
     urlLineEditPointer = mainViewUi.urlLineEdit;
     webEngineViewPointer = mainViewUi.webEngineView;
 
+    // Get a handle for the webpage.
+    QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page();
+
     // Update the webengine view from the URL line edit.
     connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString)));
 
     // Update the webengine view from the URL line edit.
     connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrl(const QString)));
 
@@ -47,9 +51,15 @@ MainView::MainView(QWidget *parent) : QWidget(parent)
     connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateUrlLineEdit()));
     connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateUrlLineEdit()));
 
     connect(webEngineViewPointer, SIGNAL(loadProgress(int)), this, SLOT(updateUrlLineEdit()));
     connect(webEngineViewPointer, SIGNAL(loadFinished(bool)), this, SLOT(updateUrlLineEdit()));
 
+    // Listen for hovered link URLs.
+    connect(webEnginePagePointer, SIGNAL(linkHovered(QString)), this, SLOT(pageLinkHovered(QString)));
+
     // Set the zoom factor.
     webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
 
     // Set the zoom factor.
     webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
 
+    // Set the focus on the WebEngine view.
+    webEngineViewPointer->setFocus();
+
     // Load a website.
     webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/")));
 }
     // Load a website.
     webEngineViewPointer->setUrl(QUrl(QStringLiteral("https://www.stoutner.com/")));
 }
@@ -60,10 +70,20 @@ void MainView::loadUrl(const QString &urlFromUser)
     webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
 }
 
     webEngineViewPointer->setUrl(QUrl::fromUserInput(urlFromUser));
 }
 
+void MainView::pageLinkHovered(const QString &linkUrl)
+{
+    // Emit a signal so that the browser window can update the status bar.
+    emit linkHovered(linkUrl);
+}
+
 void MainView::updateUrlLineEdit()
 {
 void MainView::updateUrlLineEdit()
 {
-    // Update the URL line edit.
-    urlLineEditPointer->setUrl(webEngineViewPointer->url().toString());
+    // Update the URL line edit if it does not have focus.
+    if (!urlLineEditPointer->hasFocus())
+    {
+        // 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());
 
     // 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());
index 9affb38d933492da108a3f71008aa899af6433dc..47a9f270a14c9dc07a1ef3f61cff7dc89a01525e 100644 (file)
@@ -32,9 +32,14 @@ public:
     // The default contructor.
     explicit MainView(QWidget *parent);
 
     // The default contructor.
     explicit MainView(QWidget *parent);
 
+signals:
+    // Define the signals.
+    void linkHovered(const QString &linkUrl);
+
 private Q_SLOTS:
     // Define the private slots.
     void loadUrl(const QString &urlFromUser);
 private Q_SLOTS:
     // Define the private slots.
     void loadUrl(const QString &urlFromUser);
+    void pageLinkHovered(const QString &linkUrl);
     void updateUrlLineEdit();
 
 private:
     void updateUrlLineEdit();
 
 private:
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
deleted file mode 100644 (file)
index c48e495..0000000
+++ /dev/null
@@ -1,82 +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 "mainview.h"
-#include "mainwindow.h"
-#include "settings.h"
-#include "ui_settings.h"
-
-// KDE Frameworks headers.
-#include <KActionCollection>
-#include <KConfigDialog>
-
-MainWindow::MainWindow() : KXmlGuiWindow()
-{
-    // Instantiate the main view pointer.
-    MainView *mainViewPointer = new MainView(this);
-
-    // Set the main view as the central widget.
-    setCentralWidget(mainViewPointer);
-
-    // Get a handle for the action collectoin.
-    KActionCollection *actionCollectionPointer = this->actionCollection();
-
-    // Add the standard actions.
-    KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
-    KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
-    KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
-
-    // Setup the GUI based on the privacybrowserui.rc file.
-    setupGUI();
-}
-
-void MainWindow::fileNew()
-{
-    // Display a new instance of Privacy Browser.
-    (new MainWindow)->show();
-}
-
-void MainWindow::settingsConfigure()
-{
-    // Check to make sure the dialog box isn't already displayed.
-    if (!KConfigDialog::exists(QStringLiteral("settings")))
-    {
-        // Create a general settings page.
-        QWidget *generalSettingsWidgetPointer = new QWidget;
-
-        // Instantiate the settings UI.
-        Ui::Settings settingsUi;
-
-        // Setup the UI to display the general settings widget.
-        settingsUi.setupUi(generalSettingsWidgetPointer);
-
-        // Instantiate a settings config dialog from the settings.kcfg file.
-        KConfigDialog *configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
-
-        // Add the general settings widget page.
-        configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
-
-        // Delete the config dialog when it is closed.
-        configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
-
-        // Make it so.
-        configDialogPointer->show();
-    }
-}
diff --git a/src/mainwindow.h b/src/mainwindow.h
deleted file mode 100644 (file)
index 588ac9e..0000000
+++ /dev/null
@@ -1,40 +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 MAINWINDOW_H
-#define MAINWINDOW_H
-
-// KDE Frameworks headers.
-#include <KXmlGuiWindow>
-
-class MainWindow : public KXmlGuiWindow
-{
-    // Include the Q_OBJECT macro.
-    Q_OBJECT
-
-public:
-    // The default constructor.
-    MainWindow();
-
-private Q_SLOTS:
-    // Define the private slots.
-    void fileNew();
-    void settingsConfigure();
-};
-#endif