]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add full screen support. https://redmine.stoutner.com/issues/832
authorSoren Stoutner <soren@stoutner.com>
Fri, 24 Jun 2022 23:06:47 +0000 (16:06 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 24 Jun 2022 23:06:47 +0000 (16:06 -0700)
src/dialogs/CookiesDialog.cpp
src/settings/Settings.kcfg
src/uis/SettingsGeneral.ui
src/views/BrowserView.cpp
src/views/BrowserView.h
src/windows/BrowserWindow.cpp
src/windows/BrowserWindow.h

index cfd8f8b269325cd9785f6ef35cd3a76578158d6a..4e85efe4d112f9bbf35e34121b34fd3a58af8e61 100644 (file)
@@ -274,7 +274,7 @@ CookiesDialog::CookiesDialog(std::list<QNetworkCookie> *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);
index 36193bf8f20c184a9e9e65347d5776cc8663ffd5..1bcf275ccd8634fd4a5bd879e1d5a0ebfc7ac056 100644 (file)
         <entry name="zoomFactor" type="Double">
             <default>1.00</default>
         </entry>
+
+        <entry name="fullScreenHideMenuBar" type="Bool">
+            <default>true</default>
+        </entry>
+
+        <entry name="fullScreenHideToolBars" type="Bool">
+            <default>true</default>
+        </entry>
+
+        <entry name="fullScreenHideStatusBar" type="Bool">
+            <default>true</default>
+        </entry>
     </group>
 </kcfg>
index 5248663a6d60d6bae2ae774e10bf609ee0c6a74d..5e11e864ec0d98df013b543e4389bf8d7b3c61ab 100644 (file)
     <class>GeneralSettings</class>
 
     <widget class="QWidget">
-        <layout class="QFormLayout">
-            <!-- Homepage. -->
-            <item row="0" column="0">
-                <widget class="QLabel" name="homepageLabel">
-                    <property name="text">
-                        <string>Homepage</string>
-                    </property>
-
-                    <property name="toolTip">
-                        <string>The default is https://www.mojeek.com/.</string>
-                    </property>
-                </widget>
-            </item>
-
-            <item row="0" column="1">
-                <widget class="KLineEdit" name="kcfg_homepage" />
-            </item>
-
-            <!-- Search engine. -->
-            <item row="1" column="0">
-                <widget class="QLabel">
-                    <property name="text">
-                        <string>Search engine</string>
-                    </property>
-
-                    <property name="toolTip">
-                        <string>The default is Mojeek.</string>
-                    </property>
-                </widget>
-            </item>
-
-            <item row="1" column="1">
-                <widget class="QComboBox" name="kcfg_searchEngine">
-                    <property name="sizePolicy">
-                        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
-                            <horstretch>0</horstretch>
-                            <verstretch>0</verstretch>
-                        </sizepolicy>
-                    </property>
-
-                    <property name="editable">
-                        <bool>true</bool>
-                    </property>
-
-                    <item>
-                        <property name="text">
-                            <string>Mojeek</string>
-                        </property>
+        <layout class="QVBoxLayout">
+            <item>
+                <layout class="QFormLayout">
+                    <!-- Homepage. -->
+                    <item row="0" column="0">
+                        <widget class="QLabel" name="homepageLabel">
+                            <property name="text">
+                                <string>Homepage</string>
+                            </property>
+
+                            <property name="toolTip">
+                                <string>The default is https://www.mojeek.com/.</string>
+                            </property>
+                        </widget>
                     </item>
 
-                    <item>
-                        <property name="text">
-                            <string>Monocles</string>
-                        </property>
+                    <item row="0" column="1">
+                        <widget class="KLineEdit" name="kcfg_homepage" />
                     </item>
 
-                    <item>
-                        <property name="text">
-                            <string>MetaGer</string>
-                        </property>
+                    <!-- Search engine. -->
+                    <item row="1" column="0">
+                        <widget class="QLabel">
+                            <property name="text">
+                                <string>Search engine</string>
+                            </property>
+
+                            <property name="toolTip">
+                                <string>The default is Mojeek.</string>
+                            </property>
+                        </widget>
                     </item>
 
-                    <item>
-                        <property name="text">
-                            <string>Google</string>
-                        </property>
+                    <item row="1" column="1">
+                        <widget class="QComboBox" name="kcfg_searchEngine">
+                            <property name="sizePolicy">
+                                <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+                                    <horstretch>0</horstretch>
+                                    <verstretch>0</verstretch>
+                                </sizepolicy>
+                            </property>
+
+                            <property name="editable">
+                                <bool>true</bool>
+                            </property>
+
+                            <item>
+                                <property name="text">
+                                    <string>Mojeek</string>
+                                </property>
+                            </item>
+
+                            <item>
+                                <property name="text">
+                                    <string>Monocles</string>
+                                </property>
+                            </item>
+
+                            <item>
+                                <property name="text">
+                                    <string>MetaGer</string>
+                                </property>
+                            </item>
+
+                            <item>
+                                <property name="text">
+                                    <string>Google</string>
+                                </property>
+                            </item>
+
+                            <item>
+                                <property name="text">
+                                    <string>Bing</string>
+                                </property>
+                            </item>
+
+                            <item>
+                                <property name="text">
+                                    <string>Yahoo</string>
+                                </property>
+                            </item>
+                        </widget>
                     </item>
 
-                    <item>
-                        <property name="text">
-                            <string>Bing</string>
-                        </property>
+                    <item row="2" column="1">
+                        <widget class="QLabel" name="searchEngineLabel">
+                            <property name="textInteractionFlags">
+                                <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+                            </property>
+                        </widget>
                     </item>
 
-                    <item>
-                        <property name="text">
-                            <string>Yahoo</string>
-                        </property>
+                    <!-- Zoom factor. -->
+                    <item row="3" column="0">
+                        <widget class="QLabel" name="zoomFactorLabel">
+                            <property name="text">
+                                <string>Zoom factor</string>
+                            </property>
+
+                            <property name="toolTip">
+                                <string>Valid values for the zoom factor are between 0.25 and 5.00.  The default is 1.00.</string>
+                            </property>
+                        </widget>
                     </item>
-                </widget>
-            </item>
 
-            <item row="2" column="1">
-                <widget class="QLabel" name="searchEngineLabel">
-                    <property name="textInteractionFlags">
-                        <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
-                    </property>
-                </widget>
-            </item>
+                    <item row="3" column="1">
+                        <widget class="QDoubleSpinBox" name="kcfg_zoomFactor">
+                            <property name="minimum">
+                                <double>0.250000000000000</double>
+                            </property>
 
-            <!-- Zoom factor. -->
-            <item row="3" column="0">
-                <widget class="QLabel" name="zoomFactorLabel">
-                    <property name="text">
-                        <string>Zoom factor</string>
-                    </property>
+                            <property name="maximum">
+                                <double>5.000000000000000</double>
+                            </property>
 
-                    <property name="toolTip">
-                        <string>Valid values for the zoom factor are between 0.25 and 5.00.  The default is 1.00.</string>
-                    </property>
-                </widget>
+                            <property name="singleStep">
+                                <double>0.250000000000000</double>
+                            </property>
+                        </widget>
+                    </item>
+                </layout>
             </item>
 
-            <item row="3" column="1">
-                <widget class="QDoubleSpinBox" name="kcfg_zoomFactor">
-
-                    <property name="minimum">
-                        <double>0.250000000000000</double>
+            <!-- Full screen browsing. -->
+            <item>
+                <widget class="QGroupBox">
+                    <property name="title">
+                        <string>Full Screen Browsing</string>
                     </property>
 
-                    <property name="maximum">
-                        <double>5.000000000000000</double>
-                    </property>
+                    <layout class="QVBoxLayout">
+                        <!-- Hide menu bar. -->
+                        <item>
+                            <widget class="QCheckBox" name="kcfg_fullScreenHideMenuBar">
+                                <property name="text">
+                                    <string>Hide menu bar</string>
+                                </property>
+
+                                <property name="toolTip">
+                                    <string>Hide the menu bar when browsing full screen. The default is enabled.</string>
+                                </property>
+                            </widget>
+                        </item>
+
+                        <!-- Hide toolbars. -->
+                        <item>
+                            <widget class="QCheckBox" name="kcfg_fullScreenHideToolBars">
+                                <property name="text">
+                                    <string>Hide toolbars</string>
+                                </property>
+
+                                <property name="toolTip">
+                                    <string>Hide the toolbars when browsing full screen.  The default is enabled.</string>
+                                </property>
+                            </widget>
+                        </item>
+
+                        <!-- Hide status bar. -->
+                        <item>
+                            <widget class="QCheckBox" name="kcfg_fullScreenHideStatusBar">
+                                <property name="text">
+                                    <string>Hide status bar</string>
+                                </property>
+
+                                <property name="toolTip">
+                                    <string>Hide the status bar when browsing full screen.  The default is enabled.</string>
+                                </property>
+                            </widget>
+                        </item>
+                    </layout>
+                </widget>
+            </item>
 
-                    <property name="singleStep">
-                        <double>0.250000000000000</double>
+            <!-- Spacer. -->
+            <item>
+                <spacer>
+                    <property name="orientation">
+                        <enum>Qt::Vertical</enum>
                     </property>
-                </widget>
+                </spacer>
             </item>
         </layout>
     </widget>
index 6bdbda6536cc2dcea6f421267ccc8a5781860959..e7f238fc9beacb174d292a77d6c6e5fb58d6ebe3 100644 (file)
@@ -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.
index 0aeb6a051ad51f1db0bcdab9f4c577860b6858e1..b256ec253c4d7bff353817bca34a59a2f232090c 100644 (file)
@@ -28,6 +28,7 @@
 
 // Qt toolkit headers.
 #include <QPushButton>
+#include <QWebEngineFullScreenRequest>
 #include <QWebEngineHistory>
 #include <QWebEngineProfile>
 #include <QWebEngineSettings>
@@ -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;
index d3800ad8e1674c93b7c54e77c0be5618c62eed6f..e84f9574835bdf1ad6c04df0304e518d1ee7c9cb 100644 (file)
@@ -36,6 +36,7 @@
 #include <QInputDialog>
 #include <QNetworkCookie>
 #include <QMenuBar>
+#include <QShortcut>
 #include <QStatusBar>
 
 // 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
index bfd76c0a46693b5689c2a3d3b3b655bfc15755a2..aa9e2ee0351a2c41c04178775d244f0bf1dbec7f 100644 (file)
@@ -25,6 +25,7 @@
 
 // KDE Frameworks headers.
 #include <KConfigDialog>
+#include <KToggleFullScreenAction>
 #include <KXmlGuiWindow>
 
 // 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