]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add zoom controls to the status bar. https://redmine.stoutner.com/issues/1031
authorSoren Stoutner <soren@stoutner.com>
Fri, 30 Jun 2023 20:34:47 +0000 (13:34 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 30 Jun 2023 20:34:47 +0000 (13:34 -0700)
doc/index.docbook
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

index f8b1136902b1077f8722c74e2fb9edd4c15690ac..a784979be1cd1f0abe71604adf3f94cda282df5d 100644 (file)
         <title>View</title>
 
         <variablelist>
+          <!-- Zoom In. -->
+          <varlistentry id="zoom-in">
+            <term>
+              <menuchoice>
+                <shortcut>
+                  <keycombo action="simul">&Ctrl;<keycap>+</keycap></keycombo>
+                </shortcut>
+                <guimenu>View</guimenu>
+                <guimenuitem>Zoom In</guimenuitem>
+              </menuchoice>
+            </term>
+
+            <listitem>
+              <para>
+                Increment the zoom factor by 0.25. Valid factors range from 0.25 to 5.00.
+              </para>
+            </listitem>
+          </varlistentry>
+
+
+          <!-- Zoom Out. -->
+          <varlistentry id="zoom-out">
+            <term>
+              <menuchoice>
+                <shortcut>
+                  <keycombo action="simul">&Ctrl;<keycap>-</keycap></keycombo>
+                </shortcut>
+                <guimenu>View</guimenu>
+                <guimenuitem>Zoom Out</guimenuitem>
+              </menuchoice>
+            </term>
+
+            <listitem>
+              <para>
+                Decrement the zoom factor by 0.25. Valid factors range from 0.25 to 5.00.
+              </para>
+            </listitem>
+          </varlistentry>
+
           <!-- Refresh. -->
           <varlistentry id="view-refresh">
             <term>
index 3ba0e67c4664dfafe921d19d1753a4ab58bcca5b..236b8b4f0e07962f2cdbc49757ba1cc9f9bed017 100644 (file)
@@ -62,6 +62,8 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     KStandardAction::print(tabWidgetPointer, SLOT(print()), actionCollectionPointer);
     QAction *printPreviewActionPointer = KStandardAction::printPreview(tabWidgetPointer, SLOT(printPreview()), actionCollectionPointer);
     KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
+    KStandardAction::zoomIn(this, SLOT(incrementZoom()), actionCollectionPointer);
+    KStandardAction::zoomOut(this, SLOT(decrementZoom()), actionCollectionPointer);
     KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer);
     fullScreenActionPointer = KStandardAction::fullScreen(this, SLOT(toggleFullScreen()), this, actionCollectionPointer);
     QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer);
@@ -77,7 +79,7 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     QAction *newWindowActionPointer = actionCollectionPointer->addAction(QLatin1String("new_window"));
     QAction *reloadAndBypassCacheActionPointer = actionCollectionPointer->addAction(QLatin1String("reload_and_bypass_cache"));
     viewSourceActionPointer = actionCollectionPointer->addAction(QLatin1String("view_source"));
-    QAction *viewSourceInNewTabActionPointer = actionCollectionPointer->addAction(QLatin1String("view_source_in_new_tab"));
+    viewSourceInNewTabActionPointer = actionCollectionPointer->addAction(QLatin1String("view_source_in_new_tab"));
     userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_privacy_browser"));
     userAgentWebEngineDefaultActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_webengine_default"));
     userAgentFirefoxLinuxActionPointer = actionCollectionPointer->addAction(QLatin1String("user_agent_firefox_linux"));
@@ -399,11 +401,34 @@ BrowserWindow::BrowserWindow(bool firstWindow) : KXmlGuiWindow()
     // Get a handle for the status bar.
     QStatusBar *statusBarPointer = statusBar();
 
-    // Create a progress bar.
+    // Create the status bar widgets.
     progressBarPointer = new QProgressBar();
+    QPushButton *zoomMinusButtonPointer = new QPushButton();
+    currentZoomButtonPointer = new QPushButton();
+    QPushButton *zoomPlusButtonPointer = new QPushButton();
 
-    // Add the progress bar to to the status bar.
+    // Set the button icons.
+    zoomMinusButtonPointer->setIcon(QIcon::fromTheme(QStringLiteral("list-remove-symbolic")));
+    zoomPlusButtonPointer->setIcon(QIcon::fromTheme(QStringLiteral("list-add-symbolic")));
+
+    // Set the button icons to be flat (no borders).
+    zoomMinusButtonPointer->setFlat(true);
+    currentZoomButtonPointer->setFlat(true);
+    zoomPlusButtonPointer->setFlat(true);
+
+    // Handle clicks on the zoom buttons.
+    connect(zoomMinusButtonPointer, SIGNAL(clicked()), this, SLOT(decrementZoom()));
+    connect(currentZoomButtonPointer, SIGNAL(clicked()), this, SLOT(getZoomFactorFromUser()));
+    connect(zoomPlusButtonPointer, SIGNAL(clicked()), this, SLOT(incrementZoom()));
+
+    // Remove the padding around the current zoom button text.
+    currentZoomButtonPointer->setStyleSheet("padding: 0px;");
+
+    // Add the widgets to the far right of the status bar.
     statusBarPointer->addPermanentWidget(progressBarPointer);
+    statusBarPointer->addPermanentWidget(zoomMinusButtonPointer);
+    statusBarPointer->addPermanentWidget(currentZoomButtonPointer);
+    statusBarPointer->addPermanentWidget(zoomPlusButtonPointer);
 
     // Update the status bar with the URL when a link is hovered.
     connect(tabWidgetPointer, SIGNAL(linkHovered(QString)), statusBarPointer, SLOT(showMessage(QString)));
