--- a/WebBrowser/QtHelp/HelpTocWidget.py Thu Jul 14 18:56:39 2016 +0200 +++ b/WebBrowser/QtHelp/HelpTocWidget.py Sun Jul 17 15:36:11 2016 +0200 @@ -17,24 +17,29 @@ """ Class implementing a window for showing the QtHelp TOC. - @signal linkActivated(QUrl) emitted when a TOC entry is activated @signal escapePressed() emitted when the ESC key was pressed + @signal openUrl(QUrl, str) emitted to open an entry in the current tab + @signal newTab(QUrl, str) emitted to open an entry in a new tab + @signal newBackgroundTab(QUrl, str) emitted to open an entry in a + new background tab + @signal newWindow(QUrl, str) emitted to open an entry in a new window """ - linkActivated = pyqtSignal(QUrl) escapePressed = pyqtSignal() + openUrl = pyqtSignal(QUrl) + newTab = pyqtSignal(QUrl) + newBackgroundTab = pyqtSignal(QUrl) + newWindow = pyqtSignal(QUrl) - def __init__(self, engine, mainWindow, parent=None): + def __init__(self, engine, parent=None): """ Constructor @param engine reference to the help engine (QHelpEngine) - @param mainWindow reference to the main window object (QMainWindow) @param parent reference to the parent widget (QWidget) """ super(HelpTocWidget, self).__init__(parent) self.__engine = engine - self.__mw = mainWindow self.__expandDepth = -2 self.__tocWidget = self.__engine.contentWidget() @@ -47,7 +52,7 @@ self.__tocWidget.customContextMenuRequested.connect( self.__showContextMenu) - self.__tocWidget.linkActivated.connect(self.linkActivated) + self.__tocWidget.linkActivated.connect(self.openUrl) model = self.__tocWidget.model() model.contentsCreated.connect(self.__contentsCreated) @@ -107,31 +112,24 @@ """ 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: + if self.__tocWidget.indexAt(event.pos()).isValid(): model = self.__tocWidget.model() itm = model.contentItemAt(self.__tocWidget.currentIndex()) - self.__mw.newTab(itm.url()) + 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 itemClicked(self, index): - """ - Public slot handling a click of a TOC entry. - - @param index index of the TOC clicked (QModelIndex) - """ - if not index.isValid(): - return - - model = self.__tocWidget.model() - itm = model.contentItemAt(index) - if itm: - self.linkActivated.emit(itm.url()) - def syncToContent(self, url): """ Public method to sync the TOC to the displayed page. @@ -154,16 +152,26 @@ if not self.__tocWidget.indexAt(pos).isValid(): return + model = self.__tocWidget.model() + itm = model.contentItemAt(self.__tocWidget.currentIndex()) + link = itm.url() + if link.isEmpty() or not link.isValid(): + return + menu = QMenu() curTab = menu.addAction(self.tr("Open Link")) newTab = menu.addAction(self.tr("Open Link in New Tab")) + newBackgroundTab = menu.addAction( + self.tr("Open Link in Background Tab")) + newWindow = menu.addAction(self.tr("Open Link in New Window")) menu.move(self.__tocWidget.mapToGlobal(pos)) - model = self.__tocWidget.model() - itm = model.contentItemAt(self.__tocWidget.currentIndex()) - act = menu.exec_() if act == curTab: - self.linkActivated.emit(itm.url()) + self.openUrl.emit(link) elif act == newTab: - self.__mw.newTab(itm.url()) + self.newTab.emit(link) + elif act == newBackgroundTab: + self.newBackgroundTab.emit(link) + elif act == newWindow: + self.newWindow.emit(link)