pannableview_p.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //This file is part of the Enume project which provides libraries for
  2. //extending Qt functionality.
  3. //
  4. //Copyright (C) 2010 Marko Mattila, marko.a.mattila@gmail.com
  5. //
  6. //This library is free software; you can redistribute it and/or
  7. //modify it under the terms of the GNU Lesser General Public
  8. //License as published by the Free Software Foundation; either
  9. //version 2.1 of the License, or (at your option) any later version.
  10. //
  11. //This library is distributed in the hope that it will be useful,
  12. //but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. //Lesser General Public License for more details.
  15. //
  16. //You should have received a copy of the GNU Lesser General Public
  17. //License along with this library; if not, write to the Free Software
  18. //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. #ifndef PANNABLEVIEW_P_H
  20. #define PANNABLEVIEW_P_H
  21. #include <QObject>
  22. #include <QTime>
  23. #include <QPointF>
  24. #include <QList>
  25. #include <QGraphicsWidget>
  26. class QTimeLine;
  27. class QGraphicsSceneMouseEvent;
  28. class PannableView;
  29. class PannableWidget;
  30. class PannableViewPrivate:public QObject{
  31. Q_OBJECT
  32. public:
  33. //! Constructor.
  34. //! \param parent Parent widget
  35. PannableViewPrivate( PannableView * parent );
  36. //! Dtor.
  37. virtual ~ PannableViewPrivate();
  38. //! Start scrolling
  39. //! \scroll the duration time. This is in milliseconds
  40. void startScrolling( int duration = 1000000 );
  41. //! Stop scrolling.
  42. //! \clear if this is set to true, the current position is cleaned.
  43. void stopScrolling( int clear=true);
  44. //! Handle mouse press event.
  45. //! \param event The event.
  46. //! \return true if event is handled, otherwise return false.
  47. bool mousePressEvent( QGraphicsSceneMouseEvent * event );
  48. //! Handle mouse move event.
  49. //! \param event The event.
  50. //! \return true if event is handled, otherwise return false.
  51. bool mouseMoveEvent( QGraphicsSceneMouseEvent * event );
  52. //! Handle mouse release event.
  53. //! \param event The event.
  54. //! \return true if event is handled, otherwise return false.
  55. bool mouseReleaseEvent( QGraphicsSceneMouseEvent *event );
  56. //! Handle tapping.
  57. //! \paran event The event.
  58. //! \return true if success, false otherwise
  59. bool tap( QGraphicsSceneMouseEvent * event );
  60. //! Handle swipe gesture.
  61. //! \param startPoint The point where mouse was pressed
  62. //! \param endPoint The point where mouse was released
  63. //! \return true on success, false on failure
  64. bool swipe( QPointF const & startPoint, QPointF const &endPoint );
  65. //! Method for animating the collision with one of the four ends.
  66. //! \param points A list point which are used for animation
  67. //! \param duration A duration for animation. Default is 800 ms.
  68. void animateEnd(QList<QPointF> const & points, int duration=800 );
  69. void storeSwipeStyle( QPointF const &first, QPointF const &second );
  70. //! Check if end has reached.
  71. //! \return true if end has been reached, return false otherwise.
  72. bool endReached();
  73. //! Move current position to the begining.
  74. void moveToBegin();
  75. //! Move current position to the end.
  76. void moveToEnd();
  77. //! \return true if scrolling is acgtive, false otherwise.
  78. bool isScrolling() const;
  79. //! Move the current position to \pos.
  80. //! \pos New position
  81. void moveTo(QPointF const & pos );
  82. //! Calculate the pannable widget geometry and set a new min max
  83. //! values so that if e.g. widget size changes the panning should
  84. //! still work.
  85. void recalculateGeometry();
  86. Q_SIGNALS:
  87. // Signal for stopping the animation
  88. void stopAnimation();
  89. private Q_SLOTS:
  90. //! A slot for scrolling.
  91. //! \param value not used for anything
  92. void scroll( qreal value );
  93. //! A slot for emitting posChanged() signal of parent
  94. void emitPositionChanged();
  95. public:
  96. enum SwipeStyle{
  97. Horizontal = 0,
  98. Vertical,
  99. Diagonal
  100. };
  101. // Members
  102. PannableView *q_ptr;
  103. qreal m_deltaX;
  104. qreal m_deltaY;
  105. qreal m_vX;
  106. qreal m_vY;
  107. int m_minX;
  108. int m_minY;
  109. int m_maxX;
  110. int m_maxY;
  111. QTime m_time;
  112. QTimeLine * m_scrollingTimeLine;
  113. Qt::Orientations m_orientation;
  114. bool m_skipTapGesture;
  115. PannableWidget * m_pannableWidget;
  116. bool m_enableIndicator;
  117. bool m_enableContinuousScrolling;
  118. SwipeStyle m_swipeStyle;
  119. Q_DECLARE_PUBLIC(PannableView)
  120. };
  121. //! \class PannableWidget
  122. //! \brief PannableWidget is just a simple wrapper which provides shape information used by clipping.
  123. //! This class is used internally only by PannableViewport.
  124. //! TODO: Figure out what to do with this widget.
  125. class PannableWidget: public QGraphicsWidget{
  126. public:
  127. //! PannableWidget constructor
  128. //
  129. //! \param parent optional parent
  130. PannableWidget( QGraphicsObject * parent = 0 );
  131. //! Destructor
  132. virtual ~PannableWidget();
  133. //! Shape method in order to make children to clip to shape
  134. //! \return instance shape in QPainterPath object.
  135. virtual QPainterPath shape () const;
  136. //! Set a widget for this widget
  137. virtual void setWidget( QGraphicsWidget * widget );
  138. };
  139. #endif // PANNABLEVIEW_P_H