From: Soren Stoutner Date: Fri, 24 Jun 2022 23:06:47 +0000 (-0700) Subject: Add full screen support. https://redmine.stoutner.com/issues/832 X-Git-Tag: v0.1~25 X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserPC.git;a=commitdiff_plain;h=ab3422aabe802b11f4ddf32df6a2a33e1fff9c96 Add full screen support. https://redmine.stoutner.com/issues/832 --- diff --git a/src/dialogs/CookiesDialog.cpp b/src/dialogs/CookiesDialog.cpp index cfd8f8b..4e85efe 100644 --- a/src/dialogs/CookiesDialog.cpp +++ b/src/dialogs/CookiesDialog.cpp @@ -274,7 +274,7 @@ CookiesDialog::CookiesDialog(std::list *originalCookieListPointe // Create the keyboard shortcuts. QShortcut *aShortcutPointer = new QShortcut(QKeySequence(i18nc("The add cookie key shortcut.", "a")), this); - QShortcut *eShortcutPointer = new QShortcut(QKeySequence(i18nc("The edit cookie key shorcut.", "e")), this); + QShortcut *eShortcutPointer = new QShortcut(QKeySequence(i18nc("The edit cookie key shortcut.", "e")), this); QShortcut *dShortcutPointer = new QShortcut(QKeySequence(i18nc("The delete cookie key shortcut.", "d")), this); QShortcut *deleteShortcutPointer = new QShortcut(QKeySequence::Delete, this); QShortcut *lShortcutPointer = new QShortcut(QKeySequence(i18nc("The delete all key shortcut.", "l")), this); diff --git a/src/settings/Settings.kcfg b/src/settings/Settings.kcfg index 36193bf..1bcf275 100644 --- a/src/settings/Settings.kcfg +++ b/src/settings/Settings.kcfg @@ -57,5 +57,17 @@ 1.00 + + + true + + + + true + + + + true + diff --git a/src/uis/SettingsGeneral.ui b/src/uis/SettingsGeneral.ui index 5248663..5e11e86 100644 --- a/src/uis/SettingsGeneral.ui +++ b/src/uis/SettingsGeneral.ui @@ -23,124 +23,186 @@ GeneralSettings - - - - - - Homepage - - - - The default is https://www.mojeek.com/. - - - - - - - - - - - - - Search engine - - - - The default is Mojeek. - - - - - - - - - 0 - 0 - - - - - true - - - - - Mojeek - + + + + + + + + Homepage + + + + The default is https://www.mojeek.com/. + + - - - Monocles - + + - - - MetaGer - + + + + + Search engine + + + + The default is Mojeek. + + - - - Google - + + + + + 0 + 0 + + + + + true + + + + + Mojeek + + + + + + Monocles + + + + + + MetaGer + + + + + + Google + + + + + + Bing + + + + + + Yahoo + + + - - - Bing - + + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + - - - Yahoo - + + + + + Zoom factor + + + + Valid values for the zoom factor are between 0.25 and 5.00. The default is 1.00. + + - - - - - - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - + + + + 0.250000000000000 + - - - - - Zoom factor - + + 5.000000000000000 + - - Valid values for the zoom factor are between 0.25 and 5.00. The default is 1.00. - - + + 0.250000000000000 + + + + - - - - - 0.250000000000000 + + + + + Full Screen Browsing - - 5.000000000000000 - + + + + + + Hide menu bar + + + + Hide the menu bar when browsing full screen. The default is enabled. + + + + + + + + + Hide toolbars + + + + Hide the toolbars when browsing full screen. The default is enabled. + + + + + + + + + Hide status bar + + + + Hide the status bar when browsing full screen. The default is enabled. + + + + + + - - 0.250000000000000 + + + + + Qt::Vertical - + diff --git a/src/views/BrowserView.cpp b/src/views/BrowserView.cpp index 6bdbda6..e7f238f 100644 --- a/src/views/BrowserView.cpp +++ b/src/views/BrowserView.cpp @@ -59,6 +59,9 @@ BrowserView::BrowserView(QWidget *parent) : QWidget(parent) // Set the WebEngine page. webEngineViewPointer->setPage(webEnginePagePointer); + // Handle full screen requests. + connect(webEnginePagePointer, SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)), this, SLOT(fullScreenRequested(QWebEngineFullScreenRequest))); + // Get handles for the aspects of the WebEngine. webEngineHistoryPointer = webEnginePagePointer->history(); webEngineSettingsPointer = webEngineViewPointer->settings(); @@ -461,6 +464,15 @@ void BrowserView::forward() const webEngineViewPointer->forward(); } +void BrowserView::fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest) const +{ + // Make it so. + emit fullScreenRequested(fullScreenRequest.toggleOn()); + + // Accept the request. + fullScreenRequest.accept(); +} + void BrowserView::home() const { // Load the homepage. diff --git a/src/views/BrowserView.h b/src/views/BrowserView.h index 0aeb6a0..b256ec2 100644 --- a/src/views/BrowserView.h +++ b/src/views/BrowserView.h @@ -28,6 +28,7 @@ // Qt toolkit headers. #include +#include #include #include #include @@ -60,6 +61,7 @@ signals: void addCookie(const QNetworkCookie &cookie) const; void removeCookie(const QNetworkCookie &cookie) const; void clearUrlLineEditFocus() const; + void fullScreenRequested(const bool toggleOn) const; void hideProgressBar() const; void linkHovered(const QString &linkUrl) const; void showProgressBar(const int &progress) const; @@ -96,6 +98,7 @@ private Q_SLOTS: // The private slots. void cookieAdded(const QNetworkCookie &cookie) const; void cookieRemoved(const QNetworkCookie &cookie) const; + void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest) const; void loadFinished() const; void loadProgress(const int &progress) const; void loadStarted() const; diff --git a/src/windows/BrowserWindow.cpp b/src/windows/BrowserWindow.cpp index d3800ad..e84f957 100644 --- a/src/windows/BrowserWindow.cpp +++ b/src/windows/BrowserWindow.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include // Construct the class. @@ -56,13 +57,14 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() KActionCollection *actionCollectionPointer = this->actionCollection(); // Add the standard actions. + KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer); + KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer); + KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer); + fullScreenActionPointer = KStandardAction::fullScreen(this, SLOT(toggleFullScreen()), this, actionCollectionPointer); QAction *backActionPointer = KStandardAction::back(this, SLOT(back()), actionCollectionPointer); QAction *forwardActionPointer = KStandardAction::forward(this, SLOT(forward()), actionCollectionPointer); KStandardAction::home(this, SLOT(home()), actionCollectionPointer); - KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer); - KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer); KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer); - KStandardAction::redisplay(this, SLOT(refresh()), actionCollectionPointer); // Add the custom actions. userAgentPrivacyBrowserActionPointer = actionCollectionPointer->addAction(QStringLiteral("user_agent_privacy_browser")); @@ -219,8 +221,9 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() userAgentMenuActionPointer = userAgentMenuPointer->menuAction(); searchEngineMenuActionPointer = searchEngineMenuPointer->menuAction(); - // Get a handle for the URL toolbar. - KToolBar *urlToolBarPointer = toolBar(QStringLiteral("url_toolbar")); + // Get handles for the toolbars. + navigationToolBarPointer = toolBar(QStringLiteral("navigation_toolbar")); + urlToolBarPointer = toolBar(QStringLiteral("url_toolbar")); // Create a URL line edit. urlLineEditPointer = new KLineEdit(); @@ -273,6 +276,17 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() connect(browserViewPointer, SIGNAL(addCookie(QNetworkCookie)), this, SLOT(addCookieToList(QNetworkCookie))); connect(browserViewPointer, SIGNAL(removeCookie(QNetworkCookie)), this, SLOT(removeCookieFromList(QNetworkCookie))); + // Process full screen requests. + connect(browserViewPointer, SIGNAL(fullScreenRequested(bool)), this, SLOT(fullScreenRequested(bool))); + + // Create keyboard shortcuts. + QShortcut *f11ShortcutPointer = new QShortcut(QKeySequence(i18nc("The toggle full screen shortcut.", "F11")), this); + QShortcut *escapeShortcutPointer = new QShortcut(QKeySequence::Cancel, this); + + // Connect the keyboard shortcuts to the actions. + connect(f11ShortcutPointer, SIGNAL(activated()), fullScreenActionPointer, SLOT(trigger())); + connect(escapeShortcutPointer, SIGNAL(activated()), this, SLOT(escape())); + // Load the initial website. browserViewPointer->loadInitialWebsite(); } @@ -340,6 +354,13 @@ void BrowserWindow::clearUrlLineEditFocus() const urlLineEditPointer->clearFocus(); } +void BrowserWindow::escape() const +{ + // Exit full screen browsing if it is enabled. + if (fullScreenActionPointer->isChecked()) + fullScreenActionPointer->trigger(); +} + void BrowserWindow::fileNew() const { // Display a new instance of Privacy Browser. @@ -355,6 +376,33 @@ void BrowserWindow::forward() const browserViewPointer->forward(); } +void BrowserWindow::fullScreenRequested(const bool toggleOn) +{ + // Toggle full screen mode. + if (toggleOn) // Turn full screen mode on. + { + // Set the window to be full screen. + fullScreenActionPointer->setFullScreen(window(), true); + + // Hide all the bars. + menuBar()->setVisible(false); + navigationToolBarPointer->setVisible(false); + urlToolBarPointer->setVisible(false); + statusBar()->setVisible(false); + } + else // Turn full screen mode off. + { + // Set the window to not be full screen. + fullScreenActionPointer->setFullScreen(window(), false); + + // Show all the bars. + menuBar()->setVisible(true); + navigationToolBarPointer->setVisible(true); + urlToolBarPointer->setVisible(true); + statusBar()->setVisible(true); + } +} + void BrowserWindow::getZoomFactorFromUser() { // Create an OK flag. @@ -539,13 +587,13 @@ void BrowserWindow::settingsConfigure() } } -void BrowserWindow::toggleLocalStorage() const +void BrowserWindow::toggleDomStorage() const { - // Remove the focus from teh URL line edit. + // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); - // Toggle local storage. - browserViewPointer->toggleLocalStorage(); + // Toggle DOM storage. + browserViewPointer->toggleDomStorage(); } void BrowserWindow::toggleJavaScript() const @@ -557,13 +605,53 @@ void BrowserWindow::toggleJavaScript() const browserViewPointer->toggleJavaScript(); } -void BrowserWindow::toggleDomStorage() const +void BrowserWindow::toggleLocalStorage() const { // Remove the focus from the URL line edit. urlLineEditPointer->clearFocus(); - // Toggle DOM storage. - browserViewPointer->toggleDomStorage(); + // Toggle local storage. + browserViewPointer->toggleLocalStorage(); +} + +void BrowserWindow::toggleFullScreen() +{ + // Toggle the full screen status. + if (fullScreenActionPointer->isChecked()) // Enable full screen browsing mode. + { + // Enable full screen mode. + fullScreenActionPointer->setFullScreen(window(), true); + + // Hide the menu bar if specified. + if (Settings::fullScreenHideMenuBar()) + menuBar()->setVisible(false); + + // Hide the toolbars if specified. + if (Settings::fullScreenHideToolBars()) + { + navigationToolBarPointer->setVisible(false); + urlToolBarPointer->setVisible(false); + } + + // Hide the status bar if specified. + if (Settings::fullScreenHideStatusBar()) + statusBar()->setVisible(false); + } + else // Disable full screen browsing mode. + { + // Disable full screen mode. + fullScreenActionPointer->setFullScreen(window(), false); + + // Show the menu bar. + menuBar()->setVisible(true); + + // Show the toolbars. + navigationToolBarPointer->setVisible(true); + urlToolBarPointer->setVisible(true); + + // Show the status bar. + statusBar()->setVisible(true); + } } void BrowserWindow::updateDomStorageAction(const bool &isEnabled) const diff --git a/src/windows/BrowserWindow.h b/src/windows/BrowserWindow.h index bfd76c0..aa9e2ee 100644 --- a/src/windows/BrowserWindow.h +++ b/src/windows/BrowserWindow.h @@ -25,6 +25,7 @@ // KDE Frameworks headers. #include +#include #include // Qt toolkit headers. @@ -52,8 +53,10 @@ private Q_SLOTS: void addOrEditDomainSettings() const; void back() const; void clearUrlLineEditFocus() const; + void escape() const; void fileNew() const; void forward() const; + void fullScreenRequested(const bool toggleOn); void getZoomFactorFromUser(); void home() const; void loadUrlFromLineEdit(const QString &url) const; @@ -66,6 +69,7 @@ private Q_SLOTS: void toggleDomStorage() const; void toggleJavaScript() const; void toggleLocalStorage() const; + void toggleFullScreen(); void updateDomStorageAction(const bool &isEnabled) const; void updateDomainSettingsIndicator(const bool &status, const QString &domainSettingsDomain); void updateJavaScriptAction(const bool &isEnabled); @@ -90,10 +94,12 @@ private: bool customUserAgentEnabled; QAction *domStorageActionPointer; QPalette domainSettingsPalette; + KToggleFullScreenAction *fullScreenActionPointer; QAction *javaScriptActionPointer; bool javaScriptEnabled; QAction *localStorageActionPointer; bool localStorageEnabled; + KToolBar *navigationToolBarPointer; QPalette noDomainSettingsPalette; QProgressBar *progressBarPointer; QLabel *searchEngineLabelPointer; @@ -117,6 +123,7 @@ private: QAction *userAgentSafariMacosActionPointer; QAction *userAgentCustomActionPointer; KLineEdit *urlLineEditPointer; + KToolBar *urlToolBarPointer; QAction *zoomFactorActionPointer; }; #endif