tabWidgetPointer->currentWidget()->setFocus();
}
-void TabWidget::addTab()
+PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const bool backgroundTab)
{
// Create a privacy WebEngine view.
PrivacyWebEngineView *privacyWebEngineViewPointer = new PrivacyWebEngineView();
QWebEngineSettings *webEngineSettingsPointer = webEnginePagePointer->settings();
// Update the URL line edit when the URL changes.
- connect(privacyWebEngineViewPointer, SIGNAL(urlChanged(const QUrl)), this, SLOT(updateUrl(const QUrl)));
+ connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::urlChanged, [privacyWebEngineViewPointer, this] (const QUrl &newUrl)
+ {
+ // Only update the UI if this is the current tab.
+ if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
+ {
+ // Update the URL line edit.
+ emit updateUrlLineEdit(newUrl);
+ // Update the status of the forward and back buttons.
+ emit updateBackAction(currentWebEngineHistoryPointer->canGoBack());
+ emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward());
+ }
- // Update the progress bar.
- connect(privacyWebEngineViewPointer, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
- connect(privacyWebEngineViewPointer, SIGNAL(loadProgress(const int)), this, SLOT(loadProgress(const int)));
- connect(privacyWebEngineViewPointer, SIGNAL(loadFinished(const bool)), this, SLOT(loadFinished()));
+ // Reapply the zoom factor. This is a bug in QWebEngineView that resets the zoom with every load. It can be removed once <https://redmine.stoutner.com/issues/799> is fixed.
+ privacyWebEngineViewPointer->setZoomFactor(currentZoomFactor);
+ });
+
+ // Update the progress bar when a load is started.
+ connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadStarted, [privacyWebEngineViewPointer, this] ()
+ {
+ // Store the load progress.
+ privacyWebEngineViewPointer->loadProgressInt = 0;
+
+ // Show the progress bar if this is the current tab.
+ if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
+ emit showProgressBar(0);
+ });
+
+ // Update the progress bar when a load progresses.
+ connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadProgress, [privacyWebEngineViewPointer, this] (const int progress)
+ {
+ // Store the load progress.
+ privacyWebEngineViewPointer->loadProgressInt = progress;
+
+ // Update the progress bar if this is the current tab.
+ if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
+ emit showProgressBar(progress);
+ });
+
+ // Update the progress bar when a load finishes.
+ connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::loadFinished, [privacyWebEngineViewPointer, this] ()
+ {
+ // Store the load progress.
+ privacyWebEngineViewPointer->loadProgressInt = -1;
+
+ // Hide the progress bar if this is the current tab.
+ if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
+ 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)));
// Limit WebRTC to public IP addresses.
webEngineSettingsPointer->setAttribute(QWebEngineSettings::WebRTCPublicInterfacesOnly, true);
- // Define an update cookie count lambda.
- auto updateCookieCount = [privacyWebEngineViewPointer, this] (const int numberOfCookies)
+ // Update the cookies action.
+ connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, [privacyWebEngineViewPointer, this] (const int numberOfCookies)
{
// Update the cookie action if the specified privacy WebEngine view is the current privacy WebEngine view.
if (privacyWebEngineViewPointer == currentPrivacyWebEngineViewPointer)
emit updateCookiesAction(numberOfCookies);
- };
-
- // Update the cookies action.
- connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::updateCookiesAction, this, updateCookieCount);
+ });
// Process cookie changes.
connect(webEngineCookieStorePointer, SIGNAL(cookieAdded(QNetworkCookie)), privacyWebEngineViewPointer, SLOT(addCookieToList(QNetworkCookie)));
for (QNetworkCookie *cookiePointer : *durableCookiesListPointer)
addCookieToStore(*cookiePointer, webEngineCookieStorePointer);
- // Define an update tab title lambda.
- auto updateTabTitle = [privacyWebEngineViewPointer, this] (const QString &title)
+ // Update the title when it changes.
+ connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, [this, privacyWebEngineViewPointer] (const QString &title)
{
// Get the index for this tab.
int tabIndex = tabWidgetPointer->indexOf(privacyWebEngineViewPointer);
// Update the title for this tab.
tabWidgetPointer->setTabText(tabIndex, title);
- };
- // Update the title when it changes.
- connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::titleChanged, this, updateTabTitle);
+ // Update the window title if this is the current tab.
+ if (tabIndex == tabWidgetPointer->currentIndex())
+ emit updateWindowTitle(title);
+ });
- // Define an update tab icon lambda.
- auto updateTabIcon = [privacyWebEngineViewPointer, this] (const QIcon &icon)
+ // Update the icon when it changes.
+ connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, [privacyWebEngineViewPointer, this] (const QIcon &icon)
{
// Get the index for this tab.
int tabIndex = tabWidgetPointer->indexOf(privacyWebEngineViewPointer);
tabWidgetPointer->setTabIcon(tabIndex, defaultTabIcon);
else
tabWidgetPointer->setTabIcon(tabIndex, icon);
- };
+ });
- // Update the icon when it changes.
- connect(privacyWebEngineViewPointer, &PrivacyWebEngineView::iconChanged, this, updateTabIcon);
+ // Enable spell checking.
+ webEngineProfilePointer->setSpellCheckEnabled(true);
- // Move to the new tab.
- tabWidgetPointer->setCurrentIndex(newTabIndex);
+ // Set the spell check language.
+ webEngineProfilePointer->setSpellCheckLanguages({QStringLiteral("en_US")});
+
+ // 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());
+
+ // Move to the new tab if it is not a background tab.
+ if (!backgroundTab)
+ tabWidgetPointer->setCurrentIndex(newTabIndex);
+
+ // Clear the URL line edit focus so that it populates correctly when opening a new tab from the context menu.
+ if (removeUrlLineEditFocus)
+ emit clearUrlLineEditFocus();
+
+ // Return the privacy WebEngine view pointer.
+ return privacyWebEngineViewPointer;
}
void TabWidget::applyApplicationSettings()
}
}
+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.
currentPrivacyWebEngineViewPointer->load(QUrl::fromUserInput(Settings::homepage()));
}
-void TabWidget::loadFinished() const
+PrivacyWebEngineView* TabWidget::loadBlankInitialWebsite()
{
- // Hide the progress bar.
- emit hideProgressBar();
+ // Apply the application settings.
+ applyApplicationSettings();
+
+ // Return the current privacy WebEngine view pointer.
+ return currentPrivacyWebEngineViewPointer;
}
void TabWidget::loadInitialWebsite()
}
}
-void TabWidget::loadProgress(const int &progress) const
-{
- // Show the progress bar.
- emit showProgressBar(progress);
-}
-
-void TabWidget::loadStarted() const
-{
- // Show the progress bar.
- emit showProgressBar(0);
-}
-
void TabWidget::loadUrlFromLineEdit(QString url) const
{
// Decide if the text is more likely to be a URL or a search.
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.
// Clear the URL line edit focus.
emit clearUrlLineEditFocus();
- // Update the UI.
- emit updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QStringLiteral(""));
+ // Update the actions.
+ emit updateBackAction(currentWebEngineHistoryPointer->canGoBack());
+ emit updateCookiesAction(currentPrivacyWebEngineViewPointer->cookieListPointer->size());
+ emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled));
+ emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward());
emit updateJavaScriptAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::JavascriptEnabled));
emit updateLocalStorageAction(currentPrivacyWebEngineViewPointer->localStorageEnabled);
- emit updateDomStorageAction(currentWebEngineSettingsPointer->testAttribute(QWebEngineSettings::LocalStorageEnabled));
emit updateUserAgentActions(currentWebEngineProfilePointer->httpUserAgent(), true);
emit updateZoomFactorAction(currentPrivacyWebEngineViewPointer->zoomFactor());
- emit updateUrlLineEdit(currentPrivacyWebEngineViewPointer->url());
- emit updateCookiesAction(currentPrivacyWebEngineViewPointer->cookieListPointer->size());
-}
-void TabWidget::updateUrl(const QUrl &url) const
-{
- // Update the URL line edit.
- emit updateUrlLineEdit(url);
+ // Update the URL.
+ emit updateWindowTitle(currentPrivacyWebEngineViewPointer->title());
+ emit updateDomainSettingsIndicator(currentPrivacyWebEngineViewPointer->domainSettingsName != QStringLiteral(""));
+ emit updateUrlLineEdit(currentPrivacyWebEngineViewPointer->url());
- // Update the status of the forward and back buttons.
- emit updateBackAction(currentWebEngineHistoryPointer->canGoBack());
- emit updateForwardAction(currentWebEngineHistoryPointer->canGoForward());
+ // Update the find text.
+ emit updateFindText(currentPrivacyWebEngineViewPointer->findString, currentPrivacyWebEngineViewPointer->findCaseSensitive);
+ emit updateFindTextResults(currentPrivacyWebEngineViewPointer->findTextResult);
- // Reapply the zoom factor. This is a bug in QWebEngineView that resets the zoom with every load. <https://redmine.stoutner.com/issues/799>
- currentPrivacyWebEngineViewPointer->setZoomFactor(currentZoomFactor);
+ // Update the progress bar.
+ if (currentPrivacyWebEngineViewPointer->loadProgressInt >= 0)
+ emit showProgressBar(currentPrivacyWebEngineViewPointer->loadProgressInt);
+ else
+ emit hideProgressBar();
}