WebBrowser/WebBrowserWindow.py

branch
maintenance
changeset 5730
6422afc7adc4
parent 5722
433187e73c0f
child 5734
d8b99b5fa673
diff -r 9a71bd9e2e37 -r 6422afc7adc4 WebBrowser/WebBrowserWindow.py
--- a/WebBrowser/WebBrowserWindow.py	Sun Apr 09 16:52:55 2017 +0200
+++ b/WebBrowser/WebBrowserWindow.py	Sat May 06 13:43:21 2017 +0200
@@ -21,9 +21,8 @@
     QUrl, QTextCodec, QProcess, QEvent, qVersion
 from PyQt5.QtGui import QDesktopServices, QKeySequence, QFont, QFontMetrics
 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QDockWidget, \
-    QComboBox, QLabel, QSplitter, QMenu, QToolButton, QLineEdit, \
-    QApplication, QWhatsThis, QDialog, QHBoxLayout, QProgressBar, QAction, \
-    QInputDialog
+    QComboBox, QLabel, QMenu, QToolButton, QLineEdit, QApplication, \
+    QWhatsThis, QDialog, QHBoxLayout, QProgressBar, QInputDialog
 from PyQt5.QtWebEngineWidgets import QWebEngineSettings, QWebEnginePage, \
     QWebEngineProfile, QWebEngineScript
 try:
