diff --git a/angrmanagement/ui/dialogs/command_palette.py b/angrmanagement/ui/dialogs/command_palette.py index 720dfa114..de88004e1 100644 --- a/angrmanagement/ui/dialogs/command_palette.py +++ b/angrmanagement/ui/dialogs/command_palette.py @@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Any from PySide6.QtCore import QAbstractItemModel, QMargins, QModelIndex, QRectF, QSize, Qt -from PySide6.QtGui import QBrush, QColor, QTextDocument +from PySide6.QtGui import QBrush, QColor, QPalette, QPen, QTextCharFormat, QTextCursor, QTextDocument from PySide6.QtWidgets import QDialog, QLineEdit, QListView, QStyle, QStyledItemDelegate, QVBoxLayout from thefuzz import process @@ -17,6 +17,7 @@ from angrmanagement.ui.workspace import Workspace +# pylint:disable=unused-argument,no-self-use class PaletteModel(QAbstractItemModel): """ Data provider for item palette. @@ -32,20 +33,20 @@ def __init__(self, workspace: Workspace) -> None: self._filtered_items: list[Any] = self._available_items self._filter_text: str = "" - def rowCount(self, _): + def rowCount(self, parent=None): return len(self._filtered_items) - def columnCount(self, _) -> int: # pylint:disable=no-self-use + def columnCount(self, parent=None): return 1 - def index(self, row, col, _): - return self.createIndex(row, col, None) + def index(self, row, column, parent=None): + return self.createIndex(row, column, None) - def parent(self, _): # pylint:disable=no-self-use + def parent(self, index=None): # type:ignore return QModelIndex() - def data(self, index, role): - if not index.isValid() or role != Qt.DisplayRole: + def data(self, index, role: int = Qt.ItemDataRole.DisplayRole) -> Any: + if not index.isValid() or role != Qt.ItemDataRole.DisplayRole: return None row = index.row() return self._filtered_items[row] if row < len(self._filtered_items) else None @@ -105,6 +106,7 @@ def get_items(self) -> list[Function]: instance = self.workspace.main_instance if instance and not instance.project.am_none: project = instance.project.am_obj + assert project is not None items.extend([func for _, func in project.kb.functions.items()]) return items @@ -119,7 +121,7 @@ def get_icon_color_and_text_for_item(self, item: Function) -> tuple[QColor | Non elif item.alignment: color = Conf.function_table_alignment_color else: - color = Qt.GlobalColor.gray + color = QColor(Qt.GlobalColor.gray) return (color, "f") def get_caption_for_item(self, item: Function) -> str: @@ -170,6 +172,7 @@ def _get_text_document(index): def paint(self, painter, option, index) -> None: if index.column() == 0: + painter.save() if option.state & QStyle.StateFlag.State_Selected: b = QBrush(option.palette.highlight()) painter.fillRect(option.rect, b) @@ -182,13 +185,14 @@ def paint(self, painter, option, index) -> None: annotation_text = model.get_annotation_for_item(item) if annotation_text: + if option.state & QStyle.StateFlag.State_Selected: + painter.setPen(QPen(option.palette.color(QPalette.ColorRole.HighlightedText))) painter.drawText( option.rect.marginsRemoved(QMargins(3, 3, 3, 3)), Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter, annotation_text, ) - painter.save() painter.translate(option.rect.topLeft()) if self._display_icons: @@ -201,6 +205,13 @@ def paint(self, painter, option, index) -> None: painter.drawText(icon_rect, Qt.AlignmentFlag.AlignCenter, icon_text) painter.translate(self.icon_width, 0) + if option.state & QStyle.StateFlag.State_Selected: + cursor = QTextCursor(td) + cursor.select(QTextCursor.SelectionType.Document) + char_format = QTextCharFormat() + char_format.setForeground(option.palette.highlightedText()) + cursor.mergeCharFormat(char_format) + td.drawContents(painter) painter.restore() else: @@ -214,7 +225,7 @@ def sizeHint(self, option, index) -> QSize: width = s.width() if self._display_icons: width += self.icon_width - return QSize(width, s.height()) + return QSize(int(width), int(s.height())) return super().sizeHint(option, index)