#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：SlideFrame.py
@Description：
@Author：XSH
@Time：2025/12/23 15:34
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from abc                                    import abstractmethod                       #
from PyQt5                                  import Qt                                   #
from AppInterfaces.UiInterface              import UiInterface                          #
from AppInterfaces.globalSlot               import globalSlot, AppSlot                  #
from AppCore.Contexts                       import *                                    #
from AppCore.DBModels                       import *                                    #
from AppCore.Levels                         import *                                    #
from AppUtils.utils                         import *                                    #
from AppSettings.Settings                   import *                                    #

class SlideFrame(Qt.QLabel, UiInterface):
    Number: int
    Icons : Qt.QPixmap
    clicked: Qt.pyqtSignal = Qt.pyqtSignal(object)

    def __init__(self, number: int, parent: Qt.QWidget = None):
        super(SlideFrame, self).__init__(parent)
        self.Number = number
        self.Initialization('SlideFrame', self, parent)

    def initValue(self):
        super(SlideFrame, self).initValue()


    def initProperty(self):
        super(SlideFrame, self).initProperty()
        self.setScaledContents(True)
        self.setFixedSize(250 * 0.5, 750 * 0.5)
        self.setPixmap(self.icons)



    def mousePressEvent(self, ev: Qt.QMouseEvent) -> None:
        self.IsPress = True
        self.setShadowEffect()
        if ev.button() == Qt.Qt.LeftButton:
            self.clicked.emit(self.Number)
            ev.accept()
        else:
            return super(SlideFrame, self).mousePressEvent(ev)

    def mouseReleaseEvent(self, ev: Qt.QMouseEvent) -> None:
        self.IsPress = False
        self.setShadowEffect()
        return super(SlideFrame, self).mouseReleaseEvent(ev)

    def enterEvent(self, ev: Qt.QEvent) -> None:
        self.IsHover = True
        self.setShadowEffect()
        return super(SlideFrame, self).enterEvent(ev)

    def leaveEvent(self, ev: Qt.QEvent) -> None:
        self.IsHover = False
        self.setShadowEffect()
        return super(SlideFrame, self).leaveEvent(ev)

    def setShadowEffect(self):
        ShadowEffect = Qt.QGraphicsDropShadowEffect()
        ShadowEffect.setOffset(0, 0)
        if self.IsPress:
            ShadowEffect.setColor(Qt.QColor(38, 78, 119, 127))
            ShadowEffect.setBlurRadius(22)
        elif self.IsHover:
            ShadowEffect.setColor(Qt.QColor(38, 119, 119, 127))
            ShadowEffect.setBlurRadius(35)
        else:
            ShadowEffect.setColor(Qt.QColor(38, 78, 119, 127))
            ShadowEffect.setBlurRadius(0)
        self.setGraphicsEffect(ShadowEffect)

    def initNumber(self):
        if not self.hasNumber:
            self.Number = TrayLevel.TraySlide1
    def initIcons(self):
        if not self.hasIcons:
            self.Icons = Qt.QPixmap(AppUtils.toSourceFile("Icon/Slide2.png"))


    @property
    def hasNumber(self) -> bool:
        return self.has_field('Number', int)

    @property
    def hasIcons(self):
        return self.has_field('Icons', Qt.QPixmap)

    @property
    def icons(self) -> Qt.QPixmap:
        self.initIcons()
        return self.Icons

    @property
    def number(self) -> int:
        self.initNumber()
        return self.Number

