Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion comic_translate_desktop/ui/api_config_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from comic_translate_core.languages import SOURCE_LANGUAGES
from .advanced_config import AdvancedConfigSection
from .manga_components import PanelHeading
from .motion import set_reduced_motion
from .motion import install_tab_motion, set_reduced_motion
from .theme import apply_theme


Expand All @@ -49,6 +49,7 @@ def __init__(self, config: dict, parent=None):
self._sections = QTabWidget()
self._sections.setDocumentMode(True)
self._sections.setAccessibleName(tr('设置分类'))
install_tab_motion(self._sections)
body_layout.addWidget(self._sections)
outer.addWidget(body, 1)
root = self._add_section(tr('01 翻译服务'), tr('连接你的翻译服务'), tr('配置接口、翻译方式和输出水印,保存后将在下一次任务生效。'))
Expand Down
112 changes: 103 additions & 9 deletions comic_translate_desktop/ui/editor_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import OrderedDict
from copy import deepcopy
from pathlib import Path
from PySide6.QtCore import Qt, QRect, QSize, QSettings, QTimer, QEvent, QPoint
from PySide6.QtCore import Qt, QRect, QSize, QSettings, QTimer, QEvent, QPoint, QVariantAnimation
from PySide6.QtGui import QColor, QFont, QPainter, QPixmap, QIcon, QImageReader, QShortcut, QKeySequence
from PySide6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QFrame, QLabel, QListWidget, QListWidgetItem, QPushButton, QScrollArea, QSplitter, QComboBox, QSpinBox, QDoubleSpinBox, QPlainTextEdit, QFileDialog, QMessageBox, QSizePolicy, QTabWidget, QCheckBox, QToolButton, QApplication, QLineEdit, QTextEdit, QAbstractSpinBox, QAbstractButton, QAbstractItemView, QStyledItemDelegate, QStyle)
from ..config import load_ai_config, MAIN_DIR
Expand All @@ -26,6 +26,16 @@
from .thumbnail_loader import ThumbnailLoader
from .theme import color, set_themed_icon, ui_font
from .manga_components import PanelHeading
from .motion import (
STANDARD,
fade_in,
fade_out,
install_list_motion,
install_tab_motion,
play_reveal_overlay,
play_slide_overlay,
reduced_motion,
)
from .searchable_combo import SearchableFontCombo
from .favorite_fonts import FavoriteFontBar
from .tool_flow import ToolFlowLayout
Expand Down Expand Up @@ -335,7 +345,7 @@ def _build_ui(self):
self._zoom.setInsertPolicy(QComboBox.NoInsert)
self._zoom.lineEdit().setReadOnly(True)
self._zoom.lineEdit().setAlignment(Qt.AlignCenter)
self._zoom.setMinimumWidth(88)
self._zoom.setMinimumWidth(116)
self._zoom.setToolTip(tr('缩放:Alt+滚轮以光标为中心,空格+拖动平移;Ctrl+0/1/2 适应页面/100%/适应宽度'))
toolbar.addWidget(self._zoom)
self._zoom_in_btn = QPushButton()
Expand Down Expand Up @@ -421,6 +431,7 @@ def _build_ui(self):
self.page_list.setTextElideMode(Qt.ElideMiddle)
self.page_list.currentItemChanged.connect(self._select_page)
self.page_list.itemSelectionChanged.connect(self._update_repair_controls)
install_list_motion(self.page_list)
left.addWidget(self.page_list, 1)
sidebar_footer = QFrame()
sidebar_footer.setObjectName('sidebarFooter')
Expand Down Expand Up @@ -470,7 +481,7 @@ def _build_ui(self):
self._zoom_hud_timer = QTimer(self)
self._zoom_hud_timer.setSingleShot(True)
self._zoom_hud_timer.setInterval(900)
self._zoom_hud_timer.timeout.connect(self._zoom_hud.hide)
self._zoom_hud_timer.timeout.connect(lambda: fade_out(self._zoom_hud, 160))

