Loading ui/fontformat_commands.py +7 −2 Original line number Diff line number Diff line Loading @@ -138,9 +138,14 @@ def ffmt_change_stroke_width(param_name: str, values: float, act_ffmt: FontForma def ffmt_change_font_size(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], clip_size=False, **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs for blkitem, value in zip(blkitems, values): if value < 0: if value < 0 and param_name == "font_size": continue blkitem.setFontSize(px2pt(value), clip_size=clip_size, **set_kwargs) if param_name == "font_size": setFontSize = blkitem.setFontSize value = px2pt(value) else: setFontSize = blkitem.setRelFontSize setFontSize(value, clip_size=clip_size, **set_kwargs) @font_formating(push_undostack=True) def ffmt_change_alignment(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): Loading ui/scenetext_manager.py +9 −1 Original line number Diff line number Diff line Loading @@ -591,7 +591,7 @@ class SceneTextManager(QObject): def onTextBlkItemEndEdit(self, blk_id: int): self.canvas.editing_textblkitem = None self.formatpanel.set_textblk_item(None) self.textblk_item_list[blk_id].setSelected(True) self.txtblkShapeControl.endEditing() def editingTextItem(self) -> TextBlkItem: Loading Loading @@ -685,6 +685,10 @@ class SceneTextManager(QObject): if len(blkitem_list) > 0: self.canvas.clearSelection() self.canvas.push_undo_command(PasteBlkItemsCommand(blkitem_list, pair_widget_list, self)) if len(blkitem_list) == 1: self.formatpanel.set_textblk_item(blkitem_list[0]) else: self.formatpanel.set_textblk_item(multi_select=True) def onFormatTextblks(self, fmt: FontFormat = None): if fmt is None: Loading Loading @@ -718,6 +722,10 @@ class SceneTextManager(QObject): if self.canvas.textEditMode(): textitems = self.canvas.selected_text_items() self.textEditList.set_selected_list([t.idx for t in textitems]) if len(textitems) == 1: self.formatpanel.set_textblk_item(textitems[-1]) else: self.formatpanel.set_textblk_item(multi_select=bool(textitems)) def layout_textblk(self, blkitem: TextBlkItem, text: str = None, mask: np.ndarray = None, bounding_rect: List = None, region_rect: List = None): Loading ui/text_panel.py +58 −21 Original line number Diff line number Diff line Loading @@ -149,7 +149,7 @@ class FontSizeBox(QFrame): self.fcombobox.addItems([ "5", "5.5", "6.5", "7.5", "8", "9", "10", "10.5", "11", "12", "14", "16", "18", "20", '22', "26", "28", "36", "48", "56", "72" "36", "48", "56", "72", "93", "123", "163" ]) self.fcombobox.param_changed.connect(self.param_changed) Loading @@ -164,28 +164,48 @@ class FontSizeBox(QFrame): hlayout.setSpacing(3) hlayout.setContentsMargins(0, 0, 0, 0) def getFontSize(self) -> float: return self.fcombobox.value() def getFontSize(self) -> str: return self.fcombobox.currentText() def onUpBtnClicked(self): raito = 1.25 size = self.getFontSize() newsize = int(round(size * 1.25)) multi_size=False if "+" in size: size = size.strip("+") multi_size=True size = float(size) newsize = int(round(size * raito)) if newsize == size: newsize += 1 newsize = min(1000, newsize) if newsize != size: if not multi_size: self.param_changed.emit('font_size', newsize) self.fcombobox.setCurrentText(str(newsize)) else: self.param_changed.emit('rel_font_size', raito) self.fcombobox.setCurrentText(str(newsize)+"+") def onDownBtnClicked(self): raito = 0.75 size = self.getFontSize() newsize = int(round(size * 0.75)) multi_size=False if "+" in size: size = size.strip("+") multi_size=True size = float(size) newsize = int(round(size * raito)) if newsize == size: newsize -= 1 newsize = max(1, newsize) if newsize != size: if not multi_size: self.param_changed.emit('font_size', newsize) self.fcombobox.setCurrentText(str(newsize)) else: self.param_changed.emit('rel_font_size', raito) self.fcombobox.setCurrentText(str(newsize)+"+") class SizeControlLabel(QLabel): Loading Loading @@ -459,7 +479,7 @@ class FontFormatPanel(Widget): return self.textstyle_panel.active_text_style_label def on_param_changed(self, param_name: str, value): func = FM.handle_ffmt_change.get(param_name) func = FM.handle_ffmt_change.get(param_name if not param_name == "rel_font_size" else "font_size") func_kwargs = {} if param_name == 'font_size': func_kwargs['clip_size'] = True Loading Loading @@ -507,7 +527,7 @@ class FontFormatPanel(Widget): mul = 0.01 self.lineSpacingBox.setValue(self.lineSpacingBox.value() + delta * mul) def set_active_format(self, font_format: FontFormat): def set_active_format(self, font_format: FontFormat, multi_size=False): C.active_format = font_format self.familybox.blockSignals(True) font_size = round(font_format.font_size, 1) Loading @@ -515,6 +535,8 @@ class FontFormatPanel(Widget): font_size = str(int(font_size)) else: font_size = f'{font_size:.1f}' if multi_size: font_size += "+" self.fontsizebox.fcombobox.setCurrentText(font_size) self.familybox.setCurrentText(font_format.font_family) self.colorPicker.setPickerColor(font_format.foreground_color()) Loading Loading @@ -555,7 +577,7 @@ class FontFormatPanel(Widget): if self.global_mode(): self.set_globalfmt_title() def set_textblk_item(self, textblk_item: TextBlkItem = None): def set_textblk_item(self, textblk_item: TextBlkItem = None, multi_select:bool=False): if textblk_item is None: focus_w = self.app.focusWidget() focus_p = None if focus_w is None else focus_w.parentWidget() Loading @@ -567,13 +589,28 @@ class FontFormatPanel(Widget): focus_on_fmtoptions = True if not focus_on_fmtoptions: self.textblk_item = None self.set_active_format(self.global_format) self.set_active_format(self.global_format, multi_select) if multi_select: self.textstyle_panel.setTitle('Grop') else: self.set_globalfmt_title() else: if not self.restoring_textblk: blk_fmt = textblk_item.get_fontformat() self.textblk_item = textblk_item self.set_active_format(blk_fmt) multi_size = False if not textblk_item.isEditing(): cursor = textblk_item.textCursor() cursor.setPosition(0) firstFontSize = cursor.charFormat().fontPointSize() for i in range(0,len(textblk_item.toPlainText())+1): cursor.setPosition(i) font_size = cursor.charFormat().fontPointSize() if not firstFontSize == font_size: multi_size = True break self.set_active_format(blk_fmt,multi_size) self.textstyle_panel.setTitle(f'TextBlock #{textblk_item.idx}') def on_effectbtn_clicked(self): Loading ui/texteditshapecontrol.py +2 −1 Original line number Diff line number Diff line Loading @@ -67,8 +67,9 @@ class ControlBlockItem(QGraphicsRectItem): def mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None: self.ctrl.ctrlblockPressed() blk_item = self.ctrl.blk_item if event.button() == Qt.MouseButton.LeftButton: blk_item = self.ctrl.blk_item blk_item.setSelected(True) if self.visible_rect.contains(event.pos()): self.ctrl.reshaping = True self.drag_mode = self.DRAG_RESHAPE Loading ui/textitem.py +16 −0 Original line number Diff line number Diff line Loading @@ -801,6 +801,22 @@ class TextBlkItem(QGraphicsTextItem): if repaint_background: self.update() def setRelFontSize(self, value: float, repaint_background: bool = False, set_selected: bool = False, restore_cursor: bool = False, clip_size: bool = False, **kwargs): cursor = self.textCursor() old_sizes = [] for i in range(len(self.toPlainText())): cursor.setPosition(i) cursor.setPosition(i+1, QTextCursor.MoveMode.KeepAnchor) old_sizes.append(cursor.charFormat().fontPointSize()) for i in range(len(self.toPlainText())): cursor.setPosition(i) cursor.setPosition(i+1, QTextCursor.MoveMode.KeepAnchor) self.setTextCursor(cursor) newvalue = round(old_sizes[i] * value,2) self.setFontSize(newvalue, repaint_background, True, restore_cursor, clip_size, **kwargs) cursor.clearSelection() self.squeezeBoundingRect() def setFontSize(self, value: float, repaint_background: bool = False, set_selected: bool = False, restore_cursor: bool = False, clip_size: bool = False, **kwargs): ''' value should be point size Loading Loading
ui/fontformat_commands.py +7 −2 Original line number Diff line number Diff line Loading @@ -138,9 +138,14 @@ def ffmt_change_stroke_width(param_name: str, values: float, act_ffmt: FontForma def ffmt_change_font_size(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], clip_size=False, **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs for blkitem, value in zip(blkitems, values): if value < 0: if value < 0 and param_name == "font_size": continue blkitem.setFontSize(px2pt(value), clip_size=clip_size, **set_kwargs) if param_name == "font_size": setFontSize = blkitem.setFontSize value = px2pt(value) else: setFontSize = blkitem.setRelFontSize setFontSize(value, clip_size=clip_size, **set_kwargs) @font_formating(push_undostack=True) def ffmt_change_alignment(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): Loading
ui/scenetext_manager.py +9 −1 Original line number Diff line number Diff line Loading @@ -591,7 +591,7 @@ class SceneTextManager(QObject): def onTextBlkItemEndEdit(self, blk_id: int): self.canvas.editing_textblkitem = None self.formatpanel.set_textblk_item(None) self.textblk_item_list[blk_id].setSelected(True) self.txtblkShapeControl.endEditing() def editingTextItem(self) -> TextBlkItem: Loading Loading @@ -685,6 +685,10 @@ class SceneTextManager(QObject): if len(blkitem_list) > 0: self.canvas.clearSelection() self.canvas.push_undo_command(PasteBlkItemsCommand(blkitem_list, pair_widget_list, self)) if len(blkitem_list) == 1: self.formatpanel.set_textblk_item(blkitem_list[0]) else: self.formatpanel.set_textblk_item(multi_select=True) def onFormatTextblks(self, fmt: FontFormat = None): if fmt is None: Loading Loading @@ -718,6 +722,10 @@ class SceneTextManager(QObject): if self.canvas.textEditMode(): textitems = self.canvas.selected_text_items() self.textEditList.set_selected_list([t.idx for t in textitems]) if len(textitems) == 1: self.formatpanel.set_textblk_item(textitems[-1]) else: self.formatpanel.set_textblk_item(multi_select=bool(textitems)) def layout_textblk(self, blkitem: TextBlkItem, text: str = None, mask: np.ndarray = None, bounding_rect: List = None, region_rect: List = None): Loading
ui/text_panel.py +58 −21 Original line number Diff line number Diff line Loading @@ -149,7 +149,7 @@ class FontSizeBox(QFrame): self.fcombobox.addItems([ "5", "5.5", "6.5", "7.5", "8", "9", "10", "10.5", "11", "12", "14", "16", "18", "20", '22', "26", "28", "36", "48", "56", "72" "36", "48", "56", "72", "93", "123", "163" ]) self.fcombobox.param_changed.connect(self.param_changed) Loading @@ -164,28 +164,48 @@ class FontSizeBox(QFrame): hlayout.setSpacing(3) hlayout.setContentsMargins(0, 0, 0, 0) def getFontSize(self) -> float: return self.fcombobox.value() def getFontSize(self) -> str: return self.fcombobox.currentText() def onUpBtnClicked(self): raito = 1.25 size = self.getFontSize() newsize = int(round(size * 1.25)) multi_size=False if "+" in size: size = size.strip("+") multi_size=True size = float(size) newsize = int(round(size * raito)) if newsize == size: newsize += 1 newsize = min(1000, newsize) if newsize != size: if not multi_size: self.param_changed.emit('font_size', newsize) self.fcombobox.setCurrentText(str(newsize)) else: self.param_changed.emit('rel_font_size', raito) self.fcombobox.setCurrentText(str(newsize)+"+") def onDownBtnClicked(self): raito = 0.75 size = self.getFontSize() newsize = int(round(size * 0.75)) multi_size=False if "+" in size: size = size.strip("+") multi_size=True size = float(size) newsize = int(round(size * raito)) if newsize == size: newsize -= 1 newsize = max(1, newsize) if newsize != size: if not multi_size: self.param_changed.emit('font_size', newsize) self.fcombobox.setCurrentText(str(newsize)) else: self.param_changed.emit('rel_font_size', raito) self.fcombobox.setCurrentText(str(newsize)+"+") class SizeControlLabel(QLabel): Loading Loading @@ -459,7 +479,7 @@ class FontFormatPanel(Widget): return self.textstyle_panel.active_text_style_label def on_param_changed(self, param_name: str, value): func = FM.handle_ffmt_change.get(param_name) func = FM.handle_ffmt_change.get(param_name if not param_name == "rel_font_size" else "font_size") func_kwargs = {} if param_name == 'font_size': func_kwargs['clip_size'] = True Loading Loading @@ -507,7 +527,7 @@ class FontFormatPanel(Widget): mul = 0.01 self.lineSpacingBox.setValue(self.lineSpacingBox.value() + delta * mul) def set_active_format(self, font_format: FontFormat): def set_active_format(self, font_format: FontFormat, multi_size=False): C.active_format = font_format self.familybox.blockSignals(True) font_size = round(font_format.font_size, 1) Loading @@ -515,6 +535,8 @@ class FontFormatPanel(Widget): font_size = str(int(font_size)) else: font_size = f'{font_size:.1f}' if multi_size: font_size += "+" self.fontsizebox.fcombobox.setCurrentText(font_size) self.familybox.setCurrentText(font_format.font_family) self.colorPicker.setPickerColor(font_format.foreground_color()) Loading Loading @@ -555,7 +577,7 @@ class FontFormatPanel(Widget): if self.global_mode(): self.set_globalfmt_title() def set_textblk_item(self, textblk_item: TextBlkItem = None): def set_textblk_item(self, textblk_item: TextBlkItem = None, multi_select:bool=False): if textblk_item is None: focus_w = self.app.focusWidget() focus_p = None if focus_w is None else focus_w.parentWidget() Loading @@ -567,13 +589,28 @@ class FontFormatPanel(Widget): focus_on_fmtoptions = True if not focus_on_fmtoptions: self.textblk_item = None self.set_active_format(self.global_format) self.set_active_format(self.global_format, multi_select) if multi_select: self.textstyle_panel.setTitle('Grop') else: self.set_globalfmt_title() else: if not self.restoring_textblk: blk_fmt = textblk_item.get_fontformat() self.textblk_item = textblk_item self.set_active_format(blk_fmt) multi_size = False if not textblk_item.isEditing(): cursor = textblk_item.textCursor() cursor.setPosition(0) firstFontSize = cursor.charFormat().fontPointSize() for i in range(0,len(textblk_item.toPlainText())+1): cursor.setPosition(i) font_size = cursor.charFormat().fontPointSize() if not firstFontSize == font_size: multi_size = True break self.set_active_format(blk_fmt,multi_size) self.textstyle_panel.setTitle(f'TextBlock #{textblk_item.idx}') def on_effectbtn_clicked(self): Loading
ui/texteditshapecontrol.py +2 −1 Original line number Diff line number Diff line Loading @@ -67,8 +67,9 @@ class ControlBlockItem(QGraphicsRectItem): def mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None: self.ctrl.ctrlblockPressed() blk_item = self.ctrl.blk_item if event.button() == Qt.MouseButton.LeftButton: blk_item = self.ctrl.blk_item blk_item.setSelected(True) if self.visible_rect.contains(event.pos()): self.ctrl.reshaping = True self.drag_mode = self.DRAG_RESHAPE Loading
ui/textitem.py +16 −0 Original line number Diff line number Diff line Loading @@ -801,6 +801,22 @@ class TextBlkItem(QGraphicsTextItem): if repaint_background: self.update() def setRelFontSize(self, value: float, repaint_background: bool = False, set_selected: bool = False, restore_cursor: bool = False, clip_size: bool = False, **kwargs): cursor = self.textCursor() old_sizes = [] for i in range(len(self.toPlainText())): cursor.setPosition(i) cursor.setPosition(i+1, QTextCursor.MoveMode.KeepAnchor) old_sizes.append(cursor.charFormat().fontPointSize()) for i in range(len(self.toPlainText())): cursor.setPosition(i) cursor.setPosition(i+1, QTextCursor.MoveMode.KeepAnchor) self.setTextCursor(cursor) newvalue = round(old_sizes[i] * value,2) self.setFontSize(newvalue, repaint_background, True, restore_cursor, clip_size, **kwargs) cursor.clearSelection() self.squeezeBoundingRect() def setFontSize(self, value: float, repaint_background: bool = False, set_selected: bool = False, restore_cursor: bool = False, clip_size: bool = False, **kwargs): ''' value should be point size Loading