#!D:/IDE/anaconda3/envs python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName：UiUtils.py\n
 @DateTime: 2025/7/17 14:46\n
 @Author  ：xsh
"""
from PyQt5 import Qt

class UiUtils:
    ON_COLOR    : str = "#27ae60"
    OFF_COLOR   : str = "#e74c3c"
    @staticmethod
    def center_on_screen(self: Qt.QWidget):
        # 获取屏幕尺寸
        screen_geometry = Qt.QApplication.primaryScreen().availableGeometry()
        screen_width = screen_geometry.width()
        screen_height = screen_geometry.height()

        # 获取窗口尺寸
        window_width = self.width()
        window_height = self.height()

        # 计算居中位置
        x = (screen_width - window_width) // 2
        y = (screen_height - window_height) // 2

        # 移动窗口到居中位置
        self.move(x, y)

    @classmethod
    def to_center(cls, widget: Qt.QWidget, rect: Qt.QRect = None):
        if isinstance(rect, (Qt.QRect, Qt.QRectF)):
            screen_width    = rect.width()
            screen_height   = rect.height()
        else:
            screen_geometry = Qt.QApplication.primaryScreen().availableGeometry()
            screen_width = screen_geometry.width()
            screen_height = screen_geometry.height()
        widget.move((screen_width - widget.width()) // 2, (screen_height - widget.height()) // 2)

    @classmethod
    def to_offset_center(cls, widget: Qt.QWidget, rect: Qt.QRect = None, offset_x: int = 0, offset_y: int = 0):
        if isinstance(rect, (Qt.QRect, Qt.QRectF)):
            screen_width    = rect.width()
            screen_height   = rect.height()
        else:
            screen_geometry = Qt.QApplication.primaryScreen().availableGeometry()
            screen_width = screen_geometry.width()
            screen_height = screen_geometry.height()
        widget.move((screen_width - widget.width()) // 2 + offset_x // 2, (screen_height - widget.height()) // 2 + offset_y // 2)
    @classmethod
    def getSlideStyle(cls) -> str:
        return """
            
            QWidget {
                background-color: #1e3d59;
                color: #ffffff;
                font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                font-size: 14px;
                font-weight: bold;
            }
            .QLabel {
                border: 1px solid #1e3d59;
                background-color: #2d5a7c;
                color: #ffffff;
                padding: 5px;
                font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                font-size: 12px;
            }
        """
    @classmethod
    def setColorStyle(cls, label: Qt.QLabel, enable: bool):
        label.setStyleSheet(f"""
        QLabel {{
                border: 1px solid #1e3d59;
                background-color: {cls.ON_COLOR if enable else cls.OFF_COLOR};
                color: #ffffff;
                padding: 5px;
                font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                font-size: 12px;
            }}
        """)

    @classmethod
    def getBigButtonStyle(cls) -> str:
        return """ QLabel{
                        min-width   : 100px;
                        min-height  : 30px;
                        background-color: #1e3d59;
                        color: #ffffff;
                        padding: 5px;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                        font-weight: bold;
                    }
                    QPushButton {
                        min-width   : 100px;
                        min-height  : 30px;
                        background-color: #1e3d59;
                        color: #ffffff;
                        border: 1px solid #2d5a7c;
                        border-radius: 3px;
                        padding: 5px;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                        font-weight: bold;
                    }
                    QPushButton:hover {
                        background-color: #2d5a7c;
                    }
                    QPushButton:checked {
                        background-color: #3d7ab0;
                        border-color: #3d7ab0;
                    }
                    QPushButton:checked:hover {
                        background-color: #4d8ac0;
                    }
                    QPushButton:pressed {
                        background-color: #1e3d59;
                    }
                    QComboBox {
                        min-width   : 100px;
                        min-height  : 30px;
                        background-color: #2d5a7c;
                        color: #ffffff;
                        border: 2px solid #1e3d59;
                        border-radius: 5px;
                        padding: 5px;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                    }

                    QComboBox:hover {
                        border-color: #3d7ab0;
                    }

                    QComboBox::drop-down {
                        border: none;
                        width: 20px;
                    }

                    QComboBox::down-arrow {
                        image: none;
                    }

                    QComboBox QAbstractItemView {
                        background-color: #2d5a7c;
                        color: #ffffff;
                        border: 2px solid #1e3d59;
                        border-radius: 5px;
                        selection-background-color: #3d7ab0;
                        selection-color: #ffffff;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                    }

                    QComboBox QAbstractItemView::item {
                        padding: 5px;
                        min-height  : 30px;
                    }

                    QComboBox QAbstractItemView::item:hover {
                        background-color: #3d7ab0;
                    }
                    QDoubleSpinBox
                    {
                        min-width   : 100px;
                        min-height  : 30px;
                        background-color: #2d5a7c;
                        color: #ffffff;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                    }
                    QDoubleSpinBox::groove:horizontal {
                        border: 2px solid #1e3d59;
                        height: 8px;
                        background: #2d5a7c;
                        border-radius: 4px;
                    }

                    QDoubleSpinBox::handle:horizontal {
                        background: #3d7ab0;
                        border: none;
                        width: 16px;
                        margin: -4px 0;
                        border-radius: 8px;
                    }

                    QDoubleSpinBox::handle:horizontal:hover {
                        background: #2d5a7c;
                    }

                """

    @classmethod
    def getButtonStyle(cls) -> str:
        return """ QLabel{
                        height      : 30px;
                        background-color: #1e3d59;
                        color: #ffffff;
                        padding: 5px;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                        font-weight: bold;
                    }
                    QPushButton {
                        height      : 30px;
                        background-color: #1e3d59;
                        color: #ffffff;
                        border: 1px solid #2d5a7c;
                        border-radius: 3px;
                        padding: 5px;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                        font-weight: bold;
                    }
                    QPushButton:hover {
                        background-color: #2d5a7c;
                    }
                    QPushButton:checked {
                        background-color: #3d7ab0;
                        border-color: #3d7ab0;
                    }
                    QPushButton:checked:hover {
                        background-color: #4d8ac0;
                    }
                    QPushButton:pressed {
                        background-color: #1e3d59;
                    }
                    QComboBox {
                        height      : 30px;
                        background-color: #2d5a7c;
                        color: #ffffff;
                        border: 2px solid #1e3d59;
                        border-radius: 5px;
                        padding: 5px;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                    }

                    QComboBox:hover {
                        border-color: #3d7ab0;
                    }

                    QComboBox::drop-down {
                        border: none;
                        width: 20px;
                    }

                    QComboBox::down-arrow {
                        image: none;
                    }

                    QComboBox QAbstractItemView {
                        background-color: #2d5a7c;
                        color: #ffffff;
                        border: 2px solid #1e3d59;
                        border-radius: 5px;
                        selection-background-color: #3d7ab0;
                        selection-color: #ffffff;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                    }

                    QComboBox QAbstractItemView::item {
                        padding     : 5px;
                        height      : 30px;
                    }

                    QComboBox QAbstractItemView::item:hover {
                        background-color: #3d7ab0;
                    }
                    QSpinBox
                    {
                        height      : 30px;
                        background-color: #2d5a7c;
                        color: #ffffff;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                    }
                    QSpinBox::groove:horizontal {
                        border: 2px solid #1e3d59;
                        height: 8px;
                        background: #2d5a7c;
                        border-radius: 4px;
                    }

                    QSpinBox::handle:horizontal {
                        background: #3d7ab0;
                        border: none;
                        width: 16px;
                        margin: -4px 0;
                        border-radius: 8px;
                    }

                    QSpinBox::handle:horizontal:hover {
                        background: #2d5a7c;
                    }
                    QDoubleSpinBox
                    {
                        height      : 30px;
                        background-color: #2d5a7c;
                        color: #ffffff;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                    }
                    QDoubleSpinBox::groove:horizontal {
                        border: 2px solid #1e3d59;
                        height: 8px;
                        background: #2d5a7c;
                        border-radius: 4px;
                    }

                    QDoubleSpinBox::handle:horizontal {
                        background: #3d7ab0;
                        border: none;
                        width: 16px;
                        margin: -4px 0;
                        border-radius: 8px;
                    }

                    QDoubleSpinBox::handle:horizontal:hover {
                        background: #2d5a7c;
                    }

                """

    @classmethod
    def getDrawDataStyle(cls) -> str:
        return """QWidget {
                    background-color: #1e3d59;
                    color: #ffffff;
                    font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                    font-size: 14px;
                    font-weight: bold;}
                    .QGroupBox{
                    background-color: #1e3d59;
                    color: #ffffff;
                    background-color: #1e3d59;
                    border: 1px solid #2d5a7c;
                    border-radius: 5px;
                    font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                    font-size: 14px;
                    font-weight: bold;}
                    .QLabel{
                    background-color: #1e3d59;
                    color: #ffffff;
                    font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                    font-size: 14px;
                    font-weight: bold;
                    }
                """
    @classmethod
    def getGroupBoxStyle(cls) -> str:
        return """
        QGroupBox{
            background-color: #1e3d59;
            color: #ffffff;
            background-color: #1e3d59;
            border: 1px solid #2d5a7c;
            border-radius: 5px;
            font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
            font-size: 14px;
            font-weight: bold;
            }
        """
    @classmethod
    def getControlWidgetStyle(cls) -> str:
        return  """
                    QWidget{
                        background-color    : #1e3d59;
                        border-radius       : 100px;
                        border              : 2px solid #2d5a7c;
                    }
                    
                """
    @classmethod
    def getControlButtonStyle(cls) -> str:
        return """
            QPushButton[nav="control"]
            {
                background-color: #2d5a7c;
                color: white;
                border: none;
                border-radius: 35px;
                font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                font-size: 16px;
                font-weight: bold;
            }
            QPushButton[nav="control"]:hover {
                background-color: #3d7ab0;
            }
            
            QPushButton[nav="control"]:pressed {
                background-color: #1e3d59;
            }
            
        """

    @classmethod
    def getWindowStyle(cls) -> str:
        return """QWidget {
                    background-color: #1e3d59;
                    color: #ffffff;
                    margin: 2px;
                    padding: 2px;
                    border-radius: 3px;
                    font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                    font-size: 14px;
                    font-weight: bold;
                }"""

    @classmethod
    def getTransparentStyle(cls) -> str:
        return """QWidget {
                    opacity: 0.8; /* 80% 不透明度（即 20% 透明） */
                    background-color: #1e3d59;
                    color: #ffffff;
                    border-radius: 4px;
                    }
                    QPushButton
                {
                    background-color: #2d5a7c;
                    color: white;
                    border: none;
                    border-radius: 35px;
                    font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                    font-size: 16px;
                    font-weight: bold;
                }
                QPushButton:hover {
                    background-color: #3d7ab0;
                }
                
                QPushButton:pressed {
                    background-color: #1e3d59;
                }
                QSpinBox
                    {
                        height      : 30px;
                        background-color: #2d5a7c;
                        color: #ffffff;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                    }
                    QSpinBox::groove:horizontal {
                        border: 2px solid #1e3d59;
                        height: 8px;
                        background: #2d5a7c;
                        border-radius: 4px;
                    }

                    QSpinBox::handle:horizontal {
                        background: #3d7ab0;
                        border: none;
                        width: 16px;
                        margin: -4px 0;
                        border-radius: 8px;
                    }

                    QSpinBox::handle:horizontal:hover {
                        background: #2d5a7c;
                    }
                    QDoubleSpinBox
                    {
                        height      : 30px;
                        background-color: #2d5a7c;
                        color: #ffffff;
                        font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                        font-size: 14px;
                    }
                    QDoubleSpinBox::groove:horizontal {
                        border: 2px solid #1e3d59;
                        height: 8px;
                        background: #2d5a7c;
                        border-radius: 4px;
                    }

                    QDoubleSpinBox::handle:horizontal {
                        background: #3d7ab0;
                        border: none;
                        width: 16px;
                        margin: -4px 0;
                        border-radius: 8px;
                    }

                    QDoubleSpinBox::handle:horizontal:hover {
                        background: #2d5a7c;
                    }
                """
    @classmethod
    def getWidgetStyle(cls) -> str:
        return """QWidget {
                    background-color: #1e3d59;
                    color: #ffffff;
                    margin: 2px;
                    padding: 2px;
                    border-radius: 3px;
                    font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                    font-size: 14px;
                    font-weight: bold;
                }
                QGroupBox{
                    background-color: #1e3d59;
                    color: #ffffff;
                    background-color: #1e3d59;
                    border: 1px solid #2d5a7c;
                    border-radius: 5px;
                    font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                    font-size: 14px;
                    font-weight: bold;}
                QScrollBar:vertical {
                    margin: 16px 0px 16px 0px;
                    background-color: #1f3dDD;
                    border: 0px;
                    width: 14px;
                    }
                    
                QScrollBar::handle:vertical {
                    background-color: #1f3dDD;
                    border-radius: 7px;
                    width: 13px;
                    }
                    
                QScrollBar::handle:vertical:hover {
                    background-color: #1f3dDD;
                    }
                    
                QScrollBar::sub-line:vertical {
                    subcontrol-position: top;
                    subcontrol-origin: margin;
                    background-color: #1f3dDD;
                    border: 1px solid #2d5a7c;
                    height: 16px;
                    }
                    
                QScrollBar::add-line:vertical {
                    subcontrol-position: bottom;
                    subcontrol-origin: margin;
                    background-color: #1f3dDD;
                    border: 1px solid #2d5a7c;
                    height: 16px;
                }
                QScrollBar:horizontal {
                    margin: 0px 16px 0px 16px;
                    background-color: rgb(11,54,117);
                    border: none;
                    height: 14px;
                }
                
                QScrollBar::handle:horizontal {
                    background-color: rgba(59,103,168,190);
                    border-radius: 7px;
                    height: 14px;
                }
                
                QScrollBar::handle:horizontal:hover {
                    background-color: rgba(59,103,168,220);
                }
                
                QScrollBar::add-line:horizontal {
                    subcontrol-position: right;
                    subcontrol-origin: margin;
                    background-color: rgb(11,54,117);
                    border: 1px solid rgb(11,54,117);
                    height: 12px;
                    width: 6px;
                }
                
                QScrollBar::sub-line:horizontal {
                subcontrol-position: left;
                subcontrol-origin: margin;
                background-color: rgb(11,54,117);
                border: 1px solid rgb(11,54,117);
                height: 12px;
                width: 6px;
                }
                """

    @classmethod
    def getTableStyle(cls) -> str:
        return """
            QLabel{
                min-width   : 70px;
                min-height  : 30px;
                background-color: #1e3d59;
                color: #ffffff;
                padding: 5px;
                font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                font-size: 14px;
                font-weight: bold;
            }
            QPushButton {
                min-height  : 30px;
                background-color: #1e3d59;
                color: #ffffff;
                border: 1px solid #2d5a7c;
                border-radius: 3px;
                padding: 5px;
                font-family: "Microsoft YaHei", "微软雅黑", "SimHei", "黑体";
                font-size: 14px;
                font-weight: bold;
            }
            QPushButton:hover {
                background-color: #2d5a7c;
            }
            QPushButton:checked {
                background-color: #3d7ab0;
                border-color: #3d7ab0;
            }
            QPushButton:checked:hover {
                background-color: #4d8ac0;
            }
            QPushButton:pressed {
                background-color: #1e3d59;
            }
            QTableWidget {
                background-color: #1e3d59;
                color: #ffffff;
                gridline-color: #2d5a7c;
                border: 1px solid #1e3d59;
                border-radius: 4px;
            }
            
            QTableWidget::item {
                padding: 5px;
                border-bottom: 1px solid #2d5a7c;
            }
            
            QTableWidget::item:selected {
                background-color: #3d7ab0;
                color: #ffffff;
            }
            
            /* HitBotTab specific styles */
            QTableWidget {
                background-color: #1e3d59;
                color: #ffffff;
                gridline-color: #2d5a7c;
            }
            
            /* Header styles */
            QHeaderView::section {
                background-color: #2d5a7c;
                color: #ffffff;
                padding: 8px;
                border: none;
                border-right: 1px solid #1e3d59;
                border-bottom: 1px solid #1e3d59;
                font-weight: bold;
            }
            
            /* ComboBox styles */
            QComboBox {
                background-color: #2d5a7c;
                color: #ffffff;
                border: 1px solid #1e3d59;
                border-radius: 3px;
                padding: 3px;
            }
            
            QComboBox:hover {
                background-color: #3d7ab0;
            }
            
            QComboBox::drop-down {
                border: none;
                width: 20px;
            }
            
            QComboBox::down-arrow {
                image: none;
            }

                        """