Loading ui/configpanel.py +17 −17 Original line number Diff line number Diff line Loading @@ -419,30 +419,30 @@ class ConfigPanel(Widget): self.let_fntsize_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Font Size'), parent=self, insert_stretch=True) global_fntfmt_layout.addWidget(sublock, 0, 0) self.let_fntsize_combox.index_changed.connect(self.on_fntsize_flag_changed) self.let_fntsize_combox.activated.connect(self.on_fntsize_flag_changed) self.let_fntstroke_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Stroke Size'), parent=self, insert_stretch=True) self.let_fntstroke_combox.index_changed.connect(self.on_fntstroke_flag_changed) self.let_fntstroke_combox.activated.connect(self.on_fntstroke_flag_changed) global_fntfmt_layout.addWidget(sublock, 0, 1) self.let_fntcolor_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Font Color'), parent=self, insert_stretch=True) self.let_fntcolor_combox.index_changed.connect(self.on_fontcolor_flag_changed) self.let_fntcolor_combox.activated.connect(self.on_fontcolor_flag_changed) global_fntfmt_layout.addWidget(sublock, 1, 0) self.let_fnt_scolor_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Stroke Color'), parent=self, insert_stretch=True) self.let_fnt_scolor_combox.index_changed.connect(self.on_font_scolor_flag_changed) self.let_fnt_scolor_combox.activated.connect(self.on_font_scolor_flag_changed) global_fntfmt_layout.addWidget(sublock, 1, 1) self.let_effect_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Effect'), parent=self, insert_stretch=True) self.let_effect_combox.index_changed.connect(self.on_effect_flag_changed) self.let_effect_combox.activated.connect(self.on_effect_flag_changed) global_fntfmt_layout.addWidget(sublock, 2, 0) self.let_alignment_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Alignment'), parent=self, insert_stretch=True) self.let_alignment_combox.index_changed.connect(self.on_alignment_flag_changed) self.let_alignment_combox.activated.connect(self.on_alignment_flag_changed) global_fntfmt_layout.addWidget(sublock, 2, 1) self.let_writing_mode_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Writing-mode'), parent=self, insert_stretch=True) self.let_writing_mode_combox.index_changed.connect(self.on_writing_mode_flag_changed) self.let_writing_mode_combox.activated.connect(self.on_writing_mode_flag_changed) global_fntfmt_layout.addWidget(sublock, 3, 0) self.let_family_combox, sublock = combobox_with_label([self.tr('Keep existing'), self.tr('Always use global setting')], self.tr('Font Family'), parent=self, insert_stretch=True) self.let_family_combox.index_changed.connect(self.on_family_flag_changed) self.let_family_combox.activated.connect(self.on_family_flag_changed) global_fntfmt_layout.addWidget(sublock, 3, 1) global_fntfmt_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding), 0, 2) Loading @@ -461,7 +461,7 @@ class ConfigPanel(Widget): generalConfigPanel.addTextLabel(label_save) self.rst_imgformat_combobox, imsave_sublock = generalConfigPanel.addCombobox(['PNG', 'JPG', 'WEBP'], self.tr('Result image format')) self.rst_imgformat_combobox.index_changed.connect(self.on_rst_imgformat_changed) self.rst_imgformat_combobox.activated.connect(self.on_rst_imgformat_changed) self.rst_imgquality_edit = PercentageLineEdit('100') self.rst_imgquality_edit.setFixedWidth(CONFIG_COMBOBOX_SHORT) self.rst_imgquality_edit.finish_edited.connect(self.on_edit_quality_changed) Loading Loading @@ -602,14 +602,14 @@ class ConfigPanel(Widget): if pcfg.open_recent_on_startup: self.open_on_startup_checker.setChecked(True) self.let_effect_combox.set_current_index(pcfg.let_fnteffect_flag, user_input=False) self.let_fntsize_combox.set_current_index(pcfg.let_fntsize_flag, user_input=False) self.let_fntstroke_combox.set_current_index(pcfg.let_fntstroke_flag, user_input=False) self.let_fntcolor_combox.set_current_index(pcfg.let_fntcolor_flag, user_input=False) self.let_fnt_scolor_combox.set_current_index(pcfg.let_fnt_scolor_flag, user_input=False) self.let_alignment_combox.set_current_index(pcfg.let_alignment_flag, user_input=False) self.let_family_combox.set_current_index(pcfg.let_family_flag, user_input=False) self.let_writing_mode_combox.set_current_index(pcfg.let_writing_mode_flag, user_input=False) self.let_effect_combox.setCurrentIndex(pcfg.let_fnteffect_flag) self.let_fntsize_combox.setCurrentIndex(pcfg.let_fntsize_flag) self.let_fntstroke_combox.setCurrentIndex(pcfg.let_fntstroke_flag) self.let_fntcolor_combox.setCurrentIndex(pcfg.let_fntcolor_flag) self.let_fnt_scolor_combox.setCurrentIndex(pcfg.let_fnt_scolor_flag) self.let_alignment_combox.setCurrentIndex(pcfg.let_alignment_flag) self.let_family_combox.setCurrentIndex(pcfg.let_family_flag) self.let_writing_mode_combox.setCurrentIndex(pcfg.let_writing_mode_flag) self.let_autolayout_checker.setChecked(pcfg.let_autolayout_flag) self.let_autolayout_adaptive_fntsize_checker.setChecked(pcfg.let_autolayout_adaptive_fntsz) self.selectext_minimenu_checker.setChecked(pcfg.textselect_mini_menu) Loading ui/custom_widget/combobox.py +0 −18 Original line number Diff line number Diff line Loading @@ -9,34 +9,16 @@ from utils.shared import CONFIG_COMBOBOX_LONG, CONFIG_COMBOBOX_MIDEAN, CONFIG_CO class ComboBox(QComboBox): index_changed = Signal() # https://stackoverflow.com/questions/3241830/qt-how-to-disable-mouse-scrolling-of-qcombobox def __init__(self, parent: QWidget = None, scrollWidget: QWidget = None, options: List[str] = None) -> None: super().__init__(parent) self.scrollWidget = scrollWidget if options is not None: self.addItems(options) self.currentIndexChanged.connect(self.on_current_index_changed) self._program_set_flag = False def setScrollWidget(self, scrollWidget: QWidget): self.scrollWidget = scrollWidget def on_current_index_changed(self): if self._program_set_flag: return self.index_changed.emit() def set_current_index(self, index: int, user_input: bool = True): ''' emit index_changed only if user_input is True ''' self._program_set_flag = not user_input self.setCurrentIndex(index) self._program_set_flag = False def wheelEvent(self, *args, **kwargs): if self.scrollWidget is None or self.hasFocus(): return super().wheelEvent(*args, **kwargs) Loading ui/fontformat_commands.py +7 −1 Original line number Diff line number Diff line Loading @@ -147,3 +147,9 @@ def ffmt_change_alignment(param_name: str, values: float, act_ffmt: FontFormat, restore_cursor = not is_global for blkitem, value in zip(blkitems, values): blkitem.setAlignment(value, restore_cursor=restore_cursor) @font_formating(push_undostack=True) def ffmt_change_line_spacing_type(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): restore_cursor = not is_global for blkitem, value in zip(blkitems, values): blkitem.setLineSpacingType(value, restore_cursor=restore_cursor) No newline at end of file ui/scene_textlayout.py +36 −13 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ from functools import lru_cache, cached_property from .misc import pixmap2ndarray, LruIgnoreArg from utils import shared as C from utils.fontformat import pt2px from utils.fontformat import pt2px, FontFormat, LineSpacingType def print_transform(tr: QTransform): print(f'[[{tr.m11(), tr.m12(), tr.m13()}]\n [{tr.m21(), tr.m22(), tr.m23()}]\n [{tr.m31(), tr.m32(), tr.m33()}]]') Loading Loading @@ -175,14 +175,16 @@ def line_draw_qt5(painter: QPainter, line: QTextLine, x: float, y: float, select class SceneTextLayout(QAbstractTextDocumentLayout): size_enlarged = Signal() def __init__(self, doc: QTextDocument) -> None: def __init__(self, doc: QTextDocument, fontformat: FontFormat) -> None: super().__init__(doc) self.max_height = 0 self.max_width = 0 self.available_width = 0 self.available_height = 0 self.line_spacing = 1. self.letter_spacing = 1. self.line_spacing = fontformat.line_spacing self.letter_spacing = fontformat.letter_spacing self.linespacing_type = fontformat.line_spacing_type self.fontformat = fontformat self.x_offset_lst = [] self.y_offset_lst = [] Loading Loading @@ -223,6 +225,27 @@ class SceneTextLayout(QAbstractTextDocumentLayout): self.line_spacing = line_spacing self.reLayout() def setLineSpacingType(self, linespacing_type: int): if self.linespacing_type != linespacing_type: self.linespacing_type = linespacing_type self.reLayout() def calculate_line_spacing(self, size: float, line_spacing: float = 1): if self.linespacing_type == LineSpacingType.Proportional: return line_spacing * size elif self.linespacing_type == LineSpacingType.Distance: return line_spacing * 10 + size else: raise Exception(f'Invalid line spacing type: {self.linespacing_type}') def identity_linespacing(self): if self.linespacing_type == LineSpacingType.Proportional: return 1. elif self.linespacing_type == LineSpacingType.Distance: return 0. else: raise Exception(f'Invalid line spacing type: {self.linespacing_type}') def blockBoundingRect(self, block: QTextBlock) -> QRectF: if not block.isValid(): return QRectF() Loading Loading @@ -311,8 +334,8 @@ class SceneTextLayout(QAbstractTextDocumentLayout): class VerticalTextDocumentLayout(SceneTextLayout): def __init__(self, doc: QTextDocument): super().__init__(doc) def __init__(self, doc: QTextDocument, fontformat: FontFormat): super().__init__(doc, fontformat) self.line_spaces_lst = [] self.min_height = 0 Loading Loading @@ -753,7 +776,7 @@ class VerticalTextDocumentLayout(SceneTextLayout): line_not_set.append(line) if out_of_vspace or end_char: if is_first_line: line_spacing = 1. line_spacing = self.identity_linespacing() else: line_spacing = self.line_spacing if len(width_list) == 0: Loading @@ -774,14 +797,14 @@ class VerticalTextDocumentLayout(SceneTextLayout): char_records[cidx] = {'line_width': idea_line_width} line_char_ids = [] x_offset = x_offset - idea_line_width * line_spacing x_offset = x_offset - self.calculate_line_spacing(idea_line_width, line_spacing) for line, ypos in zip(line_not_set[:-1], ypos_list[:-1]): line.setPosition(QPointF(x_offset, ypos)) if out_of_vspace: if end_char: if not len(line_not_set) == 1: x_offset = x_offset - end_w * line_spacing x_offset = x_offset - self.calculate_line_spacing(end_w, line_spacing) end_line.setPosition(QPointF(x_offset, end_ypos)) char_records[end_char_id] = {'line_width': end_w} else: Loading Loading @@ -826,8 +849,8 @@ class VerticalTextDocumentLayout(SceneTextLayout): class HorizontalTextDocumentLayout(SceneTextLayout): def __init__(self, doc: QTextDocument): super().__init__(doc) def __init__(self, doc: QTextDocument, fontformat: FontFormat): super().__init__(doc, fontformat) self.need_ideal_height = True def reLayout(self): Loading Loading @@ -954,7 +977,7 @@ class HorizontalTextDocumentLayout(SceneTextLayout): tw = line.naturalTextWidth() shrink_width = max(tw, shrink_width) self.shrink_height = max(idea_height + y_offset - doc_margin, self.shrink_height) #???? y_offset += idea_height * self.line_spacing y_offset += self.calculate_line_spacing(idea_height, self.line_spacing) line_idx += 1 char_idx += nchar Loading ui/text_advanced_format.py +20 −4 Original line number Diff line number Diff line from qtpy.QtWidgets import QVBoxLayout, QPushButton, QComboBox from typing import Any, Callable from qtpy.QtWidgets import QVBoxLayout, QPushButton, QComboBox, QLabel, QHBoxLayout from qtpy.QtCore import Signal, Qt, QRectF from .custom_widget import PanelGroupBox, PanelArea, ComboBox Loading @@ -7,22 +9,36 @@ from utils.fontformat import FontFormat class TextAdvancedFormatPanel(PanelArea): param_changed = Signal(str, object) def __init__(self, panel_name: str, config_name: str, config_expand_name: str): super().__init__(panel_name, config_name, config_expand_name) self.active_format: FontFormat = None self.linespacing_combobox = ComboBox( self.linespacing_type_combobox = ComboBox( parent=self, options=[ self.tr("Proportional"), self.tr("Distance") ] ) self.linespacing_type_combobox.activated.connect( lambda: self.on_format_changed('line_spacing_type', self.linespacing_type_combobox.currentIndex) ) linespacing_type_label = QLabel(self.tr('Line Spacing Type: ')) linespacing_type_layout = QHBoxLayout() linespacing_type_layout.addWidget(linespacing_type_label) linespacing_type_layout.addWidget(self.linespacing_type_combobox) # linespacing_type_layout.addStretch() vlayout = QVBoxLayout() vlayout.addWidget(self.linespacing_combobox) vlayout.addLayout(linespacing_type_layout) self.setContentLayout(vlayout) def set_active_format(self, font_format: FontFormat): self.active_format = font_format self.linespacing_type_combobox.setCurrentIndex(font_format.line_spacing_type) def on_format_changed(self, format_name: str, get_format: Callable): self.param_changed.emit(format_name, get_format()) No newline at end of file Loading
ui/configpanel.py +17 −17 Original line number Diff line number Diff line Loading @@ -419,30 +419,30 @@ class ConfigPanel(Widget): self.let_fntsize_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Font Size'), parent=self, insert_stretch=True) global_fntfmt_layout.addWidget(sublock, 0, 0) self.let_fntsize_combox.index_changed.connect(self.on_fntsize_flag_changed) self.let_fntsize_combox.activated.connect(self.on_fntsize_flag_changed) self.let_fntstroke_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Stroke Size'), parent=self, insert_stretch=True) self.let_fntstroke_combox.index_changed.connect(self.on_fntstroke_flag_changed) self.let_fntstroke_combox.activated.connect(self.on_fntstroke_flag_changed) global_fntfmt_layout.addWidget(sublock, 0, 1) self.let_fntcolor_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Font Color'), parent=self, insert_stretch=True) self.let_fntcolor_combox.index_changed.connect(self.on_fontcolor_flag_changed) self.let_fntcolor_combox.activated.connect(self.on_fontcolor_flag_changed) global_fntfmt_layout.addWidget(sublock, 1, 0) self.let_fnt_scolor_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Stroke Color'), parent=self, insert_stretch=True) self.let_fnt_scolor_combox.index_changed.connect(self.on_font_scolor_flag_changed) self.let_fnt_scolor_combox.activated.connect(self.on_font_scolor_flag_changed) global_fntfmt_layout.addWidget(sublock, 1, 1) self.let_effect_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Effect'), parent=self, insert_stretch=True) self.let_effect_combox.index_changed.connect(self.on_effect_flag_changed) self.let_effect_combox.activated.connect(self.on_effect_flag_changed) global_fntfmt_layout.addWidget(sublock, 2, 0) self.let_alignment_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Alignment'), parent=self, insert_stretch=True) self.let_alignment_combox.index_changed.connect(self.on_alignment_flag_changed) self.let_alignment_combox.activated.connect(self.on_alignment_flag_changed) global_fntfmt_layout.addWidget(sublock, 2, 1) self.let_writing_mode_combox, sublock = combobox_with_label([dec_program_str, use_global_str], self.tr('Writing-mode'), parent=self, insert_stretch=True) self.let_writing_mode_combox.index_changed.connect(self.on_writing_mode_flag_changed) self.let_writing_mode_combox.activated.connect(self.on_writing_mode_flag_changed) global_fntfmt_layout.addWidget(sublock, 3, 0) self.let_family_combox, sublock = combobox_with_label([self.tr('Keep existing'), self.tr('Always use global setting')], self.tr('Font Family'), parent=self, insert_stretch=True) self.let_family_combox.index_changed.connect(self.on_family_flag_changed) self.let_family_combox.activated.connect(self.on_family_flag_changed) global_fntfmt_layout.addWidget(sublock, 3, 1) global_fntfmt_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding), 0, 2) Loading @@ -461,7 +461,7 @@ class ConfigPanel(Widget): generalConfigPanel.addTextLabel(label_save) self.rst_imgformat_combobox, imsave_sublock = generalConfigPanel.addCombobox(['PNG', 'JPG', 'WEBP'], self.tr('Result image format')) self.rst_imgformat_combobox.index_changed.connect(self.on_rst_imgformat_changed) self.rst_imgformat_combobox.activated.connect(self.on_rst_imgformat_changed) self.rst_imgquality_edit = PercentageLineEdit('100') self.rst_imgquality_edit.setFixedWidth(CONFIG_COMBOBOX_SHORT) self.rst_imgquality_edit.finish_edited.connect(self.on_edit_quality_changed) Loading Loading @@ -602,14 +602,14 @@ class ConfigPanel(Widget): if pcfg.open_recent_on_startup: self.open_on_startup_checker.setChecked(True) self.let_effect_combox.set_current_index(pcfg.let_fnteffect_flag, user_input=False) self.let_fntsize_combox.set_current_index(pcfg.let_fntsize_flag, user_input=False) self.let_fntstroke_combox.set_current_index(pcfg.let_fntstroke_flag, user_input=False) self.let_fntcolor_combox.set_current_index(pcfg.let_fntcolor_flag, user_input=False) self.let_fnt_scolor_combox.set_current_index(pcfg.let_fnt_scolor_flag, user_input=False) self.let_alignment_combox.set_current_index(pcfg.let_alignment_flag, user_input=False) self.let_family_combox.set_current_index(pcfg.let_family_flag, user_input=False) self.let_writing_mode_combox.set_current_index(pcfg.let_writing_mode_flag, user_input=False) self.let_effect_combox.setCurrentIndex(pcfg.let_fnteffect_flag) self.let_fntsize_combox.setCurrentIndex(pcfg.let_fntsize_flag) self.let_fntstroke_combox.setCurrentIndex(pcfg.let_fntstroke_flag) self.let_fntcolor_combox.setCurrentIndex(pcfg.let_fntcolor_flag) self.let_fnt_scolor_combox.setCurrentIndex(pcfg.let_fnt_scolor_flag) self.let_alignment_combox.setCurrentIndex(pcfg.let_alignment_flag) self.let_family_combox.setCurrentIndex(pcfg.let_family_flag) self.let_writing_mode_combox.setCurrentIndex(pcfg.let_writing_mode_flag) self.let_autolayout_checker.setChecked(pcfg.let_autolayout_flag) self.let_autolayout_adaptive_fntsize_checker.setChecked(pcfg.let_autolayout_adaptive_fntsz) self.selectext_minimenu_checker.setChecked(pcfg.textselect_mini_menu) Loading
ui/custom_widget/combobox.py +0 −18 Original line number Diff line number Diff line Loading @@ -9,34 +9,16 @@ from utils.shared import CONFIG_COMBOBOX_LONG, CONFIG_COMBOBOX_MIDEAN, CONFIG_CO class ComboBox(QComboBox): index_changed = Signal() # https://stackoverflow.com/questions/3241830/qt-how-to-disable-mouse-scrolling-of-qcombobox def __init__(self, parent: QWidget = None, scrollWidget: QWidget = None, options: List[str] = None) -> None: super().__init__(parent) self.scrollWidget = scrollWidget if options is not None: self.addItems(options) self.currentIndexChanged.connect(self.on_current_index_changed) self._program_set_flag = False def setScrollWidget(self, scrollWidget: QWidget): self.scrollWidget = scrollWidget def on_current_index_changed(self): if self._program_set_flag: return self.index_changed.emit() def set_current_index(self, index: int, user_input: bool = True): ''' emit index_changed only if user_input is True ''' self._program_set_flag = not user_input self.setCurrentIndex(index) self._program_set_flag = False def wheelEvent(self, *args, **kwargs): if self.scrollWidget is None or self.hasFocus(): return super().wheelEvent(*args, **kwargs) Loading
ui/fontformat_commands.py +7 −1 Original line number Diff line number Diff line Loading @@ -147,3 +147,9 @@ def ffmt_change_alignment(param_name: str, values: float, act_ffmt: FontFormat, restore_cursor = not is_global for blkitem, value in zip(blkitems, values): blkitem.setAlignment(value, restore_cursor=restore_cursor) @font_formating(push_undostack=True) def ffmt_change_line_spacing_type(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): restore_cursor = not is_global for blkitem, value in zip(blkitems, values): blkitem.setLineSpacingType(value, restore_cursor=restore_cursor) No newline at end of file
ui/scene_textlayout.py +36 −13 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ from functools import lru_cache, cached_property from .misc import pixmap2ndarray, LruIgnoreArg from utils import shared as C from utils.fontformat import pt2px from utils.fontformat import pt2px, FontFormat, LineSpacingType def print_transform(tr: QTransform): print(f'[[{tr.m11(), tr.m12(), tr.m13()}]\n [{tr.m21(), tr.m22(), tr.m23()}]\n [{tr.m31(), tr.m32(), tr.m33()}]]') Loading Loading @@ -175,14 +175,16 @@ def line_draw_qt5(painter: QPainter, line: QTextLine, x: float, y: float, select class SceneTextLayout(QAbstractTextDocumentLayout): size_enlarged = Signal() def __init__(self, doc: QTextDocument) -> None: def __init__(self, doc: QTextDocument, fontformat: FontFormat) -> None: super().__init__(doc) self.max_height = 0 self.max_width = 0 self.available_width = 0 self.available_height = 0 self.line_spacing = 1. self.letter_spacing = 1. self.line_spacing = fontformat.line_spacing self.letter_spacing = fontformat.letter_spacing self.linespacing_type = fontformat.line_spacing_type self.fontformat = fontformat self.x_offset_lst = [] self.y_offset_lst = [] Loading Loading @@ -223,6 +225,27 @@ class SceneTextLayout(QAbstractTextDocumentLayout): self.line_spacing = line_spacing self.reLayout() def setLineSpacingType(self, linespacing_type: int): if self.linespacing_type != linespacing_type: self.linespacing_type = linespacing_type self.reLayout() def calculate_line_spacing(self, size: float, line_spacing: float = 1): if self.linespacing_type == LineSpacingType.Proportional: return line_spacing * size elif self.linespacing_type == LineSpacingType.Distance: return line_spacing * 10 + size else: raise Exception(f'Invalid line spacing type: {self.linespacing_type}') def identity_linespacing(self): if self.linespacing_type == LineSpacingType.Proportional: return 1. elif self.linespacing_type == LineSpacingType.Distance: return 0. else: raise Exception(f'Invalid line spacing type: {self.linespacing_type}') def blockBoundingRect(self, block: QTextBlock) -> QRectF: if not block.isValid(): return QRectF() Loading Loading @@ -311,8 +334,8 @@ class SceneTextLayout(QAbstractTextDocumentLayout): class VerticalTextDocumentLayout(SceneTextLayout): def __init__(self, doc: QTextDocument): super().__init__(doc) def __init__(self, doc: QTextDocument, fontformat: FontFormat): super().__init__(doc, fontformat) self.line_spaces_lst = [] self.min_height = 0 Loading Loading @@ -753,7 +776,7 @@ class VerticalTextDocumentLayout(SceneTextLayout): line_not_set.append(line) if out_of_vspace or end_char: if is_first_line: line_spacing = 1. line_spacing = self.identity_linespacing() else: line_spacing = self.line_spacing if len(width_list) == 0: Loading @@ -774,14 +797,14 @@ class VerticalTextDocumentLayout(SceneTextLayout): char_records[cidx] = {'line_width': idea_line_width} line_char_ids = [] x_offset = x_offset - idea_line_width * line_spacing x_offset = x_offset - self.calculate_line_spacing(idea_line_width, line_spacing) for line, ypos in zip(line_not_set[:-1], ypos_list[:-1]): line.setPosition(QPointF(x_offset, ypos)) if out_of_vspace: if end_char: if not len(line_not_set) == 1: x_offset = x_offset - end_w * line_spacing x_offset = x_offset - self.calculate_line_spacing(end_w, line_spacing) end_line.setPosition(QPointF(x_offset, end_ypos)) char_records[end_char_id] = {'line_width': end_w} else: Loading Loading @@ -826,8 +849,8 @@ class VerticalTextDocumentLayout(SceneTextLayout): class HorizontalTextDocumentLayout(SceneTextLayout): def __init__(self, doc: QTextDocument): super().__init__(doc) def __init__(self, doc: QTextDocument, fontformat: FontFormat): super().__init__(doc, fontformat) self.need_ideal_height = True def reLayout(self): Loading Loading @@ -954,7 +977,7 @@ class HorizontalTextDocumentLayout(SceneTextLayout): tw = line.naturalTextWidth() shrink_width = max(tw, shrink_width) self.shrink_height = max(idea_height + y_offset - doc_margin, self.shrink_height) #???? y_offset += idea_height * self.line_spacing y_offset += self.calculate_line_spacing(idea_height, self.line_spacing) line_idx += 1 char_idx += nchar Loading
ui/text_advanced_format.py +20 −4 Original line number Diff line number Diff line from qtpy.QtWidgets import QVBoxLayout, QPushButton, QComboBox from typing import Any, Callable from qtpy.QtWidgets import QVBoxLayout, QPushButton, QComboBox, QLabel, QHBoxLayout from qtpy.QtCore import Signal, Qt, QRectF from .custom_widget import PanelGroupBox, PanelArea, ComboBox Loading @@ -7,22 +9,36 @@ from utils.fontformat import FontFormat class TextAdvancedFormatPanel(PanelArea): param_changed = Signal(str, object) def __init__(self, panel_name: str, config_name: str, config_expand_name: str): super().__init__(panel_name, config_name, config_expand_name) self.active_format: FontFormat = None self.linespacing_combobox = ComboBox( self.linespacing_type_combobox = ComboBox( parent=self, options=[ self.tr("Proportional"), self.tr("Distance") ] ) self.linespacing_type_combobox.activated.connect( lambda: self.on_format_changed('line_spacing_type', self.linespacing_type_combobox.currentIndex) ) linespacing_type_label = QLabel(self.tr('Line Spacing Type: ')) linespacing_type_layout = QHBoxLayout() linespacing_type_layout.addWidget(linespacing_type_label) linespacing_type_layout.addWidget(self.linespacing_type_combobox) # linespacing_type_layout.addStretch() vlayout = QVBoxLayout() vlayout.addWidget(self.linespacing_combobox) vlayout.addLayout(linespacing_type_layout) self.setContentLayout(vlayout) def set_active_format(self, font_format: FontFormat): self.active_format = font_format self.linespacing_type_combobox.setCurrentIndex(font_format.line_spacing_type) def on_format_changed(self, format_name: str, get_format: Callable): self.param_changed.emit(format_name, get_format()) No newline at end of file