]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/widgets/TabWidget.cpp
Hide the find text actions by default. https://redmine.stoutner.com/issues/960
[PrivacyBrowserPC.git] / src / widgets / TabWidget.cpp
index 4edb304d0db6c45ed5d757a6d4a5f6cd20ad5596..5b5a08c630cbae3985ef41b42711d6ba88459bef 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
  *
@@ -219,6 +219,14 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const
             emit hideProgressBar();
     });
 
+    // Update the zoom factor when changed by CTRL-Scrolling.  This can be modified when <https://redmine.stoutner.com/issues/845> is fixed.
+    connect(webEnginePagePointer, &QWebEnginePage::contentsSizeChanged, [webEnginePagePointer, this] ()
+    {
+        // Only update the zoom factor action text if this is the current tab.
+        if (webEnginePagePointer == currentWebEnginePagePointer)
+            emit updateZoomFactorAction(webEnginePagePointer->zoomFactor());
+    });
+
     // Display find text results.
     connect(webEnginePagePointer, SIGNAL(findTextFinished(const QWebEngineFindTextResult &)), this, SLOT(findTextFinished(const QWebEngineFindTextResult &)));
 
@@ -267,7 +275,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const
         return false;
     });
 
-    // Disable JavaScript by default (this prevetns JavaScript from being enabled on a new tab before domain settings are loaded).
+    // Disable JavaScript by default (this prevents JavaScript from being enabled on a new tab before domain settings are loaded).
     webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
 
     // Don't allow JavaScript to open windows.
@@ -285,6 +293,12 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const
     // Limit WebRTC to public IP addresses.
     webEngineSettingsPointer->setAttribute(QWebEngineSettings::WebRTCPublicInterfacesOnly, true);
 
+    // Enable the PDF viewer (it should be enabled by default, but it is nice to be explicit in case the defaults change).
+    webEngineSettingsPointer->setAttribute(QWebEngineSettings::PdfViewerEnabled, true);
+
+    // Plugins must be enabled for the PDF viewer to work.  <https://doc.qt.io/qt-5/qtwebengine-features.html#pdf-file-viewing>
+    webEngineSettingsPointer->setAttribute(QWebEngineSettings::PluginsEnabled, true);
+
     // Update the cookies action.
     connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, [privacyWebEngineViewPointer, this] (const int numberOfCookies)
     {
@@ -335,7 +349,7 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const
     webEngineProfilePointer->setSpellCheckEnabled(true);
 
     // Set the spell check language.
-    webEngineProfilePointer->setSpellCheckLanguages({QLatin1String("en_US")});
+    webEngineProfilePointer->setSpellCheckLanguages(Settings::spellCheckLanguages());
 
     // Populate the zoom factor.  This is necessary if a URL is being loaded, like a local URL, that does not trigger `applyDomainSettings()`.
     privacyWebEngineViewPointer->setZoomFactor(Settings::zoomFactor());
@@ -548,7 +562,7 @@ void TabWidget::applyOnTheFlySearchEngine(QAction *searchEngineActionPointer)
     // Store the search engine string.
     searchEngineUrl = SearchEngineHelper::getSearchUrl(searchEngineName);
 
-    // Update the search engine actionas.
+    // Update the search engine actions.
     emit updateSearchEngineActions(searchEngineName, false);
 }
 
@@ -580,6 +594,28 @@ void TabWidget::applyOnTheFlyZoomFactor(const double &zoomFactor)
     currentPrivacyWebEngineViewPointer->setZoomFactor(zoomFactor);
 }
 
+void TabWidget::applySpellCheckLanguages() const
+{
+    // Get the number of tab.
+    int numberOfTabs = tabWidgetPointer->count();
+
+    // Set the spell check languages for each tab.
+    for (int i = 0; i < numberOfTabs; ++i)
+    {
+        // Get the WebEngine view pointer.
+        PrivacyWebEngineView *webEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(tabWidgetPointer->currentWidget());
+
+        // Get the WebEngine page pointer.
+        QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page();
+
+        // Get the WebEngine profile pointer.
+        QWebEngineProfile *webEngineProfilePointer = webEnginePagePointer->profile();
+
+        // Set the spell check languages.
+        webEngineProfilePointer->setSpellCheckLanguages(Settings::spellCheckLanguages());
+    }
+}
+
 void TabWidget::back() const
 {
     // Go back.
@@ -1052,7 +1088,7 @@ void TabWidget::toggleJavaScript() const
 
 void TabWidget::toggleLocalStorage()
 {
-    // Toggle local storeage.
+    // Toggle local storage.
     currentPrivacyWebEngineViewPointer->localStorageEnabled = !currentPrivacyWebEngineViewPointer->localStorageEnabled;
 
     // Update the local storage action.