123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #ifndef __DIALOGBASE_H__
- #define __DIALOGBASE_H__
- #include <QDialog>
- #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);
- virtual ~DialogBase();
- /* 设置标题 */
- void setTitle(const QString &title, QSize size = QSize(120, 18));
- /* 获取标题 */
- QString getTitle() const;
- protected:
- /* --------------------------------------------------
- * 给子类使用的内部接口
- * --------------------------------------------------*/
- /* 设置内容容器 */
- bool setContentWidget(QWidget *widget);
- /* 设置底栏容器 */
- bool setBottomWidget(QWidget *widget);
- protected:
- /* 初始化UI */
- virtual void initUI();
- /* 初始化其他设置 */
- virtual void initSettings();
- /* 加载QSS */
- virtual void setQSS();
- /* 设置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<spdlog::logger> m_logger = nullptr;
- QPoint m_lastPos; /* 鼠标点击的位置 */
- 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; /* 取消按钮 */
- bool m_isOK = false; /* 是否点击了确认按钮 */
- };
- #endif // __DIALOGBASE_H__
|