@@ -496,6 +521,22 @@ void BrowserWindow::clearUrlLineEditFocus() const
     urlLineEditPointer->clearFocus();
 }
 
+void BrowserWindow::decrementZoom()
+{
+    // Update the current zoom factor.
+    currentZoomFactor = currentZoomFactor - 0.25;
+
+    // Check to make sure the zoom factor is in the valid range (0.25 to 5.00).
+    if (currentZoomFactor < 0.25)
+        currentZoomFactor = 0.25;
+
+    // Set the new zoom factor.
+    tabWidgetPointer->applyOnTheFlyZoomFactor(currentZoomFactor);
+
+    // Update the on-the-fly action text.
+    updateZoomFactorAction(currentZoomFactor);
+}
+
 void BrowserWindow::escape() const
 {
     // Process the escape according to the status of the browser.
@@ -590,9 +631,6 @@ void BrowserWindow::getZoomFactorFromUser()
     // Update the zoom factor if the user clicked OK.
     if (okClicked)
     {
-        // Update the current zoom factor.
-        currentZoomFactor = newZoomFactor;
-
         // Set the new zoom factor.
         tabWidgetPointer->applyOnTheFlyZoomFactor(newZoomFactor);
 
@@ -621,6 +659,22 @@ void BrowserWindow::home() const
     tabWidgetPointer->home();
 }
 
+void BrowserWindow::incrementZoom()
+{
+    // Update the current zoom factor.
+    currentZoomFactor = currentZoomFactor + 0.25;
+
+    // Check to make sure the zoom factor is in the valid range (0.25 to 5.00).
+    if (currentZoomFactor > 5.0)
+        currentZoomFactor = 5.0;
+
+    // Set the new zoom factor.
+    tabWidgetPointer->applyOnTheFlyZoomFactor(currentZoomFactor);
+
+    // Update the on-the-fly action text.
+    updateZoomFactorAction(currentZoomFactor);
+}
+
 void BrowserWindow::loadUrlFromLineEdit(const QString &url) const
 {
     // Remove the focus from the URL line edit.
@@ -1366,8 +1420,11 @@ void BrowserWindow::updateZoomFactorAction(const double &zoomFactor)
     // Set the current zoom factor.
     currentZoomFactor = zoomFactor;
 
-    // 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());
+    // Update the zoom factor action text, formatting the double with 2 decimal places.  `0` specifies no extra field width.  `'0'` sets the format to not use scientific notation.
+    zoomFactorActionPointer->setText(ki18nc("The zoom factor action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString());
+
+    // Update the status bar zoom factor label.
+    currentZoomButtonPointer->setText(ki18nc("The status bar zoom, which is just the formatted zoom factor", "%1").subs(zoomFactor, 0, '0', 2).toString());
 }
 
 void BrowserWindow::updateSearchEngineLabel(const QString &searchEngineString) const
@@ -1381,8 +1438,23 @@ void BrowserWindow::updateUrlLineEdit(const QUrl &newUrl)
     // Get the new URL string.
     QString newUrlString = newUrl.toString();
 
-    // Update the view source checkbox.
-    viewSourceActionPointer->setChecked(newUrlString.startsWith(QLatin1String("view-source:")));
+    // Update the view source actions.
+    if (newUrlString.startsWith(QLatin1String("view-source:")))  // The source is currently being viewed.
+    {
+        // Mark the view source checkbox.
+        viewSourceActionPointer->setChecked(true);
+
+        // Update the view in new tab action text.
+        viewSourceInNewTabActionPointer->setText(i18nc("View rendered website in new tab action", "View Rendered Website in New Tab"));
+    }
+    else  // The source is not currently being viewed.
+    {
+        // Unmark the view source checkbox.
+        viewSourceActionPointer->setChecked(false);
+
+        // Update the view in new tab action text.
+        viewSourceInNewTabActionPointer->setText(i18nc("View source in new tab action", "View Source in New Tab"));
+    }
 
     // Update the URL line edit if it does not have focus.
     if (!urlLineEditPointer->hasFocus())
index 99fd146001fb69b83609b0968e231605725101de..94afae9944b65c9bea1ca971abaa499f8e3a6bc2 100644 (file)
@@ -53,6 +53,7 @@ private Q_SLOTS:
     void addOrEditDomainSettings() const;
     void back() const;
     void clearUrlLineEditFocus() const;
+    void decrementZoom();
     void escape() const;
     void findNext() const;
     void findPrevious() const;
@@ -61,6 +62,7 @@ private Q_SLOTS:
     void getZoomFactorFromUser();
     void hideFindTextActions() const;
     void home() const;
+    void incrementZoom();
     void loadUrlFromLineEdit(const QString &url) const;
     void newWindow() const;
     void refresh() const;
@@ -98,6 +100,7 @@ private:
     KConfigDialog *configDialogPointer;
     QAction *cookiesActionPointer;
     QUrl currentUrl;
+    QPushButton *currentZoomButtonPointer;
     double currentZoomFactor;
     bool customSearchEngineEnabled;
     bool customUserAgentEnabled;
@@ -144,6 +147,7 @@ private:
     KLineEdit *urlLineEditPointer;
     KToolBar *urlToolBarPointer;
     QAction *viewSourceActionPointer;
+    QAction *viewSourceInNewTabActionPointer;
     QAction *zoomFactorActionPointer;
 };
 #endif