Reimplement the URL bar as standard toolbars.
authorSoren Stoutner <soren@stoutner.com>
Sat, 26 Mar 2022 21:10:32 +0000 (14:10 -0700)
committerSoren Stoutner <soren@stoutner.com>
Sat, 26 Mar 2022 21:10:32 +0000 (14:10 -0700)
src/BrowserView.ui
src/views/BrowserView.cpp
src/views/BrowserView.h
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

index 43b958965aa64b55785534fa8cbc9c3af2ff0f40..d78eb203637643e975533f75ef3d422b2129813f 100644 (file)
                 <number>0</number>
             </property>
 
-            <!-- URL bar. -->
-            <item>
-                <layout class="QHBoxLayout">
-                    <!-- Back button. -->
-                    <item>
-                        <widget class="QPushButton" name="backButton">
-                            <property name="icon">
-                                <iconset theme="arrow-left" />
-                            </property>
-
-                            <property name="iconSize">
-                                <size>
-                                    <height>24</height>
-                                    <width>24</width>
-                                </size>
-                            </property>
-
-                            <property name="flat">
-                                <bool>true</bool>
-                            </property>
-                        </widget>
-                    </item>
-
-                    <!-- Forward button. -->
-                    <item>
-                        <widget class="QPushButton" name="forwardButton">
-                            <property name="icon">
-                                <iconset theme="arrow-right" />
-                            </property>
-
-                            <property name="iconSize">
-                                <size>
-                                    <height>24</height>
-                                    <width>24</width>
-                                </size>
-                            </property>
-
-                            <property name="flat">
-                                <bool>true</bool>
-                            </property>
-                        </widget>
-                    </item>
-
-                    <!-- Refresh button. -->
-                    <item>
-                        <widget class="QPushButton" name="refreshButton">
-                            <property name="icon">
-                                <iconset theme="view-refresh" />
-                            </property>
-
-                            <property name="iconSize">
-                                <size>
-                                    <height>24</height>
-                                    <width>24</width>
-                                </size>
-                            </property>
-
-                            <property name="flat">
-                                <bool>true</bool>
-                            </property>
-                        </widget>
-                    </item>
-
-                    <!-- Home button. -->
-                    <item>
-                        <widget class="QPushButton" name="homeButton">
-                            <property name="icon">
-                                <iconset theme="home" />
-                            </property>
-
-                            <property name="iconSize">
-                                <size>
-                                    <height>24</height>
-                                    <width>24</width>
-                                </size>
-                            </property>
-
-                            <property name="flat">
-                                <bool>true</bool>
-                            </property>
-                        </widget>
-                    </item>
-
-                    <!-- URL line edit. -->
-                    <item>
-                        <widget class="KLineEdit" name="urlLineEdit" />
-                    </item>
-
-                    <!-- JavaScript. -->
-                    <item>
-                        <widget class="QPushButton" name="javaScript">
-                            <property name="iconSize">
-                                <size>
-                                    <height>24</height>
-                                    <width>24</width>
-                                </size>
-                            </property>
-
-                            <property name="flat">
-                                <bool>true</bool>
-                            </property>
-                        </widget>
-                    </item>
-
-                    <!-- Domain Settings. -->
-                    <item>
-                        <widget class="QPushButton" name="domainSettingsButton">
-                            <property name="icon">
-                                <iconset theme="network-server-symbolic" />
-                            </property>
-
-                            <property name="iconSize">
-                                <size>
-                                    <height>24</height>
-                                    <width>24</width>
-                                </size>
-                            </property>
-
-                            <property name="flat">
-                                <bool>true</bool>
-                            </property>
-                        </widget>
-                    </item>
-                </layout>
-            </item>
-
             <!-- WebEngine view. -->
             <item>
                 <widget class="QWebEngineView" name="webEngineView" />
index 07c11301b1619f5eef790eafb42654eb20929c56..319f9e51b7624ef49776445be3d1c776025dc550 100644 (file)
@@ -23,7 +23,6 @@
 #include "Settings.h"
 #include "ui_BrowserView.h"
 #include "UrlRequestInterceptor.h"
