]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/windows/BrowserWindow.cpp
Add zoom controls to the status bar. https://redmine.stoutner.com/issues/1031
[PrivacyBrowserPC.git] / src / windows / BrowserWindow.cpp
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())