qscroller.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QSCROLLER_H
  40. #define QSCROLLER_H
  41. #include <QtCore/QObject>
  42. #include <QtCore/QPointF>
  43. #include <QtWidgets/QScrollerProperties>
  44. QT_BEGIN_NAMESPACE
  45. class QWidget;
  46. class QScrollerPrivate;
  47. class QScrollerProperties;
  48. #ifndef QT_NO_GESTURES
  49. class QFlickGestureRecognizer;
  50. class QMouseFlickGestureRecognizer;
  51. #endif
  52. class Q_WIDGETS_EXPORT QScroller : public QObject
  53. {
  54. Q_OBJECT
  55. Q_PROPERTY(State state READ state NOTIFY stateChanged)
  56. Q_PROPERTY(QScrollerProperties scrollerProperties READ scrollerProperties WRITE setScrollerProperties NOTIFY scrollerPropertiesChanged)
  57. public:
  58. enum State
  59. {
  60. Inactive,
  61. Pressed,
  62. Dragging,
  63. Scrolling
  64. };
  65. Q_ENUM(State)
  66. enum ScrollerGestureType
  67. {
  68. TouchGesture,
  69. LeftMouseButtonGesture,
  70. RightMouseButtonGesture,
  71. MiddleMouseButtonGesture
  72. };
  73. enum Input
  74. {
  75. InputPress = 1,
  76. InputMove,
  77. InputRelease
  78. };
  79. static bool hasScroller(QObject *target);
  80. static QScroller *scroller(QObject *target);
  81. static const QScroller *scroller(const QObject *target);
  82. #ifndef QT_NO_GESTURES
  83. static Qt::GestureType grabGesture(QObject *target, ScrollerGestureType gestureType = TouchGesture);
  84. static Qt::GestureType grabbedGesture(QObject *target);
  85. static void ungrabGesture(QObject *target);
  86. #endif
  87. static QList<QScroller *> activeScrollers();
  88. QObject *target() const;
  89. State state() const;
  90. bool handleInput(Input input, const QPointF &position, qint64 timestamp = 0);
  91. void stop();
  92. QPointF velocity() const;
  93. QPointF finalPosition() const;
  94. QPointF pixelPerMeter() const;
  95. QScrollerProperties scrollerProperties() const;
  96. void setSnapPositionsX( const QList<qreal> &positions );
  97. void setSnapPositionsX( qreal first, qreal interval );
  98. void setSnapPositionsY( const QList<qreal> &positions );
  99. void setSnapPositionsY( qreal first, qreal interval );
  100. public Q_SLOTS:
  101. void setScrollerProperties(const QScrollerProperties &prop);
  102. void scrollTo(const QPointF &pos);
  103. void scrollTo(const QPointF &pos, int scrollTime);
  104. void ensureVisible(const QRectF &rect, qreal xmargin, qreal ymargin);
  105. void ensureVisible(const QRectF &rect, qreal xmargin, qreal ymargin, int scrollTime);
  106. void resendPrepareEvent();
  107. Q_SIGNALS:
  108. void stateChanged(QScroller::State newstate);
  109. void scrollerPropertiesChanged(const QScrollerProperties &);
  110. private:
  111. QScrollerPrivate *d_ptr;
  112. QScroller(QObject *target);
  113. virtual ~QScroller();
  114. Q_DISABLE_COPY(QScroller)
  115. Q_DECLARE_PRIVATE(QScroller)
  116. #ifndef QT_NO_GESTURES
  117. friend class QFlickGestureRecognizer;
  118. #endif
  119. };
  120. QT_END_NAMESPACE
  121. #endif // QSCROLLER_H