QScintilla/Terminal.py

changeset 1518
e6e21910210d
parent 1509
c0b5e693b0eb
child 1565
815eb7a39944
child 1566
0cb791cc631a
--- a/QScintilla/Terminal.py	Fri Dec 30 15:20:34 2011 +0100
+++ b/QScintilla/Terminal.py	Fri Dec 30 18:33:18 2011 +0100
@@ -11,7 +11,7 @@
 import os
 import re
 
-from PyQt4.QtCore import QSignalMapper, QTimer, QByteArray, QProcess, Qt
+from PyQt4.QtCore import QSignalMapper, QTimer, QByteArray, QProcess, Qt, QEvent
 from PyQt4.QtGui import QDialog, QInputDialog, QApplication, QMenu, QPalette, QFont
 from PyQt4.Qsci import QsciScintilla
 
@@ -172,6 +172,8 @@
         
         self.__lastPos = (0, 0)
         
+        self.grabGesture(Qt.PinchGesture)
+        
         self.__startShell()
         
     def __readOutput(self):
@@ -499,6 +501,41 @@
         
         super().wheelEvent(evt)
     
+    
+    def event(self, evt):
+        """
+        Protected method handling events.
+        
+        @param evt reference to the event (QEvent)
+        @return flag indicating, if the event was handled (boolean)
+        """
+        if evt.type() == QEvent.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 (QGestureEvent
+        """
+        pinch = evt.gesture(Qt.PinchGesture)
+        if pinch:
+            if pinch.state() == Qt.GestureStarted:
+                zoom = (self.getZoom() + 10) / 10.0
+                pinch.setScaleFactor(zoom)
+            else:
+                zoom = int(pinch.scaleFactor() * 10) - 10
+                if zoom <= -9:
+                    zoom = -9
+                    pinch.setScaleFactor(0.1)
+                elif zoom >= 20:
+                    zoom = 20
+                    pinch.setScaleFactor(3.0)
+                self.zoomTo(zoom)
+            evt.accept()
     def editorCommand(self, cmd):
         """
         Public method to perform an editor command.

eric ide

mercurial