From: Soren Stoutner Date: Fri, 30 Jun 2023 20:34:47 +0000 (-0700) Subject: Add zoom controls to the status bar. https://redmine.stoutner.com/issues/1031 X-Git-Tag: v0.5~10 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=8f1b160582ac3bd86b6e7aeaafcae059aff609c0;p=PrivacyBrowserPC.git Add zoom controls to the status bar. https://redmine.stoutner.com/issues/1031 --- diff --git a/doc/index.docbook b/doc/index.docbook index f8b1136..a784979 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -518,6 +518,45 @@ View + + + + + + &Ctrl;+ + + View + Zoom In + + + + + + Increment the zoom factor by 0.25. Valid factors range from 0.25 to 5.00. + + + + + + + + + + + &Ctrl;- + + View + Zoom Out + + + + + + Decrement the zoom factor by 0.25. Valid factors range from 0.25 to 5.00. + + + + diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index 3ba0e67..236b8b4 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -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()) diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index 99fd146..94afae9 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -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