TitleBar.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef TITLEBAR_H
  2. #define TITLEBAR_H
  3. #include <QWidget>
  4. #include <QHBoxLayout>
  5. #include <QLabel>
  6. class MinimizeButton;
  7. class CloseButton;
  8. class MaximizeButton;
  9. class TitleBar : public QWidget
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit TitleBar(QWidget *parent = nullptr);
  14. QHBoxLayout *hBoxLayout;
  15. MinimizeButton *minimizeButton() const;
  16. CloseButton *closeButton() const;
  17. MaximizeButton *maximizeButton() const;
  18. private slots:
  19. void onToggleMaxState();
  20. private:
  21. MinimizeButton *minBtn;
  22. CloseButton *closeBtn;
  23. MaximizeButton *maxBtn;
  24. bool isDoubleClickEnabled;
  25. public:
  26. virtual bool eventFilter(QObject *watched, QEvent *event) override;
  27. virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
  28. virtual void mouseMoveEvent(QMouseEvent *event) override;
  29. virtual void mousePressEvent(QMouseEvent *event) override;
  30. void setDoubleClickEnabled(bool isEnabled);
  31. bool canDrag(QPoint pos);
  32. protected:
  33. bool isDragRegion(QPoint pos);
  34. bool hasButtonPressed();
  35. };
  36. class StandardTitleBar : public TitleBar
  37. {
  38. Q_OBJECT
  39. public:
  40. explicit StandardTitleBar(QWidget *parent = nullptr);
  41. void setTitle(const QString &title);
  42. void setIcon(const QIcon &icon);
  43. private:
  44. QLabel *iconLabel;
  45. QLabel *titleLabel;
  46. };
  47. #endif // TITLEBAR_H