Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix](gui): improve search-standby-view UI on KDE #888

Merged
merged 3 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions feeluown/gui/components/menu.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from typing import Optional, TYPE_CHECKING

from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtCore import Qt

from feeluown.excs import ProviderIOError
from feeluown.utils.aio import run_fn, run_afn
Expand Down Expand Up @@ -75,6 +75,7 @@ async def goto_song_album(song):
def show_similar_resource(self, song):
from feeluown.gui.components.search import SearchResultView

# TODO: add a close button, and rename it to ClosableSearchResultView
class SearchResultViewWithEsc(SearchResultView):
def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
Expand All @@ -83,7 +84,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 @@ -92,11 +101,10 @@ def keyPressEvent(self, event):
x = self._app.ui.sidebar.width()
y = self._app.height() - height - self._app.ui.player_bar.height()

# Set the size using resize() and position using move()
view.resize(width, height)
pos = self._app.mapToGlobal(QPoint(0, 0))
view.move(pos.x() + x, pos.y() + y)
view.setWindowFlags(Qt.Popup)
# Do not use Qt.Popup, because it behaves differently on different
# platforms. For example, on macOS, it will pop up a window with a
# shadow, while on Linux(KDE) it won't.
view.setGeometry(x, y, width, height)
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
Loading