LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CardWindowManager.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2013 Hewlett-Packard Development Company, L.P.
4 * Copyright (c) 2013 LG Electronics
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * LICENSE@@@ */
19 
20 
21 
22 
23 #ifndef CARDWINDOWMANAGER_H
24 #define CARDWINDOWMANAGER_H
25 
26 #include "Common.h"
27 
28 #include "WindowManagerBase.h"
29 
30 #include <QStateMachine>
31 #include <QGraphicsSceneMouseEvent>
32 #include <QGestureEvent>
33 #include <QParallelAnimationGroup>
34 #include <QMap>
35 #include <QEasingCurve>
36 #include <stdint.h>
37 
39 class MinimizeState;
40 class MaximizeState;
41 class PreparingState;
42 class LoadingState;
43 class FocusState;
44 class ReorderState;
45 
46 QT_BEGIN_NAMESPACE
47 class QTapGesture;
48 class QTapAndHoldGesture;
49 class QPropertyAnimation;
50 QT_END_NAMESPACE
51 
52 class CardWindow;
53 class CardGroup;
54 
55 
57 {
58  Q_OBJECT
59 
60 public:
61 
62  CardWindowManager(int maxWidth, int maxHeight);
63  virtual ~CardWindowManager();
64 
65  virtual void init();
66 
67  virtual void addWindow(Window* win);
68  virtual void prepareAddWindow(Window* win);
69  virtual void addWindowTimedOut(Window* win);
70  virtual void removeWindow(Window* win);
71  virtual void focusWindow(Window* win);
72 
73  CardWindow* activeWindow() const;
74  CardGroup* activeGroup() const;
75 
76  void setInModeAnimation(bool animating);
77  bool isLastWindowAddedModal() const { return m_addingModalWindow; }
78  void resize(int width, int height);
79  bool isModalDismissed() const {return m_modalDimissed; }
80  void setModalDismissed(bool val) { m_modalDimissed = val; }
81  virtual bool okToResize();
82 
83  CardWindow* modalParent() const { return m_parentOfModalCard; }
84 
85  void firstCardAlert();
86 
87  virtual bool handleNavigationEvent(QKeyEvent* keyEvent, bool& propogate);
88 
89 protected:
90 
91 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
92  virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
93  virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
94  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
95  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
96 #endif // QT_VERISON < 5.0.0
97  void tapGestureEvent(QTapGesture* event);
98  void tapAndHoldGestureEvent(QTapAndHoldGesture* event);
99  void flickGestureEvent(QGestureEvent* event);
100 
101  virtual bool sceneEvent(QEvent* event);
102 
103 private Q_SLOTS:
104 
105  void slotPositiveSpaceAboutToChange(const QRect& r, bool fullScreen, bool screenResizing);
106  void slotPositiveSpaceChangeFinished(const QRect& r);
107  void slotPositiveSpaceChanged(const QRect& r);
108  void slotLauncherVisible(bool val, bool fullyVisible);
109  void slotLauncherShown(bool val);
110 
111  void slotAnimationsFinished();
112  void slotDeletedAnimationFinished();
113  void slotTouchToShareAnimationFinished();
114 
115  void slotMaximizeActiveCardWindow();
116  void slotMinimizeActiveCardWindow();
117 
118  void slotChangeCardWindow(bool next);
119 
120  void slotFocusMaximizedCardWindow(bool focus);
121 
122  void slotTouchToShareAppUrlTransfered(const std::string& appId);
123  void slotOpacityAnimationFinished();
124  void slotDismissActiveModalWindow();
125  void slotDismissModalTimerStopped();
126 
127 Q_SIGNALS:
128 
129  void signalFocusWindow(CardWindow* win);
134  void signalEnterReorder(QPoint pt, int slice);
135  void signalExitReorder(bool canceled = true);
136  void signalFirstCardRun();
137 
138 private:
139 
140  void performPostModalWindowRemovedActions(Window* win, bool restore = true);
141  void initiateRemovalOfActiveModalWindow();
142 
143 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
144  void handleMousePressMinimized(QGraphicsSceneMouseEvent* event);
145 
146  void handleMouseMoveMinimized(QGraphicsSceneMouseEvent* event);
147  void handleMouseMoveReorder(QGraphicsSceneMouseEvent* event);
148 
149  void handleMouseReleaseMinimized(QGraphicsSceneMouseEvent* event);
150  void handleMouseReleaseReorder(QGraphicsSceneMouseEvent* event);
151 
152 #else
153  void handleTouchBeginMinimized(QTouchEvent* e);
154 
155  void handleTouchUpdateMinimized(QTouchEvent* e);
156  void handleTouchUpdateReorder(QTouchEvent* e);
157 
158  void handleTouchEndMinimized(QTouchEvent* e);
159  void handleTouchEndReorder(QTouchEvent* e);
160 
161  void slideAllGroupsOnTouchUpdate(int xOffset);
162 #endif // QT_VERSION < 5.0.0
163 
164  void handleFlickGestureMinimized(QGestureEvent* event);
165 
166  void handleTapGestureMinimized(QTapGesture* event);
167 
168  void handleTapAndHoldGestureMinimized(QTapAndHoldGesture* event);
169 
170  void handleKeyNavigationMinimized(QKeyEvent* keyEvent);
171 
172  void setCurrentState(CardWindowManagerState* newState) { m_curState = newState; }
173 
174  void maximizeActiveWindow(bool animate=true);
175  void minimizeActiveWindow(bool animate=true);
176 
177  // places the active window just off the bottom of the screen
178  // either unscaled or scaled
179  void setActiveCardOffScreen(bool fullsize=true);
180 
181  QRect normalOrScreenBounds(CardWindow* win) const;
182  QRect targetPositiveSpace() const { return m_targetPositiveSpace; }
183 
184  void prepareAddWindowSibling(CardWindow* win);
185  void addWindowTimedOutNormal(CardWindow* win);
186 
187  void removeCardFromGroupMaximized(CardWindow* win);
188  void removeCardFromGroup(CardWindow* win, bool adjustLayout=true);
189 
190  void closeWindow(CardWindow* win, bool angryCard=false);
191 
192  CardGroup* groupClosestToCenterHorizontally() const;
193 
194  void enterReorder(QPoint pt);
195  void cycleReorderSlot();
196  void moveReorderSlotRight();
197  void moveReorderSlotLeft();
198  void moveReorderSlotCenter(QPointF pt);
199  void arrangeWindowsAfterReorderChange(int duration, QEasingCurve::Type curve);
200 
201  // animate to the group next to the active group
202  void switchToNextGroup();
203  // animate to the group before the current active group
204  void switchToPrevGroup();
205 
206  void switchToNextApp();
207  void switchToPrevApp();
208  void switchToNextAppMaximized();
209  void switchToPrevAppMaximized();
210 
211  // animate all groups to center around the active group.
212  // optionally include the active card in the active group.
213  // NOTE: If you exclude the active card, the animations will
214  // not be started automatically, you will have to call m_anims.start()
215  void slideAllGroups(bool includeActiveCard = true);
216  void slideAllGroupsTo(int xOffset);
217 
218  // Does the same as slideAllGroups, but sets the positions immediately,
219  // with no animations
220  void layoutAllGroups(bool includeActiveCard = true);
221 
222  // immediately update the positions of all groups in the closed
223  // orientation, shift the centers of all groups by xDiff
224  void layoutGroups(qreal xDiff);
225 
226  // slide all non-active groups to their closed positions
227  // and snap the active group to the closest card to the center
228  // of the group
229  void slideToActiveCard();
230 
231  void setActiveGroup(CardGroup* group);
232 
233  void disableCardRestoreToMaximized();
234  void restoreCardToMaximized();
235 
236  void cancelReorder(bool dueToPenCancel=false);
237 
238  void queueFocusAction(CardWindow* win, bool focused);
239  void performPendingFocusActions();
240 
241  void queueTouchToShareAction(CardWindow* win);
242  void performPendingTouchToShareActions();
243 
244  void removePendingActionWindow(CardWindow* win);
245 
246  void setAnimationForWindow(CardWindow* win, QPropertyAnimation* anim);
247  void removeAnimationForWindow(CardWindow* win, bool includeDeletedAnimations=false);
248  bool windowHasAnimation(CardWindow* win) const;
249 
250  void setAnimationForGroup(CardGroup* group, QPropertyAnimation* anim);
251  void removeAnimationForGroup(CardGroup* group);
252  bool groupHasAnimation(CardGroup* group) const;
253  void startAnimations();
254  void clearAnimations();
255 
256  void updateAllowWindowUpdates();
257  int proceedToAddModalWindow(CardWindow* win);
258 
259  void removeWindowNoModality(CardWindow* win);
260  void removeWindowWithModality(CardWindow* win);
261  bool performCommonWindowRemovalTasks(CardWindow* w, bool checkCardGroup=true);
262  void resetMouseTrackState();
263  void resetModalFlags(bool forceReset=false);
264  void handleModalRemovalForDeletedParent(CardWindow* w);
265 
266  bool playAngryCardSounds() const;
267  void updateAngryCardThreshold();
268 
269  void markFirstCardDone();
270 
271 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
272  bool handleTouchBegin(QTouchEvent *e);
273  bool handleTouchEnd(QTouchEvent *e);
274  bool handleTouchUpdate(QTouchEvent *e);
275 #endif
276 
277  QSet<CardWindow*> m_pendingActionWinSet;
278  QSet<CardWindow*> m_pendingTouchToShareWinSet;
279 
280  QVector<CardGroup*> m_groups;
281  CardGroup* m_activeGroup;
282 
283  QRect m_normalScreenBounds;
284  QRect m_targetPositiveSpace;
285 
286  CardWindow* m_draggedWin;
287  bool m_penDown;
288 
289  CardWindow* m_cardToRestoreToMaximized;
290  CardWindow* m_parentOfModalCard;
291  bool m_lowResMode;
292  bool m_addingModalWindow;
293  bool m_initModalMaximizing;
294  bool m_modalDismissInProgress;
295  bool m_animateWindowForModalDismisal;
296  int m_dismissModalImmediately;
297  bool m_modalDimissed;
298  bool m_dismissedFirstCard;
299 
300 
301  enum ModalWindowState {
302  NoModalWindow = 0,
303  ModalWindowAddInitCheckFail,
304  ModalWindowDismissedParentSwitched,
305  ModalWindowDismissedInternally,
306  ModalWindowDismissedExternally,
307  ModalParentDismissed,
308  ModalParentDimissedWaitForChildDismissal
309  };
310 
311  ModalWindowState m_modalWindowState;
312 
313  enum NotifySystemUiControllerAction {
314  Invalid=0,
315  ModalLaunch,
316  ModalDismissNoAnimate,
317  ModalDismissAnimate
318  };
319 
320  void notifySysControllerOfModalStatus(int reason, bool restore, NotifySystemUiControllerAction type, Window* win = NULL);
321 
322  enum Movement {
323  MovementUnlocked, // not locked to an axis
324  MovementHLocked, // locked to horizontal movement
325  MovementVLocked // locked to vertical movement
326  };
327  Movement m_movement;
328  bool m_trackWithinGroup;
329  bool m_seenFlickOrTap;
330  int m_activeGroupPivot;
331 
332  enum ReorderZone {
333  ReorderZone_Center = 0,
334  ReorderZone_Left,
335  ReorderZone_Right
336  };
337  ReorderZone m_reorderZone;
338  ReorderZone getReorderZone(QPoint pt);
339 
340  QStateMachine* m_stateMachine;
341  MinimizeState* m_minimizeState;
342  MaximizeState* m_maximizeState;
343  PreparingState* m_preparingState;
344  LoadingState* m_loadingState;
345  FocusState* m_focusState;
346  ReorderState* m_reorderState;
347 
348  CardWindowManagerState* m_curState;
349 
350  // keep track of which windows have animations running
351  QMap<CardWindow*,QPropertyAnimation*> m_cardAnimMap;
352  QMap<CardGroup*,QPropertyAnimation*> m_groupAnimMap;
353 
354  // Collection of all running animations (Window + Group)
355  // It is the union of the animations mapped above
356  QParallelAnimationGroup m_anims;
357  QMap<CardWindow*,QPropertyAnimation*> m_deletedAnimMap;
358 
359  bool m_playedAngryCardStretchSound;
360 
361  bool m_animationsActive;
362 
364  friend class MinimizeState;
365  friend class MaximizeState;
366  friend class PreparingState;
367  friend class LoadingState;
368  friend class FocusState;
369  friend class ReorderState;
370 };
371 
372 #endif /* CARDWINDOWMANAGER_H */