ScrollArea.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef SCROLLAREA_H
  2. #define SCROLLAREA_H
  3. #include <QPropertyAnimation>
  4. #include <QScrollArea>
  5. #include <QScrollBar>
  6. #include "Common/SmoothScroll.h"
  7. class ScrollArea : public QScrollArea
  8. {
  9. Q_OBJECT
  10. public:
  11. explicit ScrollArea(QWidget *parent = nullptr, Qt::Orientation orient = Qt::Vertical);
  12. void setSmoothMode(const SmoothMode &mode);
  13. void setViewportMargins(int left, int top, int right, int bottom);
  14. // QWidget interface
  15. protected:
  16. void wheelEvent(QWheelEvent *event) override;
  17. signals:
  18. private:
  19. SmoothScroll *m_smoothScroll;
  20. };
  21. class SmoothScrollBar : public QScrollBar
  22. {
  23. Q_OBJECT
  24. public:
  25. explicit SmoothScrollBar(QWidget *parent = nullptr);
  26. void setValue(int value);
  27. void scrollValue(int value);
  28. void scrollTo(int value);
  29. void resetValue(int value);
  30. void setScrollAnimation(int duration, QEasingCurve easing = QEasingCurve::OutCubic);
  31. // QWidget interface
  32. protected:
  33. void mousePressEvent(QMouseEvent *event) override;
  34. void mouseReleaseEvent(QMouseEvent *event) override;
  35. void mouseMoveEvent(QMouseEvent *event) override;
  36. private:
  37. int m_duration;
  38. QPropertyAnimation *m_ani;
  39. int m_value;
  40. };
  41. class SmoothScrollArea : public QScrollArea
  42. {
  43. Q_OBJECT
  44. public:
  45. explicit SmoothScrollArea(QWidget *parent = nullptr);
  46. void setScrollAnimation(Qt::Orientation orient, int duration, QEasingCurve easing = QEasingCurve::OutCubic);
  47. void setViewportMargins(int left, int top, int right, int bottom);
  48. private:
  49. SmoothScrollBar *m_hScrollBar;
  50. SmoothScrollBar *m_vScrollBar;
  51. // QWidget interface
  52. protected:
  53. void wheelEvent(QWheelEvent *event) override;
  54. };
  55. #endif // SCROLLAREA_H