Skip to content

Commit

Permalink
[bugfix](gui): improve search view UI on KDE
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed Nov 30, 2024
1 parent eab0702 commit df9409c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
11 changes: 9 additions & 2 deletions feeluown/gui/components/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,15 @@ def keyPressEvent(self, event):
super().keyPressEvent(event)

q = f'{song.title} {song.artists_name}'
view = SearchResultViewWithEsc(self._app, parent=self._app)
view = SearchResultViewWithEsc(self._app, transparent_bg=False, parent=self._app)

view.setStyleSheet('''
SearchResultView {
border: 1px solid gray;
border-radius: 2px;
}
''')

source_in = self._app.browser.local_storage.get(KeySourceIn, None)
run_afn(view.search_and_render, q, SearchType.so, source_in)

Expand All @@ -96,7 +104,6 @@ def keyPressEvent(self, event):
view.resize(width, height)
pos = self._app.mapToGlobal(QPoint(0, 0))
view.move(pos.x() + x, pos.y() + y)
view.setWindowFlags(Qt.Popup)
view.show()
view.raise_()

Expand Down
31 changes: 19 additions & 12 deletions feeluown/gui/components/search.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from datetime import datetime

from PyQt5.QtWidgets import QAbstractItemView, QFrame, QVBoxLayout
from PyQt5.QtWidgets import QAbstractItemView, QFrame, QVBoxLayout, QScrollArea

from feeluown.library import SearchType
from feeluown.gui.page_containers.table import TableContainer, Renderer
from feeluown.gui.page_containers.scroll_area import ScrollArea
from feeluown.gui.widgets.img_card_list import ImgCardListDelegate
from feeluown.gui.widgets.songs import SongsTableView, ColumnsMode
from feeluown.gui.base_renderer import TabBarRendererMixin
from feeluown.gui.helpers import BgTransparentMixin
from feeluown.gui.helpers import BgTransparentMixin, unify_scroll_area_style, \
set_widget_bg_transparent
from feeluown.gui.widgets.magicbox import KeySourceIn, KeyType
from feeluown.gui.widgets.header import LargeHeader, MidHeader
from feeluown.gui.widgets.accordion import Accordion
Expand All @@ -30,9 +30,20 @@ def get_tab_idx(search_type):
raise ValueError("unknown search type")


class SearchResultView(ScrollArea):
def __init__(self, app, *args, **kwargs):
super().__init__(*args, **kwargs)
class SearchResultView(QScrollArea):
"""
Usage:
view = SearchResultView(app)
await view.search_and_render(q, search_type, source_in)
"""
def __init__(self, app, transparent_bg=True, parent=None):
super().__init__(parent=parent)

self.setWidgetResizable(True)
self.setFrameShape(QFrame.NoFrame)
unify_scroll_area_style(self)
if transparent_bg:
set_widget_bg_transparent(self)

self.body = Body(app)
self.setWidget(self.body)
Expand All @@ -41,15 +52,11 @@ def fillable_bg_height(self):
"""Implement VFillableBg protocol"""
return self.body.height() - self.body.accordion.height()

async def search_and_render(self, *args, **kwargs):
await self.body.search_and_render(*args, **kwargs)
async def search_and_render(self, q, search_type, source_in):
await self.body.search_and_render(q, search_type, source_in)


class Body(QFrame, BgTransparentMixin):
"""
view = SearchResultView(app, q)
await view.render()
"""
def __init__(self, app, **kwargs):
super().__init__(**kwargs)

Expand Down
14 changes: 13 additions & 1 deletion feeluown/gui/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
QAbstractListModel, QPoint
from PyQt5.QtGui import QPalette, QFontMetrics, QColor, QPainter, QMouseEvent, \
QKeySequence
from PyQt5.QtWidgets import QApplication, QScrollArea, QWidget, QShortcut
from PyQt5.QtWidgets import QApplication, QScrollArea, QWidget, QShortcut, \
QAbstractScrollArea

from feeluown.utils.aio import run_afn, run_fn
from feeluown.utils.reader import AsyncReader, Reader
Expand Down Expand Up @@ -115,6 +116,17 @@ def palette_set_bg_color(palette, color):
palette.setColor(QPalette.Inactive, QPalette.Window, color)


def unify_scroll_area_style(scroll_area: QAbstractScrollArea):
if not IS_MACOS:
scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)


def set_widget_bg_transparent(widget: QWidget):
palette = widget.palette()
palette_set_bg_color(palette, Qt.transparent)
widget.setPalette(palette)


class BgTransparentMixin:
def __init__(self: QWidget, *args, **kwargs): # type: ignore[misc]
palette = self.palette()
Expand Down

0 comments on commit df9409c

Please sign in to comment.