Commit 48f00c0c authored by dmMaze's avatar dmMaze
Browse files

add global font style options for lettering

parent e12f9312
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -87,7 +87,10 @@ class ConfigBlock(Widget):
        combox = ConfigComboBox()
        combox.addItems(sel)
        sublock = ConfigSubBlock(combox, name, discription, vertical_layout=False)
        sublock.layout().setAlignment(Qt.AlignmentFlag.AlignLeft)
        sublock.layout().setSpacing(20)
        self.addSublock(sublock)
        return combox

    def addBlock(self, widget: Union[QWidget, QLayout], name: str = None, discription: str = None) -> ConfigSubBlock:
        sublock = ConfigSubBlock(widget, name, discription)
@@ -279,17 +282,22 @@ class ConfigPanel(Widget):
        self.inpaint_sub_block = dlConfigPanel.addBlock(self.inpaint_config_panel)

        dlConfigPanel.addTextLabel(label_translator)
        self.trans_config_panel = TranslatorConfigPanel(self.tr('Translator'))
        self.trans_config_panel = TranslatorConfigPanel(label_translator)
        self.trans_sub_block = dlConfigPanel.addBlock(self.trans_config_panel)

        generalConfigPanel.addTextLabel(self.tr('Startup'))
        generalConfigPanel.addTextLabel(label_startup)
        self.open_on_startup_checker = generalConfigPanel.addCheckBox(self.tr('Reopen last project on startup'))
        self.open_on_startup_checker.stateChanged.connect(self.on_open_onstartup_changed)

        generalConfigPanel.addTextLabel(self.tr('Lettering'))
        generalConfigPanel.addCombobox([self.tr('decide by program'),
                                        self.tr('use global setting')], self.tr('font size'))

        generalConfigPanel.addTextLabel(label_lettering)
        dec_program_str = self.tr('decide by program')
        use_global_str = self.tr('use global setting')
        self.let_fntsize_combox = generalConfigPanel.addCombobox([dec_program_str, use_global_str], self.tr('font size'))
        self.let_fntsize_combox.currentIndexChanged.connect(self.on_fntsize_flag_changed)
        self.let_fntstroke_combox = generalConfigPanel.addCombobox([dec_program_str, use_global_str], self.tr('stroke'))
        self.let_fntstroke_combox.currentIndexChanged.connect(self.on_fntstroke_flag_changed)
        self.let_fntcolor_combox = generalConfigPanel.addCombobox([dec_program_str, use_global_str], self.tr('font & stroke color'))
        self.let_fntcolor_combox.currentIndexChanged.connect(self.on_fontcolor_flag_changed)

        splitter = QSplitter(Qt.Horizontal)
        splitter.addWidget(self.configTable)
@@ -322,6 +330,15 @@ class ConfigPanel(Widget):
    def on_open_onstartup_changed(self):
        self.config.open_recent_on_startup = self.open_on_startup_checker.isChecked()

    def on_fntsize_flag_changed(self):
        self.config.let_fntsize_flag = self.let_fntsize_combox.currentIndex()

    def on_fntstroke_flag_changed(self):
        self.config.let_fntstroke_flag = self.let_fntstroke_combox.currentIndex()

    def on_fontcolor_flag_changed(self):
        self.config.let_fntcolor_flag = self.let_fntcolor_combox.currentIndex()

    def focusOnTranslator(self):
        idx0, idx1 = self.trans_sub_block.idx0, self.trans_sub_block.idx1
        self.configTable.setCurrentItem(idx0, idx1)
+1 −1
Original line number Diff line number Diff line
from typing import List

from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QWidget, QFileDialog, QLabel, QSizePolicy, QComboBox, QListView, QToolBar, QMenu, QSpacerItem, QPushButton, QAction, QCheckBox, QToolButton, QSplitter, QStylePainter, QStyleOption, QStyle, QScrollArea, QLineEdit, QGroupBox, QGraphicsSimpleTextItem
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QWidget, QLabel, QComboBox, QListView, QToolBar, QMenu, QSpacerItem, QPushButton, QAction, QCheckBox, QToolButton, QSplitter, QStylePainter, QStyleOption, QStyle, QScrollArea, QLineEdit, QGroupBox, QGraphicsSimpleTextItem
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QFontMetricsF

+20 −0
Original line number Diff line number Diff line
@@ -185,6 +185,10 @@ class MainWindow(QMainWindow):
        if self.config.open_recent_on_startup:
            self.configPanel.open_on_startup_checker.setChecked(True)

        self.configPanel.let_fntsize_combox.setCurrentIndex(self.config.let_fntsize_flag)
        self.configPanel.let_fntstroke_combox.setCurrentIndex(self.config.let_fntstroke_flag)
        self.configPanel.let_fntcolor_combox.setCurrentIndex(self.config.let_fntcolor_flag)

    def setupImgTransUI(self):
        self.centralStackWidget.setCurrentIndex(0)
        if self.leftBar.showPageListLabel.checkState() == 2:
@@ -444,6 +448,22 @@ class MainWindow(QMainWindow):
        self.pageListCurrentItemChanged()

    def on_pagtrans_finished(self, page_index: int):
        
        # override font format if necessary
        override_fnt_size = self.config.let_fntsize_flag == 1
        override_fnt_stroke = self.config.let_fntstroke_flag == 1
        override_fnt_color = self.config.let_fntcolor_flag
        if override_fnt_size or override_fnt_stroke:
            gf = self.textPanel.formatpanel.global_format
            blk_list = self.imgtrans_proj.get_blklist_byidx(page_index)
            for blk in blk_list:
                if override_fnt_size:
                    blk.font_size = gf.size
                if override_fnt_stroke:
                    blk.default_stroke_width = gf.stroke_width
                if override_fnt_color:
                    blk.set_font_colors(gf.frgb, gf.srgb, accumulate=False)

        if self.config.dl.translate_target not in LANG_SUPPORT_VERTICAL:
            for blk in self.imgtrans_proj.get_blklist_byidx(page_index):
                blk.vertical = False
+10 −1
Original line number Diff line number Diff line
@@ -443,6 +443,9 @@ class ProgramConfig:
        self.global_fontformat = FontFormat()
        self.drawpanel = DrawPanelConfig()
        self.open_recent_on_startup = False
        self.let_fntsize_flag = 0
        self.let_fntstroke_flag = 0
        self.let_fntcolor_flag = 0
        if config_dict is not None:
            self.load_from_dict(config_dict)

@@ -459,6 +462,9 @@ class ProgramConfig:
            self.global_fontformat = FontFormat(**config_dict['global_fontformat'])
            self.drawpanel = DrawPanelConfig(**config_dict['drawpanel'])
            self.open_recent_on_startup = config_dict['open_recent_on_startup']
            self.let_fntsize_flag = config_dict['let_fntsize_flag']
            self.let_fntstroke_flag = config_dict['let_fntstroke_flag']
            self.let_fntcolor_flag = config_dict['let_fntcolor_flag']
        except Exception as e:
            raise InvalidProgramConfigException(e)

@@ -473,7 +479,10 @@ class ProgramConfig:
            'mask_transparency': self.mask_transparency,
            'original_transparency': self.original_transparency,
            'drawpanel': vars(self.drawpanel),
            'open_recent_on_startup': self.open_recent_on_startup
            'open_recent_on_startup': self.open_recent_on_startup,
            'let_fntsize_flag': self.let_fntsize_flag,
            'let_fntstroke_flag': self.let_fntstroke_flag,
            'let_fntcolor_flag': self.let_fntcolor_flag
        }