6933 |
6933 |
6934 def keyPressEvent(self, ev): |
6934 def keyPressEvent(self, ev): |
6935 """ |
6935 """ |
6936 Protected method to handle the user input a key at a time. |
6936 Protected method to handle the user input a key at a time. |
6937 |
6937 |
6938 @param ev key event (QKeyEvent) |
6938 @param ev key event |
|
6939 @type QKeyEvent |
6939 """ |
6940 """ |
6940 txt = ev.text() |
6941 txt = ev.text() |
6941 |
6942 |
6942 # See it is text to insert. |
6943 # See it is text to insert. |
6943 if len(txt) and txt >= " ": |
6944 if len(txt) and txt >= " ": |
|
6945 if txt in ('"', "'") and self.hasSelectedText(): |
|
6946 sline, sindex, eline, eindex = self.getSelection() |
|
6947 replaceText = txt + self.selectedText() + txt |
|
6948 self.beginUndoAction() |
|
6949 self.replaceSelectedText(replaceText) |
|
6950 self.endUndoAction() |
|
6951 self.setSelection(sline, sindex + 1, eline, eindex + 1) |
|
6952 ev.accept() |
|
6953 return |
|
6954 |
6944 super(Editor, self).keyPressEvent(ev) |
6955 super(Editor, self).keyPressEvent(ev) |
6945 else: |
6956 else: |
6946 ev.ignore() |
6957 ev.ignore() |
6947 |
6958 |
6948 def focusInEvent(self, event): |
6959 def focusInEvent(self, event): |
6952 This method checks for modifications of the current file and |
6963 This method checks for modifications of the current file and |
6953 rereads it upon request. The cursor is placed at the current position |
6964 rereads it upon request. The cursor is placed at the current position |
6954 assuming, that it is in the vicinity of the old position after the |
6965 assuming, that it is in the vicinity of the old position after the |
6955 reread. |
6966 reread. |
6956 |
6967 |
6957 @param event the event object (QFocusEvent) |
6968 @param event the event object |
|
6969 @type QFocusEvent |
6958 """ |
6970 """ |
6959 self.recolor() |
6971 self.recolor() |
6960 self.vm.editActGrp.setEnabled(True) |
6972 self.vm.editActGrp.setEnabled(True) |
6961 self.vm.editorActGrp.setEnabled(True) |
6973 self.vm.editorActGrp.setEnabled(True) |
6962 self.vm.copyActGrp.setEnabled(True) |
6974 self.vm.copyActGrp.setEnabled(True) |
7005 |
7017 |
7006 def focusOutEvent(self, event): |
7018 def focusOutEvent(self, event): |
7007 """ |
7019 """ |
7008 Protected method called when the editor loses focus. |
7020 Protected method called when the editor loses focus. |
7009 |
7021 |
7010 @param event the event object (QFocusEvent) |
7022 @param event the event object |
|
7023 @type QFocusEvent |
7011 """ |
7024 """ |
7012 self.vm.editorActGrp.setEnabled(False) |
7025 self.vm.editorActGrp.setEnabled(False) |
7013 self.setCaretWidth(0) |
7026 self.setCaretWidth(0) |
7014 |
7027 |
7015 super(Editor, self).focusOutEvent(event) |
7028 super(Editor, self).focusOutEvent(event) |
7022 showMinimized and showNormal. The windows caption is shortened |
7035 showMinimized and showNormal. The windows caption is shortened |
7023 for the minimized mode and reset to the full filename for the |
7036 for the minimized mode and reset to the full filename for the |
7024 other modes. This is to make the editor windows work nicer |
7037 other modes. This is to make the editor windows work nicer |
7025 with the QWorkspace. |
7038 with the QWorkspace. |
7026 |
7039 |
7027 @param evt the event, that was generated (QEvent) |
7040 @param evt the event, that was generated |
|
7041 @type QEvent |
7028 """ |
7042 """ |
7029 if ( |
7043 if ( |
7030 evt.type() == QEvent.WindowStateChange and |
7044 evt.type() == QEvent.WindowStateChange and |
7031 bool(self.fileName) |
7045 bool(self.fileName) |
7032 ): |
7046 ): |
7042 |
7056 |
7043 def mousePressEvent(self, event): |
7057 def mousePressEvent(self, event): |
7044 """ |
7058 """ |
7045 Protected method to handle the mouse press event. |
7059 Protected method to handle the mouse press event. |
7046 |
7060 |
7047 @param event the mouse press event (QMouseEvent) |
7061 @param event the mouse press event |
|
7062 @type QMouseEvent |
7048 """ |
7063 """ |
7049 self.vm.eventFilter(self, event) |
7064 self.vm.eventFilter(self, event) |
7050 super(Editor, self).mousePressEvent(event) |
7065 super(Editor, self).mousePressEvent(event) |
7051 |
7066 |
7052 def wheelEvent(self, evt): |
7067 def wheelEvent(self, evt): |
7053 """ |
7068 """ |
7054 Protected method to handle wheel events. |
7069 Protected method to handle wheel events. |
7055 |
7070 |
7056 @param evt reference to the wheel event (QWheelEvent) |
7071 @param evt reference to the wheel event |
|
7072 @type QWheelEvent |
7057 """ |
7073 """ |
7058 delta = evt.angleDelta().y() |
7074 delta = evt.angleDelta().y() |
7059 if evt.modifiers() & Qt.ControlModifier: |
7075 if evt.modifiers() & Qt.ControlModifier: |
7060 if delta < 0: |
7076 if delta < 0: |
7061 self.zoomOut() |
7077 self.zoomOut() |
7076 |
7092 |
7077 def event(self, evt): |
7093 def event(self, evt): |
7078 """ |
7094 """ |
7079 Public method handling events. |
7095 Public method handling events. |
7080 |
7096 |
7081 @param evt reference to the event (QEvent) |
7097 @param evt reference to the event |
7082 @return flag indicating, if the event was handled (boolean) |
7098 @type QEvent |
|
7099 @return flag indicating, if the event was handled |
|
7100 @rtype bool |
7083 """ |
7101 """ |
7084 if evt.type() == QEvent.Gesture: |
7102 if evt.type() == QEvent.Gesture: |
7085 self.gestureEvent(evt) |
7103 self.gestureEvent(evt) |
7086 return True |
7104 return True |
7087 |
7105 |
7089 |
7107 |
7090 def gestureEvent(self, evt): |
7108 def gestureEvent(self, evt): |
7091 """ |
7109 """ |
7092 Protected method handling gesture events. |
7110 Protected method handling gesture events. |
7093 |
7111 |
7094 @param evt reference to the gesture event (QGestureEvent |
7112 @param evt reference to the gesture event |
|
7113 @type QGestureEvent |
7095 """ |
7114 """ |
7096 pinch = evt.gesture(Qt.PinchGesture) |
7115 pinch = evt.gesture(Qt.PinchGesture) |
7097 if pinch: |
7116 if pinch: |
7098 if pinch.state() == Qt.GestureStarted: |
7117 if pinch.state() == Qt.GestureStarted: |
7099 zoom = (self.getZoom() + 10) / 10.0 |
7118 zoom = (self.getZoom() + 10) / 10.0 |
7111 |
7130 |
7112 def resizeEvent(self, evt): |
7131 def resizeEvent(self, evt): |
7113 """ |
7132 """ |
7114 Protected method handling resize events. |
7133 Protected method handling resize events. |
7115 |
7134 |
7116 @param evt reference to the resize event (QResizeEvent) |
7135 @param evt reference to the resize event |
|
7136 @type QResizeEvent |
7117 """ |
7137 """ |
7118 super(Editor, self).resizeEvent(evt) |
7138 super(Editor, self).resizeEvent(evt) |
7119 self.__markerMap.calculateGeometry() |
7139 self.__markerMap.calculateGeometry() |
7120 |
7140 |
7121 def viewportEvent(self, evt): |
7141 def viewportEvent(self, evt): |
7122 """ |
7142 """ |
7123 Protected method handling event of the viewport. |
7143 Protected method handling event of the viewport. |
7124 |
7144 |
7125 @param evt reference to the event (QEvent) |
7145 @param evt reference to the event |
7126 @return flag indiating that the event was handled (boolean) |
7146 @type QEvent |
|
7147 @return flag indiating that the event was handled |
|
7148 @rtype bool |
7127 """ |
7149 """ |
7128 try: |
7150 try: |
7129 self.__markerMap.calculateGeometry() |
7151 self.__markerMap.calculateGeometry() |
7130 except AttributeError: |
7152 except AttributeError: |
7131 # ignore this - there seems to be a runtime issue when the editor |
7153 # ignore this - there seems to be a runtime issue when the editor |