def mouseMove(self, event: QKeyEvent): if not self.editType: return begin = self.curMemento.begin end = self.curMemento.end newPoint: QPoint = event.pos() if self.editType == 'BEGIN': # Shift pressed if event.modifiers() == Qt.ShiftModifier: # Parallel to x axis if getBiggerDiff(end, newPoint) == 'X': newPoint = QPoint(newPoint.x(), end.y()) else: # Parallel to Y axis newPoint = QPoint(end.x(), newPoint.y()) self.selected.setBegin(newPoint) elif self.editType == 'END': # Shift pressed if event.modifiers() == Qt.ShiftModifier: # Parallel to x axis if getBiggerDiff(begin, newPoint) == 'X': newPoint = QPoint(newPoint.x(), begin.y()) else: # Parallel to y axis newPoint = QPoint(begin.x(), newPoint.y()) self.selected.setEnd(newPoint) self.app.repaint()
def mouseMove(self, event: QKeyEvent): if not self.begin or not self.isDrawing: return end = event.pos() if event.modifiers() & Qt.ShiftModifier: # if shift then draw square with bigger size if getBiggerDiff(event.pos(), self.begin) == 'X': end = QPoint(end.x(), end.x() - self.begin.x() + self.begin.y()) else: end = QPoint(end.y() - self.begin.y() + self.begin.x(), end.y()) if event.modifiers() & Qt.AltModifier: # calculate new end point newEndX = end.x() + (end.x() - self.begin.x()) newEndY = end.y() + (end.y() - self.begin.y()) end = QPoint(newEndX, newEndY) self.end = end self.app.repaint()
def mouseMove(self, event: QKeyEvent): if not self.begin or not self.isDrawing: return if event.modifiers() == Qt.ShiftModifier: if getBiggerDiff(event.pos(), self.begin) == 'X': self.end = QPoint(event.pos().x(), self.begin.y()) else: self.end = QPoint(self.begin.x(), event.pos().y()) else: self.end = event.pos() self.app.repaint()
def key_press(self, event: QKeyEvent): if event.key() == Qt.Key_L and event.modifiers() & Qt.ControlModifier: if not self._spell.enabled(): return [] f_param = KeySwitcherParams(self._textedit, self._current_lang, self._enabled) if f_param.exec_(): self._enabled = f_param.params["enabled"] self._current_lang = "ENG" if f_param.params["eng"] else "RUS" return [] if event.key() == Qt.Key_F12: self._replace_selection() return [] if not self._enabled: return [event] if event.key() == Qt.Key_Backspace: if self._current_word.strip(): self._current_word = self._current_word.strip()[:-1] return [event] char = event.text().strip() if not char: shift = event.modifiers() & Qt.ShiftModifier ctrl = event.modifiers() & Qt.ControlModifier if not (shift or ctrl): self._current_word = "" return [event] # --------------------------------------------------------------------- # check the current word, if there was any movement, e.g. mouse old_cur = self._textedit.textCursor() cursor = self._textedit.textCursor() cursor.select(QTextCursor.WordUnderCursor) word = cursor.selectedText() self._textedit.setTextCursor(old_cur) if self._current_word.strip() != word.strip(): self._current_word = "" return [event] # --------------------------------------------------------------------- # detect char language char_lang = "UNKNOWN" if char.lower() in KeySwitcher.RUSSIAN: char_lang = "RUS" if char.lower() in KeySwitcher.ENGLISH: char_lang = "ENG" # add char to current word if self._current_lang != char_lang: # and char_lang != "UNKNOWN": char = KeySwitcher.switch_charset(char, self._current_lang) event = QKeyEvent(QEvent.KeyPress, event.key(), event.modifiers(), char) self._current_word += char # early to check language if len(self._current_word) < 2: return [event] # detect language rus_chars = 0 eng_chars = 0 for char in set(self._current_word.lower()): if char in KeySwitcher.RUSSIAN: rus_chars += 1 if char in KeySwitcher.ENGLISH: eng_chars += 1 if rus_chars and eng_chars: return [event] if not self._ok_locale( self._current_word, KeySwitcher.switch_charset(self._current_word, "ENG" if rus_chars else "RUS")): return [event] + self._replace_current_word() return [event]