@@ -127,6 +126,8 @@
         @keyparam qthelp flag indicating to enable the QtHelp support (bool)
         @keyparam settingsDir directory to be used for the settings files (str)
         """
+        self.__hideNavigationTimer = None
+        
         super(WebBrowserWindow, self).__init__(parent)
         self.setObjectName(name)
         if private:
@@ -178,6 +179,9 @@
             from .StatusBar.JavaScriptIcon import JavaScriptIcon
             from .StatusBar.ImagesIcon import ImagesIcon
             from .VirusTotal.VirusTotalApi import VirusTotalAPI
+            from .Navigation.NavigationBar import NavigationBar
+            from .Navigation.NavigationContainer import NavigationContainer
+            from .Bookmarks.BookmarksToolBar import BookmarksToolBar
             
             if not self.__fromEric:
                 self.setStyle(Preferences.getUI("Style"),
@@ -216,9 +220,28 @@
             self.__tabWidget.browserOpened.connect(self.webBrowserOpened)
             
             self.__searchWidget = SearchWidget(self, self)
+            
+            self.__setIconDatabasePath()
+            
+            bookmarksModel = self.bookmarksManager().bookmarksModel()
+            self.__bookmarksToolBar = BookmarksToolBar(self, bookmarksModel,
+                                                       self)
+            self.__bookmarksToolBar.setIconSize(UI.Config.ToolBarIconSize)
+            self.__bookmarksToolBar.openUrl.connect(self.openUrl)
+            self.__bookmarksToolBar.newTab.connect(self.openUrlNewTab)
+            self.__bookmarksToolBar.newWindow.connect(self.openUrlNewWindow)
+            
+            self.__navigationBar = NavigationBar(self)
+            
+            self.__navigationContainer = NavigationContainer(self)
+            self.__navigationContainer.addWidget(self.__navigationBar)
+            self.__navigationContainer.addWidget(self.__bookmarksToolBar)
+            
             centralWidget = QWidget()
             layout = QVBoxLayout()
             layout.setContentsMargins(1, 1, 1, 1)
+            layout.setSpacing(0)
+            layout.addWidget(self.__navigationContainer)
             layout.addWidget(self.__tabWidget)
             layout.addWidget(self.__searchWidget)
             self.__tabWidget.setSizePolicy(
@@ -282,7 +305,6 @@
             
             WebBrowserWindow.BrowserWindows.append(self)
             
-            self.__setIconDatabasePath()
             self.__initWebEngineSettings()
             
             # initialize some of our class objects
@@ -378,6 +400,13 @@
             
             e5App().focusChanged.connect(self.__appFocusChanged)
             
+            self.__toolbarStates = self.saveState()
+            
+            self.__hideNavigationTimer = QTimer(self)
+            self.__hideNavigationTimer.setInterval(1000)
+            self.__hideNavigationTimer.setSingleShot(True)
+            self.__hideNavigationTimer.timeout.connect(self.__hideNavigation)
+            
             QTimer.singleShot(0, syncMgr.loadSettings)
     
     def __del__(self):
@@ -865,7 +894,7 @@
             QKeySequence(self.tr("Ctrl+Home", "Go|Home")),
             0, self, 'webbrowser_go_home')
         self.homeAct.setStatusTip(self.tr(
-            'Move to the initial help screen'))
+            'Move to the initial screen'))
         self.homeAct.setWhatsThis(self.tr(
             """<b>Home</b>"""
             """<p>Moves to the initial screen.</p>"""
@@ -1242,9 +1271,9 @@
             UI.PixmapCache.getIcon("windowFullscreen.png"),
             self.tr('&Full Screen'),
             QKeySequence(self.tr('F11')), 0,
-            self, 'webbrowser_view_full_scree')
+            self, 'webbrowser_view_full_screen')
         if not self.__initShortcutsOnly:
-            self.fullScreenAct.triggered.connect(self.__viewFullScreen)
+            self.fullScreenAct.triggered.connect(self.toggleFullScreen)
         self.__actions.append(self.fullScreenAct)
         self.addAction(self.fullScreenAct)
         
@@ -1952,6 +1981,10 @@
         """
         Private method to create the toolbars.
         """
+        # save references to toolbars in order to hide them
+        # when going full screen
+        self.__toolbars = []
+        
         filetb = self.addToolBar(self.tr("File"))
         filetb.setObjectName("FileToolBar")
         filetb.setIconSize(UI.Config.ToolBarIconSize)
@@ -1975,6 +2008,7 @@
             filetb.addSeparator()
         filetb.addAction(self.closeAct)
         filetb.addAction(self.exitAct)
+        self.__toolbars.append(filetb)
         
         self.savePageScreenMenu = QMenu(self)
         self.savePageScreenMenu.addAction(self.savePageScreenAct)
@@ -1994,6 +2028,7 @@
         edittb.addAction(self.pasteAct)
         edittb.addSeparator()
         edittb.addAction(self.selectAllAct)
+        self.__toolbars.append(edittb)
         
         viewtb = self.addToolBar(self.tr("View"))
         viewtb.setObjectName("ViewToolBar")
@@ -2003,6 +2038,7 @@
         viewtb.addAction(self.zoomOutAct)
         viewtb.addSeparator()
         viewtb.addAction(self.fullScreenAct)
+        self.__toolbars.append(viewtb)
         
         findtb = self.addToolBar(self.tr("Find"))
         findtb.setObjectName("FindToolBar")
@@ -2010,6 +2046,7 @@
         findtb.addAction(self.findAct)
         findtb.addAction(self.findNextAct)
         findtb.addAction(self.findPrevAct)
+        self.__toolbars.append(findtb)
         
         if WebBrowserWindow._useQtHelp:
             filtertb = self.addToolBar(self.tr("Filter"))
@@ -2023,6 +2060,7 @@
             self.filterCombo.activated[str].connect(
                 self.__filterQtHelpDocumentation)
             self.__setupFilterCombo()
+            self.__toolbars.append(filtertb)
         
         settingstb = self.addToolBar(self.tr("Settings"))
         settingstb.setObjectName("SettingsToolBar")
@@ -2034,6 +2072,7 @@
         settingstb.addAction(self.personalDataAct)
         settingstb.addAction(self.greaseMonkeyAct)
         settingstb.addAction(self.featurePermissionAct)
+        self.__toolbars.append(settingstb)
         
         toolstb = self.addToolBar(self.tr("Tools"))
         toolstb.setObjectName("ToolsToolBar")
@@ -2042,66 +2081,13 @@
         toolstb.addAction(self.siteInfoAct)
         toolstb.addSeparator()
         toolstb.addAction(self.synchronizationAct)
+        self.__toolbars.append(toolstb)
         
         helptb = self.addToolBar(self.tr("Help"))
         helptb.setObjectName("HelpToolBar")
         helptb.setIconSize(UI.Config.ToolBarIconSize)
         helptb.addAction(self.whatsThisAct)
-        
-        self.addToolBarBreak()
-        
-        gotb = self.addToolBar(self.tr("Go"))
-        gotb.setObjectName("GoToolBar")
-        gotb.setIconSize(UI.Config.ToolBarIconSize)
-        gotb.addAction(self.backAct)
-        gotb.addAction(self.forwardAct)
-        gotb.addAction(self.reloadAct)
-        gotb.addAction(self.stopAct)
-        gotb.addAction(self.homeAct)
-        gotb.addSeparator()
-        
-        self.__navigationSplitter = QSplitter(gotb)
-        self.__navigationSplitter.addWidget(self.__tabWidget.stackedUrlBar())
-        
-        from .WebBrowserWebSearchWidget import WebBrowserWebSearchWidget
-        self.searchEdit = WebBrowserWebSearchWidget(self)
-        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
-        sizePolicy.setHorizontalStretch(2)
-        sizePolicy.setVerticalStretch(0)
-        self.searchEdit.setSizePolicy(sizePolicy)
-        self.searchEdit.search.connect(self.__linkActivated)
-        self.__navigationSplitter.addWidget(self.searchEdit)
-        gotb.addWidget(self.__navigationSplitter)
-        
-        self.__navigationSplitter.setSizePolicy(
-            QSizePolicy.Expanding, QSizePolicy.Maximum)
-        self.__navigationSplitter.setCollapsible(0, False)
-        
-        self.backMenu = QMenu(self)
-        self.backMenu.aboutToShow.connect(self.__showBackMenu)
-        self.backMenu.triggered.connect(self.__navigationMenuActionTriggered)
-        backButton = gotb.widgetForAction(self.backAct)
-        backButton.setMenu(self.backMenu)
-        backButton.setPopupMode(QToolButton.MenuButtonPopup)
-        
-        self.forwardMenu = QMenu(self)
-        self.forwardMenu.aboutToShow.connect(self.__showForwardMenu)
-        self.forwardMenu.triggered.connect(
-            self.__navigationMenuActionTriggered)
-        forwardButton = gotb.widgetForAction(self.forwardAct)
-        forwardButton.setMenu(self.forwardMenu)
-        forwardButton.setPopupMode(QToolButton.MenuButtonPopup)
-        
-        from .Bookmarks.BookmarksToolBar import BookmarksToolBar
-        bookmarksModel = self.bookmarksManager().bookmarksModel()
-        self.bookmarksToolBar = BookmarksToolBar(self, bookmarksModel, self)
-        self.bookmarksToolBar.setObjectName("BookmarksToolBar")
-        self.bookmarksToolBar.setIconSize(UI.Config.ToolBarIconSize)
-        self.bookmarksToolBar.openUrl.connect(self.openUrl)
-        self.bookmarksToolBar.newTab.connect(self.openUrlNewTab)
-        self.bookmarksToolBar.newWindow.connect(self.openUrlNewWindow)
-        self.addToolBarBreak()
-        self.addToolBar(self.bookmarksToolBar)
+        self.__toolbars.append(helptb)
         
         self.addToolBarBreak()
         vttb = self.addToolBar(self.tr("VirusTotal"))
@@ -2125,6 +2111,7 @@
             self.virustotalScanCurrentAct.setEnabled(False)
             self.virustotalIpReportAct.setEnabled(False)
             self.virustotalDomainReportAct.setEnabled(False)
+        self.__toolbars.append(vttb)
         
     def __nextTab(self):
         """
