added loading of bin image to resources cache

This commit is contained in:
iLLiCiTiT 2021-11-24 11:09:54 +01:00
parent 025b9ccb15
commit 75545e8605

View file

@ -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