DialogBase.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. protected:
  36. /* 初始化UI */
  37. virtual void initUI();
  38. /* 初始化其他设置 */
  39. virtual void initSettings();
  40. /* 加载QSS */
  41. virtual void setQSS();
  42. /* 设置top栏的位置布局 */
  43. void layoutTop();
  44. protected slots:
  45. /* 关闭按钮点击事件 */
  46. void do_pBtn_Close_Clicked() { this->close(); }
  47. /* 确认按钮点击事件 */
  48. void do_pBtn_OK_Clicked();
  49. /* 取消按钮点击事件 */
  50. void do_pBtnCancel_clicked() { this->reject(); }
  51. /* 设置QSS */
  52. void do_setQSS(EUIStyle style);
  53. protected:
  54. /* 重写鼠标按下事件 */
  55. void mousePressEvent(QMouseEvent *event) override;
  56. /* 重写鼠标移动事件 */
  57. void mouseMoveEvent(QMouseEvent *event) override;
  58. /* 重写鼠标释放事件 */
  59. void mouseReleaseEvent(QMouseEvent *event) override;
  60. /* 显示事件 */
  61. void showEvent(QShowEvent *event) override;
  62. /* 重新设置大小 */
  63. void resizeEvent(QResizeEvent *event) override;
  64. /* 事件过滤器 */
  65. bool eventFilter(QObject *watched, QEvent *event) override;
  66. protected:
  67. std::shared_ptr<spdlog::logger> m_logger = nullptr;
  68. QPoint m_lastPos; /* 鼠标点击的位置 */
  69. QWidget* m_widgetBackground = nullptr; /* 背景容器,这个才是真正容纳所有内容的容器 */
  70. QWidget* m_widgetTop = nullptr; /* 顶部标题栏 */
  71. QWidget* m_widgetContent = nullptr; /* 内容区域 */
  72. QWidget* m_widgetBottom = nullptr; /* 底部按钮区域 */
  73. QVBoxLayout* m_layoutBackground = nullptr; /* 背景容器的布局 */
  74. QLabel* m_labelTitle = nullptr; /* 标题标签 */
  75. QPushButton* m_pBtn_Close = nullptr; /* 关闭按钮 */
  76. QPushButton* m_pBtn_OK = nullptr; /* 确认按钮 */
  77. QPushButton* m_pBtn_Cancel = nullptr; /* 取消按钮 */
  78. bool m_isOK = false; /* 是否点击了确认按钮 */
  79. };
  80. #endif // __DIALOGBASE_H__