Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dark background for icon when layer is light #1804

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion glue/icons/qt/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def layer_artist_icon(artist):
else:
bm = QtGui.QBitmap(icon_path('glue_box_point'))
color = mpl_to_qt_color(color)
pm = tint_pixmap(bm, color)
if min(color.red(), color.green(), color.blue()) > 240:
pm = tint_pixmap(bm, color, background_color=QtGui.QColor(0, 0, 0))
else:
pm = tint_pixmap(bm, color)

return QtGui.QIcon(pm)

Expand Down
10 changes: 8 additions & 2 deletions glue/utils/qt/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def cmap2pixmap(cmap, steps=50, size=(100, 100)):
return pm


def tint_pixmap(bm, color):
def tint_pixmap(bm, color, background_color=None):
"""
Re-color a monochrome pixmap object using `color`

Expand All @@ -104,18 +104,24 @@ def tint_pixmap(bm, color):
The Pixmap object
color : ``QColor``
The Qt color
background_color : ``QColor``
The background color to use

Returns
-------
pixmap : ``QPixmap``
The new pixmap
"""

if bm.depth() != 1:
raise TypeError("Input pixmap must have a depth of 1: %i" % bm.depth())

if background_color is None:
background_color = QtGui.QColor(0, 0, 0, 0)

image = bm.toImage()
image.setColor(1, color.rgba())
image.setColor(0, QtGui.QColor(0, 0, 0, 0).rgba())
image.setColor(0, background_color.rgba())

result = QtGui.QPixmap.fromImage(image)
return result
Expand Down