Loading ballontranslator/ui/canvas.py +8 −1 Original line number Diff line number Diff line Loading @@ -151,6 +151,7 @@ class Canvas(QGraphicsScene): self.addItem(self.txtblkShapeControl) self.scalefactor_changed.connect(self.onScaleFactorChanged) self.selectionChanged.connect(self.on_selection_changed) self.stroke_path_item: StrokeItem = None def scaleUp(self): Loading Loading @@ -226,6 +227,12 @@ class Canvas(QGraphicsScene): self.scaleFactorLabel.raise_() self.scaleFactorLabel.startFadeAnimation() def on_selection_changed(self): if self.txtblkShapeControl.isVisible(): blk_item = self.txtblkShapeControl.blk_item if blk_item is not None and blk_item.isEditing(): blk_item.endEdit() def keyPressEvent(self, event: QKeyEvent) -> None: if self.editing_textblkitem is not None: return super().keyPressEvent(event) Loading ballontranslator/ui/fontformatpanel.py +1 −13 Original line number Diff line number Diff line Loading @@ -408,14 +408,6 @@ class FontFormatPanel(Widget): def restoreTextBlkItem(self): if self.active_format == self.global_format: self.global_format_changed.emit() else: blkitem = self.textblk_item self.restoring_textblk = True if blkitem: blkitem.startEdit() blkitem.setTextCursor(self.text_cursor) blkitem.scene().gv.setFocus(Qt.FocusReason.NoFocusReason) self.restoring_textblk = False def changingColor(self): self.focusOnColorDialog = True Loading Loading @@ -530,17 +522,13 @@ class FontFormatPanel(Widget): elif focus_p: if focus_p == self or focus_p.parentWidget() == self: focus_on_fmtoptions = True if focus_on_fmtoptions: self.text_cursor = QTextCursor(self.textblk_item.textCursor()) else: if not focus_on_fmtoptions: self.textblk_item = None self.text_cursor = None self.set_active_format(self.global_format) self.fontfmtLabel.setText(self.global_fontfmt_str) else: if not self.restoring_textblk: blk_fmt = textblk_item.get_fontformat() self.textblk_item = textblk_item self.text_cursor = QTextCursor(self.textblk_item.textCursor()) self.set_active_format(blk_fmt) self.fontfmtLabel.setText(f'TextBlock #{textblk_item.idx}') No newline at end of file ballontranslator/ui/texteditshapecontrol.py +4 −1 Original line number Diff line number Diff line Loading @@ -220,7 +220,8 @@ class TextBlkShapeControl(QGraphicsRectItem): return if self.blk_item is not None: self.blk_item.under_ctrl = False self.blk_item.setFocus(Qt.FocusReason.NoFocusReason) if self.blk_item.isEditing(): self.blk_item.endEdit() self.blk_item.update() self.blk_item = blk_item Loading Loading @@ -271,6 +272,8 @@ class TextBlkShapeControl(QGraphicsRectItem): def ctrlblockPressed(self): self.scene().clearSelection() if self.blk_item is not None: self.blk_item.endEdit() def paint(self, painter: QPainter, option: 'QStyleOptionGraphicsItem', widget = ...) -> None: painter.setCompositionMode(QPainter.RasterOp_NotDestination) Loading ballontranslator/ui/textitem.py +13 −12 Original line number Diff line number Diff line Loading @@ -264,16 +264,6 @@ class TextBlkItem(QGraphicsTextItem): pos.setY(pos.y() + delta_x * np.sin(rad)) self.setPos(pos) def focusOutEvent(self, event: QFocusEvent) -> None: self.end_edit.emit(self.idx) cursor = self.textCursor() cursor.clearSelection() self.setTextCursor(cursor) self.setTextInteractionFlags(Qt.NoTextInteraction) super().focusOutEvent(event) self.setCacheMode(QGraphicsItem.CacheMode.DeviceCoordinateCache) def documentLayout(self) -> VerticalTextDocumentLayout: return self.document().documentLayout() Loading Loading @@ -357,13 +347,24 @@ class TextBlkItem(QGraphicsTextItem): option.state = QStyle.State_None super().paint(painter, option, widget) def startEdit(self): def startEdit(self) -> None: self.setCacheMode(QGraphicsItem.CacheMode.NoCache) self.setTextInteractionFlags(Qt.TextEditorInteraction) self.setFocus() self.begin_edit.emit(self.idx) def endEdit(self) -> None: self.end_edit.emit(self.idx) cursor = self.textCursor() cursor.clearSelection() self.setTextCursor(cursor) self.setTextInteractionFlags(Qt.NoTextInteraction) self.setCacheMode(QGraphicsItem.CacheMode.DeviceCoordinateCache) self.setFocus() def isEditing(self) -> bool: return self.textInteractionFlags() == Qt.TextEditorInteraction def mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent) -> None: self.startEdit() super().mouseDoubleClickEvent(event) Loading Loading
ballontranslator/ui/canvas.py +8 −1 Original line number Diff line number Diff line Loading @@ -151,6 +151,7 @@ class Canvas(QGraphicsScene): self.addItem(self.txtblkShapeControl) self.scalefactor_changed.connect(self.onScaleFactorChanged) self.selectionChanged.connect(self.on_selection_changed) self.stroke_path_item: StrokeItem = None def scaleUp(self): Loading Loading @@ -226,6 +227,12 @@ class Canvas(QGraphicsScene): self.scaleFactorLabel.raise_() self.scaleFactorLabel.startFadeAnimation() def on_selection_changed(self): if self.txtblkShapeControl.isVisible(): blk_item = self.txtblkShapeControl.blk_item if blk_item is not None and blk_item.isEditing(): blk_item.endEdit() def keyPressEvent(self, event: QKeyEvent) -> None: if self.editing_textblkitem is not None: return super().keyPressEvent(event) Loading
ballontranslator/ui/fontformatpanel.py +1 −13 Original line number Diff line number Diff line Loading @@ -408,14 +408,6 @@ class FontFormatPanel(Widget): def restoreTextBlkItem(self): if self.active_format == self.global_format: self.global_format_changed.emit() else: blkitem = self.textblk_item self.restoring_textblk = True if blkitem: blkitem.startEdit() blkitem.setTextCursor(self.text_cursor) blkitem.scene().gv.setFocus(Qt.FocusReason.NoFocusReason) self.restoring_textblk = False def changingColor(self): self.focusOnColorDialog = True Loading Loading @@ -530,17 +522,13 @@ class FontFormatPanel(Widget): elif focus_p: if focus_p == self or focus_p.parentWidget() == self: focus_on_fmtoptions = True if focus_on_fmtoptions: self.text_cursor = QTextCursor(self.textblk_item.textCursor()) else: if not focus_on_fmtoptions: self.textblk_item = None self.text_cursor = None self.set_active_format(self.global_format) self.fontfmtLabel.setText(self.global_fontfmt_str) else: if not self.restoring_textblk: blk_fmt = textblk_item.get_fontformat() self.textblk_item = textblk_item self.text_cursor = QTextCursor(self.textblk_item.textCursor()) self.set_active_format(blk_fmt) self.fontfmtLabel.setText(f'TextBlock #{textblk_item.idx}') No newline at end of file
ballontranslator/ui/texteditshapecontrol.py +4 −1 Original line number Diff line number Diff line Loading @@ -220,7 +220,8 @@ class TextBlkShapeControl(QGraphicsRectItem): return if self.blk_item is not None: self.blk_item.under_ctrl = False self.blk_item.setFocus(Qt.FocusReason.NoFocusReason) if self.blk_item.isEditing(): self.blk_item.endEdit() self.blk_item.update() self.blk_item = blk_item Loading Loading @@ -271,6 +272,8 @@ class TextBlkShapeControl(QGraphicsRectItem): def ctrlblockPressed(self): self.scene().clearSelection() if self.blk_item is not None: self.blk_item.endEdit() def paint(self, painter: QPainter, option: 'QStyleOptionGraphicsItem', widget = ...) -> None: painter.setCompositionMode(QPainter.RasterOp_NotDestination) Loading
ballontranslator/ui/textitem.py +13 −12 Original line number Diff line number Diff line Loading @@ -264,16 +264,6 @@ class TextBlkItem(QGraphicsTextItem): pos.setY(pos.y() + delta_x * np.sin(rad)) self.setPos(pos) def focusOutEvent(self, event: QFocusEvent) -> None: self.end_edit.emit(self.idx) cursor = self.textCursor() cursor.clearSelection() self.setTextCursor(cursor) self.setTextInteractionFlags(Qt.NoTextInteraction) super().focusOutEvent(event) self.setCacheMode(QGraphicsItem.CacheMode.DeviceCoordinateCache) def documentLayout(self) -> VerticalTextDocumentLayout: return self.document().documentLayout() Loading Loading @@ -357,13 +347,24 @@ class TextBlkItem(QGraphicsTextItem): option.state = QStyle.State_None super().paint(painter, option, widget) def startEdit(self): def startEdit(self) -> None: self.setCacheMode(QGraphicsItem.CacheMode.NoCache) self.setTextInteractionFlags(Qt.TextEditorInteraction) self.setFocus() self.begin_edit.emit(self.idx) def endEdit(self) -> None: self.end_edit.emit(self.idx) cursor = self.textCursor() cursor.clearSelection() self.setTextCursor(cursor) self.setTextInteractionFlags(Qt.NoTextInteraction) self.setCacheMode(QGraphicsItem.CacheMode.DeviceCoordinateCache) self.setFocus() def isEditing(self) -> bool: return self.textInteractionFlags() == Qt.TextEditorInteraction def mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent) -> None: self.startEdit() super().mouseDoubleClickEvent(event) Loading