LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
page.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 PAGE_H_
23 #define PAGE_H_
24 
25 #include <QUuid>
26 #include <QRectF>
27 #include <QPointer>
28 #include <QString>
29 #include <QTimer>
30 #include <QBrush>
31 #include <QObject>
32 
33 #include "thingpaintable.h"
34 #include "icon.h"
35 #include "pixmapobject.h"
36 #include "frictiontransform.h"
37 #include "dimensionstypes.h"
38 
39 class LauncherObject;
40 class QGraphicsSceneMouseEvent;
41 class QGesture;
42 class QGestureEvent;
43 class QTouchEvent;
44 class QPanGesture;
45 class QSwipeGesture;
46 class QPinchGesture;
47 class QTapAndHoldGesture;
48 class QTapGesture;
49 class FlickGesture;
50 class ScrollableObject;
51 class IconBase;
52 class IconLayout;
53 class QAbstractAnimation;
54 class QAnimationGroup;
55 class QState;
56 class QStateMachine;
57 
58 #include "KineticScroller.h"
59 
60 namespace PageScrollDirectionLock
61 {
62  enum Enum
63  {
68  };
69 }
70 
71 namespace PageAreas
72 {
73  enum Enum
74  {
76  Content, //inner area of the page; means "normal", nothing special.
77  LeftBorder, // the left edge, usually designated to trigger a horizontal page pan left
78  RightBorder, // the right edge...
79  TopBorder, // the top, same idea as left/right but for vertical scrolls in the page
80  BottomBorder // ....
81  };
82 }
83 
84 namespace PageMode
85 {
86  enum Enum
87  {
91  };
92 }
93 
95 {
96  Q_OBJECT
97 public:
100 };
101 
103 {
104  Q_OBJECT
105 public:
107  : m_qp_srcPage(p_srcPage) , m_qp_icon(p_icon) { m_valid = true; }
109  QPointer<Page> m_qp_srcPage;
110  QPointer<IconBase> m_qp_icon;
111 };
112 
113 class Page : public ThingPaintable
114 {
115  Q_OBJECT
116  Q_INTERFACES(QGraphicsItem)
117 
118  Q_PROPERTY(qint32 pageuiindex READ pageIndex WRITE setPageIndex NOTIFY signalPageIndexChanged)
119  Q_PROPERTY(QString pagename READ pageName WRITE setPageName NOTIFY signalPageNameChanged)
121  Q_PROPERTY(bool pageactive READ pageActive)
122 
123 public:
124 
125  friend class PageRestore;
126  static const char * PageNamePropertyName;
127  static const char * PageIndexPropertyName;
128  static const char * PageDesignatorPropertyName;
130  static QString PageDesignator_Favorites;
131  static QString PageDesignatorAll() { return PageDesignator_AllAlphabetic; }
133  friend class QTimer; //give it access to my stuff for page physics
134  friend class LauncherObject;
135 
137 
138  Q_INVOKABLE Page(const QRectF& pageGeometry,LauncherObject * p_belongsTo);
139  virtual ~Page();
140 
141  qint32 pageIndex() const { return m_pageUiIndex; }
142  void setPageIndex(const qint32 v) { m_pageUiIndex = v; }
143 
144  QString pageName() const { return m_pageName; }
145  void setPageName(const QString& v);
146  QString pageDesignator() const { return m_pageDesignator; }
147  void setPageDesignator(const QString& v) { m_pageDesignator = v; }
148 
149  bool pageActive() const { return m_pageActive; }
150 
151  virtual PageMode::Enum pageMode() const { return PageMode::INVALID; }
152  virtual void setPageMode(PageMode::Enum v) {}
153 
154  static QSize PageSizeFromLauncherSize(quint32 width,quint32 height);
155 
156  virtual bool resize(quint32 w, quint32 h);
157 
158  virtual bool take(Thing * p_takerThing);
159  virtual bool taking(Thing * p_victimThing, Thing * p_takerThing);
160  virtual void taken(Thing * p_takenThing,Thing * p_takerThing);
161 
162  // intended to be a general query (i.e. according to page type).
163  // Don't modify it to be more specific; better just add other functions
164  // for that
165  virtual bool canAcceptIcons() const;
166  virtual bool acceptIncomingIcon(IconBase * p_newIcon);
167  virtual bool releaseTransferredIcon(IconBase * p_transferredIcon);
168 
169  virtual bool layoutFromItemList(const ThingList& items);
170  virtual bool layoutFromItemList(const IconList& items);
171 
172  virtual bool setIconLayout(IconLayout * p_iconLayout);
173  virtual IconLayout * currentIconLayout() const;
174 
175  //layoutCoord must be in layout ICS
176  virtual IconBase * iconAtLayoutCoordinate(const QPointF& layoutCoord,QPointF * r_p_intraIconCoord);
177 
178  //this is a somewhat strange function, needed because of the way layouts work (they aren't actual graphics items)
179  // if there is a scrollableobject, then the layout is its descendant w.r.t. graphicsview so the coordinates of the page
180  // and the coords of the layout are modified by the scrollable.
181  // if there is no scrollable, then (at least for now), there is no modification
182  virtual QPointF pageCoordinateFromLayoutCoordinate(const QPointF& layoutCoord);
183  virtual QPointF layoutCoordinateFromPageCoordinate(const QPointF& pageCoordinate);
184 
185  friend uint qHash(const QPointer<Page>& p);
186 
187  virtual QRectF areaScroller() const;
188  virtual QRectF areaTopEdgeShadow() const;
189  virtual QRectF areaBottomEdgeShadow() const;
190  virtual QRectF areaLeftBorder() const;
191  virtual QRectF areaRightBorder() const;
192  virtual QRectF areaTopBorder() const;
193  virtual QRectF areaBottomBorder() const;
194  //areaCenter() is anything not a border , on the inner side of the borders
195  virtual QRectF areaCenter() const;
196 
197  virtual PageAreas::Enum classifyPageLocation(const QPointF& pageCoordinate) const;
198 
199 Q_SIGNALS:
200 
201  // params:
202  //[0] old index
203  //[1] new index
204  void signalPageIndexChanged(qint32,qint32);
205  void signalPageIndexChanged();
206 
207  // params:
208  //[0] old name
209  //[1] new name
210  void signalPageNameChanged(const QString&, const QString&);
211  void signalPageNameChanged();
212 
214 
215  void signalPageModeChanged();
217 
218  void signalIconActivatedTap(IconBase* pIcon);
219 
220  void signalPageActive();
221  void signalPageDeactivated();
222 
223  void signalRedirectFlick(FlickGesture *flickEvent,QGestureEvent * baseGestureEvent);
224 
225  //LISTEN TO THIS SIGNAL TO TRIGGER SAVES; it's much better than listening to signalPageNameChanged or something else that signals a state change.
226  void signalPageNeedsSave();
227 
228  // does what a "Done" button press on the tab bar would do
230 
231 public Q_SLOTS:
232 
233  virtual void dbg_slotPrintLayout();
234 
235 protected Q_SLOTS:
236 
237  virtual void slotAnimationEnsembleFinished();
238  virtual void slotStopAnimationEnsemble(bool * r_result=0);
239  virtual void slotStartAnimationEnsemble(bool canInterrupt=true);
241  virtual void slotAddAnimationTo(QAnimationGroup * p_addToGroup,QAbstractAnimation * p_anim,DimensionsTypes::AnimationType::Enum animType = DimensionsTypes::AnimationType::None);
242 
243  virtual void slotScrollingPhysicsUpdate(qreal t,qreal d,qreal v,qreal a);
244  virtual void slotPageOverscrolled();
245  virtual void slotUndoOverscroll();
246 
247  virtual void slotBroadcastPageActivated(QUuid pageUid);
248  virtual void slotBroadcastAllPagesDeactivated();
249 
250  virtual void slotKineticScrollerSpew(qreal oldScroll);
251 
252  //used by the scroll FSM. Only a slot to make it convenient for the FSM to call it
253  virtual void slotOkToScroll();
254 
255  virtual void slotLauncherCmdEndReorderMode();
256 
257  virtual void slotLauncherBlockedInteractions();
258  virtual void slotLauncherAllowedInteractions();
259  virtual void slotClearTouchRegisters();
260 
261  //called as the launcher is about to be brought up and shown to the user, and as it is about to be brought down and hidden
262  virtual void slotLauncherActivating();
263  virtual void slotLauncherDeactivating();
264 
265 protected:
266 
267  //this one used by PageRestore to bring back specific uids.
268  // never, ever call directly with random or invalid uids - collisions will occur
269  Q_INVOKABLE Page(const QUuid& specificUid,const QRectF& pageGeometry,LauncherObject * p_belongsTo);
270 
271  virtual void activatePage();
272  virtual void deactivatePage();
273 
274  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option=0,QWidget *widget=0);
275  virtual void paintOffscreen(QPainter *painter);
276  virtual void paintShadows(QPainter * painter);
277 
278  virtual bool sceneEvent(QEvent * event);
279  virtual bool gestureEvent(QGestureEvent *gestureEvent) { return true; }
280  virtual bool panGesture(QPanGesture *panEvent) { return true; }
281  virtual bool swipeGesture(QSwipeGesture *swipeEvent,QGestureEvent * baseGestureEvent);
282  virtual bool flickGesture(FlickGesture *flickEvent,QGestureEvent * baseGestureEvent);
283  virtual bool pinchGesture(QPinchGesture *pinchEvent) { return true; }
284  virtual bool tapAndHoldGesture(QTapAndHoldGesture *tapHoldEvent,QGestureEvent * baseGestureEvent) { return true; }
285  virtual bool tapGesture(QTapGesture *tapEvent,QGestureEvent * baseGestureEvent) { return true; }
286  virtual bool customGesture(QGesture *customGesture) { return true; }
287 
288  //DEFAULT POLICY: allow if no other gesture has claimed the touch point yet, else, reject.
289  // When the return == true, then the register is updated with the gesture as the trigger for that id
290  virtual bool okToUseFlick(int id);
291  virtual bool okToUseTap(int id);
292  virtual bool okToUseTapAndHold(int id);
293 
294  //These are to map the points from Page CS to ScrollingSurface CS
295  // if there is no ScrollingSurface assigned, then the point passed in is the point returned (and the result is 'true')
296  //ASSUMPTION: scroll surface is always completely contained inside the page (i.e. page geom totally encompasses scroll surface geom)
297  virtual QPointF translatePagePointToScrollSurfacePoint(const QPointF& point,bool clipToGeom=false);
298  virtual bool testAndTranslatePagePointToScrollSurfacePoint(const QPointF& point,QPointF& r_translatedPoint);
299 
300  virtual bool isAnimationEnsembleRunning() const;
301  virtual bool stopAnimationEnsemble();
302  virtual void animationFinishedProcessGroup(QAnimationGroup * pAnim);
303  virtual void animationFinishedProcessAnim(QAbstractAnimation * pAnim);
304 
305  virtual bool addIcon(IconBase * p_icon) { return false; }
306  virtual bool addIconNoAnimations(IconBase * p_icon) { return false; }
307  virtual bool removeIcon(const QUuid& iconUid) { return false; }
308  virtual bool removeIconNoAnimations(const QUuid& iconUid) { return false; }
309 
310  virtual IconBase * removeIconFromPageAddWaitlist(const QUuid& iconUid);
311  virtual bool isIconInPageAddWaitlist(const QUuid& iconUid);
312  virtual void addIconToPageAddWaitlist(IconBase * p_icon);
313  //returns the number of items NOT handled (still waitlisted) ...so 0 would mean total success
314  virtual qint32 addWaitlistHandler();
315 
316  virtual void removeIconFromPageRemoveWaitlist(const QUuid& iconUid);
317  virtual bool isIconInPageRemoveWaitlist(const QUuid& iconUid);
318  virtual void addIconToPageRemoveWaitlist(IconBase * p_icon);
319  virtual void addIconToPageRemoveWaitlist(const QUuid& iconUid);
320  //returns the number of items NOT handled (still waitlisted) ...so 0 would mean total success
321  virtual qint32 removeWaitlistHandler();
322 
323 protected:
324 
325  QString m_pageName;
326 
327  qint32 m_pageUiIndex; //for quick indexing in the ui (owner)
330  QPointer<LauncherObject> m_qp_currentUIOwner;
331  QPointer<PixmapObject> m_qp_backgroundPmo;
334 
337 
340 
342 
344  QPointer<QAnimationGroup> m_qp_ensembleAnimation;
345 
346  //TODO: MULTI-TOUCH: only 1 touch id can control scroll, realistically. But what happens during M.T.
347  // on seemingly conflicting scroll touches?
349  int m_scrollLockTouchId; //only valid when m_scrollDirectionLock != None
350 
351  QPointer<IconLayout> m_qp_iconLayout;
353 
354  // When an app icon needs to be added or removed (the most likely case of this is from the app installer), but this page is performing
355  // a reorder, then these "waitlists" are used to hold the icon/icon ref. When it is safe to do so, the waitlistHandler()s are called which will take care
356  // of all of these waiting icons.
357  // currently impl. as a map and set by icon uid, so that, in case instruction flow CAN manage to remove the icon from the page/system before the
358  // waitlistHandler runs, it will be easy to find the icon / ref
359 
360  QMap<QUuid,QPointer<IconBase> > m_pendingExternalIconAddWaitlist;
362 
364 
365 protected:
366 
371 
372  static const char * TouchFSMPropertyName_isTracking;
373  static const char * TouchFSMProperyName_trackedId;
374 
375  QMap<int,TouchRegister> m_touchRegisters;
376 
377  virtual bool anyTouchTracking(int * r_p_mainTouchId=0);
378 
379  virtual bool touchPointTriggerType(int id,TouchTriggerType::Enum& r_type);
381  //same as above, except will true condition also includes if the register is missing/invalid (it will create it)
383 
384  virtual RedirectingType::Enum isRedirecting(int id,Thing ** r_pp_redirectTargetThing,RedirectContext ** r_pp_redirContext);
385  virtual bool isDeferCancelled(int id,bool doCancel=false);
386  virtual bool redirectTo(int id,Thing * p_redirectTargetThing,RedirectContext * p_redirContext = 0);
387 
388  //TODO: making public as a temp workaround to let proxy redirection changes work. Redo this the OOP-correct way
389 public:
390  virtual bool changeRedirectTo(int id,Thing * p_currentlyRedirectedToThing,Thing * p_newRedirectedToThing,RedirectContext * p_redirContext = 0);
391  virtual bool cancelRedirection(int id,bool deferred=false);
392 protected:
393  virtual void setupTouchFSM();
394  virtual void startTouchFSM();
395  virtual void stopTouchFSM();
396 
397  virtual void clearAllTouchRegisters();
398 
399  //these are the interface to QT...see sceneEvent()
400  virtual bool touchStartEvent(QTouchEvent *event);
401  virtual bool touchUpdateEvent(QTouchEvent *event);
402  virtual bool touchEndEvent(QTouchEvent *event);
403 
404  virtual void handleTrackedTouchPointRelease(QTouchEvent::TouchPoint* touchPoint);
405 
406  //passing in id, but really for now only 1 id can be tracked
407  virtual void touchTrackedPointStarted(int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition);
408  virtual void touchTrackedPointMoved(int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition);
409  virtual void touchTrackedPointReleased(int id,const QPointF& scenePosition,const QPointF& lastScenePosition,const QPointF& initialPosition);
410 
411  virtual void autoScrollDown();
412  virtual void autoScrollUp();
413 
414 protected Q_SLOTS:
416 
417 Q_SIGNALS:
418 
419  //Triggers: what causes FSM state changes
420  void signalTouchFSMTouchBegin_Trigger(int touchId);
424 
425  //Actions: what the FSM outputs to signal state changes to this object
426  void signalTouchFSMBeginTrack_Action(); //on a new touch [kicks off the FSM]
427  void signalTouchFSMTouchLost_Action(); // when a new touch appears when a touch is already tracking;
428  // this is used when I only support single touch (like in this class)
429  void signalTouchFSMStationary_Action(); // when the motion stops for a period of time (TODO: implement)
430  void signalTouchFSMMoving_Action(); // when the touch point is moving again (only signalled after a stop, not after Begin)
431  void signalTouchEndTrack_Action(); // when the touch is released
432 
434 
436 
437 Q_SIGNALS:
438 
440 
441 protected:
442  virtual void setupScrollDelayFSM();
443  virtual void startScrollDelayFSM();
444  virtual void stopScrollDelayFSM();
445 
446  //this one is an easy interface from subclasses to signal the start of scroll
447  virtual void scrollActionTrigger();
448 
449  //TODO: wonky naming...especially confusing w.r.t other okTo___ functions and slotOkToScroll()
450  virtual bool okToPerformAutoScroll() const;
451 protected:
452 
457 
459 
461 
463 
465 
466 Q_SIGNALS:
467 
469 };
470 
471 uint qHash(const QPointer<Page>& p);
472 
473 #endif /* PAGE_H_ */