StateToolTip.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef STATETOOLTIP_H
  2. #define STATETOOLTIP_H
  3. #include <QGraphicsOpacityEffect>
  4. #include <QLabel>
  5. #include <QPropertyAnimation>
  6. #include <QToolButton>
  7. class StateCloseButton : public QToolButton
  8. {
  9. Q_OBJECT
  10. public:
  11. explicit StateCloseButton(QWidget *parent = nullptr);
  12. // QWidget interface
  13. protected:
  14. void mousePressEvent(QMouseEvent *event) override;
  15. void mouseReleaseEvent(QMouseEvent *event) override;
  16. void enterEvent(QEvent *event) override;
  17. void leaveEvent(QEvent *event) override;
  18. void paintEvent(QPaintEvent *event) override;
  19. private:
  20. bool m_isEnter;
  21. bool m_isPressed;
  22. };
  23. class StateToolTip : public QWidget
  24. {
  25. Q_OBJECT
  26. public:
  27. explicit StateToolTip(const QString &title, const QString &content, QWidget *parent = nullptr);
  28. void setTitle(const QString &title);
  29. void setContent(const QString &content);
  30. void setState(bool isDone = false);
  31. QPoint getSuitablePos();
  32. // QWidget interface
  33. protected:
  34. void paintEvent(QPaintEvent *event) override;
  35. signals:
  36. void closedSignal();
  37. private slots:
  38. void onCloseButtonClicked();
  39. void rotateTimerFlowSlot();
  40. void fadeOut();
  41. private:
  42. void initWidget();
  43. void setQss();
  44. void initLayout();
  45. private:
  46. QString m_title;
  47. QString m_content;
  48. QLabel *m_titleLabel;
  49. QLabel *m_contentLabel;
  50. QTimer *m_rotateTimer;
  51. QGraphicsOpacityEffect *m_opacityEffect;
  52. QPropertyAnimation *m_animation;
  53. StateCloseButton *m_closeButton;
  54. bool m_isDone;
  55. int m_rotateAngle;
  56. int m_deltaAngle;
  57. };
  58. #endif // STATETOOLTIP_H