qsmoothscrollarea.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef QSMOOTHSCROLLAREA_H
  2. #define QSMOOTHSCROLLAREA_H
  3. #include <QScrollArea>
  4. #include <QList>
  5. #include <QPair>
  6. #include <Qt>
  7. class QTimer;
  8. class QSmoothScrollArea : public QScrollArea
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit QSmoothScrollArea(QWidget *parent = 0);
  13. enum SmoothMode {
  14. NO_SMOOTH,
  15. CONSTANT,
  16. LINEAR,
  17. QUADRATIC,
  18. COSINE
  19. };
  20. SmoothMode smoothMode();
  21. void setSmoothMode(SmoothMode mode);
  22. int fps();
  23. void setFps(int fps);
  24. // value in millisecond
  25. int duration();
  26. void setDuration(int mesc);
  27. double acceration();
  28. void setAcceration(double acceleration);
  29. double smallStepRatio();
  30. void setSmallStepRatio(double smallStepRatio);
  31. double bigStepRatio();
  32. void setBigStepRatio(double bigStepRatio);
  33. Qt::Modifier smallStepModifier();
  34. void setSmallStepModifier(Qt::Modifier smallStepModifier);
  35. Qt::Modifier bigStepModifier();
  36. void setbigStepModifier(Qt::Modifier bigStepModifier);
  37. protected:
  38. virtual void wheelEvent(QWheelEvent *event);
  39. signals:
  40. public slots:
  41. void slotSmoothMove();
  42. private:
  43. double subDelta(double delta, int stepsLeft);
  44. QTimer *smoothMoveTimer;
  45. QWheelEvent *lastWheelEvent;
  46. int m_fps;
  47. int m_duration;
  48. SmoothMode m_smoothMode;
  49. double m_acceleration;
  50. double m_smallStepRatio;
  51. double m_bigStepRatio;
  52. Qt::Modifier m_smallStepModifier;
  53. Qt::Modifier m_bigStepModifier;
  54. int stepsTotal;
  55. QList< QPair<double, int> > stepsLeftQueue;
  56. };
  57. #endif // QSMOOTHSCROLLAREA_H