-#include "dialogs/DomainSettingsDialog.h"
 #include "helpers/DomainsDatabaseHelper.h"
 #include "helpers/SearchEngineHelper.h"
 #include "helpers/UserAgentHelper.h"
@@ -42,13 +41,6 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
     browserViewUi.setupUi(this);
 
     // Get handles for the views.
-    backButtonPointer = browserViewUi.backButton;
-    forwardButtonPointer = browserViewUi.forwardButton;
-    QPushButton *refreshButtonPointer = browserViewUi.refreshButton;
-    QPushButton *homeButtonPointer = browserViewUi.homeButton;
-    urlLineEditPointer = browserViewUi.urlLineEdit;
-    javaScriptButtonPointer = browserViewUi.javaScript;
-    QPushButton *domainSettingsButtonPointer = browserViewUi.domainSettingsButton;
     webEngineViewPointer = browserViewUi.webEngineView;
 
     // Get handles for the aspects of the WebEngine.
@@ -57,30 +49,12 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent)
     webEngineProfilePointer = webEnginePagePointer->profile();
     webEngineSettingsPointer = webEngineViewPointer->settings();
 
-    // Update the webengine view from the URL line edit.  TODO.  Remove.
-    connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
-
     // Update the URL line edit from the webengine view.
     connect(webEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(updateInterface()));
     connect(webEngineViewPointer, SIGNAL(loadProgress(const int)), this, SLOT(updateInterface()));
     connect(webEngineViewPointer, SIGNAL(loadFinished(const bool)), this, SLOT(updateInterface()));
 
-    // Setup the URL bar buttons.  TODO.  Remove.
-    connect(backButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(back()));
-    connect(forwardButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(forward()));
-    connect(refreshButtonPointer, SIGNAL(clicked()), webEngineViewPointer, SLOT(reload()));
-    connect(homeButtonPointer, SIGNAL(clicked()), this, SLOT(home()));
-    connect(javaScriptButtonPointer, SIGNAL(clicked()), this, SLOT(toggleJavaScript()));
-    connect(domainSettingsButtonPointer, SIGNAL(clicked()), this, SLOT(openDomainSettings()));
-
-    // Get the URL line edit palettes.  TODO.  Remove.
-    noDomainSettingsPalette = urlLineEditPointer->palette();
-    domainSettingsPalette = urlLineEditPointer->palette();
-
-    // Modify the domain settings palette.  TODO.  Remove.
-    domainSettingsPalette.setColor(QPalette::Base, QColor("#C8E6C9"));
-
-    // Instantiate the mouse event pointer.
+    // Instantiate the mouse event filter pointer.
     MouseEventFilter *mouseEventFilterPointer = new MouseEventFilter(webEngineViewPointer);
 
     // Install the mouse event filter.
@@ -177,7 +151,6 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
         webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
 
         // Apply the domain settings palette to the URL line edit.
-        urlLineEditPointer->setPalette(domainSettingsPalette);  // TODO.  Remove.
         emit updateDomainSettingsIndicator(true);
     }
     else  // The hostname does not have domain settings.
@@ -192,21 +165,11 @@ void BrowserView::applyDomainSettings(const QString &hostname, const bool reload
         webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
 
         // Apply the no domain settings palette to the URL line edit.
-        urlLineEditPointer->setPalette(noDomainSettingsPalette);  // TODO.  Remove.
         emit updateDomainSettingsIndicator(false);
     }
 
-    // Update the JavaScript button.
-    if (webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled))
-    {
-        javaScriptButtonPointer->setIcon(QIcon(":/icons/javascript-warning"));
-    }
-    else
-    {
-        javaScriptButtonPointer->setIcon(QIcon(":/icons/privacy-mode"));
-    }
-
     // Emit the on-the-fly menu update signals.
+    emit updateJavaScriptAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
     emit userAgentUpdated(webEngineProfilePointer->httpUserAgent());
     emit zoomFactorUpdated(Settings::zoomFactor());
 
