]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add on-the-fly zoom factor.
authorSoren Stoutner <soren@stoutner.com>
Sat, 19 Feb 2022 03:07:09 +0000 (20:07 -0700)
committerSoren Stoutner <soren@stoutner.com>
Sat, 19 Feb 2022 03:07:09 +0000 (20:07 -0700)
src/BrowserWindow.cpp
src/BrowserWindow.h
src/MainView.cpp
src/MainView.h
src/SettingsGeneral.ui
src/privacybrowserui.rc

index 1265c0d38a2c92a922f4d942af7e03f90330b2d5..a2eda98e36b5a23aefcc2ca5bcb8c9ef329bf02a 100644 (file)
@@ -30,6 +30,7 @@
 #include <KConfigDialog>
 
 // Qt framework headers.
+#include <QInputDialog>
 #include <QStatusBar>
 
 BrowserWindow::BrowserWindow() : KXmlGuiWindow()
@@ -57,6 +58,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     userAgentEdgeWindowsActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_edge_windows"));
     userAgentSafariMacosActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_safari_macos"));
     userAgentCustomActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_custom"));
+    zoomFactorActionPointer = actionCollectionPointer->addAction(QStringLiteral("zoom_factor"));
     searchEngineMojeekActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_mojeek"));
     searchEngineMonoclesActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_monocles"));
     searchEngineMetagerActionPointer = actionCollectionPointer->addAction(QStringLiteral("search_engine_metager"));
@@ -103,7 +105,7 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
     searchEngineYahooActionPointer->setCheckable(true);
     searchEngineCustomActionPointer->setCheckable(true);
 
-    // Set the action names.  The custom action text will be set later in the on-the-fly update slots.
+    // Set the non-mutable action names.
     userAgentPrivacyBrowserActionPointer->setText(i18nc("@action", "Privacy Browser"));
     userAgentFirefoxLinuxActionPointer->setText(i18nc("@action", "Firefox Linux"));
     userAgentChromiumLinuxActionPointer->setText(i18nc("@action", "Chromium Linux"));
@@ -120,13 +122,21 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow()
 
     // Update the on-the-fly menus.
     connect(mainViewPointer, SIGNAL(userAgentUpdated(QString)), this, SLOT(updateOnTheFlyUserAgent(QString)));
+    connect(mainViewPointer, SIGNAL(zoomFactorUpdated(double)), this, SLOT(updateOnTheFlyZoomFactor(double)));
     connect(mainViewPointer, SIGNAL(searchEngineUpdated(QString)), this, SLOT(updateOnTheFlySearchEngine(QString)));
 
     // Apply the on-the-fly settings when selected.
     connect(userAgentActionGroupPointer, SIGNAL(triggered(QAction*)), mainViewPointer, SLOT(applyOnTheFlyUserAgent(QAction*)));
     connect(searchEngineActionGroupPointer, SIGNAL(triggered(QAction*)), mainViewPointer, SLOT(applyOnTheFlySearchEngine(QAction*)));
 
-    // Initialize the on-the-fly search engine menu, as the slot connection had not been created when MainView was constructed.
+    // Display dialogs.
+    connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser()));
+
+    // Set the current zoom factor.
+    currentZoomFactor = Settings::zoomFactor();
+
+    // Initialize the on-the-fly menus, as the slot connections had not been created when MainView was constructed.
+    updateOnTheFlyZoomFactor(currentZoomFactor);
     updateOnTheFlySearchEngine(Settings::searchEngine());
 
     // Update the status bar with the URL when a link is hovered.
@@ -142,6 +152,29 @@ void BrowserWindow::fileNew() const
     (new BrowserWindow)->show();
 }
 
+void BrowserWindow::getZoomFactorFromUser()
+{
+    // Create an OK flag.
+    bool okClicked;
+
+    // Display a dialog to get the new zoom factor from the user.  Format the double to display two decimals and have a 0.25 step.
+    double newZoomFactor = QInputDialog::getDouble(this, i18nc("The tile of the on-the-fly zoom factor dialog", "On-The-Fly Zoom Factor"),
+                                                   i18nc("The instruction text of the on-the-fly zoom factor dialog", "Enter a zoom factor between 0.25 and 5.00"),
+                                                   currentZoomFactor, .025, 5.00, 2, &okClicked, Qt::WindowFlags(), 0.25);
+
+    if (okClicked)
+    {
+        // Update the current zoom factor.
+        currentZoomFactor = newZoomFactor;
+
+        // Set the new zoom factor.
+        mainViewPointer->applyOnTheFlyZoomFactor(newZoomFactor);
+
+        // Update the on-the-fly action text.
+        updateOnTheFlyZoomFactor(newZoomFactor);
+    }
+}
+
 void BrowserWindow::settingsConfigure()
 {
     // Check to make sure the dialog box isn't already displayed.
@@ -316,6 +349,11 @@ void BrowserWindow::updateOnTheFlyUserAgent(const QString &userAgent) const
     }
 }
 
