Commit 23b32407 authored by dmMaze's avatar dmMaze
Browse files

Add mini menu on text selection

parent 18500492
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -875,6 +875,18 @@ ClickableLabel#ReplaceAllBtn {
    min-height: 24px;
}

ClickableLabel#SalaDict {
    image: url(data/icons/saladict.png);
    min-width: 24px;
    min-height: 24px;
}

ClickableLabel#SearchInternet {
    image: url(data/icons/search.svg);
    min-width: 24px;
    min-height: 24px;
}

TitleBarToolBtn {
    padding-left: 4px;
    padding-right: 4px;
+5.7 KiB
Loading image diff...
+50 −6
Original line number Diff line number Diff line
from typing import List, Union, Tuple
import json

from qtpy.QtWidgets import QLayout, QHBoxLayout, QVBoxLayout, QTreeView, QWidget, QLabel, QSizePolicy, QSpacerItem, QCheckBox, QSplitter, QScrollArea, QGroupBox, QLineEdit
from qtpy.QtWidgets import QKeySequenceEdit, QLayout, QHBoxLayout, QVBoxLayout, QTreeView, QWidget, QLabel, QSizePolicy, QSpacerItem, QCheckBox, QSplitter, QScrollArea, QGroupBox, QLineEdit
from qtpy.QtCore import Qt, QModelIndex, Signal, QSize, QEvent, QItemSelection
from qtpy.QtGui import QStandardItem, QStandardItemModel, QMouseEvent, QFont, QColor, QPalette

@@ -107,8 +107,8 @@ class ConfigBlock(Widget):
        sublock.pressed.connect(lambda idx0, idx1: self.sublock_pressed.emit(idx0, idx1))
        self.subblock_list.append(sublock)

    def addCombobox(self, sel: List[str], name: str, discription: str = None, vertical_layout: bool = False, target_block: QWidget = None) -> Tuple[ConfigComboBox, QWidget]:
        combox = ConfigComboBox()
    def addCombobox(self, sel: List[str], name: str, discription: str = None, vertical_layout: bool = False, target_block: QWidget = None, fix_size: bool = True) -> Tuple[ConfigComboBox, QWidget]:
        combox = ConfigComboBox(fix_size=fix_size)
        combox.addItems(sel)
        if target_block is None:
            sublock = ConfigSubBlock(combox, name, discription, vertical_layout=vertical_layout)
@@ -294,6 +294,7 @@ class ConfigPanel(Widget):
        label_translator = self.tr('Translator')
        label_startup = self.tr('Startup')
        label_lettering = self.tr('Lettering')
        label_saladict = self.tr("SalaDict")
    
        dltableitem.appendRows([
            TableItem(label_text_det, CONFIG_FONTSIZE_TABLE),
@@ -303,7 +304,8 @@ class ConfigPanel(Widget):
        ])
        generalTableItem.appendRows([
            TableItem(label_startup, CONFIG_FONTSIZE_TABLE),
            TableItem(label_lettering, CONFIG_FONTSIZE_TABLE)
            TableItem(label_lettering, CONFIG_FONTSIZE_TABLE),
            TableItem(label_saladict, CONFIG_FONTSIZE_TABLE)
        ])

        dlConfigPanel.addTextLabel(label_text_det)
@@ -347,6 +349,18 @@ class ConfigPanel(Widget):
        self.let_uppercase_checker = generalConfigPanel.addCheckBox(self.tr('To uppercase'))
        self.let_uppercase_checker.stateChanged.connect(self.on_uppercase_changed)

        generalConfigPanel.addTextLabel(label_saladict)
        self.selectext_minimenu_checker = generalConfigPanel.addCheckBox(self.tr('Show mini menu when selecting text.'))
        self.selectext_minimenu_checker.stateChanged.connect(self.on_selectext_minimenu_changed)
        self.saladict_shortcut = QKeySequenceEdit("ALT+W", self)
        self.saladict_shortcut.keySequenceChanged.connect(self.on_saladict_shortcut_changed)
        self.saladict_shortcut.setFixedWidth(CONFIG_COMBOBOX_MIDEAN)
        generalConfigPanel.addBlockWidget(self.saladict_shortcut, self.tr("shortcut"))
        self.searchurl_combobox, _ = generalConfigPanel.addCombobox(["https://www.google.com/search?q=", "https://www.bing.com/search?q=", "https://duckduckgo.com/?q=", "https://yandex.com/search/?text=", "http://www.baidu.com/s?wd=", "https://search.yahoo.com/search;?p=", "https://www.urbandictionary.com/define.php?term="], self.tr("Search Engines"), fix_size=False)
        self.searchurl_combobox.setEditable(True)
        self.searchurl_combobox.setFixedWidth(CONFIG_COMBOBOX_LONG)
        self.searchurl_combobox.currentTextChanged.connect(self.on_searchurl_changed)

        splitter = QSplitter(Qt.Orientation.Horizontal)
        splitter.addWidget(self.configTable)
        splitter.addWidget(self.configContent)
@@ -392,6 +406,18 @@ class ConfigPanel(Widget):
    def on_uppercase_changed(self):
        self.config.let_uppercase_flag = self.let_uppercase_checker.isChecked()

    def on_selectext_minimenu_changed(self):
        self.config.textselect_mini_menu = self.selectext_minimenu_checker.isChecked()

    def on_saladict_shortcut_changed(self):
        kstr = self.saladict_shortcut.keySequence().toString()
        if kstr:
            self.config.saladict_shortcut = self.saladict_shortcut.keySequence().toString()

    def on_searchurl_changed(self):
        url = self.searchurl_combobox.currentText()
        self.config.search_url = url

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

@@ -424,4 +450,22 @@ class ConfigPanel(Widget):
        self.save_config.emit()
        return super().hideEvent(e)
        
    
 No newline at end of file
    def setupConfig(self):
        self.blockSignals(True)

        config = self.config
        if config.open_recent_on_startup:
            self.open_on_startup_checker.setChecked(True)

        self.let_effect_combox.setCurrentIndex(config.let_fnteffect_flag)
        self.let_fntsize_combox.setCurrentIndex(config.let_fntsize_flag)
        self.let_fntstroke_combox.setCurrentIndex(config.let_fntstroke_flag)
        self.let_fntcolor_combox.setCurrentIndex(config.let_fntcolor_flag)
        self.let_alignment_combox.setCurrentIndex(config.let_alignment_flag)
        self.let_autolayout_checker.setChecked(config.let_autolayout_flag)
        self.selectext_minimenu_checker.setChecked(config.textselect_mini_menu)
        self.let_uppercase_checker.setChecked(config.let_uppercase_flag)
        self.saladict_shortcut.setKeySequence(config.saladict_shortcut)
        self.searchurl_combobox.setCurrentText(config.search_url)

        self.blockSignals(False)
 No newline at end of file
+5 −1
Original line number Diff line number Diff line
@@ -93,7 +93,11 @@ class ParamWidget(QWidget):
            elif isinstance(params[param_key], dict):
                param_dict = params[param_key]
                if param_dict['type'] == 'selector':
                    param_widget = ParamComboBox(param_key, param_dict['options'])
                    if 'url' in param_key:
                        size = CONFIG_COMBOBOX_MIDEAN
                    else:
                        size = CONFIG_COMBOBOX_SHORT
                    param_widget = ParamComboBox(param_key, param_dict['options'], size=size)

                    # if cuda is not available, disable combobox 'cuda' item
                    # https://stackoverflow.com/questions/38915001/disable-specific-items-in-qcombobox
+28 −31
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ from .imgtrans_proj import ProjImgTrans
from .canvas import Canvas
from .configpanel import ConfigPanel
from .dl_manager import DLManager
from .textedit_area import TextPanel, SourceTextEdit
from .textedit_area import TextPanel, SourceTextEdit, SelectTextMiniMenu
from .drawingpanel import DrawingPanel
from .scenetext_manager import SceneTextManager
from .mainwindowbars import TitleBar, LeftBar, BottomBar
@@ -67,6 +67,8 @@ class MainWindow(FramelessWindow):
        self.imgtrans_progress_msgbox.setStyleSheet(styleSheet)
        self.export_doc_thread.progress_bar.setStyleSheet(styleSheet)
        self.import_doc_thread.progress_bar.setStyleSheet(styleSheet)
        # sel_menu_size = self.selectext_minimenu.sizeHint()
        # self.selectext_minimenu.setFixedWidth(sel_menu_size.width())
        return super().setStyleSheet(styleSheet)

    def setupThread(self):
@@ -149,7 +151,7 @@ class MainWindow(FramelessWindow):
        self.presetPanel.hide()
        self.presetPanel.hide_signal.connect(self.save_config)
        self.presetPanel.load_preset.connect(self.textPanel.formatpanel.on_load_preset)
        self.st_manager = SceneTextManager(self.app, self.canvas, self.textPanel)
        self.st_manager = SceneTextManager(self.app, self, self.canvas, self.textPanel)
        self.st_manager.new_textblk.connect(self.canvas.search_widget.on_new_textblk)
        self.canvas.search_widget.pairwidget_list = self.st_manager.pairwidget_list
        self.canvas.search_widget.textblk_item_list = self.st_manager.textblk_item_list
@@ -171,6 +173,9 @@ class MainWindow(FramelessWindow):
        self.centralStackWidget.addWidget(self.comicTransSplitter)
        self.centralStackWidget.addWidget(self.configPanel)

        self.selectext_minimenu = self.st_manager.selectext_minimenu = SelectTextMiniMenu(self.app, self.configPanel.config, self)
        self.selectext_minimenu.block_current_editor.connect(self.st_manager.on_block_current_editor)
        self.selectext_minimenu.hide()

        mainVBoxLayout = QVBoxLayout(self)
        mainVBoxLayout.addWidget(self.titleBar)
@@ -186,21 +191,23 @@ class MainWindow(FramelessWindow):

    def setupConfig(self):

        self.bottomBar.originalSlider.setValue(int(self.config.original_transparency * 100))
        self.drawingPanel.maskTransperancySlider.setValue(int(self.config.mask_transparency * 100))
        self.leftBar.initRecentProjMenu(self.config.recent_proj_list)
        config = self.st_manager.config = self.config

        self.bottomBar.originalSlider.setValue(int(config.original_transparency * 100))
        self.drawingPanel.maskTransperancySlider.setValue(int(config.mask_transparency * 100))
        self.leftBar.initRecentProjMenu(config.recent_proj_list)
        self.leftBar.save_config.connect(self.save_config)
        self.leftBar.imgTransChecker.setChecked(True)
        self.st_manager.formatpanel.global_format = self.config.global_fontformat
        self.st_manager.formatpanel.set_active_format(self.config.global_fontformat)
        self.st_manager.formatpanel.global_format = config.global_fontformat
        self.st_manager.formatpanel.set_active_format(config.global_fontformat)
        
        self.rightComicTransStackPanel.setHidden(True)
        self.st_manager.setTextEditMode(False)

        self.bottomBar.ocrChecker.setCheckState(self.config.dl.enable_ocr)
        self.bottomBar.transChecker.setChecked(self.config.dl.enable_translate)
        self.bottomBar.ocrChecker.setCheckState(config.dl.enable_ocr)
        self.bottomBar.transChecker.setChecked(config.dl.enable_translate)

        self.dl_manager = dl_manager = DLManager(self.config, self.imgtrans_proj)
        self.dl_manager = dl_manager = DLManager(config, self.imgtrans_proj)
        dl_manager.update_translator_status.connect(self.updateTranslatorStatus)
        dl_manager.update_inpainter_status.connect(self.updateInpainterStatus)
        dl_manager.finish_translate_page.connect(self.finishTranslatePage)
@@ -219,41 +226,31 @@ class MainWindow(FramelessWindow):
        self.bottomBar.translatorStatusbtn.clicked.connect(self.translatorStatusBtnPressed)
        self.bottomBar.transTranspageBtn.run_target.connect(self.on_transpagebtn_pressed)

        self.titleBar.darkModeAction.setChecked(self.config.darkmode)
        self.titleBar.darkModeAction.setChecked(config.darkmode)

        self.drawingPanel.set_config(self.config.drawpanel)
        self.drawingPanel.set_config(config.drawpanel)
        self.drawingPanel.initDLModule(dl_manager)

        self.st_manager.config = self.config
        
        self.global_search_widget.imgtrans_proj = self.imgtrans_proj
        self.global_search_widget.setupReplaceThread(self.st_manager.pairwidget_list, self.st_manager.textblk_item_list)
        self.global_search_widget.replace_thread.finished.connect(self.on_global_replace_finished)

        self.configPanel.blockSignals(True)
        if self.config.open_recent_on_startup:
            self.configPanel.open_on_startup_checker.setChecked(True)
        self.configPanel.let_effect_combox.setCurrentIndex(self.config.let_fnteffect_flag)
        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)
        self.configPanel.let_alignment_combox.setCurrentIndex(self.config.let_alignment_flag)
        self.configPanel.let_autolayout_checker.setChecked(self.config.let_autolayout_flag)
        self.configPanel.let_uppercase_checker.setChecked(self.config.let_uppercase_flag)
        self.configPanel.setupConfig()
        self.configPanel.save_config.connect(self.save_config)
        self.configPanel.blockSignals(False)

        textblock_mode = self.config.imgtrans_textblock
        if self.config.imgtrans_textedit:
        textblock_mode = config.imgtrans_textblock
        if config.imgtrans_textedit:
            if textblock_mode:
                self.bottomBar.textblockChecker.setChecked(True)
            self.bottomBar.texteditChecker.click()
        elif self.config.imgtrans_paintmode:
        elif config.imgtrans_paintmode:
            self.bottomBar.paintChecker.click()

        self.presetPanel.initPresets(self.config.font_presets)
        self.presetPanel.initPresets(config.font_presets)

        self.canvas.search_widget.set_config(self.config)
        self.global_search_widget.set_config(self.config)
        self.canvas.search_widget.set_config(config)
        self.global_search_widget.set_config(config)

        if self.rightComicTransStackPanel.isHidden():
            self.setPaintMode()
Loading