--- a/eric7/HelpViewer/HelpViewerImpl_qtb.py Fri Oct 15 20:08:41 2021 +0200 +++ b/eric7/HelpViewer/HelpViewerImpl_qtb.py Fri Oct 15 20:09:38 2021 +0200 @@ -7,7 +7,7 @@ Module implementing the QTextBrowser based help viewer class. """ -from PyQt6.QtCore import Qt, QByteArray, QUrl +from PyQt6.QtCore import Qt, QByteArray, QUrl, QEvent from PyQt6.QtGui import QDesktopServices, QImage from PyQt6.QtWidgets import QTextBrowser @@ -33,6 +33,8 @@ self.__zoomCount = 0 self.sourceChanged.connect(self.titleChanged) + + self.grabGesture(Qt.GestureType.PinchGesture) def setUrl(self, url): """ @@ -153,6 +155,18 @@ self.zoomOut() self.zoomChanged.emit() + def setScale(self, scale): + """ + Public method to set the zoom level. + + @param scale zoom level to set + @type int + """ + if -5 <= scale <= 10: + self.zoomOut(scale) + self.__zoomCount = scale + self.zoomChanged.emit() + def resetScale(self): """ Public method to reset the zoom level. @@ -205,5 +219,78 @@ else: QTextBrowser.wheelEvent(self, evt) - # TODO: implement context menu + def keyPressEvent(self, evt): + """ + Public method to handle key press events. + + @param evt reference to the key event + @type QKeyEvent + """ + if evt.key() == Qt.Key.Key_ZoomIn: + self.scaleUp() + evt.accept() + elif evt.key() == Qt.Key.Key_ZoomOut: + self.scaleDown() + evt.accept() + elif evt.key() == Qt.Key.Key_Plus: + if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: + self.scaleUp() + evt.accept() + elif evt.key() == Qt.Key.Key_Minus: + if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: + self.scaleDown() + evt.accept() + elif evt.key() == Qt.Key.Key_0: + if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: + self.resetScale() + evt.accept() + elif evt.key() == Qt.Key.Key_Backspace: + self.backward() + evt.accept() + + def event(self, evt): + """ + Public method handling events. + + @param evt reference to the event + @type QEvent + @return flag indicating the event was handled + @rtype bool + """ + if evt.type() == QEvent.Type.Gesture: + self.gestureEvent(evt) + return True + + return super().event(evt) + + def gestureEvent(self, evt): + """ + Protected method handling gesture events. + + @param evt reference to the gesture event + @type QGestureEvent + """ + pinch = evt.gesture(Qt.GestureType.PinchGesture) + if pinch: + if pinch.state() == Qt.GestureState.GestureStarted: + zoom = (self.getZoom() + 6) / 10.0 + pinch.setTotalScaleFactor(zoom) + elif pinch.state() == Qt.GestureState.GestureUpdated: + zoom = int(pinch.totalScaleFactor() * 10) - 6 + if zoom <= -5: + zoom = -5 + pinch.setTotalScaleFactor(0.1) + elif zoom >= 10: + zoom = 10 + pinch.setTotalScaleFactor(1.6) + self.setScale(zoom) + evt.accept() + + # TODO: implement context menu + # - Open Link + # - Open Link in New Page + # - Open Link in Background Page + # - Copy + # - Copy Link LOcation + # - Select All # TODO: add Ctrl+LMB action (open link in new page)