tipwidget.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 WIDTH = 256;
  22. static const int HEIGHT = 56;
  23. static void display(FormType type, QWidget* parent = Q_NULLPTR, int nTitleHeight = 48);
  24. static void display(FormType type, QString text, QWidget* parent = Q_NULLPTR, int nTitleHeight = 48);
  25. explicit TipWidget(FormType type, QWidget *parent = 0);
  26. TipWidget(FormType type, QString& text, QWidget *parent = 0);
  27. ~TipWidget();
  28. void setEndPos(int x, int y);
  29. void run();
  30. public slots:
  31. void onBtnClose();
  32. void onFadeOut();
  33. protected:
  34. void paintEvent(QPaintEvent *event) override;
  35. private:
  36. void setFormType(FormType type);
  37. private:
  38. Ui::TipWidget *ui;
  39. QColor _backgroundColor{246, 255, 237};
  40. QColor _borderColor{183, 235, 143};
  41. QRect _endRect;
  42. QTimer* _pKillTimer{nullptr};
  43. QPropertyAnimation* _animation{nullptr};
  44. QPropertyAnimation* _animFadeOut{nullptr};
  45. QString m_tipText; /* 提示文本 */
  46. bool m_customText; /* 自定义文本标志 */
  47. };
  48. #endif // TIPWIDGET_H