mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
added loading of bin image to resources cache
This commit is contained in:
parent
025b9ccb15
commit
75545e8605
1 changed files with 53 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue