tipwidget.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef TIPWIDGET_H
  2. #define TIPWIDGET_H
  3. #include <QWidget>
  4. class QPropertyAnimation;
  5. namespace Ui {
  6. class TipWidget;
  7. }
  8. class TipWidget : public QWidget
  9. {
  10. Q_OBJECT
  11. public:
  12. enum FormType
  13. {
  14. OPERATOR_OK = 0, // 操作成功!
  15. OPERATOR_FAIL, // 操作失败!
  16. OPERATOR_TIP, // 普通提示!
  17. OPERATOR_WARN, // 需注意!
  18. };
  19. public:
  20. static const int WIDTH = 168;
  21. static const int HEIGHT = 56;
  22. static void display(FormType type, QWidget* parent = Q_NULLPTR, int nTitleHeight = 48);
  23. static void display(FormType type, QString text, QWidget* parent = Q_NULLPTR, int nTitleHeight = 48);
  24. explicit TipWidget(FormType type, QWidget *parent = 0);
  25. TipWidget(FormType type, QString& text, QWidget *parent = 0);
  26. ~TipWidget();
  27. void setEndPos(int x, int y);
  28. void run();
  29. public slots:
  30. void onBtnClose();
  31. void onFadeOut();
  32. protected:
  33. void paintEvent(QPaintEvent *event) override;
  34. private:
  35. void setFormType(FormType type);
  36. private:
  37. Ui::TipWidget *ui;
  38. QColor _backgroundColor{246, 255, 237};
  39. QColor _borderColor{183, 235, 143};
  40. QRect _endRect;
  41. QTimer* _pKillTimer{nullptr};
  42. QPropertyAnimation* _animation{nullptr};
  43. QPropertyAnimation* _animFadeOut{nullptr};
  44. QString m_tipText; /* 提示文本 */
  45. bool m_customText; /* 自定义文本标志 */
  46. };
  47. #endif // TIPWIDGET_H