You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.3 KiB

# coding:utf-8
from PySide6.QtCore import QEasingCurve, Qt, QPropertyAnimation
from PySide6.QtGui import QWheelEvent
from PySide6.QtWidgets import QScrollArea, QScrollBar
from ...common.smooth_scroll import SmoothScroll
from .scroll_bar import ScrollBar, SmoothScrollBar, SmoothScrollDelegate
class ScrollArea(QScrollArea):
""" Smooth scroll area """
def __init__(self, parent=None):
super().__init__(parent)
self.scrollDelagate = SmoothScrollDelegate(self)
class SingleDirectionScrollArea(QScrollArea):
""" Single direction scroll area"""
def __init__(self, parent=None, orient=Qt.Vertical):
"""
Parameters
----------
parent: QWidget
parent widget
orient: Orientation
scroll orientation
"""
super().__init__(parent)
self.smoothScroll = SmoothScroll(self, orient)
self.vScrollBar = SmoothScrollBar(Qt.Vertical, self)
self.hScrollBar = SmoothScrollBar(Qt.Horizontal, self)
def setVerticalScrollBarPolicy(self, policy):
super().setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.vScrollBar.setForceHidden(policy == Qt.ScrollBarAlwaysOff)
def setHorizontalScrollBarPolicy(self, policy):
super().setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.hScrollBar.setForceHidden(policy == Qt.ScrollBarAlwaysOff)
def setSmoothMode(self, mode):
""" set smooth mode
Parameters
----------
mode: SmoothMode
smooth scroll mode
"""
self.smoothScroll.setSmoothMode(mode)
def wheelEvent(self, e: QWheelEvent):
self.smoothScroll.wheelEvent(e)
e.setAccepted(True)
class SmoothScrollArea(QScrollArea):
""" Smooth scroll area """
def __init__(self, parent=None):
super().__init__(parent)
self.delegate = SmoothScrollDelegate(self, True)
def setScrollAnimation(self, orient, duration, easing=QEasingCurve.OutCubic):
""" set scroll animation
Parameters
----------
orient: Orient
scroll orientation
duration: int
scroll duration
easing: QEasingCurve
animation type
"""
bar = self.delegate.hScrollBar if orient == Qt.Horizontal else self.delegate.vScrollBar
bar.setScrollAnimation(duration, easing)