mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-09-15 06:59:34 +02:00
refactor: more tweaks in pagination.py
This commit is contained in:
@@ -5,12 +5,15 @@
|
||||
from typing import override
|
||||
from warnings import catch_warnings
|
||||
|
||||
import structlog
|
||||
from PySide6.QtCore import QEvent, QObject, Qt, Signal
|
||||
from PySide6.QtWidgets import QHBoxLayout, QPushButton, QWidget
|
||||
|
||||
from tagstudio.qt.views.pagination_view import PaginationView
|
||||
from tagstudio.qt.views.styles.stylesheets import pagination_style
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
|
||||
class Pagination(QWidget):
|
||||
HEIGHT = 36
|
||||
@@ -21,9 +24,6 @@ class Pagination(QWidget):
|
||||
|
||||
def __init__(self, parent: QWidget | None = None) -> None:
|
||||
super().__init__(parent)
|
||||
self.page_count: int = 0
|
||||
self.current_page_index: int = 0
|
||||
|
||||
self.setHidden(True)
|
||||
self.setObjectName("pagination")
|
||||
self.setAttribute(Qt.WidgetAttribute.WA_StyledBackground)
|
||||
@@ -139,10 +139,10 @@ class Pagination(QWidget):
|
||||
button.setHidden(True)
|
||||
view.current_page_field.setText(str(i + 1))
|
||||
|
||||
start_offset = max(0, (index - 4) - 4)
|
||||
end_offset = min(page_count - 1, (index + 4) - 4)
|
||||
start_offset = max(0, index - view.BUFFER_PAGE_COUNT * 2)
|
||||
end_offset = min(page_count - 1, index)
|
||||
if i < index:
|
||||
if (i != 0) and i >= index - 4:
|
||||
if (i != 0) and i >= index - view.BUFFER_PAGE_COUNT:
|
||||
if button := self._get_button_at(
|
||||
view.start_buffer_layout, i - start_offset
|
||||
):
|
||||
@@ -155,7 +155,7 @@ class Pagination(QWidget):
|
||||
if button := self._get_button_at(view.end_buffer_layout, i):
|
||||
button.setHidden(True)
|
||||
elif i > index:
|
||||
if i != page_count - 1 and i <= index + 4:
|
||||
if i != page_count - 1 and i <= index + view.BUFFER_PAGE_COUNT:
|
||||
if button := self._get_button_at(view.end_buffer_layout, i - end_offset):
|
||||
button.setHidden(False)
|
||||
button.setText(str(i + 1))
|
||||
@@ -179,11 +179,9 @@ class Pagination(QWidget):
|
||||
view.validator.setTop(page_count)
|
||||
if emit:
|
||||
self.index.emit(index)
|
||||
self.current_page_index = index
|
||||
self.page_count = page_count
|
||||
|
||||
def _goto_page(self, index: int):
|
||||
self.update_buttons(self.page_count, index)
|
||||
self.update_buttons(self.layout().validator.top(), index)
|
||||
|
||||
def _assign_click(self, button: QPushButton, index: int):
|
||||
with catch_warnings(record=True):
|
||||
|
||||
@@ -22,7 +22,6 @@ class Tile(QWidget):
|
||||
super().__init__()
|
||||
self.setObjectName("tile")
|
||||
self.setAttribute(Qt.WidgetAttribute.WA_StyledBackground)
|
||||
self.title: str = title
|
||||
self.copy_callback: Callable[[], None] | None = None
|
||||
self.edit_callback: Callable[[], None] | None = None
|
||||
self.remove_callback: Callable[[], None] | None = None
|
||||
@@ -79,22 +78,24 @@ class Tile(QWidget):
|
||||
@override
|
||||
def enterEvent(self, event: QEnterEvent) -> None:
|
||||
# NOTE: You could pass the hover event to the inner widget if needed.
|
||||
layout = self.layout()
|
||||
if self.copy_callback:
|
||||
self.layout().copy_button.setHidden(False)
|
||||
layout.copy_button.setHidden(False)
|
||||
if self.edit_callback:
|
||||
self.layout().edit_button.setHidden(False)
|
||||
layout.edit_button.setHidden(False)
|
||||
if self.remove_callback:
|
||||
self.layout().remove_button.setHidden(False)
|
||||
layout.remove_button.setHidden(False)
|
||||
return super().enterEvent(event)
|
||||
|
||||
@override
|
||||
def leaveEvent(self, event: QEvent) -> None:
|
||||
layout = self.layout()
|
||||
if self.copy_callback:
|
||||
self.layout().copy_button.setHidden(True)
|
||||
layout.copy_button.setHidden(True)
|
||||
if self.edit_callback:
|
||||
self.layout().edit_button.setHidden(True)
|
||||
layout.edit_button.setHidden(True)
|
||||
if self.remove_callback:
|
||||
self.layout().remove_button.setHidden(True)
|
||||
layout.remove_button.setHidden(True)
|
||||
return super().leaveEvent(event)
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user