Galerie : clic photo = éditeur, +/- centré, pastille orange simple
- Plus de crayon : clic direct sur la miniature ouvre l'éditeur - Boutons − quantité + centrés sous la photo - Pastille orange (sans texte) en haut à droite si ratio ≠ 3:2 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Écran d'import — galerie avec édition et quantités."""
|
||||
"""Écran d'import — galerie avec quantités et recadrage."""
|
||||
|
||||
from PyQt6.QtWidgets import (
|
||||
QWidget, QVBoxLayout, QHBoxLayout, QPushButton,
|
||||
@@ -11,7 +11,7 @@ from ui.style import scale, scaled_font, Sizes, back_btn_style, green_btn
|
||||
|
||||
|
||||
class PhotoCard(QFrame):
|
||||
"""Carte photo : miniature + crayon édition + compteur quantité."""
|
||||
"""Carte photo : clic sur photo = éditeur, +/- centré, pastille orange si ratio ≠ 3:2."""
|
||||
|
||||
def __init__(self, path, main_window, parent=None):
|
||||
super().__init__(parent)
|
||||
@@ -32,64 +32,45 @@ class PhotoCard(QFrame):
|
||||
layout.setContentsMargins(4, 4, 4, 4)
|
||||
layout.setSpacing(4)
|
||||
|
||||
# Conteneur miniature (pour superposer le warning)
|
||||
from PyQt6.QtWidgets import QStackedLayout
|
||||
# Conteneur miniature (pour superposer la pastille)
|
||||
thumb_container = QWidget()
|
||||
thumb_container.setFixedSize(200, 140)
|
||||
thumb_stack = QVBoxLayout(thumb_container)
|
||||
thumb_stack.setContentsMargins(0, 0, 0, 0)
|
||||
thumb_stack.setSpacing(0)
|
||||
thumb_container.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||
thumb_container.mousePressEvent = lambda e: self._edit()
|
||||
|
||||
thumb_layout = QVBoxLayout(thumb_container)
|
||||
thumb_layout.setContentsMargins(0, 0, 0, 0)
|
||||
thumb_layout.setSpacing(0)
|
||||
|
||||
# Miniature — taille fixe
|
||||
self.thumb_label = QLabel()
|
||||
self.thumb_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
self.thumb_label.setFixedSize(200, 140)
|
||||
self._pixmap_original = QPixmap(self.path)
|
||||
self._update_thumbnail()
|
||||
thumb_stack.addWidget(self.thumb_label)
|
||||
thumb_layout.addWidget(self.thumb_label)
|
||||
|
||||
# Warning ratio (petit indicateur discret)
|
||||
self.ratio_warning = QLabel("⚠")
|
||||
self.ratio_warning.setFixedSize(22, 22)
|
||||
self.ratio_warning.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
self.ratio_warning.setStyleSheet("""
|
||||
# Pastille orange (ratio ≠ 3:2)
|
||||
self.ratio_dot = QLabel()
|
||||
self.ratio_dot.setFixedSize(14, 14)
|
||||
self.ratio_dot.setStyleSheet("""
|
||||
QLabel {
|
||||
background: rgba(255, 152, 0, 0.8);
|
||||
color: white;
|
||||
border-radius: 11px;
|
||||
font-size: 13px;
|
||||
background: rgba(255, 152, 0, 0.85);
|
||||
border-radius: 7px;
|
||||
}
|
||||
""")
|
||||
self.ratio_warning.setToolTip("Photo à recadrer")
|
||||
self.ratio_warning.hide()
|
||||
# Positionner en haut à droite de la miniature
|
||||
self.ratio_warning.setParent(thumb_container)
|
||||
self.ratio_warning.move(174, 4)
|
||||
self.ratio_dot.hide()
|
||||
self.ratio_dot.setParent(thumb_container)
|
||||
self.ratio_dot.move(182, 4)
|
||||
|
||||
self._check_ratio()
|
||||
layout.addWidget(thumb_container)
|
||||
|
||||
# Barre du bas : crayon + quantité
|
||||
# Barre du bas : − quantité + (centré)
|
||||
bar = QHBoxLayout()
|
||||
bar.setSpacing(4)
|
||||
|
||||
# Crayon édition
|
||||
self.edit_btn = QPushButton("✎")
|
||||
self.edit_btn.setFixedSize(36, 36)
|
||||
self.edit_btn.setStyleSheet("""
|
||||
QPushButton {
|
||||
background: #2196F3; color: white;
|
||||
border-radius: 18px; font-size: 18px;
|
||||
}
|
||||
QPushButton:pressed { background: #1976D2; }
|
||||
""")
|
||||
self.edit_btn.setToolTip("Éditer")
|
||||
self.edit_btn.clicked.connect(self._edit)
|
||||
bar.addWidget(self.edit_btn)
|
||||
bar.setSpacing(6)
|
||||
|
||||
bar.addStretch()
|
||||
|
||||
# Compteur quantité
|
||||
self.minus_btn = QPushButton("−")
|
||||
self.minus_btn.setFixedSize(32, 32)
|
||||
self.minus_btn.setStyleSheet("""
|
||||
@@ -120,10 +101,12 @@ class PhotoCard(QFrame):
|
||||
self.plus_btn.clicked.connect(self._increment)
|
||||
bar.addWidget(self.plus_btn)
|
||||
|
||||
bar.addStretch()
|
||||
|
||||
layout.addLayout(bar)
|
||||
|
||||
def _check_ratio(self):
|
||||
"""Vérifie si la photo est au ratio 3:2 (10x15). Sinon, affiche le warning."""
|
||||
"""Affiche la pastille orange si ratio ≠ 3:2."""
|
||||
if self._pixmap_original.isNull():
|
||||
return
|
||||
w = self._pixmap_original.width()
|
||||
@@ -131,11 +114,10 @@ class PhotoCard(QFrame):
|
||||
if w == 0 or h == 0:
|
||||
return
|
||||
ratio = max(w, h) / min(w, h)
|
||||
# Tolérance de 5% autour du ratio 1.5 (3:2)
|
||||
if abs(ratio - 1.5) > 0.075:
|
||||
self.ratio_warning.show()
|
||||
self.ratio_dot.show()
|
||||
else:
|
||||
self.ratio_warning.hide()
|
||||
self.ratio_dot.hide()
|
||||
|
||||
def _edit(self):
|
||||
self.main_window.show_editor(self.path)
|
||||
@@ -189,34 +171,23 @@ class PhotoCard(QFrame):
|
||||
thumb_h = max(100, int(window_height * 0.16))
|
||||
thumb_w = max(140, int(thumb_h * 1.45))
|
||||
self.thumb_label.setFixedSize(thumb_w, thumb_h)
|
||||
# Redimensionner le conteneur aussi
|
||||
self.thumb_label.parent().setFixedSize(thumb_w, thumb_h)
|
||||
self._update_thumbnail()
|
||||
# Repositionner le warning en haut à droite
|
||||
warn_size = max(18, int(window_height * 0.025))
|
||||
self.ratio_warning.setFixedSize(warn_size, warn_size)
|
||||
self.ratio_warning.move(thumb_w - warn_size - 4, 4)
|
||||
self.ratio_warning.setStyleSheet(f"""
|
||||
|
||||
# Pastille orange
|
||||
dot_size = max(10, int(window_height * 0.018))
|
||||
self.ratio_dot.setFixedSize(dot_size, dot_size)
|
||||
self.ratio_dot.move(thumb_w - dot_size - 4, 4)
|
||||
self.ratio_dot.setStyleSheet(f"""
|
||||
QLabel {{
|
||||
background: rgba(255, 152, 0, 0.8);
|
||||
color: white;
|
||||
border-radius: {warn_size // 2}px;
|
||||
font-size: {warn_size - 4}px;
|
||||
background: rgba(255, 152, 0, 0.85);
|
||||
border-radius: {dot_size // 2}px;
|
||||
}}
|
||||
""")
|
||||
|
||||
btn_size = max(28, int(window_height * 0.04))
|
||||
font_size = max(12, int(window_height * 0.02))
|
||||
|
||||
self.edit_btn.setFixedSize(btn_size, btn_size)
|
||||
self.edit_btn.setStyleSheet(f"""
|
||||
QPushButton {{
|
||||
background: #2196F3; color: white;
|
||||
border-radius: {btn_size//2}px; font-size: {font_size+2}px;
|
||||
}}
|
||||
QPushButton:pressed {{ background: #1976D2; }}
|
||||
""")
|
||||
|
||||
self.minus_btn.setFixedSize(btn_size, btn_size)
|
||||
self.minus_btn.setStyleSheet(f"""
|
||||
QPushButton {{
|
||||
@@ -317,7 +288,6 @@ class ImportScreen(QWidget):
|
||||
|
||||
def set_photos(self, photo_paths):
|
||||
"""Affiche les photos dans la grille."""
|
||||
# Clear
|
||||
while self.grid_layout.count():
|
||||
item = self.grid_layout.takeAt(0)
|
||||
if item.widget():
|
||||
|
||||
Reference in New Issue
Block a user