Add Acrobat style right tools panel
This commit is contained in:
@@ -22,7 +22,6 @@ from PySide6.QtWidgets import (
|
||||
QSplitter,
|
||||
QStatusBar,
|
||||
QToolBar,
|
||||
QWidget,
|
||||
QVBoxLayout,
|
||||
)
|
||||
|
||||
@@ -34,6 +33,7 @@ from pdfreaderlite.core.file_association import (
|
||||
from pdfreaderlite.core.document import EncryptedPdfError, FormField, PdfDocument, SearchMatch
|
||||
from pdfreaderlite.resources import pdf_icon_path, software_icon_path
|
||||
from pdfreaderlite.ui.pdf_viewer import PdfViewer
|
||||
from pdfreaderlite.ui.right_tools import RightToolsPanel
|
||||
from pdfreaderlite.ui.sidebar import Sidebar
|
||||
from pdfreaderlite.ui.signature_dialog import SignatureDialog
|
||||
|
||||
@@ -50,6 +50,7 @@ class MainWindow(QMainWindow):
|
||||
self.sidebar = Sidebar()
|
||||
self.search_box = QLineEdit()
|
||||
self.search_results = QListWidget()
|
||||
self.right_tools = RightToolsPanel(self.search_box, self.search_results)
|
||||
|
||||
self._build_window()
|
||||
self._build_actions()
|
||||
@@ -618,18 +619,11 @@ class MainWindow(QMainWindow):
|
||||
self.resize(1320, 860)
|
||||
self.setStatusBar(QStatusBar())
|
||||
|
||||
right_panel = QWidget()
|
||||
right_layout = QVBoxLayout(right_panel)
|
||||
right_layout.setContentsMargins(8, 8, 8, 8)
|
||||
right_layout.addWidget(self.search_box)
|
||||
right_layout.addWidget(self.search_results)
|
||||
right_panel.setMinimumWidth(260)
|
||||
|
||||
splitter = QSplitter()
|
||||
splitter.addWidget(self.sidebar)
|
||||
splitter.addWidget(self.viewer)
|
||||
splitter.addWidget(right_panel)
|
||||
splitter.setSizes([220, 830, 270])
|
||||
splitter.addWidget(self.right_tools)
|
||||
splitter.setSizes([220, 820, 320])
|
||||
self.setCentralWidget(splitter)
|
||||
|
||||
self.search_box.setPlaceholderText("搜索文本,按 Enter")
|
||||
@@ -778,6 +772,74 @@ class MainWindow(QMainWindow):
|
||||
help_menu.addAction(self.shortcuts_action)
|
||||
help_menu.addAction(self.open_log_dir_action)
|
||||
help_menu.addAction(self.about_action)
|
||||
self._build_right_tools_panel()
|
||||
|
||||
def _build_right_tools_panel(self) -> None:
|
||||
self.right_tools.add_section(
|
||||
"编辑 PDF",
|
||||
[
|
||||
self.add_text_action,
|
||||
self.insert_image_action,
|
||||
self.cover_action,
|
||||
self.undo_action,
|
||||
self.redo_action,
|
||||
],
|
||||
)
|
||||
self.right_tools.add_section(
|
||||
"注释",
|
||||
[
|
||||
self.highlight_action,
|
||||
self.underline_action,
|
||||
self.strikeout_action,
|
||||
self.note_action,
|
||||
self.rectangle_action,
|
||||
self.circle_action,
|
||||
self.line_action,
|
||||
self.arrow_action,
|
||||
self.annotation_list_action,
|
||||
],
|
||||
)
|
||||
self.right_tools.add_section(
|
||||
"页面",
|
||||
[
|
||||
self.rotate_action,
|
||||
self.delete_action,
|
||||
self.move_page_action,
|
||||
self.insert_blank_action,
|
||||
self.insert_pdf_action,
|
||||
self.extract_pages_action,
|
||||
self.split_pdf_action,
|
||||
self.merge_pdfs_action,
|
||||
],
|
||||
)
|
||||
self.right_tools.add_section(
|
||||
"签名与表单",
|
||||
[
|
||||
self.signature_action,
|
||||
self.draw_signature_action,
|
||||
self.form_fill_action,
|
||||
],
|
||||
)
|
||||
self.right_tools.add_section(
|
||||
"导出与安全",
|
||||
[
|
||||
self.export_current_image_action,
|
||||
self.export_pages_images_action,
|
||||
self.images_to_pdf_action,
|
||||
self.metadata_action,
|
||||
self.save_encrypted_action,
|
||||
self.remove_password_action,
|
||||
],
|
||||
)
|
||||
self.right_tools.add_section(
|
||||
"设置",
|
||||
[
|
||||
self.register_pdf_action,
|
||||
self.default_apps_action,
|
||||
self.open_log_dir_action,
|
||||
],
|
||||
)
|
||||
self.right_tools.finish()
|
||||
|
||||
def _build_toolbar(self) -> None:
|
||||
toolbar = QToolBar("主工具栏")
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
|
||||
from PySide6.QtGui import QAction
|
||||
from PySide6.QtWidgets import (
|
||||
QFrame,
|
||||
QLineEdit,
|
||||
QListWidget,
|
||||
QPushButton,
|
||||
QScrollArea,
|
||||
QSizePolicy,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
)
|
||||
|
||||
|
||||
class ToolSection(QFrame):
|
||||
def __init__(self, title: str, actions: Iterable[QAction]) -> None:
|
||||
super().__init__()
|
||||
self.setObjectName("toolSection")
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(8, 8, 8, 8)
|
||||
layout.setSpacing(6)
|
||||
|
||||
title_button = QPushButton(title)
|
||||
title_button.setObjectName("toolSectionTitle")
|
||||
title_button.setEnabled(False)
|
||||
layout.addWidget(title_button)
|
||||
|
||||
for action in actions:
|
||||
button = QPushButton(action.text())
|
||||
button.setToolTip(action.toolTip() or action.text())
|
||||
button.clicked.connect(action.trigger)
|
||||
button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
|
||||
layout.addWidget(button)
|
||||
|
||||
|
||||
class RightToolsPanel(QWidget):
|
||||
def __init__(self, search_box: QLineEdit, search_results: QListWidget) -> None:
|
||||
super().__init__()
|
||||
self.search_box = search_box
|
||||
self.search_results = search_results
|
||||
self.sections_container = QWidget()
|
||||
self.sections_layout = QVBoxLayout(self.sections_container)
|
||||
self.sections_layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.sections_layout.setSpacing(8)
|
||||
|
||||
scroll = QScrollArea()
|
||||
scroll.setWidgetResizable(True)
|
||||
scroll.setFrameShape(QFrame.Shape.NoFrame)
|
||||
scroll.setWidget(self.sections_container)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(8, 8, 8, 8)
|
||||
layout.setSpacing(8)
|
||||
layout.addWidget(search_box)
|
||||
layout.addWidget(search_results, 1)
|
||||
layout.addWidget(scroll, 2)
|
||||
self.setMinimumWidth(300)
|
||||
|
||||
def add_section(self, title: str, actions: Iterable[QAction]) -> None:
|
||||
self.sections_layout.addWidget(ToolSection(title, actions))
|
||||
|
||||
def finish(self) -> None:
|
||||
self.sections_layout.addStretch(1)
|
||||
Reference in New Issue
Block a user