Skip to content

Commit e5696d6

Browse files
committed
refactor(app_blocker): paint picker icons through their QIcon engine
1 parent b407d3e commit e5696d6

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎src/prefabs/appPickerItemDelegate.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from typing import Optional
22

33
from PySide6.QtCore import QModelIndex, QRect, QSize, Qt
4-
from PySide6.QtGui import QColor, QFontMetrics, QPainter, QPixmap
4+
from PySide6.QtGui import QColor, QFontMetrics, QPainter
55
from PySide6.QtWidgets import QListView, QStyle, QStyleOptionViewItem
66
from qfluentwidgets import FluentIcon, ListItemDelegate, drawIcon, isDarkTheme
77
from qfluentwidgets.common.color import autoFallbackThemeColor, themeColor
88
from qfluentwidgets.common.font import getFont
99

10-
from app_blocker.appBlockerBackend import AppKind
10+
from app_blocker.appBlockerBackend import AppKind, InstalledApp
1111
from models.appPickerListModel import AppPickerListModel, AppPickerModelItem
1212

1313

@@ -97,10 +97,12 @@ def _paintCheckbox(self, painter: QPainter, option: QStyleOptionViewItem, item:
9797

9898
painter.restore()
9999

100-
def _paintIcon(self, painter: QPainter, icon_rect: QRect, pixmap: Optional[QPixmap]) -> None:
100+
def _paintIcon(self, painter: QPainter, icon_rect: QRect, app: InstalledApp) -> None:
101101
painter.save()
102-
if pixmap is not None and not pixmap.isNull():
103-
painter.drawPixmap(icon_rect, pixmap)
102+
# app_icon validates the file decodes (and warms the engine's base pixmap), the icon is then
103+
# painted through its engine so dpr scaling and pixmap caching (QPixmapCache) are Qt's job
104+
if app.app_icon is not None:
105+
app.app_qicon.paint(painter, icon_rect)
104106
else:
105107
# draw a rounded placeholder with an application icon when the app has no icon
106108
c = 255 if isDarkTheme() else 0
@@ -196,7 +198,7 @@ def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIn
196198
self._paintBackgroundAndIndicator(painter, option, index)
197199
self._paintCheckbox(painter, option, item)
198200

199-
self._paintIcon(painter, self._getIconRect(option), item.app.app_icon)
201+
self._paintIcon(painter, self._getIconRect(option), item.app)
200202

201203
badge_word = "Blocked" if item.already_blocked else item.app.kind.value.capitalize()
202204
text_rect = self._getTextRect(option)

0 commit comments

Comments
 (0)