#ifndef __DIALOGBASE_H__ #define __DIALOGBASE_H__ #include #include "spdlog/spdlog.h" #include "UIStyleManager.h" class QMouseEvent; class QVBoxLayout; class QPushButton; class QWidget; class QLabel; class QPoint; /** * @brief 这个基础类主要为了实现弹窗通用的拖动和阴影效果 * 1、父类的QSS通过信号来主动设置,避免和子类冲突 * */ class DialogBase : public QDialog { Q_OBJECT public: explicit DialogBase(QWidget *parent = nullptr); explicit DialogBase(bool isFullScreen, QWidget *parent = nullptr); virtual ~DialogBase(); /* 设置标题 */ void setTitle(const QString &title, QSize size = QSize(120, 18)); /* 获取标题 */ QString getTitle() const; /* 获取是否点击了确定按钮 */ virtual bool isOK() const { return m_isOK; } protected: /* -------------------------------------------------- * 给子类使用的内部接口 * --------------------------------------------------*/ /* 设置内容容器 */ bool setContentWidget(QWidget *widget); /* 设置底栏容器 */ bool setBottomWidget(QWidget *widget); /* 移除底栏 */ bool removeBottomWidget(); /* 获取内容指针 */ QWidget* getContentWidget() const { return m_widgetContent; } /* 获取底部容器指针 */ QWidget* getBottomWidget() const { return m_widgetBottom; } /* 点击确定按钮之前执行的操作 */ virtual bool isOKClicked(); /* 设置一个控件报警,边框显示红色 * 注意:这个功能需要在qss里设置属性[Warn=true],并实现相应的报警样式 */ void setWarn(QWidget* widget, bool isWarn = true); protected: /* 初始化UI */ virtual void initUI(); /* 初始化其他设置 */ virtual void initSettings(); /* 加载QSS */ virtual void setParentQSS(); /* 设置top栏的位置布局 */ void layoutTop(); protected slots: /* 关闭按钮点击事件 */ void do_pBtn_Close_Clicked() { this->close(); } /* 确认按钮点击事件 */ void do_pBtn_OK_Clicked(); /* 取消按钮点击事件 */ void do_pBtnCancel_clicked() { this->reject(); } /* 设置QSS */ void do_setQSS(EUIStyle style); protected: /* 重写鼠标按下事件 */ void mousePressEvent(QMouseEvent *event) override; /* 重写鼠标移动事件 */ void mouseMoveEvent(QMouseEvent *event) override; /* 重写鼠标释放事件 */ void mouseReleaseEvent(QMouseEvent *event) override; /* 显示事件 */ void showEvent(QShowEvent *event) override; /* 重新设置大小 */ void resizeEvent(QResizeEvent *event) override; /* 事件过滤器 */ bool eventFilter(QObject *watched, QEvent *event) override; protected: std::shared_ptr m_logger = nullptr; bool m_isOK = false; /* 是否点击了确认按钮 */ private: bool m_isFullScreen = false; /* 是否全屏显示,给时间选择和日期选择弹窗使用的,设置背后透明背景全屏 */ QPoint m_lastPos; /* 鼠标点击的位置 */ QWidget* m_widgetTransparent = nullptr; /* 透明背景容器,在m_widgetBackground下面,全屏时, m_widgetBackground在这个透明容器中移动 */ QWidget* m_widgetBackground = nullptr; /* 背景容器,这个才是真正容纳所有内容的容器 */ QWidget* m_widgetTop = nullptr; /* 顶部标题栏 */ QWidget* m_widgetContent = nullptr; /* 内容区域 */ QWidget* m_widgetBottom = nullptr; /* 底部按钮区域 */ QVBoxLayout* m_layoutBackground = nullptr; /* 背景容器的布局 */ QLabel* m_labelTitle = nullptr; /* 标题标签 */ QPushButton* m_pBtn_Close = nullptr; /* 关闭按钮 */ QPushButton* m_pBtn_OK = nullptr; /* 确认按钮 */ QPushButton* m_pBtn_Cancel = nullptr; /* 取消按钮 */ }; #endif // __DIALOGBASE_H__