@@ -291,9 +254,6 @@ void BrowserView::loadInitialWebsite()
 
 void BrowserView::loadUrlFromLineEdit(QString url) const
 {
-    // Remove the focus from the URL line edit.  TODO.  Remove.
-    urlLineEditPointer->clearFocus();
-
     // Decide if the text is more likely to be a URL or a search.
     if (url.contains("."))  // The text is likely a URL.
     {
@@ -314,24 +274,6 @@ void BrowserView::loadUrlFromLineEdit(QString url) const
     }
 }
 
-void BrowserView::openDomainSettings() const
-{
-    // Instantiate the domain settings window.
-    DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
-
-    // Set the dialog window title.
-    domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
-
-    // Set the modality.
-    domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
-
-    // Show the dialog.
-    domainSettingsDialogPointer->show();
-
-    // Reload the tabs when domain settings are updated.
-    connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), this, SLOT(applyDomainSettingsAndReload()));
-}
-
 void BrowserView::pageLinkHovered(const QString &linkUrl) const
 {
     // Emit a signal so that the browser window can update the status bar.
@@ -349,15 +291,8 @@ void BrowserView::toggleJavaScript() const
     // Toggle JavaScript.
     webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, !webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
 
-    // Update the JavaScript button.
-    if (webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled))
-    {
-        javaScriptButtonPointer->setIcon(QIcon(":/icons/javascript-warning"));
-    }
-    else
-    {
-        javaScriptButtonPointer->setIcon(QIcon(":/icons/privacy-mode"));
-    }
+    // Update the JavaScript icon.
+    emit updateJavaScriptAction(webEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
 
     // Reload the website.
     webEngineViewPointer->reload();
@@ -365,20 +300,11 @@ void BrowserView::toggleJavaScript() const
 
 void BrowserView::updateInterface() const
 {
-    // Update the URL line edit if it does not have focus.  TODO.  Remove block.
-    if (!urlLineEditPointer->hasFocus())
-    {
-        // Update the URL line edit.
-        urlLineEditPointer->setText(webEngineViewPointer->url().toString());
-    }
-
     // Update the URL line edit.
     emit updateUrlLineEdit(webEngineViewPointer->url().toString());
 
     // Update the status of the forward and back buttons.
-    backButtonPointer->setEnabled(webEngineHistoryPointer->canGoBack());  // TODO Remove.
     emit updateBackAction(webEngineHistoryPointer->canGoBack());
-    forwardButtonPointer->setEnabled(webEngineHistoryPointer->canGoForward());  // TODO Remove.
     emit updateForwardAction(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.  <https://bugreports.qt.io/browse/QTBUG-51992>
index 27c4439cd64dd117b73f5aa889978d3a041415c3..3ba8bc7ea262b53d2df7862ce3de98a34d0c6372 100644 (file)
@@ -45,13 +45,14 @@ public:
 signals:
     // The signals.
     void linkHovered(const QString &linkUrl) const;
-    void userAgentUpdated(const QString &userAgent) const;
-    void searchEngineUpdated(const QString &searchEngine) const;
+    void userAgentUpdated(const QString &userAgent) const;  // TODO.  Possibly rename.
+    void searchEngineUpdated(const QString &searchEngine) const;  //TODO.  Possibly rename.
     void updateBackAction(const bool &isEnabled) const;
     void updateDomainSettingsIndicator(const bool status) const;
     void updateForwardAction(const bool &isEnabled) const;
+    void updateJavaScriptAction(const bool &isEnabled) const;
     void updateUrlLineEdit(const QString &newUrl) const;
-    void zoomFactorUpdated(const double &zoomFactor) const;
+    void zoomFactorUpdated(const double &zoomFactor) const;  //TODO.  Possibly rename.
 
 public Q_SLOTS:
     // The public slots.
@@ -64,24 +65,17 @@ public Q_SLOTS:
     void forward() const;
     void home() const;
     void loadUrlFromLineEdit(QString url) const;
+    void toggleJavaScript() const;
     void refresh() const;
 
 private Q_SLOTS:
     // The private slots.
     void pageLinkHovered(const QString &linkUrl) const;
-    void toggleJavaScript() const;
-    void openDomainSettings() const;
     void updateInterface() const;
 
 private:
     // The private variables.
-    QPushButton *backButtonPointer;
-    QPalette domainSettingsPalette;  // TODO.  Remove.
-    QPushButton *forwardButtonPointer;
-    QPushButton *javaScriptButtonPointer;
-    QPalette noDomainSettingsPalette;  // TODO.  Remove.
     QString searchEngineUrl;
-    KLineEdit *urlLineEditPointer;
     QWebEngineHistory *webEngineHistoryPointer;
     QWebEngineProfile *webEngineProfilePointer;
     QWebEngineSettings *webEngineSettingsPointer;
index 5a84d40c97df93be9cf436b198e3431f3177299a..d83dd69b5e515b12a2baf6fa9cd3e8689ac93d7a 100644 (file)
@@ -22,6 +22,7 @@
 #include "Settings.h"
 #include "ui_SettingsPrivacy.h"
 #include "ui_SettingsGeneral.h"
+#include "dialogs/DomainSettingsDialog.h"
 #include "helpers/SearchEngineHelper.h"
 #include "helpers/UserAgentHelper.h"
 
@@ -70,6 +71,8 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     forwardActionPointer = actionCollectionPointer->addAction(QStringLiteral("forward"));
     refreshActionPointer = actionCollectionPointer->addAction(QStringLiteral("refresh"));
     homeActionPointer = actionCollectionPointer->addAction(QStringLiteral("home"));
+    javaScriptActionPointer = actionCollectionPointer->addAction(QStringLiteral("javascript"));
+    domainSettingsActionPointer = actionCollectionPointer->addAction(QStringLiteral("domain_settings"));
 
     // Create the action groups
     QActionGroup *userAgentActionGroupPointer = new QActionGroup(this);
@@ -127,12 +130,15 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     forwardActionPointer->setText(i18nc("Forward button", "Forward"));
     refreshActionPointer->setText(i18nc("Refresh button", "Refresh"));
     homeActionPointer->setText(i18nc("Home button", "Home"));
+    javaScriptActionPointer->setText(i18nc("JavaScript button", "JavaScript"));
+    domainSettingsActionPointer->setText(i18nc("Domain Settings button", "Domain Settings"));
 
     // Set the action icons.
     backActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("arrow-left")));
     forwardActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("arrow-right")));
     refreshActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
     homeActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("home")));
