コード例 #1
0
ファイル: tagslineedit.py プロジェクト: xoriole/tribler
    def keyPressEvent(self, event: QKeyEvent) -> None:
        event.setAccepted(False)
        unknown = False

        if event == QKeySequence.SelectAll:
            self.selectAll()
            event.accept()
        elif event == QKeySequence.SelectPreviousChar:
            self.move_cursor(
                self.text_layout.previousCursorPosition(self.cursor_ind), True)
            event.accept()
        elif event == QKeySequence.SelectNextChar:
            self.move_cursor(
                self.text_layout.nextCursorPosition(self.cursor_ind), True)
            event.accept()
        else:
            if event.key() == Qt.Key_Left:
                if self.cursor_ind == 0:
                    self.edit_previous_tag()
                else:
                    self.move_cursor(
                        self.text_layout.previousCursorPosition(
                            self.cursor_ind), False)

                event.accept()
            elif event.key() == Qt.Key_Right:
                if self.cursor_ind == len(self.tags[self.editing_index].text):
                    self.edit_next_tag()
                else:
                    self.move_cursor(
                        self.text_layout.nextCursorPosition(self.cursor_ind),
                        False)

                event.accept()
            elif event.key() == Qt.Key_Home:
                if self.cursor_ind == 0 and self.editing_index > 0:
                    self.edit_tag(0)
                else:
                    self.move_cursor(0, False)

                event.accept()
            elif event.key() == Qt.Key_End:
                if (self.cursor_ind == len(self.tags[self.editing_index].text)
                        and self.editing_index < len(self.tags) - 1):
                    self.edit_tag(len(self.tags) - 1)
                else:
                    self.move_cursor(len(self.tags[self.editing_index].text),
                                     False)

                event.accept()
            elif event.key() == Qt.Key_Backspace:
                if self.tags[self.editing_index].text:
                    self.remove_backwards_character()
                elif self.editing_index > 0:
                    self.edit_previous_tag()

                event.accept()
            elif event.key() == Qt.Key_Space:
                if self.tags[self.editing_index].text:
                    self.tags.insert(self.editing_index + 1, Tag("", QRectF()))
                    self.edit_next_tag()

                event.accept()
            elif event.key() == Qt.Key_Escape:
                self.escape_pressed.emit()
                event.accept()

            elif event.key() == Qt.Key_Return:
                self.enter_pressed.emit()
                event.accept()
            else:
                unknown = True

        if unknown:
            if self.has_selection_active():
                self.remove_selection()
            txt = self.tags[self.editing_index].text
            txt = txt[:self.cursor_ind] + event.text().lower(
            ) + txt[self.cursor_ind:]
            self.tags[self.editing_index].text = txt
            self.cursor_ind += len(event.text())
            event.accept()

        if event.isAccepted():
            self.update_display_text()
            self.compute_tag_rects()
            self.update_cursor_blinking()

            self.update()
コード例 #2
0
 def _keyReleaseEvent(self, evt: QtGui.QKeyEvent) -> None:
     measure_editor = self._measureEditorUnderMouse()
     if isinstance(measure_editor, MeasureEditor):
         measure_evt = self.__makeKeyEvent(measure_editor, evt)
         self.keyReleaseMeasureEvent(measure_editor, measure_evt)
         evt.setAccepted(measure_evt.isAccepted())