Add configurable cover annotations
This commit is contained in:
@@ -89,6 +89,8 @@ class MainWindow(QMainWindow):
|
||||
)
|
||||
self.annotation_line_width = int(self.settings.value("annotationStyle/lineWidth", 2, int))
|
||||
self.annotation_opacity = float(self.settings.value("annotationStyle/opacity", 1.0, float))
|
||||
self.cover_color = QColor(self.settings.value("coverStyle/color", "#ffffff", str))
|
||||
self.cover_opacity = float(self.settings.value("coverStyle/opacity", 1.0, float))
|
||||
|
||||
self.sessions: list[DocumentSession] = []
|
||||
self.active_session_index = -1
|
||||
@@ -2441,10 +2443,68 @@ class MainWindow(QMainWindow):
|
||||
return
|
||||
if not self._ensure_can_edit("遮盖"):
|
||||
return
|
||||
self.document.add_cover_area(self.viewer.page_index)
|
||||
self.viewer.render()
|
||||
self._refresh_annotation_panel()
|
||||
self.statusBar().showMessage("遮盖区域已添加,记得保存", 3000)
|
||||
dialog = QDialog(self)
|
||||
dialog.setWindowTitle("遮盖")
|
||||
layout = QFormLayout(dialog)
|
||||
|
||||
selected_color = QColor(self.cover_color)
|
||||
color_button = QPushButton(selected_color.name().upper())
|
||||
|
||||
def update_color_button() -> None:
|
||||
color_button.setText(selected_color.name().upper())
|
||||
color_button.setStyleSheet(
|
||||
f"background: {selected_color.name()}; color: {'#ffffff' if selected_color.lightness() < 128 else '#202124'};"
|
||||
)
|
||||
|
||||
def choose_color() -> None:
|
||||
nonlocal selected_color
|
||||
color = QColorDialog.getColor(selected_color, self, "选择遮盖颜色")
|
||||
if color.isValid():
|
||||
selected_color = color
|
||||
update_color_button()
|
||||
|
||||
color_button.clicked.connect(choose_color)
|
||||
update_color_button()
|
||||
|
||||
opacity_input = QDoubleSpinBox()
|
||||
opacity_input.setRange(10, 100)
|
||||
opacity_input.setSingleStep(5)
|
||||
opacity_input.setDecimals(0)
|
||||
opacity_input.setValue(self.cover_opacity * 100)
|
||||
opacity_input.setSuffix("%")
|
||||
|
||||
text_input = QLineEdit()
|
||||
text_input.setPlaceholderText("可选")
|
||||
|
||||
layout.addRow("颜色", color_button)
|
||||
layout.addRow("透明度", opacity_input)
|
||||
layout.addRow("文字", text_input)
|
||||
|
||||
buttons = QDialogButtonBox(
|
||||
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
||||
)
|
||||
buttons.accepted.connect(dialog.accept)
|
||||
buttons.rejected.connect(dialog.reject)
|
||||
layout.addRow(buttons)
|
||||
if dialog.exec() != QDialog.DialogCode.Accepted:
|
||||
return
|
||||
|
||||
self.cover_color = selected_color
|
||||
self.cover_opacity = opacity_input.value() / 100
|
||||
self.settings.setValue("coverStyle/color", self.cover_color.name())
|
||||
self.settings.setValue("coverStyle/opacity", self.cover_opacity)
|
||||
try:
|
||||
self.document.add_cover_area(
|
||||
self.viewer.page_index,
|
||||
(self.cover_color.redF(), self.cover_color.greenF(), self.cover_color.blueF()),
|
||||
self.cover_opacity,
|
||||
text_input.text(),
|
||||
)
|
||||
self.viewer.render()
|
||||
self._refresh_annotation_panel()
|
||||
self.statusBar().showMessage("遮盖区域已添加,记得保存", 3000)
|
||||
except Exception as exc:
|
||||
QMessageBox.critical(self, "遮盖失败", f"无法添加遮盖区域:\n{exc}")
|
||||
|
||||
def _remember_file(self, path: str) -> None:
|
||||
files = [item for item in self.recent_files if item != path]
|
||||
|
||||
Reference in New Issue
Block a user