diff -r fd172973428e -r 85503ff2fce9 eric7/HelpViewer/HelpViewerImpl_qtb.py --- a/eric7/HelpViewer/HelpViewerImpl_qtb.py Thu Oct 07 20:22:02 2021 +0200 +++ b/eric7/HelpViewer/HelpViewerImpl_qtb.py Mon Oct 11 19:59:45 2021 +0200 @@ -7,21 +7,119 @@ Module implementing the QTextBrowser based help viewer class. """ +from PyQt6.QtCore import Qt, QByteArray, QUrl +from PyQt6.QtGui import QDesktopServices, QImage from PyQt6.QtWidgets import QTextBrowser from .HelpViewerImpl import HelpViewerImpl -class HelpViewerImpl_qtb(QTextBrowser, HelpViewerImpl): +class HelpViewerImpl_qtb(HelpViewerImpl, QTextBrowser): """ Class implementing the QTextBrowser based help viewer class. """ - def __init__(self, parent): + def __init__(self, engine, parent=None): """ Constructor + @param engine reference to the help engine + @type QHelpEngine @param parent reference to the parent widget @type QWidget """ - super().__init__(parent) -# HelpViewerImpl.__init__(self) + QTextBrowser.__init__(self, parent=parent) + HelpViewerImpl.__init__(self, engine) + + self.sourceChanged.connect(self.titleChanged) + + def setUrl(self, url): + """ + Public method to set the URL of the document to be shown. + + @param url source of the document + @type QUrl + """ + self.setSource(url) + + def doSetSource(self, url, type): + """ + Public method to load the data and show it. + + @param url DESCRIPTION + @type TYPE + @param type DESCRIPTION + @type TYPE + """ + data = self.getData(url) + if data is None: + QDesktopServices.openUrl(url) + return + + if url != QUrl("about:blank"): + super().doSetSource(url, type) + + self.setHtml(data) + self.sourceChanged.emit(url) + self.loadFinished.emit(True) + + def title(self): + """ + Public method get the page title. + + @return page title + @rtype str + """ + return self.documentTitle() + + def loadResource(self, type_, name): + """ + Public method to load data of the specified type from the resource with + the given name. + + @param type_ resource type + @type int + @param name resource name + @type QUrl + """ + ba = QByteArray() + + if type_ < 4: # QTextDocument.ResourceType.MarkdownResource + url = self._engine.findFile(name) + ba = self._engine.fileData(url) + if url.toString().lower().endswith(".svg"): + image = QImage() + image.loadFromData(ba, "svg") + if not image.isNull(): + return image + + return ba + + def mousePressEvent(self, evt): + """ + Protected method called by a mouse press event. + + @param evt reference to the mouse event + @type QMouseEvent + """ + if evt.button() == Qt.MouseButton.XButton1: + self.backward() + elif evt.button() == Qt.MouseButton.XButton2: + self.forward() + else: + super().mousePressEvent(evt) + + def gotoHistory(self, index): + """ + Public method to step through the history. + + @param index history index (<0 backward, >0 forward) + @type int + """ + if index < 0: + # backward + for ind in range(-index): + self.backward() + else: + # forward + for ind in range(index): + self.forward()