Loading README.md +1 −0 Original line number Diff line number Diff line Loading @@ -146,6 +146,7 @@ OCR并翻译选中文本框 * 0-9调整嵌字/原图透明度 * 文本编辑下 ```Ctrl+B``` 加粗,```Ctrl+U``` 下划线,```Ctrl+I``` 斜体 * 字体样式面板-"特效"修改透明度添加阴影 * ```Ctrl+Arrow Keys``` 或 ```Ctrl+WASD``` 在文本块间切换 <img src="doc/src/configpanel.png"> Loading README_EN.md +1 −0 Original line number Diff line number Diff line Loading @@ -181,6 +181,7 @@ OCR & Translate Selected Area * ```0-9``` to adjust opacity of text layer * For text editing: bold - ```Ctrl+B```, underline - ```Ctrl+U```, Italics - ```Ctrl+I``` * Set text shadow and transparency in the text style panel -> Effect. * ```Ctrl+Arrow Keys``` or ```Ctrl+WASD``` to switch between text blocks. <img src="doc/src/configpanel.png"> Loading ui/canvas.py +26 −13 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ try: except: from qtpy.QtGui import QUndoStack, QUndoCommand from .misc import ndarray2pixmap from .misc import ndarray2pixmap, QKEY, QNUMERIC_KEYS, ARROWKEY2DIRECTION from .config_proj import ProjImgTrans from .textitem import TextBlkItem, TextBlock from .texteditshapecontrol import TextBlkShapeControl Loading @@ -25,17 +25,6 @@ CANVAS_SCALE_MAX = 10.0 CANVAS_SCALE_MIN = 0.01 CANVAS_SCALE_SPEED = 0.1 QKEY = Qt.Key QNUMERIC_KEYS = {QKEY.Key_0:0,QKEY.Key_1:1,QKEY.Key_2:2,QKEY.Key_3:3,QKEY.Key_4:4,QKEY.Key_5:5,QKEY.Key_6:6,QKEY.Key_7:7,QKEY.Key_8:8,QKEY.Key_9:9} ARROWKEY2DIRECTION = { QKEY.Key_Left: QPointF(-1., 0.), QKEY.Key_Right: QPointF(1., 0.), QKEY.Key_Up: QPointF(0., -1.), QKEY.Key_Down: QPointF(0., 1.), } class MoveByKeyCommand(QUndoCommand): def __init__(self, blkitems: List[TextBlkItem], direction: QPointF, shape_ctrl: TextBlkShapeControl) -> None: super().__init__() Loading Loading @@ -192,6 +181,8 @@ class Canvas(QGraphicsScene): painting_shape = 0 erasing_pen = QPen() image_edit_mode = ImageEditMode.NONE # weird sometimes qt can't catch altmodifier: arow keys+alt alt_pressed = False scale_tool_mode = False Loading @@ -199,9 +190,9 @@ class Canvas(QGraphicsScene): proj_savestate_changed = Signal(bool) textstack_changed = Signal() drop_open_folder = Signal(str) context_menu_requested = Signal(QPoint, bool) incanvas_selection_changed = Signal() switch_text_item = Signal(int, QKeyEvent) def __init__(self, parent=None): super().__init__(parent) Loading Loading @@ -304,6 +295,10 @@ class Canvas(QGraphicsScene): self.textlayer_trans_slider: QSlider = None self.originallayer_trans_slider: QSlider = None def on_switch_item(self, switch_delta: int, key_event: QKeyEvent = None): if self.textEditMode() and self.editing_textblkitem is None: self.switch_text_item.emit(switch_delta, key_event) def img_window_size(self): if self.imgtrans_proj.inpainted_valid: return self.inpaintLayer.pixmap().size() Loading Loading @@ -480,8 +475,26 @@ class Canvas(QGraphicsScene): if self.hasFocus() and not self.block_selection_signal: self.incanvas_selection_changed.emit() def keyReleaseEvent(self, event: QKeyEvent) -> None: if event.key() == QKEY.Key_Alt: self.alt_pressed = False return super().keyReleaseEvent(event) def keyPressEvent(self, event: QKeyEvent) -> None: key = event.key() if key == QKEY.Key_Alt: self.alt_pressed = True modifiers = event.modifiers() if (modifiers == Qt.KeyboardModifier.AltModifier or self.alt_pressed) and not key == QKEY.Key_Alt: if key in {QKEY.Key_W, QKEY.Key_A, QKEY.Key_Left, QKEY.Key_Up}: self.on_switch_item(-1, event) return elif key in {QKEY.Key_S, QKEY.Key_D, QKEY.Key_Right, QKEY.Key_Down}: self.on_switch_item(1, event) return if self.editing_textblkitem is not None: return super().keyPressEvent(event) elif key in ARROWKEY2DIRECTION: Loading ui/misc.py +12 −1 Original line number Diff line number Diff line Loading @@ -3,10 +3,21 @@ from pathlib import Path import numpy as np import os.path as osp from qtpy.QtGui import QPixmap, QColor, QImage, QTextDocument, QTextCursor from qtpy.QtCore import Qt, QPointF from utils import shared as C from utils.structures import Tuple, Union, List, Dict, Config, field, nested_dataclass from utils.textblock import TextBlock QKEY = Qt.Key QNUMERIC_KEYS = {QKEY.Key_0:0,QKEY.Key_1:1,QKEY.Key_2:2,QKEY.Key_3:3,QKEY.Key_4:4,QKEY.Key_5:5,QKEY.Key_6:6,QKEY.Key_7:7,QKEY.Key_8:8,QKEY.Key_9:9} ARROWKEY2DIRECTION = { QKEY.Key_Left: QPointF(-1., 0.), QKEY.Key_Right: QPointF(1., 0.), QKEY.Key_Up: QPointF(0., -1.), QKEY.Key_Down: QPointF(0., 1.), } # return bgr tuple def qrgb2bgr(color: Union[QColor, Tuple, List] = None) -> Tuple[int, int, int]: Loading ui/scenetext_manager.py +29 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import copy from qtpy.QtWidgets import QApplication, QWidget from qtpy.QtCore import QObject, QRectF, Qt, Signal, QPointF, QPoint from qtpy.QtGui import QTextCursor, QFontMetrics, QFont, QTextCharFormat, QClipboard from qtpy.QtGui import QKeyEvent, QTextCursor, QFontMetrics, QFont, QTextCharFormat, QClipboard try: from qtpy.QtWidgets import QUndoCommand except: Loading Loading @@ -325,6 +325,7 @@ class SceneTextManager(QObject): self.app = app self.mainwindow = mainwindow self.canvas = canvas canvas.switch_text_item.connect(self.on_switch_textitem) self.selectext_minimenu: SelectTextMiniMenu = None self.canvas.scalefactor_changed.connect(self.adjustSceneTextRect) self.canvas.end_create_textblock.connect(self.onEndCreateTextBlock) Loading Loading @@ -357,6 +358,33 @@ class SceneTextManager(QObject): self.prev_blkitem: TextBlkItem = None def on_switch_textitem(self, switch_delta: int, key_event: QKeyEvent = None): n_blk = len(self.textblk_item_list) if n_blk < 1 or self.is_editting(): return sel_blks = self.canvas.selected_text_items(sort=False) if len(sel_blks) == 0: return sel_blk = sel_blks[0] tgt_idx = sel_blk.idx + switch_delta if tgt_idx < 0: tgt_idx += n_blk elif tgt_idx >= n_blk: tgt_idx -= n_blk blk = self.textblk_item_list[tgt_idx] self.canvas.block_selection_signal = True self.canvas.clearSelection() blk.setSelected(True) self.canvas.block_selection_signal = False self.canvas.gv.ensureVisible(blk) self.txtblkShapeControl.setBlkItem(blk) edit = self.pairwidget_list[tgt_idx].e_trans self.changeHoveringWidget(edit) self.textEditList.set_selected_list([blk.idx]) key_event.accept() def setTextEditMode(self, edit: bool = False): if edit: self.textpanel.show() Loading Loading
README.md +1 −0 Original line number Diff line number Diff line Loading @@ -146,6 +146,7 @@ OCR并翻译选中文本框 * 0-9调整嵌字/原图透明度 * 文本编辑下 ```Ctrl+B``` 加粗,```Ctrl+U``` 下划线,```Ctrl+I``` 斜体 * 字体样式面板-"特效"修改透明度添加阴影 * ```Ctrl+Arrow Keys``` 或 ```Ctrl+WASD``` 在文本块间切换 <img src="doc/src/configpanel.png"> Loading
README_EN.md +1 −0 Original line number Diff line number Diff line Loading @@ -181,6 +181,7 @@ OCR & Translate Selected Area * ```0-9``` to adjust opacity of text layer * For text editing: bold - ```Ctrl+B```, underline - ```Ctrl+U```, Italics - ```Ctrl+I``` * Set text shadow and transparency in the text style panel -> Effect. * ```Ctrl+Arrow Keys``` or ```Ctrl+WASD``` to switch between text blocks. <img src="doc/src/configpanel.png"> Loading
ui/canvas.py +26 −13 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ try: except: from qtpy.QtGui import QUndoStack, QUndoCommand from .misc import ndarray2pixmap from .misc import ndarray2pixmap, QKEY, QNUMERIC_KEYS, ARROWKEY2DIRECTION from .config_proj import ProjImgTrans from .textitem import TextBlkItem, TextBlock from .texteditshapecontrol import TextBlkShapeControl Loading @@ -25,17 +25,6 @@ CANVAS_SCALE_MAX = 10.0 CANVAS_SCALE_MIN = 0.01 CANVAS_SCALE_SPEED = 0.1 QKEY = Qt.Key QNUMERIC_KEYS = {QKEY.Key_0:0,QKEY.Key_1:1,QKEY.Key_2:2,QKEY.Key_3:3,QKEY.Key_4:4,QKEY.Key_5:5,QKEY.Key_6:6,QKEY.Key_7:7,QKEY.Key_8:8,QKEY.Key_9:9} ARROWKEY2DIRECTION = { QKEY.Key_Left: QPointF(-1., 0.), QKEY.Key_Right: QPointF(1., 0.), QKEY.Key_Up: QPointF(0., -1.), QKEY.Key_Down: QPointF(0., 1.), } class MoveByKeyCommand(QUndoCommand): def __init__(self, blkitems: List[TextBlkItem], direction: QPointF, shape_ctrl: TextBlkShapeControl) -> None: super().__init__() Loading Loading @@ -192,6 +181,8 @@ class Canvas(QGraphicsScene): painting_shape = 0 erasing_pen = QPen() image_edit_mode = ImageEditMode.NONE # weird sometimes qt can't catch altmodifier: arow keys+alt alt_pressed = False scale_tool_mode = False Loading @@ -199,9 +190,9 @@ class Canvas(QGraphicsScene): proj_savestate_changed = Signal(bool) textstack_changed = Signal() drop_open_folder = Signal(str) context_menu_requested = Signal(QPoint, bool) incanvas_selection_changed = Signal() switch_text_item = Signal(int, QKeyEvent) def __init__(self, parent=None): super().__init__(parent) Loading Loading @@ -304,6 +295,10 @@ class Canvas(QGraphicsScene): self.textlayer_trans_slider: QSlider = None self.originallayer_trans_slider: QSlider = None def on_switch_item(self, switch_delta: int, key_event: QKeyEvent = None): if self.textEditMode() and self.editing_textblkitem is None: self.switch_text_item.emit(switch_delta, key_event) def img_window_size(self): if self.imgtrans_proj.inpainted_valid: return self.inpaintLayer.pixmap().size() Loading Loading @@ -480,8 +475,26 @@ class Canvas(QGraphicsScene): if self.hasFocus() and not self.block_selection_signal: self.incanvas_selection_changed.emit() def keyReleaseEvent(self, event: QKeyEvent) -> None: if event.key() == QKEY.Key_Alt: self.alt_pressed = False return super().keyReleaseEvent(event) def keyPressEvent(self, event: QKeyEvent) -> None: key = event.key() if key == QKEY.Key_Alt: self.alt_pressed = True modifiers = event.modifiers() if (modifiers == Qt.KeyboardModifier.AltModifier or self.alt_pressed) and not key == QKEY.Key_Alt: if key in {QKEY.Key_W, QKEY.Key_A, QKEY.Key_Left, QKEY.Key_Up}: self.on_switch_item(-1, event) return elif key in {QKEY.Key_S, QKEY.Key_D, QKEY.Key_Right, QKEY.Key_Down}: self.on_switch_item(1, event) return if self.editing_textblkitem is not None: return super().keyPressEvent(event) elif key in ARROWKEY2DIRECTION: Loading
ui/misc.py +12 −1 Original line number Diff line number Diff line Loading @@ -3,10 +3,21 @@ from pathlib import Path import numpy as np import os.path as osp from qtpy.QtGui import QPixmap, QColor, QImage, QTextDocument, QTextCursor from qtpy.QtCore import Qt, QPointF from utils import shared as C from utils.structures import Tuple, Union, List, Dict, Config, field, nested_dataclass from utils.textblock import TextBlock QKEY = Qt.Key QNUMERIC_KEYS = {QKEY.Key_0:0,QKEY.Key_1:1,QKEY.Key_2:2,QKEY.Key_3:3,QKEY.Key_4:4,QKEY.Key_5:5,QKEY.Key_6:6,QKEY.Key_7:7,QKEY.Key_8:8,QKEY.Key_9:9} ARROWKEY2DIRECTION = { QKEY.Key_Left: QPointF(-1., 0.), QKEY.Key_Right: QPointF(1., 0.), QKEY.Key_Up: QPointF(0., -1.), QKEY.Key_Down: QPointF(0., 1.), } # return bgr tuple def qrgb2bgr(color: Union[QColor, Tuple, List] = None) -> Tuple[int, int, int]: Loading
ui/scenetext_manager.py +29 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ import copy from qtpy.QtWidgets import QApplication, QWidget from qtpy.QtCore import QObject, QRectF, Qt, Signal, QPointF, QPoint from qtpy.QtGui import QTextCursor, QFontMetrics, QFont, QTextCharFormat, QClipboard from qtpy.QtGui import QKeyEvent, QTextCursor, QFontMetrics, QFont, QTextCharFormat, QClipboard try: from qtpy.QtWidgets import QUndoCommand except: Loading Loading @@ -325,6 +325,7 @@ class SceneTextManager(QObject): self.app = app self.mainwindow = mainwindow self.canvas = canvas canvas.switch_text_item.connect(self.on_switch_textitem) self.selectext_minimenu: SelectTextMiniMenu = None self.canvas.scalefactor_changed.connect(self.adjustSceneTextRect) self.canvas.end_create_textblock.connect(self.onEndCreateTextBlock) Loading Loading @@ -357,6 +358,33 @@ class SceneTextManager(QObject): self.prev_blkitem: TextBlkItem = None def on_switch_textitem(self, switch_delta: int, key_event: QKeyEvent = None): n_blk = len(self.textblk_item_list) if n_blk < 1 or self.is_editting(): return sel_blks = self.canvas.selected_text_items(sort=False) if len(sel_blks) == 0: return sel_blk = sel_blks[0] tgt_idx = sel_blk.idx + switch_delta if tgt_idx < 0: tgt_idx += n_blk elif tgt_idx >= n_blk: tgt_idx -= n_blk blk = self.textblk_item_list[tgt_idx] self.canvas.block_selection_signal = True self.canvas.clearSelection() blk.setSelected(True) self.canvas.block_selection_signal = False self.canvas.gv.ensureVisible(blk) self.txtblkShapeControl.setBlkItem(blk) edit = self.pairwidget_list[tgt_idx].e_trans self.changeHoveringWidget(edit) self.textEditList.set_selected_list([blk.idx]) key_event.accept() def setTextEditMode(self, edit: bool = False): if edit: self.textpanel.show() Loading