FlowLayout.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef FLOWLAYOUT_H
  2. #define FLOWLAYOUT_H
  3. #include <QLayout>
  4. #include <QParallelAnimationGroup>
  5. #include <QPropertyAnimation>
  6. class FlowLayout : public QLayout
  7. {
  8. public:
  9. /**
  10. * @brief FlowLayout
  11. * @param parent: parent window or layout
  12. * @param needAni: whether to add moving animation
  13. * @param isTight: whether to use the tight layout when widgets are hidden
  14. */
  15. FlowLayout(QWidget *parent = nullptr, bool needAni = false, bool isTight = false);
  16. ~FlowLayout();
  17. public:
  18. QSize sizeHint() const override;
  19. void addItem(QLayoutItem *) override;
  20. QLayoutItem *itemAt(int index) const override;
  21. QLayoutItem *takeAt(int index) override;
  22. int count() const override;
  23. QSize minimumSize() const override;
  24. Qt::Orientations expandingDirections() const override;
  25. void setGeometry(const QRect &) override;
  26. bool hasHeightForWidth() const override;
  27. int heightForWidth(int) const override;
  28. void addWidget(QWidget *w);
  29. void setAnimation(int duration, QEasingCurve ease = QEasingCurve::Linear);
  30. void removeAllItems();
  31. void takeAllWidgets();
  32. int verticalSpacing() const;
  33. void setVerticalSpacing(int verticalSpacing);
  34. int horizontalSpacing() const;
  35. void setHorizontalSpacing(int horizontalSpacing);
  36. protected:
  37. int doLayout(const QRect &rect, bool move) const;
  38. private:
  39. QList<QLayoutItem *> m_items;
  40. QList<QPropertyAnimation *> m_anis;
  41. QParallelAnimationGroup *m_aniGroup;
  42. int m_verticalSpacing;
  43. int m_horizontalSpacing;
  44. bool m_needAni;
  45. bool m_isTight;
  46. };
  47. #endif // FLOWLAYOUT_H