WebBrowser/QtHelp/HelpTocWidget.py

changeset 5252
321c2003745d
parent 5038
df7103c3f2a6
child 5389
9b1c800daff3
diff -r 2f22b20ea9ad -r 321c2003745d WebBrowser/QtHelp/HelpTocWidget.py
--- a/WebBrowser/QtHelp/HelpTocWidget.py	Mon Oct 17 18:57:24 2016 +0200
+++ b/WebBrowser/QtHelp/HelpTocWidget.py	Mon Oct 17 19:51:51 2016 +0200
@@ -9,8 +9,8 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import pyqtSignal, Qt, QEvent, QUrl
-from PyQt5.QtWidgets import QWidget, QVBoxLayout, QMenu
+from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl
+from PyQt5.QtWidgets import QWidget, QVBoxLayout, QMenu, QApplication
 
 
 class HelpTocWidget(QWidget):
@@ -43,7 +43,6 @@
         self.__expandDepth = -2
         
         self.__tocWidget = self.__engine.contentWidget()
-        self.__tocWidget.viewport().installEventFilter(self)
         self.__tocWidget.setContextMenuPolicy(Qt.CustomContextMenu)
         self.__tocWidget.setSortingEnabled(True)
         
@@ -52,11 +51,36 @@
         
         self.__tocWidget.customContextMenuRequested.connect(
             self.__showContextMenu)
-        self.__tocWidget.linkActivated.connect(self.openUrl)
+        self.__tocWidget.linkActivated.connect(self.__linkActivated)
         
         model = self.__tocWidget.model()
         model.contentsCreated.connect(self.__contentsCreated)
     
+    @pyqtSlot(QUrl)
+    def __linkActivated(self, url):
+        """
+        Private slot handling the activation of an entry.
+        
+        @param url URL of the activated entry
+        @type QUrl
+        """
+        if not url.isEmpty() and url.isValid():
+            buttons = QApplication.mouseButtons()
+            modifiers = QApplication.keyboardModifiers()
+            
+            if buttons & Qt.MidButton:
+                self.newTab.emit(url)
+            else:
+                if modifiers & (Qt.ControlModifier | Qt.ShiftModifier) == \
+                        (Qt.ControlModifier | Qt.ShiftModifier):
+                    self.newBackgroundTab.emit(url)
+                elif modifiers & Qt.ControlModifier:
+                    self.newTab.emit(url)
+                elif modifiers & Qt.ShiftModifier:
+                    self.newWindow.emit(url)
+                else:
+                    self.openUrl.emit(url)
+    
     def __contentsCreated(self):
         """
         Private slot to be run after the contents was generated.
@@ -102,34 +126,6 @@
         if evt.key() == Qt.Key_Escape:
             self.escapePressed.emit()
     
-    def eventFilter(self, watched, event):
-        """
-        Public method called to filter the event queue.
-        
-        @param watched the QObject being watched (QObject)
-        @param event the event that occurred (QEvent)
-        @return flag indicating whether the event was handled (boolean)
-        """
-        if self.__tocWidget and watched == self.__tocWidget.viewport() and \
-           event.type() == QEvent.MouseButtonRelease:
-            if self.__tocWidget.indexAt(event.pos()).isValid():
-                model = self.__tocWidget.model()
-                itm = model.contentItemAt(self.__tocWidget.currentIndex())
-                if itm:
-                    link = itm.url()
-                    if not link.isEmpty() and link.isValid():
-                        if event.button() == Qt.LeftButton:
-                            if event.modifiers() & Qt.ControlModifier:
-                                self.newTab.emit(link)
-                            elif event.modifiers() & Qt.ShiftModifier:
-                                self.newWindow.emit(link)
-                            else:
-                                self.openUrl.emit(link)
-                        elif event.button() == Qt.MidButton:
-                            self.newTab.emit(link)
-        
-        return QWidget.eventFilter(self, watched, event)
-    
     def syncToContent(self, url):
         """
         Public method to sync the TOC to the displayed page.

eric ide

mercurial