QString TabWidget::webEngineDefaultUserAgent = QLatin1String("");
// Construct the class.
-TabWidget::TabWidget(QWidget *parent) : QWidget(parent)
+TabWidget::TabWidget(QWidget *windowPointer) : QWidget(windowPointer)
{
// Create a QProcess to check if KDE is running.
QProcess *checkIfRunningKdeQProcessPointer = new QProcess();
// Set the loading favorite icon movie file name.
loadingFavoriteIconMoviePointer->setFileName(QStringLiteral(":/icons/loading.gif"));
+ // Stop the loading favorite icon movie if the window is destroyed. Otherwise, the app will crash if there is more than one window open and a window is closed while at tab is loading.
+ connect(windowPointer, SIGNAL(destroyed()), this, SLOT(stopLoadingFavoriteIconMovie()));
+
// Add the first tab.
addFirstTab();
TabWidget::~TabWidget()
{
+ // Get the number of tabs.
+ int numberOfTabs = qTabWidgetPointer->count();
+
// Manually delete each WebEngine page.
- for (int i = 0; i < qTabWidgetPointer->count(); ++i)
+ for (int i = 0; i < numberOfTabs; ++i)
{
// Get the privacy WebEngine view.
PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(qTabWidgetPointer->widget(i));
// Create a no tabs loading variable.
bool noTabsLoading = true;
+ // Get the number of tabs.
+ int numberOfTabs = qTabWidgetPointer->count();
+
// Check to see if any other tabs are loading.
- for (int i = 0; i < qTabWidgetPointer->count(); i++)
+ for (int i = 0; i < numberOfTabs; i++)
{
// Get the privacy WebEngine view for the tab.
- PrivacyWebEngineView *webEngineViewPointer = qobject_cast<PrivacyWebEngineView*>(qTabWidgetPointer->widget(i));
+ PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView*>(qTabWidgetPointer->widget(i));
- // Check to see if it is currently loading.
- if (webEngineViewPointer->isLoading)
+ // Check to see if it is currently loading. If at least one tab is loading, this flag will end up being marked `false` when the for loop has finished.
+ if (privacyWebEngineViewPointer->isLoading)
noTabsLoading = false;
}
// Don't allow JavaScript to open windows.
webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
- // Allow keyboard navigation.
- webEngineSettingsPointer->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, true);
+ // Allow keyboard navigation between links and input fields.
+ webEngineSettingsPointer->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, Settings::spatialNavigation());
// Enable full screen support.
webEngineSettingsPointer->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
else
qTabWidgetPointer->setTabPosition(QTabWidget::South);
+ // Get the number of tabs.
+ int numberOfTabs = qTabWidgetPointer->count();
+
+ // Apply the spatial navigation settings to each WebEngine.
+ for (int i = 0; i < numberOfTabs; ++i) {
+ // Get the WebEngine view pointer.
+ PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(qTabWidgetPointer->widget(i));
+
+ // Apply the spatial navigation settings to each page.
+ privacyWebEngineViewPointer->page()->settings()->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, Settings::spatialNavigation());
+ }
+
// Set the search engine URL.
searchEngineUrl = SearchEngineHelper::getSearchUrl(Settings::searchEngine());
for (int i = 0; i < numberOfTabs; ++i)
{
// Get the WebEngine view pointer.
- PrivacyWebEngineView *webEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(qTabWidgetPointer->currentWidget());
+ PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(qTabWidgetPointer->widget(i));
// Get the WebEngine page pointer.
- QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page();
+ QWebEnginePage *webEnginePagePointer = privacyWebEngineViewPointer->page();
// Get the WebEngine profile pointer.
QWebEngineProfile *webEngineProfilePointer = webEnginePagePointer->profile();
emit linkHovered(linkUrl);
}
+void TabWidget::stopLoadingFavoriteIconMovie() const
+{
+ // Stop the loading favorite icon movie. Otherwise, the browser will crash if a second window is closed while a tab in it is loading. <https://redmine.stoutner.com/issues/1010>
+ loadingFavoriteIconMoviePointer->stop();
+}
+
void TabWidget::print() const
{
// Create a printer.