CAM: Fix: Tools without icon now display the thumbnail from the FCStd file

This commit is contained in:
Samuel Abels
2025-06-29 12:57:32 +02:00
parent 2f051136fe
commit 0a7cf449bc
3 changed files with 29 additions and 33 deletions

View File

@@ -714,11 +714,6 @@ class ToolBitShape(Asset):
self.icon = cast(
ToolBitShapeIcon, cam_assets.get_or_none(f"toolbitshapesvg://{self.id}.svg")
)
if self.icon:
return self.icon
self.icon = cast(
ToolBitShapeIcon, cam_assets.get_or_none(f"toolbitshapesvg://{self.name.lower()}.svg")
)
if self.icon:
return self.icon
@@ -726,11 +721,6 @@ class ToolBitShape(Asset):
self.icon = cast(
ToolBitShapeIcon, cam_assets.get_or_none(f"toolbitshapepng://{self.id}.png")
)
if self.icon:
return self.icon
self.icon = cast(
ToolBitShapeIcon, cam_assets.get_or_none(f"toolbitshapepng://{self.name.lower()}.png")
)
if self.icon:
return self.icon
return None

View File

@@ -20,6 +20,7 @@
# * *
# ***************************************************************************
from PySide import QtGui, QtCore
from .shapewidget import ShapeWidget
class ShapeButton(QtGui.QToolButton):
@@ -27,10 +28,6 @@ class ShapeButton(QtGui.QToolButton):
super(ShapeButton, self).__init__(parent)
self.shape = shape
# Remove default text handling and use a custom layout
# self.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
# self.setText(f"{shape.label}\n{shape.id}")
self.vbox = QtGui.QVBoxLayout(self)
self.vbox.setAlignment(
QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter
@@ -38,8 +35,7 @@ class ShapeButton(QtGui.QToolButton):
self.vbox.setContentsMargins(0, 0, 0, 0)
self.vbox.setSpacing(0)
self.icon_widget = QtGui.QLabel()
self.icon_widget.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
self.icon_widget = ShapeWidget(self.shape, QtCore.QSize(71, 70))
self.label_widget = QtGui.QLabel(shape.label)
self.label_widget.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
@@ -60,22 +56,7 @@ class ShapeButton(QtGui.QToolButton):
self.setFixedSize(128, 128)
self.setBaseSize(128, 128)
# Adjust icon size to make space for text.
# Total height is 128. Let's allocate 70 for icon, 25 for label, 25 for ID.
self.icon_size = QtCore.QSize(71, 70)
# self.setIconSize(self.icon_size) # Removed as custom layout handles sizing
self._update_icon()
def set_text(self, text):
# Update the text of the label widget
self.label_widget.setText(text)
def _update_icon(self):
icon = self.shape.get_icon()
if icon:
# Set the pixmap on the icon_widget QLabel
pixmap = icon.get_qpixmap(self.icon_size)
self.icon_widget.setPixmap(pixmap)
else:
self.icon_widget.clear() # Clear pixmap if no icon

View File

@@ -19,18 +19,32 @@
# * USA *
# * *
# ***************************************************************************
from typing import Optional
from PySide import QtGui, QtCore
def _png2qpixmap(data, icon_size):
pixmap = QtGui.QPixmap()
pixmap.loadFromData(data, "PNG")
# Scale the pixmap if the requested size is different
if pixmap.size() != icon_size:
pixmap = pixmap.scaled(
icon_size,
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation,
)
return pixmap
class ShapeWidget(QtGui.QWidget):
def __init__(self, shape, parent=None):
def __init__(self, shape, icon_size: Optional[QtCore.QSize] = None, parent=None):
super(ShapeWidget, self).__init__(parent)
self.layout = QtGui.QVBoxLayout(self)
self.layout.setAlignment(QtCore.Qt.AlignHCenter)
self.shape = shape
ratio = self.devicePixelRatioF()
self.icon_size = QtCore.QSize(200 * ratio, 235 * ratio)
self.icon_size = icon_size or QtCore.QSize(200 * ratio, 235 * ratio)
self.icon_widget = QtGui.QLabel()
self.layout.addWidget(self.icon_widget)
@@ -41,3 +55,14 @@ class ShapeWidget(QtGui.QWidget):
if icon:
pixmap = icon.get_qpixmap(self.icon_size)
self.icon_widget.setPixmap(pixmap)
return
thumbnail = self.shape.get_thumbnail()
if thumbnail:
ratio = self.devicePixelRatioF()
size = self.icon_size * ratio
pixmap = _png2qpixmap(thumbnail, size)
self.icon_widget.setPixmap(pixmap)
return
self.icon_widget.clear() # Clear pixmap if no icon