StackedWidget.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef STACKEDWIDGET_H
  2. #define STACKEDWIDGET_H
  3. #include <QStackedWidget>
  4. #include <QPropertyAnimation>
  5. #include <QGraphicsOpacityEffect>
  6. class OpacityAniStackedWidget : public QStackedWidget
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit OpacityAniStackedWidget(QWidget *parent = nullptr);
  11. void addWidget(QWidget *w);
  12. void setCurrentIndex(int index);
  13. void setCurrentWidget(QWidget *w);
  14. private slots:
  15. void onAniFinished();
  16. private:
  17. int m_nextIndex;
  18. QList<QGraphicsOpacityEffect *> m_effects;
  19. QList<QPropertyAnimation *> m_anis;
  20. };
  21. struct PopUpAniInfo
  22. {
  23. public:
  24. PopUpAniInfo(QWidget *w, int dx, int dy, QPropertyAnimation *a)
  25. {
  26. widget = w;
  27. deltaX = dx;
  28. deltaY = dy;
  29. ani = a;
  30. }
  31. QWidget *widget;
  32. int deltaX;
  33. int deltaY;
  34. QPropertyAnimation *ani;
  35. };
  36. class PopUpAniStackedWidget : public QStackedWidget
  37. {
  38. Q_OBJECT
  39. public:
  40. explicit PopUpAniStackedWidget(QWidget *parent = nullptr);
  41. void addWidget(QWidget *widget, int deltaX = 0, int deltaY = 76);
  42. void setCurrentIndex(int index, bool needPopOut = false, bool showNextWidgetDirectly = true, int duration = 250,
  43. QEasingCurve easingCurve = QEasingCurve::OutQuad);
  44. void setCurrentWidget(QWidget *widget, bool needPopOut = false, bool showNextWidgetDirectly = true,
  45. int duration = 250, QEasingCurve easingCurve = QEasingCurve::OutQuad);
  46. private slots:
  47. void setAnimation(QPropertyAnimation *ani, const QPoint &startValue, const QPoint &endValue, int duration,
  48. QEasingCurve easingCurve = QEasingCurve::Linear);
  49. void onAniFinished();
  50. signals:
  51. void aniFinished();
  52. void aniStart();
  53. private:
  54. QList<PopUpAniInfo> m_aniInfos;
  55. int m_nextIndex;
  56. QPropertyAnimation *m_ani;
  57. };
  58. #endif // STACKEDWIDGET_H