@@ -2351,6 +2338,7 @@
         @param b flag indicating availability of the backwards action (boolean)
         """
         self.backAct.setEnabled(b)
+        self.__navigationBar.backButton().setEnabled(b)
         
     def setForwardAvailable(self, b):
         """
@@ -2360,6 +2348,7 @@
             (boolean)
         """
         self.forwardAct.setEnabled(b)
+        self.__navigationBar.forwardButton().setEnabled(b)
         
     def setLoadingActions(self, b):
         """
@@ -2370,6 +2359,9 @@
         self.reloadAct.setEnabled(not b)
         self.stopAct.setEnabled(b)
         
+        self.__navigationBar.reloadButton().setEnabled(not b)
+        self.__navigationBar.stopButton().setEnabled(b)
+        
     def __addBookmark(self):
         """
         Private slot called to add the displayed file to the bookmarks.
@@ -2543,7 +2535,7 @@
         
         self.cookieJar().close()
         
-        self.bookmarksToolBar.setModel(None)
+        self.__bookmarksToolBar.setModel(None)
         self.bookmarksManager().close()
         
         self.historyManager().close()
@@ -2566,7 +2558,7 @@
         
         self.flashCookieManager().shutdown()
         
-        self.searchEdit.openSearchManager().close()
+        self.__navigationBar.searchEdit().openSearchManager().close()
         
         if len(WebBrowserWindow.BrowserWindows) == 1:
             # it is the last window
@@ -2579,7 +2571,7 @@
             if self.__helpInstaller:
                 self.__helpInstaller.stop()
         
-        self.searchEdit.saveSearches()
+        self.__navigationBar.searchEdit().saveSearches()
         
         self.__tabWidget.closeAllBrowsers(shutdown=True)
         
@@ -2667,9 +2659,9 @@
         self.currentBrowser().zoomReset()
         self.__zoomWidget.setValue(self.currentBrowser().zoomValue())
     
-    def __viewFullScreen(self):
-        """
-        Private slot called to toggle fullscreen mode.
+    def toggleFullScreen(self):
+        """
+        Public slot called to toggle the full screen mode.
         """
         if self.__htmlFullScreen:
             self.currentBrowser().triggerPageAction(
@@ -2679,17 +2671,9 @@
         if self.isFullScreen():
             # switch back to normal
             self.showNormal()
-            self.menuBar().show()
-            self.fullScreenAct.setIcon(
-                UI.PixmapCache.getIcon("windowFullscreen.png"))
-            self.fullScreenAct.setIconText(self.tr('Full Screen'))
         else:
             # switch to full screen
             self.showFullScreen()
-            self.menuBar().hide()
-            self.fullScreenAct.setIcon(
-                UI.PixmapCache.getIcon("windowRestore.png"))
-            self.fullScreenAct.setIconText(self.tr('Restore Window'))
     
     def enterHtmlFullScreen(self):
         """
@@ -2699,6 +2683,45 @@
         self.showFullScreen()
         self.__htmlFullScreen = True
     
+    def isFullScreenNavigationVisible(self):
+        """
+        Public method to check, if full screen navigation is active.
+        
+        @return flag indicating visibility of the navigation container in full
+            screen mode
+        @rtype bool
+        """
+        return self.isFullScreen() and self.__navigationContainer.isVisible()
+    
+    def showFullScreenNavigation(self):
+        """
+        Public slot to show full screen navigation.
+        """
+        if self.__htmlFullScreen:
+            return
+        
+        if self.__hideNavigationTimer.isActive():
+            self.__hideNavigationTimer.stop()
+        
+        self.__navigationContainer.show()
+    
+    def hideFullScreenNavigation(self):
+        """
+        Public slot to hide full screen navigation.
+        """
+        if not self.__hideNavigationTimer.isActive():
+            self.__hideNavigationTimer.start()
+    
+    def __hideNavigation(self):
+        """
+        Private slot to hide full screen navigation by timer.
+        """
+        browser = self.currentBrowser()
+        mouseInBrowser = browser and browser.underMouse()
+        
+        if self.isFullScreen() and mouseInBrowser:
+            self.__navigationContainer.hide()
+    
     def __copy(self):
         """
         Private slot called to handle the copy action.
@@ -2832,7 +2855,7 @@
         
         self.__tabWidget.preferencesChanged()
         
-        self.searchEdit.preferencesChanged()
+        self.__navigationBar.searchEdit().preferencesChanged()
         
         self.autoScroller().preferencesChanged()
         
@@ -3250,57 +3273,6 @@
         self.editMessageFilterAct.setEnabled(
             E5ErrorMessage.messageHandlerInstalled())
         
-    def __showBackMenu(self):
-        """
-        Private slot showing the backwards navigation menu.
-        """
-        self.backMenu.clear()
-        history = self.currentBrowser().history()
-        historyCount = history.count()
-        backItems = history.backItems(historyCount)
-        for index in range(len(backItems) - 1, -1, -1):
-            item = backItems[index]
-            act = QAction(self)
-            act.setData(-1 * (index + 1))
-            icon = WebBrowserWindow.icon(item.url())
-            act.setIcon(icon)
-            act.setText(item.title())
-            self.backMenu.addAction(act)
-        
-    def __showForwardMenu(self):
-        """
-        Private slot showing the forwards navigation menu.
-        """
-        self.forwardMenu.clear()
-        history = self.currentBrowser().history()
-        historyCount = history.count()
-        forwardItems = history.forwardItems(historyCount)
-        for index in range(len(forwardItems)):
-            item = forwardItems[index]
-            act = QAction(self)
-            act.setData(index + 1)
-            icon = WebBrowserWindow.icon(item.url())
-            act.setIcon(icon)
-            act.setText(item.title())
-            self.forwardMenu.addAction(act)
-        
-    def __navigationMenuActionTriggered(self, act):
-        """
-        Private slot to go to the selected page.
-        
-        @param act reference to the action selected in the navigation menu
-            (QAction)
-        """
-        offset = act.data()
-        history = self.currentBrowser().history()
-        historyCount = history.count()
-        if offset < 0:
-            # go back
-            history.goToItem(history.backItems(historyCount)[-1 * offset - 1])
-        else:
-            # go forward
-            history.goToItem(history.forwardItems(historyCount)[offset - 1])
-        
     def __clearPrivateData(self):
         """
         Private slot to clear the private data.
@@ -3319,7 +3291,7 @@
                 self.__tabWidget.clearClosedTabsList()
                 self.webProfile().clearAllVisitedLinks()
             if searches:
-                self.searchEdit.clear()
+                self.__navigationBar.searchEdit().clear()
             if downloads:
                 self.downloadManager().cleanup()
                 self.downloadManager().hide()
@@ -3744,7 +3716,7 @@
         
         @return reference to the opensearch manager object (OpenSearchManager)
         """
-        return self.searchEdit.openSearchManager()
+        return self.__navigationBar.searchEdit().openSearchManager()
     
     def __aboutToShowTextEncodingMenu(self):
         """
@@ -4021,11 +3993,30 @@
                bool(self.windowState() & Qt.WindowFullScreen):
                 # enter full screen mode
                 self.__windowStates = evt.oldState()
+                self.__toolbarStates = self.saveState()
+                self.menuBar().hide()
+                self.statusBar().hide()
+                self.__searchWidget.hide()
+                self.__tabWidget.tabBar().hide()
+                for toolbar in self.__toolbars:
+                    toolbar.hide()
+                self.__navigationBar.exitFullScreenButton().setVisible(True)
+                self.__navigationContainer.hide()
+            
             elif bool(evt.oldState() & Qt.WindowFullScreen) and \
                     not bool(self.windowState() & Qt.WindowFullScreen):
                 # leave full screen mode
                 self.setWindowState(self.__windowStates)
                 self.__htmlFullScreen = False
+                self.menuBar().show()
+                self.statusBar().show()
+                self.restoreState(self.__toolbarStates)
+                self.__tabWidget.tabBar().show()
+                self.__navigationBar.exitFullScreenButton().setVisible(False)
+                self.__navigationContainer.show()
+            
+            if self.__hideNavigationTimer:
+                self.__hideNavigationTimer.stop()
         
         return super(WebBrowserWindow, self).event(evt)
     

eric ide

mercurial