File indexing completed on 2025-01-26 04:11:39

0001 """
0002 SPDX-FileCopyrightText: 2022 Ivan Santa Maria <ghevan@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-2.0-or-later
0005 """
0006 from PyQt5.QtGui import QIcon, QPixmap, QColor, QPainter
0007 
0008 needDarkIcon = False
0009 
0010 def setNeedDarkIcon(color):
0011     global needDarkIcon
0012     needDarkIcon = True if color.value() > 100 else False
0013     return
0014 
0015 def getThemedIcon(filepath) -> QIcon:
0016     global needDarkIcon
0017     pixmap = QPixmap(filepath)
0018     painter = QPainter(pixmap)
0019     painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
0020 
0021     if needDarkIcon:
0022         painter.fillRect(pixmap.rect(),QColor(32,32,32))
0023     else:
0024         painter.fillRect(pixmap.rect(),QColor(255,255,255))
0025 
0026     painter.end()
0027     return QIcon(pixmap)