+void BrowserWindow::updateOnTheFlyZoomFactor(const double &zoomFactor) const
+{
+    // Update the zoom factor action text, formatting the double with 2 decimal places.
+    zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
+}
 
 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
 {
index 8158100cc6e04f49bd348e9afe7b82298a6c6de2..357909e3dc43bcf5bf2b2998f8b0cb5c62525f81 100644 (file)
@@ -41,9 +41,11 @@ public:
 private Q_SLOTS:
     // The private slots.
     void fileNew() const;
+    void getZoomFactorFromUser();
     void settingsConfigure();
     void updateOnTheFlySearchEngine(const QString &searchEngine) const;
     void updateOnTheFlyUserAgent(const QString &userAgent) const;
+    void updateOnTheFlyZoomFactor(const double &zoomFactor) const;
     void updateSearchEngineLabel(const QString &searchEngineString) const;
     void updateStatusBar(const QString &statusBarMessage) const;
     void updateUserAgentLabel(const QString &userAgentName) const;
@@ -51,6 +53,7 @@ private Q_SLOTS:
 private:
     // The private variables.
     MainView *mainViewPointer;
+    double currentZoomFactor;
     QLabel *searchEngineLabelPointer;
     QAction *searchEngineMojeekActionPointer;
     QAction *searchEngineMonoclesActionPointer;
@@ -68,5 +71,6 @@ private:
     QAction *userAgentEdgeWindowsActionPointer;
     QAction *userAgentSafariMacosActionPointer;
     QAction *userAgentCustomActionPointer;
+    QAction *zoomFactorActionPointer;
 };
 #endif
index 99c9355053652253527d727961ba751041dbb898..04cc1ee87d86082db817e3023d110000904e52e7 100644 (file)
@@ -156,12 +156,13 @@ void MainView::applyDomainSettings(bool reloadWebsite) const
     // Apply the user agent.
     webEngineProfilePointer->setHttpUserAgent(UserAgentHelper::getUserAgent(Settings::userAgent()));
 
-    // Emit the user agent updated signal, which causes the on-the-fly menu to be updated.
-    emit userAgentUpdated(Settings::userAgent());
-
     // Set the zoom factor.
     webEngineViewPointer->setZoomFactor(Settings::zoomFactor());
 
+    // Emit the on-the-fly menu update signals.
+    emit userAgentUpdated(Settings::userAgent());
+    emit zoomFactorUpdated(Settings::zoomFactor());
+
     // Reload the website if requested.
     if (reloadWebsite)
     {
@@ -196,6 +197,12 @@ void MainView::applyOnTheFlyUserAgent(QAction *userAgentActionPointer) const
     webEngineViewPointer->reload();
 }
 
+void MainView::applyOnTheFlyZoomFactor(const double &zoomFactor) const
+{
+    // Set the zoom factor.
+    webEngineViewPointer->setZoomFactor(zoomFactor);
+}
+
 void MainView::goHome() const
 {
     // Load the homepage.
index 506d0be27fe26ef6febd61e350980f21f9e7b3b4..38b5928dcc328affceffde0e786293c9e28c1402 100644 (file)
@@ -38,11 +38,15 @@ public:
     // The primary contructor.
     explicit MainView(QWidget *parent);
 
+    // The public functions.
+    void applyOnTheFlyZoomFactor(const double &zoomFactor) const;
+
 signals:
     // The signals.
     void linkHovered(const QString &linkUrl) const;
     void userAgentUpdated(const QString &userAgent) const;
     void searchEngineUpdated(const QString &searchEngine) const;
+    void zoomFactorUpdated(const double &zoomFactor) const;
 
 public Q_SLOTS:
     // The public slots.
index 41b520069058f1c61aacc750270d8eba1c991acd..9e33b8a4ad5b7c54654b5a34c7a5bdfff52b7577 100644 (file)
                     <property name="maximum">
                         <double>5.000000000000000</double>
                     </property>
+
+                    <property name="singleStep">
+                        <double>0.250000000000000</double>
+                    </property>
                 </widget>
             </item>
         </layout>
index 516486f617b0257679f8bcbc8f3d4e2595ab940e..c15b1544f920409cc500aa66e9b123b3984a3406 100644 (file)
@@ -38,6 +38,8 @@
                 <Action name="user_agent_custom" />
             </Menu>
 
+            <Action name="zoom_factor" />
+
             <Separator />
 
             <Menu name="search_engine"> <text>Search Engine</text>