Skip to content

Commit

Permalink
fix: Multiple textblock select applies the font style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kagenihisomi committed Jan 30, 2024
1 parent 8640526 commit 901dcec
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions ui/fontformat_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from . import shared_widget as SW
from utils.fontformat import FontFormat
from .textitem import TextBlkItem
from itertools import cycle

global_default_set_kwargs = dict(set_selected=False, restore_cursor=False)
local_default_set_kwargs = dict(set_selected=True, restore_cursor=True)
Expand Down Expand Up @@ -63,29 +64,36 @@ def wrapper(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool,
@font_formating()
def ffmt_change_family(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.setFontFamily(value, **set_kwargs)

@font_formating()
def ffmt_change_italic(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.setFontItalic(value, **set_kwargs)

@font_formating()
def ffmt_change_underline(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.setFontUnderline(value, **set_kwargs)

@font_formating()
def ffmt_change_weight(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.setFontWeight(value, **set_kwargs)

@font_formating()
def ffmt_change_bold(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem] = None, **kwargs):
"""
In PyQT, bold is a font weight, unlike italics and underline
"""
if not isinstance(blkitems, List):
blkitems = [blkitems]
if not isinstance(values, List):
Expand All @@ -99,50 +107,58 @@ def ffmt_change_bold(param_name: str, values: str, act_ffmt: FontFormat, is_glob
@font_formating(push_undostack=True)
def ffmt_change_letter_spacing(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.setLetterSpacing(value, **set_kwargs)

@font_formating(push_undostack=True)
def ffmt_change_line_spacing(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.setLineSpacing(value, **set_kwargs)

@font_formating(push_undostack=True)
def ffmt_change_vertical(param_name: str, values: bool, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
# set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.setVertical(value)

@font_formating()
def ffmt_change_frgb(param_name: str, values: tuple, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.setFontColor(value, **set_kwargs)

@font_formating(push_undostack=True)
def ffmt_change_srgb(param_name: str, values: tuple, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.setStrokeColor(value, **set_kwargs)

@font_formating(push_undostack=True)
def ffmt_change_stroke_width(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.blk.stroke_decide_by_colordiff = False
blkitem.setStrokeWidth(value, **set_kwargs)

@font_formating()
def ffmt_change_size(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs):
set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
if value < 0:
continue
blkitem.setFontSize(value, **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):
restore_cursor = not is_global
for blkitem, value in zip(blkitems, values):
vals = cycle(values)
for blkitem, value in zip(blkitems, vals):
blkitem.setAlignment(value, restore_cursor=restore_cursor)

0 comments on commit 901dcec

Please sign in to comment.