diff --git a/pySimBlocks/gui/graphics/block_item.py b/pySimBlocks/gui/graphics/block_item.py index d12a49a..e0a58d8 100644 --- a/pySimBlocks/gui/graphics/block_item.py +++ b/pySimBlocks/gui/graphics/block_item.py @@ -21,7 +21,7 @@ from typing import TYPE_CHECKING from PySide6.QtCore import QPoint, QPointF, QRectF, Qt -from PySide6.QtGui import QPainterPath, QPen +from PySide6.QtGui import QPainterPath, QPen, QFont from PySide6.QtWidgets import QGraphicsItem, QGraphicsRectItem, QStyle from pySimBlocks.gui.dialogs.block_dialog import BlockDialog @@ -50,6 +50,7 @@ class BlockItem(QGraphicsRectItem): GRID_DY = 5 SELECTION_HANDLE_SIZE = 8 SELECTION_HANDLE_HIT_SIZE = 16 + TYPE_LABEL_MIN_HEIGHT = 45 def __init__(self, instance: "BlockInstance", @@ -182,12 +183,28 @@ def paint(self, painter, option, widget=None): painter.setPen(QPen(t.block_border, 3)) painter.drawRect(self.rect()) - if selected: - painter.setPen(t.text_selected) - else: - painter.setPen(t.text) - painter.drawText(self.rect(), Qt.AlignCenter, self.instance.name) + rect = self.rect() + + # --- Nom (centré, police normale) + name_font = QFont("Sans Serif", 9) + painter.setFont(name_font) + painter.setPen(t.text_selected if selected else t.text) + + name_rect = QRectF(rect.x(), rect.y(), rect.width(), rect.height() * 0.60) + painter.drawText(name_rect, Qt.AlignCenter | Qt.AlignBottom, self.instance.name) + + # --- Type (petite police, italique, couleur atténuée) — uniquement si assez de place + if rect.height() >= self.TYPE_LABEL_MIN_HEIGHT: + type_font = QFont("Sans Serif", 8) + type_font.setItalic(True) + painter.setFont(type_font) + painter.setPen(t.text_type_selected if selected else t.text_type) + + type_rect = QRectF(rect.x(), rect.y() + rect.height() * 0.58, rect.width(), rect.height() * 0.38) + painter.drawText(type_rect, Qt.AlignCenter | Qt.AlignTop, self.instance.meta.type) + + # --- Handles de sélection if selected: half = self.SELECTION_HANDLE_SIZE / 2 r = self.rect() @@ -197,7 +214,6 @@ def paint(self, painter, option, widget=None): (r.left(), r.bottom()), (r.right(), r.bottom()), ] - painter.setPen(QPen(t.block_border_selected, 1)) painter.setBrush(t.text_selected) for x, y in corners: diff --git a/pySimBlocks/gui/graphics/theme.py b/pySimBlocks/gui/graphics/theme.py index ad2428d..23badaa 100644 --- a/pySimBlocks/gui/graphics/theme.py +++ b/pySimBlocks/gui/graphics/theme.py @@ -74,8 +74,10 @@ class Theme: #: Default text color. text: QColor + text_type: QColor #: Selected text color. text_selected: QColor + text_type_selected: QColor #: Connection wire color. wire: QColor @@ -110,11 +112,15 @@ def make_theme() -> Theme: block_border_selected = QColor("#4A78FF") text = QColor("#F0F0F0") if is_dark else QColor("#1E1E1E") + text_type = QColor("#7EB8D4") if is_dark else QColor("#2E7CA8") text_selected = QColor("#FFFFFF") if is_dark else QColor("#000000") + text_type_selected = QColor("#A8D4E8") if is_dark else QColor("#1A5C80") wire = QColor("#E6E6E6") if is_dark else QColor("#1A1A1A") text = _ensure_contrast(text, block_bg, min_delta=90.0) + text_type = _ensure_contrast(text_type, block_bg, min_delta=90.0) text_selected = _ensure_contrast(text_selected, block_bg_selected, min_delta=90.0) + text_type_selected = _ensure_contrast(text_type_selected, block_bg_selected, min_delta=90.0) block_border = _ensure_contrast(block_border, block_bg, min_delta=60.0) block_border_selected = _ensure_contrast(block_border_selected, block_bg_selected, min_delta=60.0) wire = _ensure_contrast(wire, scene_bg, min_delta=110.0) @@ -129,7 +135,9 @@ def make_theme() -> Theme: block_border=block_border, block_border_selected=block_border_selected, text=text, + text_type=text_type, text_selected=text_selected, + text_type_selected=text_type_selected, wire=wire, port_in=port_in, port_out=port_out, diff --git a/pySimBlocks/gui/widgets/block_list.py b/pySimBlocks/gui/widgets/block_list.py index d90d810..1384713 100644 --- a/pySimBlocks/gui/widgets/block_list.py +++ b/pySimBlocks/gui/widgets/block_list.py @@ -160,13 +160,13 @@ def _apply_filter(self, text: str): for i in range(self.tree.topLevelItemCount()): category_item = self.tree.topLevelItem(i) category_name = category_item.text(0) - category_match = category_name.lower().startswith(query) + category_match = query in category_name.lower() # ← startswith → in visible_children = 0 for j in range(category_item.childCount()): block_item = category_item.child(j) block_name = block_item.text(0) - block_match = block_name.lower().startswith(query) + block_match = query in block_name.lower() # ← startswith → in visible = (not query) or category_match or block_match block_item.setHidden(not visible) if visible: