Files
copydev-imposing-tool/app/dialogs/add_text_dialog.py
Jules e7a27018e5 V2.3.0 — Ajout texte/image + barre outils verticale
- Ajout de texte libre sur les pages (Annotations > Ajouter du texte)
  - Texte multi-ligne, police, taille, couleur au choix
  - Position X/Y en mm, appliquer a page courante/toutes/paires/impaires
- Ajout d'image sur les pages (Annotations > Ajouter une image)
  - PNG/JPG/BMP/GIF/TIFF, position, taille, ratio auto
  - Memes options d'application
- Barre d'outils verticale a droite avec toutes les fonctions :
  - IMPOSITION : Livret, N-Up, Repetition, Manuel, Joindre
  - PAGES : Recadrer, Pg blanche, Fusionner
  - ANNOTATIONS : Texte, Image, Numeros, Masquer
  - REPERES : Coupe +/-, Bleed +/-
- Toolbar horizontale : Ouvrir, Enregistrer, Imprimer, Zoom

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 13:50:55 +01:00

118 lines
4.2 KiB
Python

"""Dialogue Ajouter du texte sur une page."""
from PyQt6.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QLabel,
QGroupBox, QComboBox, QSpinBox, QLineEdit,
QDialogButtonBox, QDoubleSpinBox, QTextEdit,
QColorDialog, QPushButton)
from PyQt6.QtGui import QColor
from PyQt6.QtCore import Qt
from reportlab.lib.units import mm
class AddTextDialog(QDialog):
def __init__(self, total_pages=1, current_page=0, parent=None):
super().__init__(parent)
self.setWindowTitle("Ajouter du texte")
self.setMinimumWidth(450)
self._total_pages = total_pages
self._current_page = current_page
self._color = QColor(0, 0, 0)
self._setup_ui()
def _setup_ui(self):
layout = QVBoxLayout(self)
# Texte
grp_text = QGroupBox("Texte")
tl = QVBoxLayout(grp_text)
self.edit_text = QTextEdit()
self.edit_text.setPlaceholderText("Saisissez le texte a ajouter...")
self.edit_text.setMaximumHeight(80)
tl.addWidget(self.edit_text)
layout.addWidget(grp_text)
# Police
grp_font = QGroupBox("Police")
fl = QHBoxLayout(grp_font)
self.combo_font = QComboBox()
self.combo_font.addItems(["Helvetica", "Helvetica-Bold", "Times-Roman",
"Times-Bold", "Courier", "Courier-Bold"])
fl.addWidget(self.combo_font)
fl.addWidget(QLabel("Taille :"))
self.spin_size = QSpinBox()
self.spin_size.setRange(4, 200)
self.spin_size.setValue(12)
fl.addWidget(self.spin_size)
self.btn_color = QPushButton("Couleur")
self.btn_color.setStyleSheet("background: black; color: white; padding: 4px 12px;")
self.btn_color.clicked.connect(self._choose_color)
fl.addWidget(self.btn_color)
layout.addWidget(grp_font)
# Position
grp_pos = QGroupBox("Position (mm depuis le bas-gauche)")
pl = QHBoxLayout(grp_pos)
pl.addWidget(QLabel("X :"))
self.spin_x = QDoubleSpinBox()
self.spin_x.setRange(0, 2000)
self.spin_x.setValue(20)
self.spin_x.setSuffix(" mm")
pl.addWidget(self.spin_x)
pl.addWidget(QLabel("Y :"))
self.spin_y = QDoubleSpinBox()
self.spin_y.setRange(0, 2000)
self.spin_y.setValue(20)
self.spin_y.setSuffix(" mm")
pl.addWidget(self.spin_y)
layout.addWidget(grp_pos)
# Appliquer a
grp_apply = QGroupBox("Appliquer a")
al = QHBoxLayout(grp_apply)
self.combo_apply = QComboBox()
self.combo_apply.addItems([
f"Page courante ({self._current_page + 1})",
"Toutes les pages",
"Pages paires",
"Pages impaires"
])
al.addWidget(self.combo_apply)
layout.addWidget(grp_apply)
buttons = QDialogButtonBox(
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
)
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
layout.addWidget(buttons)
def _choose_color(self):
color = QColorDialog.getColor(self._color, self)
if color.isValid():
self._color = color
self.btn_color.setStyleSheet(
f"background: {color.name()}; color: {'white' if color.lightness() < 128 else 'black'}; padding: 4px 12px;"
)
def get_settings(self):
apply_text = self.combo_apply.currentText()
if "courante" in apply_text:
apply_to = "current"
elif "paires" in apply_text.lower():
apply_to = "even"
elif "impaires" in apply_text.lower():
apply_to = "odd"
else:
apply_to = "all"
return {
"text": self.edit_text.toPlainText(),
"font_name": self.combo_font.currentText(),
"font_size": self.spin_size.value(),
"color": (self._color.redF(), self._color.greenF(), self._color.blueF()),
"x": self.spin_x.value() * mm,
"y": self.spin_y.value() * mm,
"apply_to": apply_to,
"current_page": self._current_page,
}