+    domainSettingsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("network-server-symbolic")));
 
     // Update the on-the-fly menus.
     connect(browserViewPointer, SIGNAL(userAgentUpdated(QString)), this, SLOT(updateOnTheFlyUserAgent(QString)));
@@ -151,10 +157,13 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     connect(forwardActionPointer, SIGNAL(triggered()), this, SLOT(forward()));
     connect(refreshActionPointer, SIGNAL(triggered()), this, SLOT(refresh()));
     connect(homeActionPointer, SIGNAL(triggered()), this, SLOT(home()));
+    connect(javaScriptActionPointer, SIGNAL(triggered()), this, SLOT(toggleJavaScript()));
+    connect(domainSettingsActionPointer, SIGNAL(triggered()), this, SLOT(openDomainSettings()));
 
     // Update the URL toolbar actions.
     connect(browserViewPointer, SIGNAL(updateBackAction(bool)), backActionPointer, SLOT(setEnabled(bool)));
     connect(browserViewPointer, SIGNAL(updateForwardAction(bool)), forwardActionPointer, SLOT(setEnabled(bool)));
+    connect(browserViewPointer, SIGNAL(updateJavaScriptAction(bool)), this, SLOT(updateJavaScriptAction(bool)));
 
     // Setup the GUI based on the browser_ui.rc file.
     setupGUI(StandardWindowOption::Default, ("browser_ui.rc"));
@@ -165,8 +174,10 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     // Create a URL line edit.
     urlLineEditPointer = new KLineEdit();
 
-    // Add the URL line edit to the URL toolbar.
+    // Populate the URL toolbar.
     urlToolBarPointer->addWidget(urlLineEditPointer);
+    urlToolBarPointer->addAction(javaScriptActionPointer);
+    urlToolBarPointer->addAction(domainSettingsActionPointer);
 
     // Load a new URL from the URL line edit.
     connect(urlLineEditPointer, SIGNAL(returnKeyPressed(const QString)), this, SLOT(loadUrlFromLineEdit(const QString)));
