#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：DirectionOperation.py
@Description：
@Author：XSH
@Time：2025/12/19 13: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 *                                  #

class DirectionOperation(Qt.QLabel, UiInterface):
    AxisMoveSignal              : Qt.pyqtSignal = Qt.pyqtSignal(object)                #
    ButtonUp                    : Qt.QLabel                #
    ButtonDown                  : Qt.QLabel                #
    ButtonLeft                  : Qt.QLabel                #
    ButtonRight                 : Qt.QLabel                #
    ButtonInit                  : Qt.QLabel                #
    IconInit                    : Qt.QPixmap               #
    IconDirection               : Qt.QPixmap               #
    def __init__(self, parent: Qt.QWidget = None):
        super(DirectionOperation, self).__init__(parent)
        self.Initialization("", self, parent)

    def initValue(self):
        self.initButtonUp                    ()
        self.initButtonDown                  ()
        self.initButtonLeft                  ()
        self.initButtonRight                 ()
        self.initButtonInit                  ()
        self.initIconInit                    ()
        self.initIconDirection               ()

    def initProperty(self):
        super(DirectionOperation, self).initProperty()
        self.setFixedSize(150, 150)
        self.setScaledContents( True)
        self.setPixmap(self.IconDirection)
        self.ButtonInit.setScaledContents( True)
        self.ButtonInit.setPixmap(self.IconInit)

        self.ButtonUp                    .setAttribute(Qt.Qt.WA_TranslucentBackground, True)
        self.ButtonDown                  .setAttribute(Qt.Qt.WA_TranslucentBackground, True)
        self.ButtonLeft                  .setAttribute(Qt.Qt.WA_TranslucentBackground, True)
        self.ButtonRight                 .setAttribute(Qt.Qt.WA_TranslucentBackground, True)
        self.ButtonInit                  .setAttribute(Qt.Qt.WA_TranslucentBackground, True)

        self.ButtonUp                    .setFixedSize(50, 50)
        self.ButtonDown                  .setFixedSize(50, 50)
        self.ButtonLeft                  .setFixedSize(50, 50)
        self.ButtonRight                 .setFixedSize(50, 50)
        self.ButtonInit                  .setFixedSize(50, 50)

        self.ButtonUp                    .installEventFilter(self)
        self.ButtonDown                  .installEventFilter(self)
        self.ButtonLeft                  .installEventFilter(self)
        self.ButtonRight                 .installEventFilter(self)
        self.ButtonInit                  .installEventFilter(self)

    def eventFilter(self, obj: Qt.QObject, ev: Qt.QEvent) -> bool:
        if obj == self.ButtonUp:
            if ev.type() == Qt.QEvent.MouseButtonPress:
                self.AxisMoveSignal.emit(MoveDirection.Up)
                print("Up")
                return True
        elif obj == self.ButtonDown:
            if ev.type() == Qt.QEvent.MouseButtonPress:
                self.AxisMoveSignal.emit(MoveDirection.Down)
                print("Down")
                return True
        elif obj == self.ButtonLeft:
            if ev.type() == Qt.QEvent.MouseButtonPress:
                self.AxisMoveSignal.emit(MoveDirection.Left)
                print("Left")
                return True
        elif obj == self.ButtonRight:
            if ev.type() == Qt.QEvent.MouseButtonPress:
                self.AxisMoveSignal.emit(MoveDirection.Right)
                print("Right")
                return True
        elif obj == self.ButtonInit:
            if ev.type() == Qt.QEvent.MouseButtonPress:
                self.AxisMoveSignal.emit(MoveDirection.Init)
                print("Init")
                return True

        return super(DirectionOperation, self).eventFilter(obj, ev)


    def initLayouts(self):
        if self.hasWindowLayouts:
            return
        self.setContentsMargins(0, 0, 0, 0)
        main_layout: Qt.QGridLayout = Qt.QGridLayout()
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)

        main_layout.addWidget(self.ButtonUp                    , 0, 1, 1, 1)
        main_layout.addWidget(self.ButtonLeft                  , 1, 0, 1, 1)
        main_layout.addWidget(self.ButtonInit                  , 1, 1, 1, 1)
        main_layout.addWidget(self.ButtonRight                 , 1, 2, 1, 1)
        main_layout.addWidget(self.ButtonDown                  , 2, 1, 1, 1)
        self.setLayout(main_layout)





    def initButtonUp        (self):
        if not self.hasButtonUp        :
            self.ButtonUp         = Qt.QLabel  ()

    def initButtonDown      (self):
        if not self.hasButtonDown      :
            self.ButtonDown       = Qt.QLabel  ()


    def initButtonLeft      (self):
        if not self.hasButtonLeft      :
            self.ButtonLeft       = Qt.QLabel  ()


    def initButtonRight     (self):
        if not self.hasButtonRight     :
            self.ButtonRight      = Qt.QLabel  ()


    def initButtonInit      (self):
        if not self.hasButtonInit      :
            self.ButtonInit       = Qt.QLabel  ()


    def initIconInit        (self):
        if not self.hasIconInit        :
            self.IconInit         = Qt.QPixmap      (AppUtils.toSourceFile("Icon/Change.png"))
            self.IconInit = self.IconInit.scaled(50, 50, Qt.Qt.IgnoreAspectRatio, Qt.Qt.SmoothTransformation)


    def initIconDirection   (self):
        if not self.hasIconDirection   :
            self.IconDirection    = Qt.QPixmap      (AppUtils.toSourceFile("Icon/GimbalDashboard.png"))
            self.IconDirection = self.IconDirection.scaled(150, 150, Qt.Qt.IgnoreAspectRatio, Qt.Qt.SmoothTransformation)





    @property
    def hasDirectionFrame              (self) -> bool:
        return self.has_field('DirectionFrame'  , Qt.QLabel      )

    @property
    def hasButtonUp                    (self) -> bool:
        return self.has_field('ButtonUp'        , Qt.QPushButton )

    @property
    def hasButtonDown                  (self) -> bool:
        return self.has_field('ButtonDown'      , Qt.QPushButton )

    @property
    def hasButtonLeft                  (self) -> bool:
        return self.has_field('ButtonLeft'      , Qt.QPushButton )

    @property
    def hasButtonRight                 (self) -> bool:
        return self.has_field('ButtonRight'     , Qt.QPushButton )

    @property
    def hasButtonInit                  (self) -> bool:
        return self.has_field('ButtonInit'      , Qt.QPushButton )

    @property
    def hasIconInit                    (self) -> bool:
        return self.has_field('IconInit'        , Qt.QPixmap     )

    @property
    def hasIconDirection               (self) -> bool:
        return self.has_field('IconDirection'   , Qt.QPixmap     )




