LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
thing.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 #ifndef THING_H_
23 #define THING_H_
24 
25 #include <QGraphicsObject>
26 #include <QUuid>
27 #include <QPointer>
28 #include <QString>
29 #include <QList>
30 #include <QRectF>
31 #include <QDebug>
32 
33 class QGraphicsSceneMouseEvent;
34 
35 namespace TouchTriggerType
36 {
37  enum Enum
38  {
40  Tap,
43  //add other gesture types here as needed
44  };
45 }
46 
47 
48 namespace RedirectingType
49 {
50  enum Enum
51  {
56  };
57 }
58 
59 class Thing;
60 class RedirectContext;
62 {
63 public:
64  TouchRegister() : valid(false) {}
65  TouchRegister(int _id,TouchTriggerType::Enum _triggerType)
66  : touchId(_id) , triggerType(_triggerType) , valid(true) , pause(false) , redirecting(false) , deferredCancel(false), qpRedirectTarget(0) , pRedirectContext(0) {}
67  int touchId;
69  bool valid; //when reading the 'register', if this is false, then all other values are invalid
70  bool pause;
73  QPointer<Thing> qpRedirectTarget;
75 
76  friend QDebug& operator<<(QDebug dbg,const TouchRegister& reg);
77 };
78 
79 QDebug& operator<<(QDebug dbg,const TouchRegister& reg);
80 
81 class RedirectContext : public QObject
82 {
83  Q_OBJECT
84 public:
85  RedirectContext() : m_valid(false) , m_dbg_onDestruct(false) {}
86  virtual ~RedirectContext();
87  virtual bool isValid() const { return m_valid; }
88  bool m_valid;
90 };
91 
92 class Thing : public QGraphicsObject
93 {
94  Q_OBJECT
95 
96 public:
97  Thing();
98  virtual ~Thing();
99  virtual QUuid uid() const;
100  virtual QRectF geometry() const = 0;
101 
102  // every "thing" must at least consider a resize, which is why i am making it pure-v.
103  // the return value can let the item indicate 'false' if it wants to flag that it can't resize to
104  // the new size. The upstream ui elements can act on or ignore that as desired
105  virtual bool resize(quint32 newWidth,quint32 newHeight) = 0;
106 
107  //called by another Thing on 'this' (me), to offer p_offer for the taking.
108  // if this wants it, it will initiate a take() sequence immediately. It is expected that
109  // offeringThing will allow the take if it called offer.
110  // returns false if this doesn't want the offered thing.
111  // returns true at the end of the take sequence (actually, returns the return of take())
112  virtual bool offer(Thing * p_offer,Thing * p_offeringThing);
113 
114  //called to transfer this (my) Thing's belongs-to to another Thing
115  // e.g. icons between pages, etc
116  // returns false if rejected
117  virtual bool take(Thing * p_takerThing);
118 
119  //called by the Thing that I own, to tell me some other Thing is trying to take it
120  // I can return "false" to prevent the abduction
121  virtual bool taking(Thing * p_victimThing, Thing * p_takerThing);
122 
123  //called by the Thing that I used to own, to tell me some other Thing took it
124  virtual void taken(Thing * p_takenThing,Thing * p_takerThing);
125 
126  virtual uint hashValue() const;
127  friend uint qHash(const Thing& t);
128 
129  //Since I want to avoid multiple inheriting (c++) at all costs, going to give Thing-s the ability to accept touch events
130  // at least from other Thing-s
131 
132  virtual void touchTrackedPointStarted(int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition);
133  virtual void touchTrackedPointMoved(int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition);
134  virtual void touchTrackedPointReleased(int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition);
135  virtual void redirectTouchPrepare(Thing * p_sourceThing,const TouchRegister& touchRegister,int contextHint=0);
136  virtual void redirectedTouchTrackedPointMoved(Thing * p_sourceThing,int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition,const RedirectContext& redirContext);
137  virtual void redirectedTouchTrackedPointReleased(Thing * p_sourceThing,int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition,const RedirectContext& redirContext);
138 
139 Q_SIGNALS:
140 
141  //provided so that owners of Thing-s can hook onto a signal w/o caring about subclasses
142  void signalThingGeometryChanged(const QRectF&);
143 
144 public Q_SLOTS:
145 
146  // TODO: REMOVE: made its way in here for some incorrect reason...
147  // These two toggle this item's painting and repainting of itself as a part of the QGraphics View system
148  // then AutoRepaint is disabled, the item will only be painted when its paint function is called explicitly
149  // By default, the base class impl. does nothing
150  virtual void slotEnableIconAutoRepaint();
151  virtual void slotDisableIconAutoRepaint();
152 
153 protected:
154 
155  Thing(const QUuid& specificUid);
156 
157 // virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
158 // virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
159 // virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
160 
161 protected:
162 
163  QPointer<Thing> m_qp_takerOwner; //the last Thing that performed a successful take() on this Thing
164 
165 private:
166 
167  QUuid m_uid;
168 
169 };
170 
171 typedef QList<Thing *> ThingList;
172 typedef ThingList::const_iterator ThingListConstIter;
173 typedef ThingList::iterator ThingListIter;
174 
175 uint qHash(const Thing& t);
176 uint qHash(const QPointer<Thing>& qpt);
177 
178 #include <QHash>
179 
180 #endif /* THING_H_ */