mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-08-16 17:19:32 +02:00
fix(ui) fix suggest box icon and opacity edge cases
This commit is contained in:
@@ -84,18 +84,11 @@ class FieldSuggestBox(SuggestBox[BaseFieldTemplate]):
|
||||
else:
|
||||
return ([], [])
|
||||
|
||||
@override
|
||||
def _on_shift_held(self, held: bool) -> None:
|
||||
if held:
|
||||
self.set_hint_icon(self._rm.hint_field_create)
|
||||
else:
|
||||
self._update_hint_icon()
|
||||
|
||||
return super()._on_shift_held(held)
|
||||
|
||||
@override
|
||||
def _update_hint_icon(self) -> None:
|
||||
if self.layout().search_field.text() and len(self._search_results) > 0:
|
||||
if self._is_shift_held:
|
||||
self.set_hint_icon(self._rm.hint_field_create)
|
||||
elif self.layout().search_field.text() and len(self._search_results) > 0:
|
||||
self.set_hint_icon(self._rm.hint_field_add)
|
||||
elif self.layout().search_field.text():
|
||||
self.set_hint_icon(self._rm.hint_field_create)
|
||||
|
||||
@@ -110,12 +110,12 @@ class SuggestBox[T](QWidget):
|
||||
self.layout().hint_icon_action.setIcon(QPixmap())
|
||||
|
||||
def _on_shift_held(self, held: bool) -> None:
|
||||
self._is_shift_held = held
|
||||
for i in range(0, self.layout().content_layout.count()):
|
||||
underlined_widget = self.layout().content_layout.itemAt(i).widget()
|
||||
assert isinstance(underlined_widget, UnderlinedWidget)
|
||||
|
||||
if held and i == self._selection_index:
|
||||
self._is_shift_held = True
|
||||
opacity_effect = QGraphicsOpacityEffect(self)
|
||||
opacity_effect.setOpacity(0.3)
|
||||
underlined_widget.widget.setGraphicsEffect(opacity_effect)
|
||||
@@ -123,8 +123,8 @@ class SuggestBox[T](QWidget):
|
||||
len(self._search_results) > i
|
||||
and _item_id(self._search_results[i]) not in self.added
|
||||
):
|
||||
self._is_shift_held = False
|
||||
underlined_widget.widget.setGraphicsEffect(None) # pyright: ignore[reportArgumentType]
|
||||
self._update_hint_icon()
|
||||
|
||||
def _on_index_updated(self, delta: int) -> None:
|
||||
# Initialize the widget count (non-hidden)
|
||||
@@ -156,10 +156,12 @@ class SuggestBox[T](QWidget):
|
||||
if i == self._selection_index:
|
||||
underlined_widget.toggle_underline(is_hidden=False)
|
||||
self.layout().scroll_area.ensureWidgetVisible(
|
||||
underlined_widget, xmargin=24, ymargin=0
|
||||
underlined_widget, xmargin=16, ymargin=0
|
||||
)
|
||||
else:
|
||||
underlined_widget.toggle_underline(is_hidden=True)
|
||||
|
||||
self._on_shift_held(self._is_shift_held)
|
||||
self._update_hint_icon()
|
||||
|
||||
def _clear_search_query(self) -> None:
|
||||
@@ -216,7 +218,7 @@ class SuggestBox[T](QWidget):
|
||||
self._selection_index = 0
|
||||
if self.layout().content_layout.count() > 0:
|
||||
self.layout().scroll_area.ensureWidgetVisible(
|
||||
self.layout().content_layout.itemAt(0).widget(), xmargin=24, ymargin=0
|
||||
self.layout().content_layout.itemAt(0).widget(), xmargin=16, ymargin=0
|
||||
)
|
||||
|
||||
# Get results for the search query
|
||||
|
||||
@@ -91,23 +91,15 @@ class TagSuggestBox(SuggestBox[Tag]):
|
||||
self._clear_search_query()
|
||||
self.done.emit("*") # The query does not matter
|
||||
|
||||
@override
|
||||
def _on_shift_held(self, held: bool) -> None:
|
||||
# Bypass normal _update_hint_icon() behavior first
|
||||
if not held and self._is_selected_item_added():
|
||||
self.set_hint_icon(self._rm.hint_tag_added)
|
||||
elif held:
|
||||
self.set_hint_icon(self._rm.hint_tag_create)
|
||||
else:
|
||||
self._update_hint_icon()
|
||||
|
||||
return super()._on_shift_held(held)
|
||||
|
||||
@override
|
||||
def _update_hint_icon(self) -> None:
|
||||
results = bool(len(self._search_results) > 0)
|
||||
|
||||
if results and self._is_selected_item_added():
|
||||
if not self._is_shift_held and self._is_selected_item_added():
|
||||
self.set_hint_icon(self._rm.hint_tag_added)
|
||||
elif self._is_shift_held:
|
||||
self.set_hint_icon(self._rm.hint_tag_create)
|
||||
elif results and self._is_selected_item_added():
|
||||
self.set_hint_icon(self._rm.hint_tag_added)
|
||||
elif results:
|
||||
self.set_hint_icon(self._rm.hint_tag_add)
|
||||
|
||||
Reference in New Issue
Block a user