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.
Software_Architecture/src/Client/styles/LeftPanelStyleManager.h

347 lines
9.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* @file LeftPanelStyleManager.h
* @brief 左侧设备管理面板专用样式管理器
* @details 专门管理左侧面板的视觉样式和交互效果
* @author UBEES Development Team
* @date 2024
*/
#ifndef LEFTPANELSTYLEMANAGER_H
#define LEFTPANELSTYLEMANAGER_H
#include <QObject>
#include <QString>
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QPropertyAnimation>
#include <QGraphicsDropShadowEffect>
#include <QTimer>
#include <QMap>
#include <QColor>
#include <QPointF>
// 前向声明
class DeviceListPanel;
class DeviceCard;
/**
* @class LeftPanelStyleManager
* @brief 左侧面板样式管理器
* @details 专门负责左侧设备管理面板的样式应用和动画效果
*/
class LeftPanelStyleManager : public QObject
{
Q_OBJECT
public:
/**
* @brief 获取样式管理器单例实例
* @return LeftPanelStyleManager* 单例指针
*/
static LeftPanelStyleManager* getInstance();
/**
* @brief 应用左侧面板样式
* @param panel 设备列表面板指针
* @return bool 成功返回true失败返回false
*/
bool applyLeftPanelStyle(DeviceListPanel* panel);
/**
* @brief 应用设备卡片样式
* @param card 设备卡片指针
* @return bool 成功返回true失败返回false
*/
bool applyDeviceCardStyle(DeviceCard* card);
/**
* @brief 设置按钮样式类型
* @param button 按钮指针
* @param buttonType 按钮类型 ("add", "delete", "refresh", "control", "details", "location")
*/
void setButtonStyleType(QPushButton* button, const QString& buttonType);
/**
* @brief 设置状态指示器样式
* @param indicator 状态指示器标签
* @param status 状态类型 ("online", "offline", "warning", "maintenance")
*/
void setStatusIndicatorStyle(QLabel* indicator, const QString& status);
/**
* @brief 设置设备状态标签样式
* @param statusLabel 状态标签
* @param status 状态类型
*/
void setDeviceStatusLabelStyle(QLabel* statusLabel, const QString& status);
/**
* @brief 创建按钮悬停动画
* @param button 目标按钮
* @return QPropertyAnimation* 动画对象指针
*/
QPropertyAnimation* createButtonHoverAnimation(QPushButton* button);
/**
* @brief 创建卡片选择动画
* @param card 目标卡片
* @return QPropertyAnimation* 动画对象指针
*/
QPropertyAnimation* createCardSelectionAnimation(DeviceCard* card);
/**
* @brief 创建状态变化动画
* @param widget 目标控件
* @param fromStatus 原状态
* @param toStatus 新状态
* @return QPropertyAnimation* 动画对象指针
*/
QPropertyAnimation* createStatusChangeAnimation(QWidget* widget,
const QString& fromStatus,
const QString& toStatus);
/**
* @brief 应用加载动画
* @param widget 目标控件
* @param isLoading 是否显示加载状态
*/
void applyLoadingAnimation(QWidget* widget, bool isLoading);
/**
* @brief 设置面板标题样式
* @param titleLabel 标题标签
* @param level 标题级别 (1=主标题, 2=副标题, 3=小标题)
*/
void setPanelTitleStyle(QLabel* titleLabel, int level = 1);
/**
* @brief 设置设备计数标签样式
* @param countLabel 计数标签
* @param totalCount 总数
* @param onlineCount 在线数
*/
void setDeviceCountStyle(QLabel* countLabel, int totalCount, int onlineCount);
/**
* @brief 应用空列表提示样式
* @param emptyLabel 空列表提示标签
*/
void applyEmptyListStyle(QLabel* emptyLabel);
/**
* @brief 刷新所有样式
* @return bool 成功返回true失败返回false
*/
bool refreshAllStyles();
/**
* @brief 设备卡片动画类型枚举
*/
enum class CardAnimation {
None, ///< 无动画
FadeIn, ///< 淡入
SlideIn, ///< 滑入
ScaleIn, ///< 缩放进入
Bounce ///< 弹跳
};
/**
* @brief 播放设备卡片动画
* @param card 目标卡片
* @param animation 动画类型
* @param duration 动画时长(毫秒)
*/
void playCardAnimation(DeviceCard* card, CardAnimation animation, int duration = 300);
/**
* @brief 按钮状态枚举
*/
enum class ButtonState {
Normal, ///< 正常状态
Hover, ///< 悬停状态
Pressed, ///< 按下状态
Disabled ///< 禁用状态
};
/**
* @brief 更新按钮状态样式
* @param button 目标按钮
* @param state 按钮状态
*/
void updateButtonState(QPushButton* button, ButtonState state);
private:
/**
* @brief 私有构造函数(单例模式)
*/
explicit LeftPanelStyleManager(QObject *parent = nullptr);
/**
* @brief 析构函数
*/
~LeftPanelStyleManager() = default;
/**
* @brief 禁用拷贝构造函数
*/
LeftPanelStyleManager(const LeftPanelStyleManager&) = delete;
/**
* @brief 禁用赋值操作符
*/
LeftPanelStyleManager& operator=(const LeftPanelStyleManager&) = delete;
/**
* @brief 加载左侧面板样式文件
* @return bool 成功返回true失败返回false
*/
bool loadLeftPanelStyleSheet();
/**
* @brief 加载后备样式(当样式文件无法加载时使用)
*/
void loadFallbackStyles();
/**
* @brief 初始化样式映射表
*/
void initializeStyleMaps();
/**
* @brief 创建阴影效果
* @param widget 目标控件
* @param blurRadius 模糊半径
* @param color 阴影颜色
* @param offset 偏移量
* @return QGraphicsDropShadowEffect* 阴影效果指针
*/
QGraphicsDropShadowEffect* createShadowEffect(QWidget* widget,
int blurRadius = 10,
const QColor& color = QColor(74, 144, 226, 100),
const QPointF& offset = QPointF(0, 2));
/**
* @brief 应用渐变背景
* @param widget 目标控件
* @param startColor 起始颜色
* @param endColor 结束颜色
* @param direction 渐变方向 (0=垂直, 1=水平, 2=对角线)
*/
void applyGradientBackground(QWidget* widget,
const QColor& startColor,
const QColor& endColor,
int direction = 0);
private:
static LeftPanelStyleManager* m_instance; ///< 单例实例
QString m_leftPanelStyleSheet; ///< 左侧面板样式表
QMap<QString, QString> m_buttonStyleMap; ///< 按钮样式映射
QMap<QString, QString> m_statusColorMap; ///< 状态颜色映射
QMap<QWidget*, QPropertyAnimation*> m_animations; ///< 动画映射表
QTimer* m_animationTimer; ///< 动画定时器
signals:
/**
* @brief 样式应用完成信号
* @param widget 应用样式的控件
* @param success 是否成功
*/
void styleApplied(QWidget* widget, bool success);
/**
* @brief 动画播放完成信号
* @param widget 播放动画的控件
* @param animationType 动画类型
*/
void animationFinished(QWidget* widget, const QString& animationType);
public slots:
/**
* @brief 刷新样式槽函数
*/
void refreshStyles();
/**
* @brief 停止所有动画
*/
void stopAllAnimations();
/**
* @brief 清理动画资源
*/
void cleanupAnimations();
};
/**
* @brief 左侧面板样式工具类
* @details 提供便捷的左侧面板样式操作静态方法
*/
class LeftPanelStyleUtils
{
public:
/**
* @brief 快速应用左侧面板样式
* @param panel 设备列表面板
* @return bool 成功返回true失败返回false
*/
static bool applyLeftPanelStyle(DeviceListPanel* panel);
/**
* @brief 快速设置添加按钮样式
* @param button 目标按钮
*/
static void setAddButton(QPushButton* button);
/**
* @brief 快速设置删除按钮样式
* @param button 目标按钮
*/
static void setDeleteButton(QPushButton* button);
/**
* @brief 快速设置刷新按钮样式
* @param button 目标按钮
*/
static void setRefreshButton(QPushButton* button);
/**
* @brief 快速设置在线状态指示器
* @param indicator 状态指示器
*/
static void setOnlineIndicator(QLabel* indicator);
/**
* @brief 快速设置离线状态指示器
* @param indicator 状态指示器
*/
static void setOfflineIndicator(QLabel* indicator);
/**
* @brief 快速设置警告状态指示器
* @param indicator 状态指示器
*/
static void setWarningIndicator(QLabel* indicator);
/**
* @brief 快速播放卡片添加动画
* @param card 设备卡片
*/
static void playCardAddAnimation(DeviceCard* card);
/**
* @brief 快速播放卡片删除动画
* @param card 设备卡片
*/
static void playCardRemoveAnimation(DeviceCard* card);
/**
* @brief 快速播放状态变化动画
* @param card 设备卡片
* @param newStatus 新状态
*/
static void playStatusChangeAnimation(DeviceCard* card, const QString& newStatus);
};
#endif // LEFTPANELSTYLEMANAGER_H