Merge pull request 'UI-fix' (#23) from main into mamingyi
commit
81e849f281
@ -0,0 +1,371 @@
|
||||
# word_style_ui.py
|
||||
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QLabel,
|
||||
QPushButton, QTabWidget, QFrame, QTextEdit,
|
||||
QToolButton, QMenuBar, QStatusBar, QGroupBox,
|
||||
QComboBox, QSpinBox, QFontComboBox, QToolBar)
|
||||
from PyQt5.QtCore import Qt, QSize
|
||||
from PyQt5.QtGui import QFont, QIcon, QPalette, QColor
|
||||
|
||||
class WordRibbonTab(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
layout = QHBoxLayout()
|
||||
layout.setSpacing(10)
|
||||
layout.setContentsMargins(10, 5, 10, 5)
|
||||
self.setLayout(layout)
|
||||
|
||||
class WordRibbon(QFrame):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
self.setFrameStyle(QFrame.NoFrame)
|
||||
self.setFixedHeight(120)
|
||||
|
||||
# 主布局
|
||||
main_layout = QVBoxLayout()
|
||||
main_layout.setContentsMargins(0, 0, 0, 0)
|
||||
main_layout.setSpacing(0)
|
||||
|
||||
# 标签栏
|
||||
self.tab_bar = QWidget()
|
||||
self.tab_bar.setFixedHeight(25)
|
||||
self.tab_bar.setStyleSheet("""
|
||||
QWidget {
|
||||
background-color: #f3f2f1;
|
||||
border-bottom: 1px solid #e1e1e1;
|
||||
}
|
||||
""")
|
||||
|
||||
tab_layout = QHBoxLayout()
|
||||
tab_layout.setContentsMargins(10, 0, 0, 0)
|
||||
tab_layout.setSpacing(0)
|
||||
|
||||
# 创建标签按钮
|
||||
self.tabs = {}
|
||||
tab_names = ['文件', '开始', '插入', '设计', '布局', '引用', '邮件', '审阅', '视图', '帮助']
|
||||
for name in tab_names:
|
||||
tab_btn = QPushButton(name)
|
||||
tab_btn.setFlat(True)
|
||||
tab_btn.setFixedHeight(25)
|
||||
tab_btn.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
padding: 5px 15px;
|
||||
font-size: 12px;
|
||||
color: #333333;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #e1e1e1;
|
||||
}
|
||||
QPushButton:checked {
|
||||
background-color: #ffffff;
|
||||
border: 1px solid #d0d0d0;
|
||||
border-bottom: 1px solid #ffffff;
|
||||
}
|
||||
""")
|
||||
self.tabs[name] = tab_btn
|
||||
tab_layout.addWidget(tab_btn)
|
||||
|
||||
self.tab_bar.setLayout(tab_layout)
|
||||
|
||||
# 功能区
|
||||
self.ribbon_area = QFrame()
|
||||
self.ribbon_area.setStyleSheet("""
|
||||
QFrame {
|
||||
background-color: #ffffff;
|
||||
border: 1px solid #d0d0d0;
|
||||
border-top: none;
|
||||
}
|
||||
""")
|
||||
|
||||
ribbon_layout = QHBoxLayout()
|
||||
ribbon_layout.setContentsMargins(10, 5, 10, 5)
|
||||
ribbon_layout.setSpacing(15)
|
||||
|
||||
# 开始标签的内容(最常用的功能)
|
||||
self.setup_home_tab(ribbon_layout)
|
||||
|
||||
self.ribbon_area.setLayout(ribbon_layout)
|
||||
|
||||
main_layout.addWidget(self.tab_bar)
|
||||
main_layout.addWidget(self.ribbon_area)
|
||||
self.setLayout(main_layout)
|
||||
|
||||
# 设置默认选中的标签
|
||||
self.tabs['开始'].setChecked(True)
|
||||
|
||||
def setup_home_tab(self, layout):
|
||||
"""设置开始标签的功能区内容"""
|
||||
|
||||
# 剪贴板组
|
||||
clipboard_group = self.create_ribbon_group("剪贴板")
|
||||
paste_btn = self.create_ribbon_button("粘贴", "Ctrl+V", "paste")
|
||||
cut_btn = self.create_ribbon_button("剪切", "Ctrl+X", "cut")
|
||||
copy_btn = self.create_ribbon_button("复制", "Ctrl+C", "copy")
|
||||
|
||||
clipboard_layout = QVBoxLayout()
|
||||
clipboard_layout.addWidget(paste_btn)
|
||||
|
||||
small_btn_layout = QHBoxLayout()
|
||||
small_btn_layout.addWidget(cut_btn)
|
||||
small_btn_layout.addWidget(copy_btn)
|
||||
clipboard_layout.addLayout(small_btn_layout)
|
||||
|
||||
clipboard_group.setLayout(clipboard_layout)
|
||||
layout.addWidget(clipboard_group)
|
||||
|
||||
# 字体组
|
||||
font_group = self.create_ribbon_group("字体")
|
||||
|
||||
# 字体选择
|
||||
font_layout = QHBoxLayout()
|
||||
self.font_combo = QFontComboBox()
|
||||
self.font_combo.setFixedWidth(120)
|
||||
self.font_size_combo = QComboBox()
|
||||
self.font_size_combo.addItems(['8', '9', '10', '11', '12', '14', '16', '18', '20', '22', '24', '26', '28', '36', '48', '72'])
|
||||
self.font_size_combo.setFixedWidth(50)
|
||||
self.font_size_combo.setCurrentText('12')
|
||||
|
||||
font_layout.addWidget(self.font_combo)
|
||||
font_layout.addWidget(self.font_size_combo)
|
||||
|
||||
# 字体样式按钮
|
||||
font_style_layout = QHBoxLayout()
|
||||
self.bold_btn = self.create_toggle_button("B", "bold")
|
||||
self.italic_btn = self.create_toggle_button("I", "italic")
|
||||
self.underline_btn = self.create_toggle_button("U", "underline")
|
||||
|
||||
font_style_layout.addWidget(self.bold_btn)
|
||||
font_style_layout.addWidget(self.italic_btn)
|
||||
font_style_layout.addWidget(self.underline_btn)
|
||||
|
||||
font_main_layout = QVBoxLayout()
|
||||
font_main_layout.addLayout(font_layout)
|
||||
font_main_layout.addLayout(font_style_layout)
|
||||
|
||||
font_group.setLayout(font_main_layout)
|
||||
layout.addWidget(font_group)
|
||||
|
||||
# 段落组
|
||||
paragraph_group = self.create_ribbon_group("段落")
|
||||
|
||||
# 对齐方式
|
||||
align_layout = QHBoxLayout()
|
||||
self.align_left_btn = self.create_toggle_button("左对齐", "align_left")
|
||||
self.align_center_btn = self.create_toggle_button("居中", "align_center")
|
||||
self.align_right_btn = self.create_toggle_button("右对齐", "align_right")
|
||||
self.align_justify_btn = self.create_toggle_button("两端对齐", "align_justify")
|
||||
|
||||
align_layout.addWidget(self.align_left_btn)
|
||||
align_layout.addWidget(self.align_center_btn)
|
||||
align_layout.addWidget(self.align_right_btn)
|
||||
align_layout.addWidget(self.align_justify_btn)
|
||||
|
||||
paragraph_layout = QVBoxLayout()
|
||||
paragraph_layout.addLayout(align_layout)
|
||||
|
||||
paragraph_group.setLayout(paragraph_layout)
|
||||
layout.addWidget(paragraph_group)
|
||||
|
||||
# 样式组
|
||||
styles_group = self.create_ribbon_group("样式")
|
||||
styles_layout = QVBoxLayout()
|
||||
styles_layout.addWidget(QLabel("样式"))
|
||||
styles_group.setLayout(styles_layout)
|
||||
layout.addWidget(styles_group)
|
||||
|
||||
# 编辑组
|
||||
editing_group = self.create_ribbon_group("编辑")
|
||||
find_btn = self.create_ribbon_button("查找", "Ctrl+F", "find")
|
||||
replace_btn = self.create_ribbon_button("替换", "Ctrl+H", "replace")
|
||||
|
||||
editing_layout = QVBoxLayout()
|
||||
editing_layout.addWidget(find_btn)
|
||||
editing_layout.addWidget(replace_btn)
|
||||
editing_group.setLayout(editing_layout)
|
||||
layout.addWidget(editing_group)
|
||||
|
||||
layout.addStretch()
|
||||
|
||||
def create_ribbon_group(self, title):
|
||||
"""创建功能区组"""
|
||||
group = QGroupBox(title)
|
||||
group.setStyleSheet("""
|
||||
QGroupBox {
|
||||
font-size: 11px;
|
||||
font-weight: normal;
|
||||
color: #333333;
|
||||
border: 1px solid #e1e1e1;
|
||||
border-radius: 0px;
|
||||
margin-top: 5px;
|
||||
padding-top: 5px;
|
||||
}
|
||||
QGroupBox::title {
|
||||
subcontrol-origin: margin;
|
||||
left: 10px;
|
||||
padding: 0 5px 0 5px;
|
||||
}
|
||||
""")
|
||||
return group
|
||||
|
||||
def create_ribbon_button(self, text, shortcut, icon_name):
|
||||
"""创建功能区按钮"""
|
||||
btn = QToolButton()
|
||||
btn.setText(text)
|
||||
btn.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
|
||||
btn.setFixedSize(60, 60)
|
||||
btn.setStyleSheet("""
|
||||
QToolButton {
|
||||
border: 1px solid transparent;
|
||||
border-radius: 3px;
|
||||
background-color: transparent;
|
||||
font-size: 11px;
|
||||
color: #333333;
|
||||
}
|
||||
QToolButton:hover {
|
||||
background-color: #f0f0f0;
|
||||
border: 1px solid #d0d0d0;
|
||||
}
|
||||
QToolButton:pressed {
|
||||
background-color: #e1e1e1;
|
||||
border: 1px solid #c0c0c0;
|
||||
}
|
||||
""")
|
||||
return btn
|
||||
|
||||
def create_toggle_button(self, text, icon_name):
|
||||
"""创建切换按钮"""
|
||||
btn = QToolButton()
|
||||
btn.setText(text)
|
||||
btn.setCheckable(True)
|
||||
btn.setToolButtonStyle(Qt.ToolButtonTextOnly)
|
||||
btn.setFixedSize(30, 25)
|
||||
btn.setStyleSheet("""
|
||||
QToolButton {
|
||||
border: 1px solid #d0d0d0;
|
||||
border-radius: 2px;
|
||||
background-color: transparent;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
}
|
||||
QToolButton:hover {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
QToolButton:checked {
|
||||
background-color: #e1e1e1;
|
||||
border: 1px solid #c0c0c0;
|
||||
}
|
||||
""")
|
||||
return btn
|
||||
|
||||
class WordStatusBar(QStatusBar):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
"""设置状态栏"""
|
||||
self.setStyleSheet("""
|
||||
QStatusBar {
|
||||
background-color: #f3f2f1;
|
||||
border-top: 1px solid #d0d0d0;
|
||||
font-size: 11px;
|
||||
color: #333333;
|
||||
}
|
||||
""")
|
||||
|
||||
# 添加状态栏项目
|
||||
self.page_label = QLabel("第 1 页,共 1 页")
|
||||
self.words_label = QLabel("字数: 0")
|
||||
self.language_label = QLabel("中文(中国)")
|
||||
self.input_mode_label = QLabel("插入")
|
||||
|
||||
self.addPermanentWidget(self.page_label)
|
||||
self.addPermanentWidget(self.words_label)
|
||||
self.addPermanentWidget(self.language_label)
|
||||
self.addPermanentWidget(self.input_mode_label)
|
||||
|
||||
class WordTextEdit(QTextEdit):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
"""设置文本编辑区域样式"""
|
||||
self.setStyleSheet("""
|
||||
QTextEdit {
|
||||
background-color: #ffffff;
|
||||
border: 1px solid #d0d0d0;
|
||||
font-family: 'Calibri', 'Microsoft YaHei', '微软雅黑', sans-serif;
|
||||
font-size: 12pt;
|
||||
color: #000000;
|
||||
padding: 20px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
""")
|
||||
|
||||
# 设置页面边距和背景
|
||||
self.setViewportMargins(50, 50, 50, 50)
|
||||
|
||||
# 设置默认字体
|
||||
font = QFont("Calibri", 12)
|
||||
font.setStyleStrategy(QFont.PreferAntialias)
|
||||
self.setFont(font)
|
||||
|
||||
# 启用自动换行
|
||||
self.setLineWrapMode(QTextEdit.WidgetWidth)
|
||||
|
||||
# 设置光标宽度
|
||||
self.setCursorWidth(2)
|
||||
|
||||
class WordStyleToolBar(QToolBar):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
"""设置快速访问工具栏"""
|
||||
self.setFixedHeight(30)
|
||||
self.setStyleSheet("""
|
||||
QToolBar {
|
||||
background-color: #f3f2f1;
|
||||
border-bottom: 1px solid #d0d0d0;
|
||||
spacing: 5px;
|
||||
}
|
||||
""")
|
||||
|
||||
# 快速访问按钮
|
||||
save_btn = self.create_quick_button("保存", "Ctrl+S")
|
||||
undo_btn = self.create_quick_button("撤销", "Ctrl+Z")
|
||||
redo_btn = self.create_quick_button("重做", "Ctrl+Y")
|
||||
|
||||
self.addWidget(save_btn)
|
||||
self.addWidget(undo_btn)
|
||||
self.addWidget(redo_btn)
|
||||
self.addSeparator()
|
||||
|
||||
def create_quick_button(self, text, shortcut):
|
||||
"""创建快速访问按钮"""
|
||||
btn = QToolButton()
|
||||
btn.setText(text)
|
||||
btn.setToolButtonStyle(Qt.ToolButtonTextOnly)
|
||||
btn.setFixedSize(40, 25)
|
||||
btn.setStyleSheet("""
|
||||
QToolButton {
|
||||
border: none;
|
||||
background-color: transparent;
|
||||
font-size: 11px;
|
||||
color: #333333;
|
||||
}
|
||||
QToolButton:hover {
|
||||
background-color: #e1e1e1;
|
||||
}
|
||||
""")
|
||||
return btn
|
||||
Loading…
Reference in new issue