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 (
|
from PyQt6.QtWidgets import (
|
||||||
QWidget, QVBoxLayout, QHBoxLayout, QPushButton,
|
QWidget, QVBoxLayout, QHBoxLayout, QPushButton,
|
||||||
@@ -11,7 +11,7 @@ from ui.style import scale, scaled_font, Sizes, back_btn_style, green_btn
|
|||||||
|
|
||||||
|
|
||||||
class PhotoCard(QFrame):
|
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):
|
def __init__(self, path, main_window, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@@ -32,64 +32,45 @@ class PhotoCard(QFrame):
|
|||||||
layout.setContentsMargins(4, 4, 4, 4)
|
layout.setContentsMargins(4, 4, 4, 4)
|
||||||
layout.setSpacing(4)
|
layout.setSpacing(4)
|
||||||
|
|
||||||
# Conteneur miniature (pour superposer le warning)
|
# Conteneur miniature (pour superposer la pastille)
|
||||||
from PyQt6.QtWidgets import QStackedLayout
|
|
||||||
thumb_container = QWidget()
|
thumb_container = QWidget()
|
||||||
thumb_container.setFixedSize(200, 140)
|
thumb_container.setFixedSize(200, 140)
|
||||||
thumb_stack = QVBoxLayout(thumb_container)
|
thumb_container.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||||
thumb_stack.setContentsMargins(0, 0, 0, 0)
|
thumb_container.mousePressEvent = lambda e: self._edit()
|
||||||
thumb_stack.setSpacing(0)
|
|
||||||
|
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 = QLabel()
|
||||||
self.thumb_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
self.thumb_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||||
self.thumb_label.setFixedSize(200, 140)
|
self.thumb_label.setFixedSize(200, 140)
|
||||||
self._pixmap_original = QPixmap(self.path)
|
self._pixmap_original = QPixmap(self.path)
|
||||||
self._update_thumbnail()
|
self._update_thumbnail()
|
||||||
thumb_stack.addWidget(self.thumb_label)
|
thumb_layout.addWidget(self.thumb_label)
|
||||||
|
|
||||||
# Warning ratio (petit indicateur discret)
|
# Pastille orange (ratio ≠ 3:2)
|
||||||
self.ratio_warning = QLabel("⚠")
|
self.ratio_dot = QLabel()
|
||||||
self.ratio_warning.setFixedSize(22, 22)
|
self.ratio_dot.setFixedSize(14, 14)
|
||||||
self.ratio_warning.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
self.ratio_dot.setStyleSheet("""
|
||||||
self.ratio_warning.setStyleSheet("""
|
|
||||||
QLabel {
|
QLabel {
|
||||||
background: rgba(255, 152, 0, 0.8);
|
background: rgba(255, 152, 0, 0.85);
|
||||||
color: white;
|
border-radius: 7px;
|
||||||
border-radius: 11px;
|
|
||||||
font-size: 13px;
|
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
self.ratio_warning.setToolTip("Photo à recadrer")
|
self.ratio_dot.hide()
|
||||||
self.ratio_warning.hide()
|
self.ratio_dot.setParent(thumb_container)
|
||||||
# Positionner en haut à droite de la miniature
|
self.ratio_dot.move(182, 4)
|
||||||
self.ratio_warning.setParent(thumb_container)
|
|
||||||
self.ratio_warning.move(174, 4)
|
|
||||||
|
|
||||||
self._check_ratio()
|
self._check_ratio()
|
||||||
layout.addWidget(thumb_container)
|
layout.addWidget(thumb_container)
|
||||||
|
|
||||||
# Barre du bas : crayon + quantité
|
# Barre du bas : − quantité + (centré)
|
||||||
bar = QHBoxLayout()
|
bar = QHBoxLayout()
|
||||||
bar.setSpacing(4)
|
bar.setSpacing(6)
|
||||||
|
|
||||||
# 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.addStretch()
|
bar.addStretch()
|
||||||
|
|
||||||
# Compteur quantité
|
|
||||||
self.minus_btn = QPushButton("−")
|
self.minus_btn = QPushButton("−")
|
||||||
self.minus_btn.setFixedSize(32, 32)
|
self.minus_btn.setFixedSize(32, 32)
|
||||||
self.minus_btn.setStyleSheet("""
|
self.minus_btn.setStyleSheet("""
|
||||||
@@ -120,10 +101,12 @@ class PhotoCard(QFrame):
|
|||||||
self.plus_btn.clicked.connect(self._increment)
|
self.plus_btn.clicked.connect(self._increment)
|
||||||
bar.addWidget(self.plus_btn)
|
bar.addWidget(self.plus_btn)
|
||||||
|
|
||||||
|
bar.addStretch()
|
||||||
|
|
||||||
layout.addLayout(bar)
|
layout.addLayout(bar)
|
||||||
|
|
||||||
def _check_ratio(self):
|
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():
|
if self._pixmap_original.isNull():
|
||||||
return
|
return
|
||||||
w = self._pixmap_original.width()
|
w = self._pixmap_original.width()
|
||||||
@@ -131,11 +114,10 @@ class PhotoCard(QFrame):
|
|||||||
if w == 0 or h == 0:
|
if w == 0 or h == 0:
|
||||||
return
|
return
|
||||||
ratio = max(w, h) / min(w, h)
|
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:
|
if abs(ratio - 1.5) > 0.075:
|
||||||
self.ratio_warning.show()
|
self.ratio_dot.show()
|
||||||
else:
|
else:
|
||||||
self.ratio_warning.hide()
|
self.ratio_dot.hide()
|
||||||
|
|
||||||
def _edit(self):
|
def _edit(self):
|
||||||
self.main_window.show_editor(self.path)
|
self.main_window.show_editor(self.path)
|
||||||
@@ -189,34 +171,23 @@ class PhotoCard(QFrame):
|
|||||||
thumb_h = max(100, int(window_height * 0.16))
|
thumb_h = max(100, int(window_height * 0.16))
|
||||||
thumb_w = max(140, int(thumb_h * 1.45))
|
thumb_w = max(140, int(thumb_h * 1.45))
|
||||||
self.thumb_label.setFixedSize(thumb_w, thumb_h)
|
self.thumb_label.setFixedSize(thumb_w, thumb_h)
|
||||||
# Redimensionner le conteneur aussi
|
|
||||||
self.thumb_label.parent().setFixedSize(thumb_w, thumb_h)
|
self.thumb_label.parent().setFixedSize(thumb_w, thumb_h)
|
||||||
self._update_thumbnail()
|
self._update_thumbnail()
|
||||||
# Repositionner le warning en haut à droite
|
|
||||||
warn_size = max(18, int(window_height * 0.025))
|
# Pastille orange
|
||||||
self.ratio_warning.setFixedSize(warn_size, warn_size)
|
dot_size = max(10, int(window_height * 0.018))
|
||||||
self.ratio_warning.move(thumb_w - warn_size - 4, 4)
|
self.ratio_dot.setFixedSize(dot_size, dot_size)
|
||||||
self.ratio_warning.setStyleSheet(f"""
|
self.ratio_dot.move(thumb_w - dot_size - 4, 4)
|
||||||
|
self.ratio_dot.setStyleSheet(f"""
|
||||||
QLabel {{
|
QLabel {{
|
||||||
background: rgba(255, 152, 0, 0.8);
|
background: rgba(255, 152, 0, 0.85);
|
||||||
color: white;
|
border-radius: {dot_size // 2}px;
|
||||||
border-radius: {warn_size // 2}px;
|
|
||||||
font-size: {warn_size - 4}px;
|
|
||||||
}}
|
}}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
btn_size = max(28, int(window_height * 0.04))
|
btn_size = max(28, int(window_height * 0.04))
|
||||||
font_size = max(12, int(window_height * 0.02))
|
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.setFixedSize(btn_size, btn_size)
|
||||||
self.minus_btn.setStyleSheet(f"""
|
self.minus_btn.setStyleSheet(f"""
|
||||||
QPushButton {{
|
QPushButton {{
|
||||||
@@ -317,7 +288,6 @@ class ImportScreen(QWidget):
|
|||||||
|
|
||||||
def set_photos(self, photo_paths):
|
def set_photos(self, photo_paths):
|
||||||
"""Affiche les photos dans la grille."""
|
"""Affiche les photos dans la grille."""
|
||||||
# Clear
|
|
||||||
while self.grid_layout.count():
|
while self.grid_layout.count():
|
||||||
item = self.grid_layout.takeAt(0)
|
item = self.grid_layout.takeAt(0)
|
||||||
if item.widget():
|
if item.widget():
|
||||||
|
|||||||
Reference in New Issue
Block a user