Enhance reader layout polish
This commit is contained in:
@@ -2,10 +2,12 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtCore import QSize, Qt, Signal
|
||||
from PySide6.QtGui import QAction
|
||||
from PySide6.QtWidgets import (
|
||||
QFrame,
|
||||
QHBoxLayout,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QListWidget,
|
||||
QPushButton,
|
||||
@@ -45,6 +47,9 @@ class ToolSection(QFrame):
|
||||
for action in actions:
|
||||
button = QPushButton(action.text())
|
||||
button.setObjectName("rightToolButton")
|
||||
if not action.icon().isNull():
|
||||
button.setIcon(action.icon())
|
||||
button.setIconSize(QSize(16, 16))
|
||||
button.setToolTip(action.toolTip() or action.text())
|
||||
button.setFlat(True)
|
||||
button.setCheckable(action.isCheckable())
|
||||
@@ -63,6 +68,8 @@ class ToolSection(QFrame):
|
||||
|
||||
|
||||
class RightToolsPanel(QWidget):
|
||||
collapse_requested = Signal()
|
||||
|
||||
def __init__(self, search_box: QLineEdit, search_results: QListWidget) -> None:
|
||||
super().__init__()
|
||||
self.search_box = search_box
|
||||
@@ -80,15 +87,33 @@ class RightToolsPanel(QWidget):
|
||||
scroll.setFrameShape(QFrame.Shape.NoFrame)
|
||||
scroll.setWidget(self.sections_container)
|
||||
|
||||
header = QWidget()
|
||||
header.setObjectName("rightToolsHeader")
|
||||
header_layout = QHBoxLayout(header)
|
||||
header_layout.setContentsMargins(0, 0, 0, 0)
|
||||
header_layout.setSpacing(6)
|
||||
title = QLabel("工具")
|
||||
title.setObjectName("rightToolsTitle")
|
||||
collapse_button = QToolButton()
|
||||
collapse_button.setObjectName("rightToolsCollapseButton")
|
||||
collapse_button.setText("‹")
|
||||
collapse_button.setToolTip("收起工具面板")
|
||||
collapse_button.clicked.connect(self.collapse_requested.emit)
|
||||
header_layout.addWidget(title)
|
||||
header_layout.addStretch(1)
|
||||
header_layout.addWidget(collapse_button)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(8, 8, 8, 8)
|
||||
layout.setSpacing(8)
|
||||
layout.addWidget(header)
|
||||
layout.addWidget(search_box)
|
||||
layout.addWidget(search_results)
|
||||
layout.addWidget(scroll, 1)
|
||||
search_results.setVisible(False)
|
||||
search_results.setMaximumHeight(170)
|
||||
self.setMinimumWidth(300)
|
||||
self.setMinimumWidth(260)
|
||||
self.setMaximumWidth(300)
|
||||
|
||||
def add_section(self, title: str, actions: Iterable[QAction]) -> None:
|
||||
self.sections_layout.addWidget(ToolSection(title, actions))
|
||||
|
||||
Reference in New Issue
Block a user