]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/widgets/TabWidget.cpp
Implement finding of text withing a page.
[PrivacyBrowserPC.git] / src / widgets / TabWidget.cpp
index 4a3c1455ecc63acc1c327bcd5bddd2683ac83d76..3a1b54f33f2028f411b5eefadb14d346f794bb13 100644 (file)
@@ -216,6 +216,9 @@ PrivacyWebEngineView* TabWidget::addTab(const bool focusNewWebEngineView)
             emit hideProgressBar();
     });
 
+    // Display find text results.
+    connect(webEnginePagePointer, SIGNAL(findTextFinished(const QWebEngineFindTextResult &)), this, SLOT(findTextFinished(const QWebEngineFindTextResult &)));
+
     // Handle full screen requests.
     connect(webEnginePagePointer, SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)), this, SLOT(fullScreenRequested(QWebEngineFullScreenRequest)));
 
@@ -612,6 +615,52 @@ void TabWidget::deleteTab(const int tabIndex)
     }
 }
 
+void TabWidget::findPrevious(const QString &text) const
+{
+    // Store the current text.
+    currentPrivacyWebEngineViewPointer->findString = text;
+
+    // Find the previous text in the current privacy WebEngine.
+    if (currentPrivacyWebEngineViewPointer->findCaseSensitive)
+        currentPrivacyWebEngineViewPointer->findText(text, QWebEnginePage::FindCaseSensitively|QWebEnginePage::FindBackward);
+    else
+        currentPrivacyWebEngineViewPointer->findText(text, QWebEnginePage::FindBackward);
+}
+
+void TabWidget::findText(const QString &text) const
+{
+    // Store the current text.
+    currentPrivacyWebEngineViewPointer->findString = text;
+
+    // Find the text in the current privacy WebEngine.
+    if (currentPrivacyWebEngineViewPointer->findCaseSensitive)
+        currentPrivacyWebEngineViewPointer->findText(text, QWebEnginePage::FindCaseSensitively);
+    else
+        currentPrivacyWebEngineViewPointer->findText(text);
+
+    // Clear the currently selected text in the WebEngine page if the find text is empty.
+    if (text.isEmpty())
+        currentWebEnginePagePointer->action(QWebEnginePage::Unselect)->activate(QAction::Trigger);
+}
+
+void TabWidget::findTextFinished(const QWebEngineFindTextResult &findTextResult)
+{
+    // Update the find text UI if it wasn't simply wiping the current find text selection.  Otherwise the UI temporarially flashes `0/0`.
+    if (wipingCurrentFindTextSelection)  // The current selection is being wiped.
+    {
+        // Reset the flag.
+        wipingCurrentFindTextSelection = false;
+    }
+    else  // A new search has been performed.
+    {
+        // Store the result.
+        currentPrivacyWebEngineViewPointer->findTextResult = findTextResult;
+
+        // Update the UI.
+        emit updateFindTextResults(findTextResult);
+    }
+}
+
 void TabWidget::forward() const
 {
     // Go forward.
@@ -867,6 +916,21 @@ void TabWidget::toggleDomStorage() const
     currentPrivacyWebEngineViewPointer->reload();
 }
 
+void TabWidget::toggleFindCaseSensitive(const QString &text)
+{
+    // Toggle find case sensitive.
+    currentPrivacyWebEngineViewPointer->findCaseSensitive = !currentPrivacyWebEngineViewPointer->findCaseSensitive;
+
+    // Set the wiping current find text selection flag.
+    wipingCurrentFindTextSelection = true;
+
+    // Wipe the previous search.  Otherwise currently highlighted words will remain highlighted.
+    findText(QStringLiteral(""));
+
+    // Update the find text.
+    findText(text);
+}
+
 void TabWidget::toggleJavaScript() const
 {
     // Toggle JavaScript.
@@ -904,19 +968,25 @@ void TabWidget::updateUiWithTabSettings()
     // Clear the URL line edit focus.
     emit clearUrlLineEditFocus();
 
-    // Update the UI.
+    // Update the actions.
     emit updateBackAction(currentWebEngineHistoryPointer->canGoBack());
     emit updateCookiesAction(currentPrivacyWebEngineViewPointer->cookieListPointer->size());
-    emit updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QStringLiteral(""));
     emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled));
     emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward());
     emit updateJavaScriptAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
     emit updateLocalStorageAction(currentPrivacyWebEngineViewPointer->localStorageEnabled);
-    emit updateWindowTitle(currentPrivacyWebEngineViewPointer->title());
-    emit updateUrlLineEdit(currentPrivacyWebEngineViewPointer->url());
     emit updateUserAgentActions(currentWebEngineProfilePointer->httpUserAgent(), true);
     emit updateZoomFactorAction(currentPrivacyWebEngineViewPointer->zoomFactor());
 
+    // Update the URL.
+    emit updateWindowTitle(currentPrivacyWebEngineViewPointer->title());
+    emit updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QStringLiteral(""));
+    emit updateUrlLineEdit(currentPrivacyWebEngineViewPointer->url());
+
+    // Update the find text.
+    emit updateFindText(currentPrivacyWebEngineViewPointer->findString, currentPrivacyWebEngineViewPointer->findCaseSensitive);
+    emit updateFindTextResults(currentPrivacyWebEngineViewPointer->findTextResult);
+
     // Update the progress bar.
     if (currentPrivacyWebEngineViewPointer->loadProgressInt >= 0)
         emit showProgressBar(currentPrivacyWebEngineViewPointer->loadProgressInt);