DialogBase.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef __DIALOGBASE_H__
  2. #define __DIALOGBASE_H__
  3. #include <QDialog>
  4. #include "spdlog/spdlog.h"
  5. #include "UIStyleManager.h"
  6. class QMouseEvent;
  7. class QVBoxLayout;
  8. class QPushButton;
  9. class QWidget;
  10. class QLabel;
  11. class QPoint;
  12. /**
  13. * @brief 这个基础类主要为了实现弹窗通用的拖动和阴影效果
  14. * 1、父类的QSS通过信号来主动设置,避免和子类冲突
  15. *
  16. */
  17. class DialogBase : public QDialog
  18. {
  19. Q_OBJECT
  20. public:
  21. explicit DialogBase(QWidget *parent = nullptr);
  22. virtual ~DialogBase();
  23. /* 设置标题 */
  24. void setTitle(const QString &title, QSize size = QSize(120, 18));
  25. /* 获取标题 */
  26. QString getTitle() const;
  27. protected:
  28. /* --------------------------------------------------
  29. * 给子类使用的内部接口
  30. * --------------------------------------------------*/
  31. /* 设置内容容器 */
  32. bool setContentWidget(QWidget *widget);
  33. /* 设置底栏容器 */
  34. bool setBottomWidget(QWidget *widget);
  35. /* 移除底栏 */
  36. bool removeBottomWidget();
  37. /* 获取内容指针 */
  38. QWidget* getContentWidget() const { return m_widgetContent; }
  39. /* 获取底部容器指针 */
  40. QWidget* getBottomWidget() const { return m_widgetBottom; }
  41. protected:
  42. /* 初始化UI */
  43. virtual void initUI();
  44. /* 初始化其他设置 */
  45. virtual void initSettings();
  46. /* 加载QSS */
  47. virtual void setQSS();
  48. /* 设置top栏的位置布局 */
  49. void layoutTop();
  50. protected slots:
  51. /* 关闭按钮点击事件 */
  52. void do_pBtn_Close_Clicked() { this->close(); }
  53. /* 确认按钮点击事件 */
  54. void do_pBtn_OK_Clicked();
  55. /* 取消按钮点击事件 */
  56. void do_pBtnCancel_clicked() { this->reject(); }
  57. /* 设置QSS */
  58. void do_setQSS(EUIStyle style);
  59. protected:
  60. /* 重写鼠标按下事件 */
  61. void mousePressEvent(QMouseEvent *event) override;
  62. /* 重写鼠标移动事件 */
  63. void mouseMoveEvent(QMouseEvent *event) override;
  64. /* 重写鼠标释放事件 */
  65. void mouseReleaseEvent(QMouseEvent *event) override;
  66. /* 显示事件 */
  67. void showEvent(QShowEvent *event) override;
  68. /* 重新设置大小 */
  69. void resizeEvent(QResizeEvent *event) override;
  70. /* 事件过滤器 */
  71. bool eventFilter(QObject *watched, QEvent *event) override;
  72. protected:
  73. std::shared_ptr<spdlog::logger> m_logger = nullptr;
  74. bool m_isOK = false; /* 是否点击了确认按钮 */
  75. private:
  76. QPoint m_lastPos; /* 鼠标点击的位置 */
  77. QWidget* m_widgetBackground = nullptr; /* 背景容器,这个才是真正容纳所有内容的容器 */
  78. QWidget* m_widgetTop = nullptr; /* 顶部标题栏 */
  79. QWidget* m_widgetContent = nullptr; /* 内容区域 */
  80. QWidget* m_widgetBottom = nullptr; /* 底部按钮区域 */
  81. QVBoxLayout* m_layoutBackground = nullptr; /* 背景容器的布局 */
  82. QLabel* m_labelTitle = nullptr; /* 标题标签 */
  83. QPushButton* m_pBtn_Close = nullptr; /* 关闭按钮 */
  84. QPushButton* m_pBtn_OK = nullptr; /* 确认按钮 */
  85. QPushButton* m_pBtn_Cancel = nullptr; /* 取消按钮 */
  86. };
  87. #endif // __DIALOGBASE_H__