WebBrowser/QtHelp/HelpSearchWidget.py

changeset 5252
321c2003745d
parent 5038
df7103c3f2a6
child 5389
9b1c800daff3
--- a/WebBrowser/QtHelp/HelpSearchWidget.py	Mon Oct 17 18:57:24 2016 +0200
+++ b/WebBrowser/QtHelp/HelpSearchWidget.py	Mon Oct 17 19:51:51 2016 +0200
@@ -9,7 +9,7 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import pyqtSignal, Qt, QEvent, QUrl
+from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl
 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QTextBrowser, QApplication, \
     QMenu
 
@@ -56,14 +56,12 @@
         self.setFocusProxy(self.__query)
         
         self.__query.search.connect(self.__search)
-        self.__result.requestShowLink.connect(self.openUrl)
+        self.__result.requestShowLink.connect(self.__linkActivated)
         
         self.__engine.searchingStarted.connect(self.__searchingStarted)
         self.__engine.searchingFinished.connect(self.__searchingFinished)
         
         self.__browser = self.__result.findChildren(QTextBrowser)[0]
-        if self.__browser:
-            self.__browser.viewport().installEventFilter(self)
     
     def __search(self):
         """
@@ -86,29 +84,30 @@
         """
         QApplication.restoreOverrideCursor()
     
-    def eventFilter(self, watched, event):
+    @pyqtSlot(QUrl)
+    def __linkActivated(self, url):
         """
-        Public method called to filter the event queue.
+        Private slot handling the activation of an entry.
         
-        @param watched the QObject being watched (QObject)
-        @param event the event that occurred (QEvent)
-        @return flag indicating whether the event was handled (boolean)
+        @param url URL of the activated entry
+        @type QUrl
         """
-        if self.__browser and watched == self.__browser.viewport() and \
-           event.type() == QEvent.MouseButtonRelease:
-            link = self.__result.linkAt(event.pos())
-            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)
+        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 keyPressEvent(self, evt):
         """

eric ide

mercurial