canvas_tools_frame = QFrame()
canvas_tools_frame.setObjectName('canvasToolBar')
Expand Down Expand Up @@ -600,8 +611,10 @@ def _build_ui(self):
self.block_list.setMouseTracking(True)
self.block_list.setItemDelegate(_BlockItemDelegate(self.block_list))
self.block_list.currentRowChanged.connect(self._load_properties)
install_list_motion(self.block_list)
self._inspector_tabs = QTabWidget()
self._inspector_tabs.setDocumentMode(True)
install_tab_motion(self._inspector_tabs)
self._inspector_splitter = QSplitter(Qt.Vertical)
self._inspector_splitter.setObjectName('inspectorSplitter')
self._inspector_splitter.setChildrenCollapsible(False)
Expand Down Expand Up @@ -634,6 +647,8 @@ def _build_ui(self):
self._source_text.setReadOnly(True)
self._source_text.setFixedHeight(92)
self._source_text.setFont(ui_font(japanese=True))
self._source_anim = None
self._source_anim_gen = 0
text_props.addWidget(self._source_text)
self._source_toggle.toggled.connect(self._toggle_source_text)
target_label = QLabel(tr('译文'))
Expand Down Expand Up @@ -963,7 +978,10 @@ def _sync_zoom_display(self, value):
self._zoom_hud.setText(text)
self._zoom_hud.adjustSize()
self._place_zoom_hud()
was_visible = self._zoom_hud.isVisible()
self._zoom_hud.show()
if not was_visible:
fade_in(self._zoom_hud, 110)
self._zoom_hud.raise_()
self._zoom_hud_timer.start()

Expand Down Expand Up @@ -1013,7 +1031,18 @@ def _apply_panel_layout(self):
button.blockSignals(True)
button.setChecked(effective[index])
button.blockSignals(False)
panel.setVisible(effective[index])
was_visible = panel.isVisible()
want_visible = effective[index]
if self.isVisible() and was_visible != want_visible:
edge = 'left' if index == 0 else 'right'
if want_visible:
panel.setVisible(True)
play_reveal_overlay(panel, edge=edge, duration=190)
else:
play_slide_overlay(panel, edge=edge, duration=160)
panel.setVisible(False)
else:
panel.setVisible(want_visible)
button.setToolTip(tr('窗口较窄时暂时收起;展开此栏会让出另一个侧栏的位置。')
if self._desired_panels[index] and not effective[index] and not focused else '')
if not compact and self._was_compact and not focused and self._wide_splitter_state is not None:
Expand All @@ -1024,12 +1053,28 @@ def _apply_panel_layout(self):
def _toggle_canvas_focus(self, focused):
if focused:
self._focus_splitter_state = self.splitter.saveState()
self._apply_panel_layout()
if not focused:
self._apply_panel_layout()
else:
self.splitter.restoreState(self._focus_splitter_state)
self._apply_panel_layout()
for widget in (self._canvas_heading, self._status, self._pages_toggle, self._properties_toggle):
widget.setVisible(not focused)
for widget, edge, slide_hide in (
(self._canvas_heading, 'top', True),
(self._status, 'bottom', True),
(self._pages_toggle, 'top', False),
(self._properties_toggle, 'top', False),
):
want_visible = not focused
was_visible = widget.isVisible()
if self.isVisible() and was_visible != want_visible:
if want_visible:
widget.setVisible(True)
play_reveal_overlay(widget, edge=edge, duration=155)
else:
if slide_hide:
play_slide_overlay(widget, edge=edge, duration=135)
widget.setVisible(False)
else:
widget.setVisible(want_visible)
self._update_toolbar_labels()

def _update_toolbar_labels(self):
Expand Down Expand Up @@ -1126,7 +1171,56 @@ def _apply_source_layout(self):
self._source_toggle.setChecked(expanded)
self._source_toggle.blockSignals(False)
self._source_toggle.setArrowType(Qt.DownArrow if expanded else Qt.RightArrow)
self._source_text.setVisible(expanded)
if getattr(self, '_source_anim', None) is not None:
self._source_anim.stop()
self._source_anim.deleteLater()
self._source_anim = None
self._source_anim_gen += 1
gen = self._source_anim_gen

if not self.isVisible() or reduced_motion():
self._source_text.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self._source_text.setFixedHeight(92 if expanded else 0)
self._source_text.setVisible(expanded)
return

was_visible = self._source_text.isVisible()
if was_visible == expanded and self._source_text.height() == (92 if expanded else 0):
return

start_h = self._source_text.height() if was_visible else 0
end_h = 92 if expanded else 0
self._source_text.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self._source_text.setVisible(True)
self._source_text.setFixedHeight(start_h)

anim = QVariantAnimation(self)
anim.setDuration(195 if expanded else 160)
anim.setStartValue(float(start_h))
anim.setEndValue(float(end_h))
anim.setEasingCurve(STANDARD)

