pannableview.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_HH
  20. #define PANNABLEVIEW_HH
  21. #include <QGraphicsWidget>
  22. #include <QPainterPath>
  23. #include <QTimeLine>
  24. #include "hybridfw_global.h"
  25. class PannableViewPrivate;
  26. class PannableWidgetPrivate;
  27. //! \class PannableView
  28. //! Class PannableView is a simple view for the PannableWidget which can contain any kind
  29. //! of QGraphicsWidget based items. PannableView provide either vertical or horizontal
  30. //! scrolling. It is possible to set both directions on and then PannableView scrolls to
  31. //! the both directions. This view can be used for clipping part of the pannable area away
  32. //! for example if panning in vertical it clips all the items that are outside of this
  33. //! view's visible area.
  34. //!
  35. //! Usage:
  36. //! // Create a layout or a QGraphicsWidget
  37. //! QGraphicsLinearLayout * layout = new QGraphicsLinearLayout(Qt::Vertical);
  38. //! for(int i=0; i< 1500; i++){
  39. //! layout->addItem( new MyCustomItem );
  40. //! }
  41. //!
  42. //! QGraphicsWidget * widget = new QGraphicsWidget;
  43. //! widget->setLayout( layout );
  44. //!
  45. //! PannableView * view = new PannableView(Qt::Vertical, 865,480 );
  46. //! view->setWidget( widget );
  47. //! QGraphicsScene scene(0,0,856,480);
  48. //! scene.addItem( view );
  49. //!
  50. //! ...
  51. //!
  52. //!
  53. //! TODO:
  54. //! - provide a signal for notifying scrolling state: scrolling started, scrolling, scrolling ended
  55. //! - Add a scroll indicator to indicate current scrolling position
  56. //! - Make this class to use Qt's property system
  57. //! - Let a user define if she wants some of the hardcoded animations to be executed or not
  58. class DLL_EXPORT PannableView:
  59. public QGraphicsWidget
  60. {
  61. Q_OBJECT
  62. public:
  63. //! Constructor. Create PannableView object, with specified properties.
  64. //! \param orientation Qt::Horizontal or Qt::Vertical. These enums are possible to be ORed also.
  65. //! \param width The width of the view
  66. //! \param height The height of the view
  67. //! \param parent optional parent
  68. PannableView( Qt::Orientations orientation, qreal width, qreal height, QGraphicsItem * parent = 0 );
  69. //! Constructor.
  70. //! \param orientation Qt::Horizontal or Qt::Vertical. These are possible to "or" also.
  71. //! \param parent An optional parent
  72. PannableView( Qt::Orientations orientation, QGraphicsItem * parent = 0 );
  73. //! Destructor
  74. virtual ~PannableView();
  75. //! Set a pannable widget to this view.
  76. //! NOTE: Make sure that this view is in the scene before adding the widget.
  77. //! \param widget A widget that with some content.
  78. void setWidget( QGraphicsWidget * widget );
  79. //! \return true if view is scrolling, false is returned otherwise
  80. bool isScrolling() const;
  81. //! Move current position to the begining
  82. void moveToBegin();
  83. //! Move current position to the end.
  84. void moveToEnd();
  85. //! Enable continous scrolling. This means that when one of the ends of the pannable
  86. //! widget has been reached the widget moves to the opposite end.
  87. //! \param enable True if enabling continuous scrolling, false disables it.
  88. void enableContinuousScrolling( bool enable );
  89. //! Enable scroll indicator. Scroll indicator indicates current scrolling position.
  90. //! \param enable True if enabling scroll indicator, false disables it.
  91. void enableScrollIndicator( bool enable );
  92. //! \return The panning orientation.
  93. Qt::Orientations orientation() const;
  94. public Q_SLOTS:
  95. //! Move pannable viewport to the \p item.
  96. //! \param item This item is centered to the view.
  97. void moveToItem( QGraphicsItem * item);
  98. //! Set orienation for PannableView. The \p orientation can be either vertical or
  99. //! horizontal or both.
  100. //! \param orientation Qt::Vertical or Qt::Horizontal or OR combination of these.
  101. void setOrientation( Qt::Orientations orientation );
  102. protected:
  103. //! reimp
  104. virtual bool sceneEvent ( QEvent * event );
  105. Q_SIGNALS:
  106. //! This signal is emitted when position of the pannable item has been changed. The density of how often this
  107. //! signal is emitted can be changed with \see setPosChangedInterval(int interval)
  108. //! \param viewRect The rectangle of the viewport.
  109. void posChanged(QRectF const & viewRect );
  110. //! A signal for indicating tapping.
  111. //! \param point tapped position.
  112. void tapped(QPointF const & point );
  113. private:
  114. // Private members
  115. PannableViewPrivate * d_ptr;
  116. Q_DECLARE_PRIVATE(PannableView);
  117. Q_DISABLE_COPY(PannableView);
  118. };
  119. #endif