diff -r 1294772ac8e6 -r f3d2172d663e UI/Previewers/PreviewerHTML.py --- a/UI/Previewers/PreviewerHTML.py Fri Aug 11 14:41:23 2017 +0200 +++ b/UI/Previewers/PreviewerHTML.py Fri Aug 11 17:50:49 2017 +0200 @@ -22,8 +22,9 @@ import sys from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QSize, QThread +from PyQt5.QtGui import QCursor from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QCheckBox, \ - QSizePolicy + QSizePolicy, QToolTip from E5Gui.E5Application import e5App @@ -53,6 +54,7 @@ try: from PyQt5.QtWebEngineWidgets import QWebEngineView self.previewView = QWebEngineView(self) + self.previewView.page().linkHovered.connect(self.__showLink) self.__usesWebKit = False except ImportError: from PyQt5.QtWebKitWidgets import QWebPage, QWebView @@ -143,6 +145,16 @@ Preferences.setUI("ShowFilePreviewSSI", checked) self.processEditor() + @pyqtSlot(str) + def __showLink(self, urlStr): + """ + Private slot to show the hovered link in a tooltip. + + @param urlStr hovered URL + @type str + """ + QToolTip.showText(QCursor.pos(), urlStr, self.previewView) + def processEditor(self, editor=None): """ Public slot to process an editor's text. @@ -196,13 +208,17 @@ Preferences.getEditor("PreviewMarkdownHTMLFormat"), Preferences.getEditor("PreviewRestDocutilsHTMLFormat")) - def __setHtml(self, filePath, html): + def __setHtml(self, filePath, html, rootPath): """ Private method to set the HTML to the view and restore the scroll bars positions. - @param filePath file path of the previewed editor (string) - @param html processed HTML text ready to be shown (string) + @param filePath file path of the previewed editor + @type str + @param html processed HTML text ready to be shown + @type str + @param rootPath path of the web site root + @type str """ self.__previewedPath = Utilities.normcasepath( Utilities.fromNativeSeparators(filePath)) @@ -215,7 +231,11 @@ self.__restoreScrollBarPositions) if not filePath: filePath = "/" - self.previewView.setHtml(html, baseUrl=QUrl.fromLocalFile(filePath)) + if rootPath: + baseUrl = QUrl.fromLocalFile(rootPath + "/index.html") + else: + baseUrl = QUrl.fromLocalFile(filePath) + self.previewView.setHtml(html, baseUrl=baseUrl) if self.__previewedEditor: self.__previewedEditor.setFocus() @@ -343,10 +363,11 @@ Class implementing a thread to process some text into HTML usable by the previewer view. - @signal htmlReady(str,str) emitted with the file name and processed HTML - to signal the availability of the processed HTML + @signal htmlReady(str, str, str) emitted with the file name, the processed + HTML and the web site root path to signal the availability of the + processed HTML """ - htmlReady = pyqtSignal(str, str) + htmlReady = pyqtSignal(str, str, str) def __init__(self, parent=None): """ @@ -418,7 +439,7 @@ with self.__lock: if not self.__haveData: - self.htmlReady.emit(filePath, html) + self.htmlReady.emit(filePath, html, rootPath) break # else - next iteration