DialogBase.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. /* 获取是否点击了确定按钮 */
  28. virtual bool isOK() const { return m_isOK; }
  29. protected:
  30. /* --------------------------------------------------
  31. * 给子类使用的内部接口
  32. * --------------------------------------------------*/
  33. /* 设置内容容器 */
  34. bool setContentWidget(QWidget *widget);
  35. /* 设置底栏容器 */
  36. bool setBottomWidget(QWidget *widget);
  37. /* 移除底栏 */
  38. bool removeBottomWidget();
  39. /* 获取内容指针 */
  40. QWidget* getContentWidget() const { return m_widgetContent; }
  41. /* 获取底部容器指针 */
  42. QWidget* getBottomWidget() const { return m_widgetBottom; }
  43. /* 点击确定按钮之前执行的操作 */
  44. virtual bool isOKClicked();
  45. protected:
  46. /* 初始化UI */
  47. virtual void initUI();
  48. /* 初始化其他设置 */
  49. virtual void initSettings();
  50. /* 加载QSS */
  51. virtual void setParentQSS();
  52. /* 设置top栏的位置布局 */
  53. void layoutTop();
  54. protected slots:
  55. /* 关闭按钮点击事件 */
  56. void do_pBtn_Close_Clicked() { this->close(); }
  57. /* 确认按钮点击事件 */
  58. void do_pBtn_OK_Clicked();
  59. /* 取消按钮点击事件 */
  60. void do_pBtnCancel_clicked() { this->reject(); }
  61. /* 设置QSS */
  62. void do_setQSS(EUIStyle style);
  63. protected:
  64. /* 重写鼠标按下事件 */
  65. void mousePressEvent(QMouseEvent *event) override;
  66. /* 重写鼠标移动事件 */
  67. void mouseMoveEvent(QMouseEvent *event) override;
  68. /* 重写鼠标释放事件 */
  69. void mouseReleaseEvent(QMouseEvent *event) override;
  70. /* 显示事件 */
  71. void showEvent(QShowEvent *event) override;
  72. /* 重新设置大小 */
  73. void resizeEvent(QResizeEvent *event) override;
  74. /* 事件过滤器 */
  75. bool eventFilter(QObject *watched, QEvent *event) override;
  76. protected:
  77. std::shared_ptr<spdlog::logger> m_logger = nullptr;
  78. bool m_isOK = false; /* 是否点击了确认按钮 */
  79. private:
  80. QPoint m_lastPos; /* 鼠标点击的位置 */
  81. QWidget* m_widgetBackground = nullptr; /* 背景容器,这个才是真正容纳所有内容的容器 */
  82. QWidget* m_widgetTop = nullptr; /* 顶部标题栏 */
  83. QWidget* m_widgetContent = nullptr; /* 内容区域 */
  84. QWidget* m_widgetBottom = nullptr; /* 底部按钮区域 */
  85. QVBoxLayout* m_layoutBackground = nullptr; /* 背景容器的布局 */
  86. QLabel* m_labelTitle = nullptr; /* 标题标签 */
  87. QPushButton* m_pBtn_Close = nullptr; /* 关闭按钮 */
  88. QPushButton* m_pBtn_OK = nullptr; /* 确认按钮 */
  89. QPushButton* m_pBtn_Cancel = nullptr; /* 取消按钮 */
  90. };
  91. #endif // __DIALOGBASE_H__