From 75545e86058bda6cefcc1faebdf8fbfa48a73b5b Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 24 Nov 2021 11:09:54 +0100 Subject: [PATCH] added loading of bin image to resources cache --- .../project_manager/project_manager/style.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/openpype/tools/project_manager/project_manager/style.py b/openpype/tools/project_manager/project_manager/style.py index b138072cfd..d3d6857a63 100644 --- a/openpype/tools/project_manager/project_manager/style.py +++ b/openpype/tools/project_manager/project_manager/style.py @@ -1,3 +1,6 @@ +import os +from Qt import QtCore, QtGui + from avalon.vendor import qtawesome @@ -63,9 +66,59 @@ class ResourceCache: color=cls.colors["standard"], color_disabled=cls.colors["disabled"] ), + "remove": cls.get_remove_icon() } return cls.icons @classmethod def get_color(cls, color_name): return cls.colors[color_name] + + @classmethod + def get_remove_icon(cls): + src_image = get_remove_image() + normal_pix = paint_image_with_color( + src_image, + QtGui.QColor(cls.colors["standard"]) + ) + disabled_pix = paint_image_with_color( + src_image, + QtGui.QColor(cls.colors["disabled"]) + ) + icon = QtGui.QIcon(normal_pix) + icon.addPixmap(disabled_pix, QtGui.QIcon.Disabled, QtGui.QIcon.On) + icon.addPixmap(disabled_pix, QtGui.QIcon.Disabled, QtGui.QIcon.Off) + return icon + + +def get_remove_image(): + image_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "images", + "bin.png" + ) + return QtGui.QImage(image_path) + + +def paint_image_with_color(image, color): + """TODO: This function should be imported from utils. + + At the moment of creation is not available yet. + """ + width = image.width() + height = image.height() + + alpha_mask = image.createAlphaMask() + alpha_region = QtGui.QRegion(QtGui.QBitmap.fromImage(alpha_mask)) + + pixmap = QtGui.QPixmap(width, height) + pixmap.fill(QtCore.Qt.transparent) + + painter = QtGui.QPainter(pixmap) + painter.setClipRegion(alpha_region) + painter.setPen(QtCore.Qt.NoPen) + painter.setBrush(color) + painter.drawRect(QtCore.QRect(0, 0, width, height)) + painter.end() + + return pixmap