def _on_val(val):
if gen != self._source_anim_gen:
return
self._source_text.setFixedHeight(max(0, int(round(float(val)))))

def _on_done():
if gen != self._source_anim_gen:
return
self._source_anim = None
self._source_text.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
if expanded:
self._source_text.setFixedHeight(92)
self._source_text.setVisible(True)
else:
self._source_text.setFixedHeight(0)
self._source_text.setVisible(False)

anim.valueChanged.connect(_on_val)
anim.finished.connect(_on_done)
self._source_anim = anim
anim.start()

def _set_editable(self, enabled):
restored = 0 <= self._loaded_row < len(self.items) and self.items[self._loaded_row].get('restore_original', False)
Expand Down
2 changes: 2 additions & 0 deletions comic_translate_desktop/ui/error_log_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ..ai_diagnosis import AiDiagnosis
from .theme import ui_font
from .manga_components import PanelHeading
from .motion import install_tab_motion


class DiagnosisWorker(QThread):
Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(self, diagnostics, parent=None):
self._sections.setAccessibleName(tr('诊断工作区'))
self._sections.addTab(self._build_prompt_panel(), tr('01 诊断资料'))
self._sections.addTab(self._build_ai_panel(), tr('02 AI 对话'))
install_tab_motion(self._sections)
content.addWidget(self._sections, 1)
content.addWidget(self._file_label)
root.addWidget(body, 1)
Expand Down
30 changes: 24 additions & 6 deletions comic_translate_desktop/ui/halftone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from math import ceil, hypot, sqrt

from PySide6.QtCore import QByteArray, QRectF, Qt
from PySide6.QtGui import QPainter, QPainterPath
from PySide6.QtGui import QPainter, QPainterPath, QPixmap
from PySide6.QtSvg import QSvgRenderer

from .theme import theme
Expand Down Expand Up @@ -78,28 +78,46 @@ def _renderer(width, height, compact, mask, profile, direction, dot_color):
return QSvgRenderer(QByteArray(halftone_svg(width, height, compact, mask, profile, direction, dot_color)))


@lru_cache(maxsize=96)
def _tone_pixmap(width, height, dpr_tenth, compact, mask, profile, direction, dot_color):
dpr = max(1.0, dpr_tenth / 10.0)
pix = QPixmap(max(1, round(width * dpr)), max(1, round(height * dpr)))
pix.fill(Qt.transparent)
pix.setDevicePixelRatio(dpr)
p = QPainter(pix)
_renderer(width, height, compact, mask, profile, direction, dot_color).render(
p, QRectF(0, 0, width, height)
)
p.end()
return pix


def draw_tone(painter, bounds, *, compact=False, mask='linear', profile='section', direction='left'):
if bounds.width() <= 0 or bounds.height() <= 0:
return
palette = theme()
renderer = _renderer(max(1, round(bounds.width())), max(1, round(bounds.height())),
compact, mask, profile, direction, palette['tone'])
w = max(1, round(bounds.width()))
h = max(1, round(bounds.height()))
dev = painter.device()
dpr = dev.devicePixelRatioF() if dev is not None and hasattr(dev, 'devicePixelRatioF') else 1.0
dpr_tenth = max(10, round(dpr * 10))
pix = _tone_pixmap(w, h, dpr_tenth, compact, mask, profile, direction, palette['tone'])
painter.save()
if palette['toneBlend'] == 'multiply':
# QWidget 中用 Qt 的对应混合模式实现 SVG 的 mix-blend-mode: multiply。
painter.setCompositionMode(QPainter.CompositionMode_Multiply)
else:
painter.setOpacity(palette['toneAlpha'])
renderer.render(painter, bounds)
painter.drawPixmap(bounds, pix, QRectF(0, 0, pix.width(), pix.height()))
painter.restore()


def draw_corner_tones(painter, bounds, *, compact=False):
"""Small page-edge accents; keep the central reading area open."""
if bounds.width() < 320 or bounds.height() < 150:
return
width = min(192, bounds.width() * .24)
height = min(112, bounds.height() * .28)
width = max(16, round(min(192, bounds.width() * .24) / 8) * 8)
height = max(16, round(min(112, bounds.height() * .28) / 8) * 8)
painter.save()
painter.setRenderHint(QPainter.Antialiasing)
painter.setOpacity(.3 if theme()['toneBlend'] == 'multiply' else 1.0)
Expand Down
Loading
Loading