LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
thingpaintable.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2011-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 "thing.h"
23 #include <QString>
24 #include <QRectF>
25 
26 #ifndef THINGPAINTABLE_H_
27 #define THINGPAINTABLE_H_
28 
29 class ThingPaintable : public Thing
30 {
31  Q_OBJECT
32  Q_PROPERTY(QString uistate READ readUiState WRITE writeUiState RESET resetUiState NOTIFY signalUiStateChanged)
33 
34  //this property is needed because QGraphicsObject doesn't provide for position changed signals, and
35  // during icon animations, I need to know to update-paint the layout and scroller within Page
36  // (see code for Page, ScrollableObject, and IconLayout)
37  // Even though OpenGL the way this system uses it repaints the whole screen on each update, Qt itself doesn't
38  // have that assumption. On a regular setPos() on a QGraphicsObject, only that object and anything under it will
39  // be marked for paint updates...but this isn't correct necessarily because the scroller and layout will partially
40  // paint based on a "viewport" area that the scroller set. So the paint() needs to go through the scroller,
41  // which means I need a way to signal that sequence...
42  Q_PROPERTY(QPointF animatePosition READ pos WRITE setPos NOTIFY signalPositionChanged)
43 
44 public:
45 
46  //used to identify ThingPaintables when they are in a list returned by QGraphicsView/QGraphicsScene. Since QGraphicsItems
47  // are not QObject, I cannot use qobject_casts as I would normally to determine type. Thus, I'll use QGI's setData()/data()
48  // with this key to determine
51  static bool isItemThingPaintable(QGraphicsItem * p_qgitem);
52  //this is a convenience, a-la qobject_cast...same semantics
54 
55  ThingPaintable(const QRectF& geom);
56  virtual ~ThingPaintable();
57 
58  // object properties
59  virtual QString readUiState() const { return m_uiState; }
60  virtual void writeUiState(const QString& s) { m_uiState = s; }
61  virtual void resetUiState() { m_uiState = QString(""); }
62 
63  //from Thing
64  virtual QRectF geometry() const { return m_geom; }
65 
66  //this
67  virtual QRectF positionRelativeGeometry() const;
68  virtual QRectF untranslateFromPosition(const QRectF& rect) const;
69  virtual QRectF boundingRect() const { return m_boundingRect; }
70 
71  virtual bool resize(const QSize& newSize);
72  virtual bool resize(quint32 newWidth,quint32 newHeight);
73 
74  //these two are required...
75  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option=0,QWidget *widget=0) = 0;
76  virtual void paintOffscreen(QPainter *painter) = 0;
77 
78  //these are optional
79  virtual void paint(QPainter *painter, const QRectF& sourceRect);
80  virtual void paint(QPainter *painter, const QRectF& sourceRect,qint32 renderOpt);
81  virtual void paint(QPainter * painter, const QRectF& sourceRect,const QPointF& painterTranslate);
82  virtual void paint(QPainter * painter, const QRectF& sourceRect,const QPointF& painterTranslate,qint32 renderOpt);
83 
84  virtual void paintOffscreen(QPainter *painter,const QRect& sourceRect,const QPoint& targetOrigin);
85  virtual void paintOffscreen(QPainter *painter,const QRect& sourceRect,const QRect& targetRect);
86 
87 Q_SIGNALS:
88 
89 // params:
90  //[0] old geom
91  //[1] new geom
92  void signalGeometryChanged(const QRectF&,const QRectF&);
93  void signalGeometryChanged();
94 
95  void signalUiStateChanged();
96  void signalPositionChanged();
97 
98 protected:
99 
100  ThingPaintable(const QUuid& specificUid,const QRectF& geom);
101 
102  virtual void recomputeBoundingRect();
103  virtual void recomputeBoundingRect(const QRectF& virtualGeom);
104 
105 protected:
106 
107  QRectF m_geom;
109 
110  // object properties
111  QString m_uiState;
112 };
113 
114 uint qHash(const ThingPaintable& t);
115 uint qHash(const QPointer<ThingPaintable>& qpt);
116 
117 #endif /* THINGPAINTABLE_H_ */