@@ -260,6 +271,27 @@ void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
     browserViewPointer->loadUrlFromLineEdit(url);
 }
 
+void BrowserWindow::openDomainSettings() const
+{
+    // Remove the focus from the URL line edit.
+    urlLineEditPointer->clearFocus();
+
+    // Instantiate the domain settings window.
+    DomainSettingsDialog *domainSettingsDialogPointer = new DomainSettingsDialog();
+
+    // Set the dialog window title.
+    domainSettingsDialogPointer->setWindowTitle(i18nc("The domain settings dialog title", "Domain Settings"));
+
+    // Set the modality.
+    domainSettingsDialogPointer->setWindowModality(Qt::WindowModality::WindowModal);;
+
+    // Show the dialog.
+    domainSettingsDialogPointer->show();
+
+    // Reload the tabs when domain settings are updated.
+    connect(domainSettingsDialogPointer, SIGNAL(domainSettingsUpdated()), browserViewPointer, SLOT(applyDomainSettingsAndReload()));
+}
+
 void BrowserWindow::refresh() const
 {
     // Remove the focus from the URL line edit.
@@ -269,6 +301,15 @@ void BrowserWindow::refresh() const
     browserViewPointer->refresh();
 }
 
+void BrowserWindow::toggleJavaScript() const
+{
+    // Remove the focus from the URL line edit.
+    urlLineEditPointer->clearFocus();
+
+    // Toggle JavaScript.
+    browserViewPointer->toggleJavaScript();
+}
+
 void BrowserWindow::settingsConfigure()
 {
     // Check to make sure the dialog box isn't already displayed.
@@ -344,13 +385,20 @@ void BrowserWindow::settingsConfigure()
     }
 }
 
-void BrowserWindow::updateDomainSettingsIndicator(const bool status) const
+void BrowserWindow::updateDomainSettingsIndicator(const bool &status) const
 {
     // Set the domain palette according to the status.
     if (status) urlLineEditPointer->setPalette(domainSettingsPalette);
     else urlLineEditPointer->setPalette(noDomainSettingsPalette);
 }
 
+void BrowserWindow::updateJavaScriptAction(const bool &isEnabled) const
+{
+    // Set the icon according to the status.
+    if (isEnabled) javaScriptActionPointer->setIcon(QIcon(":/icons/javascript-warning"));
+    else javaScriptActionPointer->setIcon(QIcon(":/icons/privacy-mode"));
+}
+
 void BrowserWindow::updateOnTheFlySearchEngine(const QString &searchEngine) const
 {
     // Initialize the custom search engine flag.
index f86c1b2f11f7bfdd58ba3fa76ab106b229db6a82..7fa60500390cbc170dbdeb392ee1e41d234b72fc 100644 (file)
@@ -47,9 +47,12 @@ private Q_SLOTS:
     void getZoomFactorFromUser();
     void home() const;
     void loadUrlFromLineEdit(const QString &url) const;
+    void openDomainSettings() const;
     void refresh() const;
     void settingsConfigure();
-    void updateDomainSettingsIndicator(const bool status) const;
+    void toggleJavaScript() const;
+    void updateDomainSettingsIndicator(const bool &status) const;
+    void updateJavaScriptAction(const bool &isEnabled) const;
     void updateOnTheFlySearchEngine(const QString &searchEngine) const;
     void updateOnTheFlyUserAgent(const QString &userAgent) const;
     void updateOnTheFlyZoomFactor(const double &zoomFactor);
@@ -62,10 +65,12 @@ private:
     QAction *backActionPointer;
     BrowserView *browserViewPointer;
     KConfigDialog *configDialogPointer;
+    QAction *domainSettingsActionPointer;
     QPalette domainSettingsPalette;
     double currentZoomFactor;
     QAction *forwardActionPointer;
     QAction *homeActionPointer;
+    QAction *javaScriptActionPointer;
     QPalette noDomainSettingsPalette;
     QLabel *searchEngineLabelPointer;
     QAction *searchEngineMojeekActionPointer;