|
|
|
|
@ -22,6 +22,7 @@ from ui.calendar_widget import CalendarWidget
|
|
|
|
|
from ui.weather_floating_widget import WeatherFloatingWidget
|
|
|
|
|
from ui.quote_floating_widget import QuoteFloatingWidget
|
|
|
|
|
from ui.calendar_floating_widget import CalendarFloatingWidget
|
|
|
|
|
from ui.ai_chat_panel import AIChatPanel
|
|
|
|
|
|
|
|
|
|
# 导入主题管理器
|
|
|
|
|
from ui.theme_manager import theme_manager
|
|
|
|
|
@ -359,7 +360,7 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
# 更新日历组件样式
|
|
|
|
|
if hasattr(self, 'calendar_widget') and self.calendar_widget is not None:
|
|
|
|
|
# 日历组件有自己的主题管理机制,只需触发其主题更新
|
|
|
|
|
self.calendar_widget.apply_theme()
|
|
|
|
|
self.calendar_widget.apply_theme(is_dark)
|
|
|
|
|
|
|
|
|
|
def update_ribbon_styles(self, is_dark):
|
|
|
|
|
"""更新功能区样式"""
|
|
|
|
|
@ -461,6 +462,12 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
def on_city_changed(self, city):
|
|
|
|
|
"""城市选择变化处理"""
|
|
|
|
|
print(f"城市选择变化: {city}")
|
|
|
|
|
# 同步Ribbon和天气悬浮窗口的城市选择
|
|
|
|
|
if hasattr(self, 'ribbon') and hasattr(self.ribbon, 'city_combo'):
|
|
|
|
|
self.ribbon.city_combo.setCurrentText(city)
|
|
|
|
|
if hasattr(self, 'weather_floating_widget') and hasattr(self.weather_floating_widget, 'city_combo'):
|
|
|
|
|
self.weather_floating_widget.city_combo.setCurrentText(city)
|
|
|
|
|
|
|
|
|
|
if city == '自动定位':
|
|
|
|
|
self.refresh_weather() # 重新自动定位
|
|
|
|
|
else:
|
|
|
|
|
@ -572,82 +579,82 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
self.menubar = menubar # 保存为实例变量以便后续样式更新
|
|
|
|
|
|
|
|
|
|
# 文件菜单
|
|
|
|
|
file_menu = menubar.addMenu('文件(F)')
|
|
|
|
|
file_menu = menubar.addMenu('文件操作')
|
|
|
|
|
self.file_menu = file_menu # 保存为实例变量
|
|
|
|
|
|
|
|
|
|
# 新建
|
|
|
|
|
new_action = QAction('新建(N)', self)
|
|
|
|
|
new_action = QAction('新建文档', self)
|
|
|
|
|
new_action.setShortcut('Ctrl+N')
|
|
|
|
|
new_action.triggered.connect(self.new_document)
|
|
|
|
|
file_menu.addAction(new_action)
|
|
|
|
|
|
|
|
|
|
# 导入文件 - 改为导入功能
|
|
|
|
|
open_action = QAction('导入文件(I)...', self)
|
|
|
|
|
open_action = QAction('导入文本文件...', self)
|
|
|
|
|
open_action.setShortcut('Ctrl+O')
|
|
|
|
|
open_action.triggered.connect(self.import_file)
|
|
|
|
|
file_menu.addAction(open_action)
|
|
|
|
|
|
|
|
|
|
# 保存
|
|
|
|
|
save_action = QAction('保存(S)', self)
|
|
|
|
|
save_action = QAction('保存文档', self)
|
|
|
|
|
save_action.setShortcut('Ctrl+S')
|
|
|
|
|
save_action.triggered.connect(self.save_file)
|
|
|
|
|
file_menu.addAction(save_action)
|
|
|
|
|
|
|
|
|
|
# 另存为
|
|
|
|
|
save_as_action = QAction('另存为(A)...', self)
|
|
|
|
|
save_as_action = QAction('另存为...', self)
|
|
|
|
|
save_as_action.triggered.connect(self.save_as_file)
|
|
|
|
|
file_menu.addAction(save_as_action)
|
|
|
|
|
|
|
|
|
|
file_menu.addSeparator()
|
|
|
|
|
|
|
|
|
|
# 退出
|
|
|
|
|
exit_action = QAction('退出(X)', self)
|
|
|
|
|
exit_action = QAction('退出程序', self)
|
|
|
|
|
exit_action.triggered.connect(self.close)
|
|
|
|
|
file_menu.addAction(exit_action)
|
|
|
|
|
|
|
|
|
|
# 开始菜单
|
|
|
|
|
start_menu = menubar.addMenu('开始(S)')
|
|
|
|
|
start_menu.setObjectName("startMenu")
|
|
|
|
|
self.start_menu = start_menu # 保存为实例变量
|
|
|
|
|
# 编辑菜单
|
|
|
|
|
edit_menu = menubar.addMenu('编辑操作')
|
|
|
|
|
edit_menu.setObjectName("editMenu")
|
|
|
|
|
self.start_menu = edit_menu # 保存为实例变量
|
|
|
|
|
|
|
|
|
|
# 撤销
|
|
|
|
|
undo_action = QAction('撤销(U)', self)
|
|
|
|
|
undo_action = QAction('撤销操作', self)
|
|
|
|
|
undo_action.setShortcut('Ctrl+Z')
|
|
|
|
|
undo_action.triggered.connect(self.undo)
|
|
|
|
|
start_menu.addAction(undo_action)
|
|
|
|
|
edit_menu.addAction(undo_action)
|
|
|
|
|
|
|
|
|
|
# 重做
|
|
|
|
|
redo_action = QAction('重做(R)', self)
|
|
|
|
|
redo_action = QAction('重做操作', self)
|
|
|
|
|
redo_action.setShortcut('Ctrl+Y')
|
|
|
|
|
redo_action.triggered.connect(self.redo)
|
|
|
|
|
start_menu.addAction(redo_action)
|
|
|
|
|
edit_menu.addAction(redo_action)
|
|
|
|
|
|
|
|
|
|
start_menu.addSeparator()
|
|
|
|
|
edit_menu.addSeparator()
|
|
|
|
|
|
|
|
|
|
# 剪切
|
|
|
|
|
cut_action = QAction('剪切(T)', self)
|
|
|
|
|
cut_action = QAction('剪切内容', self)
|
|
|
|
|
cut_action.setShortcut('Ctrl+X')
|
|
|
|
|
cut_action.triggered.connect(self.cut)
|
|
|
|
|
start_menu.addAction(cut_action)
|
|
|
|
|
edit_menu.addAction(cut_action)
|
|
|
|
|
|
|
|
|
|
# 复制
|
|
|
|
|
copy_action = QAction('复制(C)', self)
|
|
|
|
|
copy_action = QAction('复制内容', self)
|
|
|
|
|
copy_action.setShortcut('Ctrl+C')
|
|
|
|
|
copy_action.triggered.connect(self.copy)
|
|
|
|
|
start_menu.addAction(copy_action)
|
|
|
|
|
edit_menu.addAction(copy_action)
|
|
|
|
|
|
|
|
|
|
# 粘贴
|
|
|
|
|
paste_action = QAction('粘贴(P)', self)
|
|
|
|
|
paste_action = QAction('粘贴内容', self)
|
|
|
|
|
paste_action.setShortcut('Ctrl+V')
|
|
|
|
|
paste_action.triggered.connect(self.paste)
|
|
|
|
|
start_menu.addAction(paste_action)
|
|
|
|
|
edit_menu.addAction(paste_action)
|
|
|
|
|
|
|
|
|
|
# 视图菜单
|
|
|
|
|
view_menu = menubar.addMenu('视图(V)')
|
|
|
|
|
view_menu = menubar.addMenu('视图设置')
|
|
|
|
|
self.view_menu = view_menu # 保存为实例变量
|
|
|
|
|
|
|
|
|
|
# 阅读视图
|
|
|
|
|
read_view_action = QAction('阅读视图', self)
|
|
|
|
|
read_view_action = QAction('切换到阅读视图', self)
|
|
|
|
|
read_view_action.triggered.connect(self.toggle_reading_view)
|
|
|
|
|
view_menu.addAction(read_view_action)
|
|
|
|
|
|
|
|
|
|
@ -660,18 +667,18 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
|
|
|
|
|
view_menu.addSeparator()
|
|
|
|
|
|
|
|
|
|
# 模式选择子菜单
|
|
|
|
|
theme_menu = view_menu.addMenu('模式')
|
|
|
|
|
# 主题模式选择
|
|
|
|
|
theme_menu = view_menu.addMenu('主题模式')
|
|
|
|
|
|
|
|
|
|
# 白色模式
|
|
|
|
|
self.light_mode_action = QAction('白色模式', self)
|
|
|
|
|
self.light_mode_action = QAction('浅色主题', self)
|
|
|
|
|
self.light_mode_action.setCheckable(True)
|
|
|
|
|
self.light_mode_action.setChecked(not theme_manager.is_dark_theme()) # 根据当前主题设置
|
|
|
|
|
self.light_mode_action.triggered.connect(self.set_light_mode)
|
|
|
|
|
theme_menu.addAction(self.light_mode_action)
|
|
|
|
|
|
|
|
|
|
# 黑色模式
|
|
|
|
|
self.dark_mode_action = QAction('黑色模式', self)
|
|
|
|
|
self.dark_mode_action = QAction('深色主题', self)
|
|
|
|
|
self.dark_mode_action.setCheckable(True)
|
|
|
|
|
self.dark_mode_action.setChecked(theme_manager.is_dark_theme()) # 根据当前主题设置
|
|
|
|
|
self.dark_mode_action.triggered.connect(self.set_dark_mode)
|
|
|
|
|
@ -679,56 +686,56 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
|
|
|
|
|
view_menu.addSeparator()
|
|
|
|
|
|
|
|
|
|
# 视图模式选择
|
|
|
|
|
view_mode_menu = view_menu.addMenu('视图模式')
|
|
|
|
|
# 工作模式选择
|
|
|
|
|
work_mode_menu = view_menu.addMenu('工作模式')
|
|
|
|
|
|
|
|
|
|
# 打字模式
|
|
|
|
|
self.typing_mode_action = QAction('打字模式', self)
|
|
|
|
|
self.typing_mode_action = QAction('打字练习模式', self)
|
|
|
|
|
self.typing_mode_action.setCheckable(True)
|
|
|
|
|
self.typing_mode_action.setChecked(True) # 默认打字模式
|
|
|
|
|
self.typing_mode_action.triggered.connect(lambda: self.set_view_mode("typing"))
|
|
|
|
|
view_mode_menu.addAction(self.typing_mode_action)
|
|
|
|
|
work_mode_menu.addAction(self.typing_mode_action)
|
|
|
|
|
|
|
|
|
|
# 学习模式
|
|
|
|
|
self.learning_mode_action = QAction('学习模式', self)
|
|
|
|
|
self.learning_mode_action = QAction('学习记忆模式', self)
|
|
|
|
|
self.learning_mode_action.setCheckable(True)
|
|
|
|
|
self.learning_mode_action.setChecked(False)
|
|
|
|
|
# 设置学习模式快捷键 (Qt会自动在macOS上映射Ctrl为Cmd)
|
|
|
|
|
self.learning_mode_action.setShortcut('Ctrl+L')
|
|
|
|
|
self.learning_mode_action.triggered.connect(lambda: self.set_view_mode("learning"))
|
|
|
|
|
view_mode_menu.addAction(self.learning_mode_action)
|
|
|
|
|
work_mode_menu.addAction(self.learning_mode_action)
|
|
|
|
|
|
|
|
|
|
view_menu.addSeparator()
|
|
|
|
|
|
|
|
|
|
# 附加工具功能
|
|
|
|
|
weather_menu = view_menu.addMenu('附加工具')
|
|
|
|
|
tools_menu = view_menu.addMenu('实用工具')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 刷新天气
|
|
|
|
|
refresh_weather_action = QAction('刷新天气', self)
|
|
|
|
|
refresh_weather_action.setShortcut('F5')
|
|
|
|
|
refresh_weather_action.triggered.connect(self.refresh_weather)
|
|
|
|
|
weather_menu.addAction(refresh_weather_action)
|
|
|
|
|
tools_menu.addAction(refresh_weather_action)
|
|
|
|
|
|
|
|
|
|
# 显示详细天气
|
|
|
|
|
show_weather_action = QAction('显示详细天气', self)
|
|
|
|
|
show_weather_action.triggered.connect(self.show_detailed_weather)
|
|
|
|
|
weather_menu.addAction(show_weather_action)
|
|
|
|
|
tools_menu.addAction(show_weather_action)
|
|
|
|
|
|
|
|
|
|
# 天气悬浮窗口
|
|
|
|
|
toggle_floating_weather_action = QAction('天气悬浮窗口', self)
|
|
|
|
|
toggle_floating_weather_action.triggered.connect(self.toggle_floating_weather)
|
|
|
|
|
weather_menu.addAction(toggle_floating_weather_action)
|
|
|
|
|
tools_menu.addAction(toggle_floating_weather_action)
|
|
|
|
|
|
|
|
|
|
# 每日谏言悬浮窗口切换动作
|
|
|
|
|
toggle_floating_quote_action = QAction('每日谏言悬浮窗口', self)
|
|
|
|
|
toggle_floating_quote_action.triggered.connect(self.toggle_floating_quote)
|
|
|
|
|
weather_menu.addAction(toggle_floating_quote_action)
|
|
|
|
|
tools_menu.addAction(toggle_floating_quote_action)
|
|
|
|
|
|
|
|
|
|
# 日历悬浮窗口切换动作
|
|
|
|
|
toggle_floating_calendar_action = QAction('日历悬浮窗口', self)
|
|
|
|
|
toggle_floating_calendar_action.triggered.connect(self.toggle_floating_calendar)
|
|
|
|
|
weather_menu.addAction(toggle_floating_calendar_action)
|
|
|
|
|
tools_menu.addAction(toggle_floating_calendar_action)
|
|
|
|
|
# 插入菜单
|
|
|
|
|
insert_menu = menubar.addMenu('插入(I)')
|
|
|
|
|
|
|
|
|
|
@ -786,29 +793,17 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
export_docx_action.triggered.connect(self.export_as_docx)
|
|
|
|
|
export_menu.addAction(export_docx_action)
|
|
|
|
|
|
|
|
|
|
# 布局菜单
|
|
|
|
|
layout_menu = menubar.addMenu('布局(L)')
|
|
|
|
|
|
|
|
|
|
# 引用菜单
|
|
|
|
|
reference_menu = menubar.addMenu('引用(R)')
|
|
|
|
|
reference_menu = menubar.addMenu('AI功能')
|
|
|
|
|
|
|
|
|
|
# DeepSeek AI对话功能
|
|
|
|
|
self.deepseek_dialog_action = QAction('DeepSeek AI对话', self)
|
|
|
|
|
self.deepseek_dialog_action = QAction('AI智能对话', self)
|
|
|
|
|
self.deepseek_dialog_action.setShortcut('Ctrl+D')
|
|
|
|
|
self.deepseek_dialog_action.triggered.connect(self.open_deepseek_dialog)
|
|
|
|
|
reference_menu.addAction(self.deepseek_dialog_action)
|
|
|
|
|
|
|
|
|
|
# 邮件菜单
|
|
|
|
|
mail_menu = menubar.addMenu('邮件(M)')
|
|
|
|
|
|
|
|
|
|
# 审阅菜单
|
|
|
|
|
review_menu = menubar.addMenu('审阅(W)')
|
|
|
|
|
|
|
|
|
|
# 开发工具菜单
|
|
|
|
|
developer_menu = menubar.addMenu('开发工具(Q)')
|
|
|
|
|
|
|
|
|
|
# 应用选项菜单
|
|
|
|
|
app_menu = menubar.addMenu('应用选项(O)')
|
|
|
|
|
app_menu = menubar.addMenu('应用选项')
|
|
|
|
|
|
|
|
|
|
# 小游戏子菜单
|
|
|
|
|
games_menu = app_menu.addMenu('小游戏')
|
|
|
|
|
@ -824,7 +819,7 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
games_menu.addAction(minesweeper_game_action)
|
|
|
|
|
|
|
|
|
|
# 帮助菜单
|
|
|
|
|
help_menu = menubar.addMenu('帮助(H)')
|
|
|
|
|
help_menu = menubar.addMenu('帮助')
|
|
|
|
|
|
|
|
|
|
# 关于
|
|
|
|
|
about_action = QAction('关于 MagicWord', self)
|
|
|
|
|
@ -833,8 +828,12 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_document_area(self, main_layout):
|
|
|
|
|
"""创建文档编辑区域"""
|
|
|
|
|
"""创建文档编辑区域和AI对话面板"""
|
|
|
|
|
|
|
|
|
|
# 创建水平分割器
|
|
|
|
|
splitter = QSplitter(Qt.Horizontal)
|
|
|
|
|
|
|
|
|
|
# ========== 左侧:文档编辑区域 ==========
|
|
|
|
|
# 创建滚动区域
|
|
|
|
|
from PyQt5.QtWidgets import QScrollArea
|
|
|
|
|
|
|
|
|
|
@ -911,7 +910,22 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
document_container.setLayout(document_layout)
|
|
|
|
|
|
|
|
|
|
self.scroll_area.setWidget(document_container)
|
|
|
|
|
main_layout.addWidget(self.scroll_area)
|
|
|
|
|
|
|
|
|
|
# ========== 右侧:AI对话面板 ==========
|
|
|
|
|
self.ai_chat_panel = AIChatPanel()
|
|
|
|
|
self.ai_chat_panel.setMinimumWidth(320)
|
|
|
|
|
|
|
|
|
|
# 添加左右两部分到分割器
|
|
|
|
|
splitter.addWidget(self.scroll_area)
|
|
|
|
|
splitter.addWidget(self.ai_chat_panel)
|
|
|
|
|
|
|
|
|
|
# 设置分割器大小比例(文档区:对话区 = 70:30)
|
|
|
|
|
splitter.setSizes([700, 300])
|
|
|
|
|
splitter.setStretchFactor(0, 2) # 文档区可伸缩
|
|
|
|
|
splitter.setStretchFactor(1, 1) # 对话区可伸缩
|
|
|
|
|
|
|
|
|
|
# 添加分割器到主布局
|
|
|
|
|
main_layout.addWidget(splitter)
|
|
|
|
|
|
|
|
|
|
def init_network_services(self):
|
|
|
|
|
"""初始化网络服务"""
|
|
|
|
|
@ -925,6 +939,7 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
self.quote_thread.quote_fetched.connect(self.update_quote_display)
|
|
|
|
|
self.quote_thread.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init_typing_logic(self):
|
|
|
|
|
"""初始化打字逻辑"""
|
|
|
|
|
# 使用默认内容初始化打字逻辑
|
|
|
|
|
@ -964,6 +979,22 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
if hasattr(self.ribbon, 'body_text_btn'):
|
|
|
|
|
self.ribbon.body_text_btn.clicked.connect(self.on_body_text_clicked)
|
|
|
|
|
|
|
|
|
|
# 样式预览按钮信号
|
|
|
|
|
if hasattr(self.ribbon, 'body_text_preview_btn'):
|
|
|
|
|
self.ribbon.body_text_preview_btn.clicked.connect(self.on_body_text_clicked)
|
|
|
|
|
if hasattr(self.ribbon, 'no_spacing_preview_btn'):
|
|
|
|
|
self.ribbon.no_spacing_preview_btn.clicked.connect(self.on_no_spacing_clicked)
|
|
|
|
|
if hasattr(self.ribbon, 'heading1_preview_btn'):
|
|
|
|
|
self.ribbon.heading1_preview_btn.clicked.connect(self.on_heading1_clicked)
|
|
|
|
|
if hasattr(self.ribbon, 'heading2_preview_btn'):
|
|
|
|
|
self.ribbon.heading2_preview_btn.clicked.connect(self.on_heading2_clicked)
|
|
|
|
|
if hasattr(self.ribbon, 'heading3_preview_btn'):
|
|
|
|
|
self.ribbon.heading3_preview_btn.clicked.connect(self.on_heading3_clicked)
|
|
|
|
|
if hasattr(self.ribbon, 'subtitle_preview_btn'):
|
|
|
|
|
self.ribbon.subtitle_preview_btn.clicked.connect(self.on_subtitle_clicked)
|
|
|
|
|
if hasattr(self.ribbon, 'emphasis_preview_btn'):
|
|
|
|
|
self.ribbon.emphasis_preview_btn.clicked.connect(self.on_emphasis_clicked)
|
|
|
|
|
|
|
|
|
|
# 查找和替换按钮信号
|
|
|
|
|
if hasattr(self.ribbon, 'find_btn'):
|
|
|
|
|
self.ribbon.find_btn.clicked.connect(self.show_find_dialog)
|
|
|
|
|
@ -1472,6 +1503,18 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
"""正文按钮点击处理"""
|
|
|
|
|
self.apply_body_text_style()
|
|
|
|
|
|
|
|
|
|
def on_subtitle_clicked(self):
|
|
|
|
|
"""副标题按钮点击处理"""
|
|
|
|
|
self.apply_subtitle_style()
|
|
|
|
|
|
|
|
|
|
def on_emphasis_clicked(self):
|
|
|
|
|
"""强调按钮点击处理"""
|
|
|
|
|
self.apply_emphasis_style()
|
|
|
|
|
|
|
|
|
|
def on_no_spacing_clicked(self):
|
|
|
|
|
"""无间隔按钮点击处理"""
|
|
|
|
|
self.apply_no_spacing_style()
|
|
|
|
|
|
|
|
|
|
def on_align_left_clicked(self):
|
|
|
|
|
"""左对齐按钮点击处理"""
|
|
|
|
|
self.apply_alignment(Qt.AlignLeft)
|
|
|
|
|
@ -1579,6 +1622,84 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
self.text_edit.setCurrentCharFormat(char_format)
|
|
|
|
|
self.text_edit.textCursor().setBlockFormat(block_format)
|
|
|
|
|
|
|
|
|
|
def apply_subtitle_style(self):
|
|
|
|
|
"""应用副标题样式"""
|
|
|
|
|
cursor = self.text_edit.textCursor()
|
|
|
|
|
|
|
|
|
|
# 创建字符格式
|
|
|
|
|
char_format = QTextCharFormat()
|
|
|
|
|
char_format.setFontPointSize(16) # 副标题字号
|
|
|
|
|
char_format.setFontWeight(QFont.Bold) # 加粗
|
|
|
|
|
char_format.setFontItalic(True) # 斜体
|
|
|
|
|
|
|
|
|
|
# 创建块格式(段落格式)
|
|
|
|
|
block_format = QTextBlockFormat()
|
|
|
|
|
block_format.setTopMargin(12)
|
|
|
|
|
block_format.setBottomMargin(8)
|
|
|
|
|
|
|
|
|
|
# 应用格式
|
|
|
|
|
if cursor.hasSelection():
|
|
|
|
|
# 如果有选中文本,只更改选中文本的格式
|
|
|
|
|
cursor.mergeCharFormat(char_format)
|
|
|
|
|
else:
|
|
|
|
|
# 如果没有选中文本,更改当前段落的格式
|
|
|
|
|
cursor.setBlockFormat(block_format)
|
|
|
|
|
cursor.mergeCharFormat(char_format)
|
|
|
|
|
# 将光标移动到段落末尾并添加换行
|
|
|
|
|
cursor.movePosition(QTextCursor.EndOfBlock)
|
|
|
|
|
cursor.insertText("\n")
|
|
|
|
|
|
|
|
|
|
# 设置文本编辑器的默认格式
|
|
|
|
|
self.text_edit.setCurrentCharFormat(char_format)
|
|
|
|
|
self.text_edit.textCursor().setBlockFormat(block_format)
|
|
|
|
|
|
|
|
|
|
def apply_emphasis_style(self):
|
|
|
|
|
"""应用强调样式"""
|
|
|
|
|
cursor = self.text_edit.textCursor()
|
|
|
|
|
|
|
|
|
|
# 创建字符格式
|
|
|
|
|
char_format = QTextCharFormat()
|
|
|
|
|
char_format.setFontPointSize(12) # 正文字号
|
|
|
|
|
char_format.setFontWeight(QFont.Bold) # 加粗
|
|
|
|
|
char_format.setFontItalic(True) # 斜体
|
|
|
|
|
char_format.setForeground(QColor(0, 0, 128)) # 深蓝色
|
|
|
|
|
|
|
|
|
|
# 应用格式(只影响字符格式,不影响段落格式)
|
|
|
|
|
if cursor.hasSelection():
|
|
|
|
|
# 如果有选中文本,只更改选中文本的格式
|
|
|
|
|
cursor.mergeCharFormat(char_format)
|
|
|
|
|
else:
|
|
|
|
|
# 如果没有选中文本,设置默认字符格式供后续输入使用
|
|
|
|
|
self.text_edit.setCurrentCharFormat(char_format)
|
|
|
|
|
|
|
|
|
|
def apply_no_spacing_style(self):
|
|
|
|
|
"""应用无间隔样式"""
|
|
|
|
|
cursor = self.text_edit.textCursor()
|
|
|
|
|
|
|
|
|
|
# 创建字符格式
|
|
|
|
|
char_format = QTextCharFormat()
|
|
|
|
|
char_format.setFontPointSize(12) # 正文字号
|
|
|
|
|
char_format.setFontWeight(QFont.Normal) # 正常粗细
|
|
|
|
|
|
|
|
|
|
# 创建块格式(段落格式)
|
|
|
|
|
block_format = QTextBlockFormat()
|
|
|
|
|
block_format.setTopMargin(0) # 无上边距
|
|
|
|
|
block_format.setBottomMargin(0) # 无下边距
|
|
|
|
|
block_format.setLineHeight(100, QTextBlockFormat.SingleHeight) # 行高100%,无额外间距
|
|
|
|
|
|
|
|
|
|
# 应用格式
|
|
|
|
|
if cursor.hasSelection():
|
|
|
|
|
# 如果有选中文本,只更改选中文本的格式
|
|
|
|
|
cursor.mergeCharFormat(char_format)
|
|
|
|
|
else:
|
|
|
|
|
# 如果没有选中文本,更改当前段落的格式
|
|
|
|
|
cursor.setBlockFormat(block_format)
|
|
|
|
|
cursor.mergeCharFormat(char_format)
|
|
|
|
|
|
|
|
|
|
# 设置文本编辑器的默认格式
|
|
|
|
|
self.text_edit.setCurrentCharFormat(char_format)
|
|
|
|
|
self.text_edit.textCursor().setBlockFormat(block_format)
|
|
|
|
|
|
|
|
|
|
def apply_alignment(self, alignment):
|
|
|
|
|
"""应用段落对齐方式"""
|
|
|
|
|
cursor = self.text_edit.textCursor()
|
|
|
|
|
@ -1819,6 +1940,9 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
# 如果有天气数据,更新显示
|
|
|
|
|
if hasattr(self, 'current_weather_data') and self.current_weather_data:
|
|
|
|
|
self.weather_floating_widget.update_weather(self.current_weather_data)
|
|
|
|
|
# 刷新天气数据以确保显示最新信息
|
|
|
|
|
else:
|
|
|
|
|
self.refresh_weather()
|
|
|
|
|
|
|
|
|
|
def on_weather_floating_closed(self):
|
|
|
|
|
"""天气悬浮窗口关闭时的处理"""
|
|
|
|
|
|