diff -r 2f22b20ea9ad -r 321c2003745d Helpviewer/HelpTocWidget.py --- a/Helpviewer/HelpTocWidget.py Mon Oct 17 18:57:24 2016 +0200 +++ b/Helpviewer/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): @@ -38,7 +38,6 @@ self.__expandDepth = -2 self.__tocWidget = self.__engine.contentWidget() - self.__tocWidget.viewport().installEventFilter(self) self.__tocWidget.setContextMenuPolicy(Qt.CustomContextMenu) self.__layout = QVBoxLayout(self) @@ -46,11 +45,31 @@ self.__tocWidget.customContextMenuRequested.connect( self.__showContextMenu) - self.__tocWidget.linkActivated.connect(self.linkActivated) + self.__tocWidget.linkActivated.connect(self.__linkActivated) model = self.__tocWidget.model() model.contentsCreated.connect(self.__expandTOC) + @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.__mw.newTab(url) + else: + if modifiers & Qt.ControlModifier: + self.__mw.newTab(url) + else: + self.linkActivated.emit(url) + def __expandTOC(self): """ Private slot to expand the table of contents. @@ -89,27 +108,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() and \ - event.button() == Qt.LeftButton: - self.itemClicked(self.__tocWidget.currentIndex()) - elif self.__tocWidget.indexAt(event.pos()).isValid() and \ - event.button() == Qt.MidButton: - model = self.__tocWidget.model() - itm = model.contentItemAt(self.__tocWidget.currentIndex()) - self.__mw.newTab(itm.url()) - - return QWidget.eventFilter(self, watched, event) - def itemClicked(self, index): """ Public slot handling a click of a TOC entry.