def wheelEvent(self, event: QWheelEvent) -> None: # pylint: disable=invalid-name """With Ctrl depressed, zoom the current image, otherwise fire the next/previous functions.""" modifiers = QApplication.keyboardModifiers() if event.angleDelta().y() == 120 and modifiers == Qt.ControlModifier: self.view.scale(0.75, 0.75) elif event.angleDelta().y() == 120: self.previous() elif event.angleDelta().y( ) == -120 and modifiers == Qt.ControlModifier: self.view.scale(1.25, 1.25) elif event.angleDelta().y() == -120: self.next()
def GetSelectionMode(): if QApplication.keyboardModifiers() == Qt.ShiftModifier: return SelectionMode.MODIFY return SelectionMode.NORMAL
def keyPressEvent(self, key_event): key = key_event.key() if key == Qt.Key_Enter or key == Qt.Key_Return: super(TextEdit, self).keyPressEvent(key_event) update_cursor = QTextCursor(self.textCursor()) # Auto - indent if self._auto_indent: block = QTextBlock(update_cursor.block().previous()) data = block.text() pos = block.length() if pos >= len(data): pos = len(data) - 1 idx = -1 for i in range(pos, 0, -1): if data[i] == '\n': idx = i break while (idx + 1) < len(data) \ and data[idx + 1].isspace() \ and data[idx + 1] != '\n' \ and data[idx + 1] != '\r': update_cursor.insertText(data[idx + 1]) idx += 1 elif key == Qt.Key_Tab or key == Qt.Key_Backtab: modifiers = QApplication.keyboardModifiers() indent_line = "" if self._indent_with_space: indent_line = ' ' * self._indent_size else: indent_line = '\t' current_text_cursor = QTextCursor(self.textCursor()) selection_start = current_text_cursor.selectionStart() selection_end = current_text_cursor.selectionEnd() if selection_start == selection_end: if not (modifiers & Qt.ShiftModifier): current_text_cursor.insertText(indent_line) else: current_text_cursor.setPosition(current_text_cursor.block().position()) text = current_text_cursor.block().text() for i in range(0, min(len(indent_line), len(text))): if not text[i].isspace(): break current_text_cursor.deleteChar() else: text_block = QTextBlock(self.document().findBlock(selection_start)) while text_block.isValid() and text_block.position() <= selection_end: current_text_cursor.setPosition(text_block.position()) if not (modifiers & Qt.ShiftModifier): current_text_cursor.insertText(indent_line) selection_end += len(indent_line) else: qDebug("<<<") text = current_text_cursor.block().text() for i in range(0, min(len(indent_line), len(text))): if not text[i].isspace(): break current_text_cursor.deleteChar() selection_end -= 1 text_block = text_block.next() else: super(TextEdit, self).keyPressEvent(key_event)