LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
scrollableobject.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #include "thingpaintable.h"
23 #include <QRectF>
24 #include <QRect>
25 
26 class QPainter;
27 class QGraphicsSceneMouseEvent;
28 
29 #ifndef SCROLLABLEOBJECT_H_
30 #define SCROLLABLEOBJECT_H_
31 
33 {
34  Q_OBJECT
35  Q_INTERFACES(QGraphicsItem)
36 
37  Q_PROPERTY(qint32 scroll READ scrollValue WRITE setScrollValue)
38 
39 public:
40 
41  ScrollableObject(const QRectF& geometry);
42  virtual ~ScrollableObject();
43 
44  virtual QRect screenGeometry() const;
45 
46  virtual qint32 scrollValue() const = 0;
47  virtual void setScrollValue(qint32 v) = 0;
48  virtual qint32 rawScrollValue() const;
49  virtual qint32 scrollValueNeededToEscapeOverscroll();
50  virtual quint32 scrollAmountUntilTopOverscroll();
51  virtual quint32 scrollAmountUntilBottomOverscroll();
52  virtual void enable();
53  virtual void disable();
54 
55  virtual QPointF mapToContentSpace(const QPointF& scrollerSpacePointF);
56  virtual QPointF mapToContentSpace(const QPoint& scrollerSpacePoint);
57  virtual QPointF mapFromContentSpace(const QPointF& contentSpacePointF);
58 
59  virtual bool mapToContentSpace(const QPointF& scrollerSpacePointF,QPointF& r_mappedPointF);
60  virtual bool mapToContentSpace(const QPoint& scrollerSpacePoint,QPointF& r_mappedPointF);
61  virtual bool mapFromContentSpace(const QPointF& contentSpacePoint,QPointF& r_mappedScrollerSpacePointF);
62 
63  virtual bool resize(const QSize& newSize);
64  virtual bool resize(quint32 w,quint32 h);
65 
66  virtual qint32 topLimit() const;
67  virtual qint32 bottomLimit() const;
68 
69  virtual bool isInOverscroll() { return m_inOverscroll; }
70  virtual qint32 overscrollAmount() { return m_overscrollVal; }
71 
72 public Q_SLOTS:
73 
74  //these all do the same thing, but are in different flavors to make it easier for a wide variety of sources to
75  // set the proper m_sourceGeom. Owners only need to connect to one of them, and subclasses must implement all of them
76  // which also serves as a reminder that they need
77  // to set content geom correctly during initialization, etc.
78  virtual void slotSourceGeomChanged(const QRectF& newGeom) = 0;
79  virtual void slotSourceContentSizeChanged(const QSizeF& newContentSize) = 0;
80  virtual void slotSourceContentSizeChanged(const QSize& newContentSize) = 0;
81 
82 protected:
83 
84  virtual void resetToInitialSourceArea();
85  virtual void resetToInitialTargetArea();
86 
87  virtual void setSourceContentGeom(const QRectF& newContentGeom) = 0;
88 
89  virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
90  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
91  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
92 
93  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option=0,QWidget *widget=0);
94  virtual void paintOffscreen(QPainter *painter);
95 
96  /*
97  * m_geom: the geometry, running from -w/2,-h/2 -> w/2,h/2 (floats)
98  *
99  * m_screenGeom: a version of m_geom that is rounded correctly to
100  * pixel coordinates (ints), but same neg->pos coord space
101  *
102  * m_boundingRect: m_geom with a bit of padding on the edges in accordance with QG'view rules
103  *
104  * m_sourceRect: the coordinates FROM which to paint from the "content". It is in the CONTENT's
105  * coordinate space. So, e.g. for a pixmap content source (like ScrollingSurface),
106  * the coordinate space will be from 0,0 -> m_sourceContentSize
107  * For sources that are in a logical item space more like regular g'items,
108  * or layouts, etc, the cs will be from (-w_of_item/2,-h_of_item/2),[size of item]
109  *
110  * m_targetRect:
111  * the coordinates INTO which to paint in the painter provided to paint(). It should be in the
112  * painter's cs; Since the paint() function is being called by the QG'view system automatically,
113  * the origin will have been translated to the item's origin by the QGV sys
114  */
116  QRectF m_sourceRect;
123 
124  QRectF m_sourceGeom; //from which the sourceRect is taken; to be set by subclasses
125 
126 };
127 #endif /* SCROLLABLEOBJECT_H_ */