LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CardWindow.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2013 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 CARDWINDOW_H
23 #define CARDWINDOW_H
24 
25 #include "Common.h"
26 #include "Settings.h"
27 #include "Event.h"
28 #include "HostWindow.h"
29 #include "AppLaunchOptionsEvent.h"
30 #include "SystemUiController.h"
31 
32 #include <WindowProperties.h>
33 
34 #include <QGraphicsSceneMouseEvent>
35 #include <QTouchEvent>
36 #include <QPainterPath>
37 #include <QPainter>
38 #include <QVector3D>
39 #include <QTransform>
40 #include <QPointer>
41 #include <QPropertyAnimation>
42 
43 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
44 #include <QGesture>
45 #endif
46 
48 
49 class CardLoading;
50 class PIpcMessage;
51 class FlickGesture;
52 class SingleClickGesture;
53 class CardGroup;
54 class GhostCard;
55 class CardRoundedCornerShaderStage;
56 class BearingEvent;
57 
58 class CardWindow : public HostWindow
59 {
60  Q_OBJECT
62  Q_PROPERTY(float dimming READ dimming WRITE setDimming)
63 
64 public:
65 
66  CardWindow(WindowType::Type type, HostWindowData* data, IpcClientHost* clientHost=0);
67  virtual ~CardWindow();
68 
69  virtual QRectF boundingRect() const { return m_boundingRect; }
70 
71  void onMessageReceived(const PIpcMessage& msg);
72 
73  bool fullScreen() const { return m_winProps.fullScreen; }
74  bool isBlockScreenTimeout() const { return m_winProps.isBlockScreenTimeout; }
75  bool isSubtleLightbar() const { return m_winProps.isSubtleLightbar; }
76  bool activeTouchpanel() const { return m_winProps.activeTouchpanel; }
77  bool alsDisabled() const { return m_winProps.alsDisabled; }
78  bool gyroEvents() const { return m_winProps.gyroEnabled; }
79  bool compassEvents() const { return m_winProps.compassEnabled; }
80  uint32_t overlayNotificationsPosition() const { return m_winProps.overlayNotificationsPosition; }
81  bool suppressBannerMessages() const { return m_winProps.suppressBannerMessages; }
82  bool suppressGestures() const { return m_winProps.suppressGestures; }
83  uint32_t dockBrightness() const { return m_winProps.dockBrightness; }
84  bool hasCustomStatusBarColor() const { return (m_winProps.flags & WindowProperties::isSetStatusBarColor) != WindowProperties::isSetNothing; }
85  unsigned int statusBarColor() const { return m_winProps.statusBarColor; }
86 
87  virtual void inputEvent(Event* e);
88  virtual void resizeEvent(int w, int h);
89  virtual void resizeEventSync(int w, int h);
90  virtual void resizeWindowBufferEvent(int w, int h, QRect windowScreenBounds, bool forceSync=false, bool ignoreFixedOrient=false);
91  virtual void flipEventSync(bool fromQueue = false);
92  virtual void queueUpWindowForFlip(QRect windowScreenBounds, bool sync);
93  virtual void queuedFlipCanceled(QRect windowScreenBounds);
94  virtual void flipEventAsync(QRect windowScreenBounds, bool fromQueue = false);
95  virtual void asynchFlipCompleted(int newWidth, int newHeight, int newScreenWidth, int newScreenHeight);
96 
97  void queueFocusAction(bool focused);
99  virtual void focusEvent(bool enable);
100  virtual void aboutToFocusEvent(bool enable) {}
101  bool focused() const { return m_focused; }
102 
103  void enableShadow();
104  void disableShadow();
105 
108 
109  virtual void setAddedToWindowManager() { m_addedToWm = true; }
110  bool addedToWindowManager() const { return m_addedToWm; }
111 
112  virtual void setWindowProperties (const WindowProperties& props);
113 
114  bool rotationLockMaximized() const;
115 
117  void adjustForPositiveSpaceSize(int width, int height) const;
118 
119  virtual Event::Orientation getCardFixedOrientation() { return m_appFixedOrientation; }
120 
121  virtual void displayOff() {}
122  virtual void displayDimmed() {}
123 
124  virtual bool isHost() const { return false; }
125  virtual bool supportsPause() const { return false; }
126  virtual void pause() {}
127 
128  bool delayPrepare();
129  void stopLoadingOverlay();
130 
131  void setModalParent(CardWindow* parent);
132  void setCardIsModalParent(bool isParent) { m_isCardModalParent = isParent;}
133  bool isCardModalParent() const { return m_isCardModalParent; }
134 
139  };
140 
142  void setModalChild(CardWindow* w);
143  CardWindow* getModalChild() const { return m_modalChild; }
144 
145  void setAppLaunchOptions(const AppLaunchOptionsEventWrapper& options);
146 
147  const std::string &splashBackgroundName() const {
148  return m_splashBackgroundName;
149  }
150 
153  }
154 
156  return m_launchInNewGroup;
157  }
158 
159  void setPaintCompositionMode(QPainter::CompositionMode mode);
160  QPainterPath paintPath() const { return m_paintPath; }
161 
162  struct Position {
163  QVector3D trans;
164  qreal zRot;
165 
166  Position();
167  bool operator ==(const Position& other);
168  Position operator +(const Position& right) const;
169  Position operator -(const Position& right) const;
170  Position operator *(qreal right) const;
171 
172  QTransform toTransform() const;
173  };
174 
176  void setPosition(const CardWindow::Position& pos);
177 
178  CardGroup* cardGroup() const;
179  void setCardGroup(CardGroup* group);
180 
181  // an attached CardWindow will cause CardGroup x/y changes
182  // to effect the x/y pos of the window
183  bool attachedToGroup() const;
184  void setAttachedToGroup(bool attached);
185 
186  virtual void setMaximized(bool enable);
187  virtual bool isMaximized() const { return m_maximized; }
188 
189  // This are called only when Card is maximized
190  virtual void positiveSpaceAboutToChange(const QRect& r, bool fullScreen);
191  virtual void positiveSpaceChanged(const QRect& r);
192  virtual void positiveSpaceChangeFinished(const QRect& r);
193 
194  //cheats for telling the loading section that it is infact, big, if you fix this the right way, please remove
195  virtual void setMaxAndLoading(bool enable);
196  virtual bool isMaxAndLoading() const { return m_maxAndLoading; }
197 
198  void setBoundingRect(int width, int height) {
199 
200  int visibleWidth = width;
201  int visibleHeight = height;
202 
203  if(type() != WindowType::Type_ModalChildWindowCard) {
204  m_boundingRect.setRect(-width/2, -height/2, width, height);
205  }
206  else {
207 
208  // If we have the right width/height ignore
209  if(boundingRect().width() == visibleWidth && boundingRect().height() == visibleHeight)
210  return;
211 
212  qreal curY = boundingRect().y();
213  //g_debug("__BEFORE KARTHIK CardWindow::setBoundingRect w: %d h: %d x: %f y: %f w: %f h: %f rotating: %d", width, height, boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height(), SystemUiController::instance()->isUiRotating());
214  m_boundingRect.setRect(-width/2, curY, width, height);
215  //g_debug("__AFTER KARTHIK CardWindow::setBoundingRect w: %d h: %d x: %f y: %f w: %f h: %f rotating: %d", width, height, boundingRect().x(), boundingRect().y(), boundingRect().width(), boundingRect().height(), SystemUiController::instance()->isUiRotating());
216  }
217 
218  setVisibleDimensions(visibleWidth, visibleHeight);
219  }
220 
221  void computeModalWindowPlacementInf(int newPosSpace);
222  virtual QRectF transitionBoundingRect();
223 
225 
226  void allowUpdates(bool allow);
227 
228  void setDimm(bool dimm);
229  float dimming() const { return m_dimming; }
230  void setDimming(float dimming) { m_dimming = dimming; update(); }
231 
232 protected Q_SLOTS:
233 
234  void slotLoadingFinished();
235  void slotDisplayStateChanged(int state);
236  virtual void slotUiRotated();
237 
238  void slotShowIME();
239  void slotHideIME();
240 
241 protected:
242 
243  CardWindow(WindowType::Type type, const QPixmap& pixmap);
244  void init();
245 
246  virtual void setVisibleDimensions(int width, int height);
247 
248  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
249 
250  virtual void paintBase(QPainter* painter, bool maximized);
251  virtual void paintOverlay(QPainter* painter, bool maximized) {}
252 
253  virtual void keyPressEvent(QKeyEvent* event);
254  virtual void keyReleaseEvent(QKeyEvent* event);
255 
256  virtual bool sceneEvent(QEvent* event);
257  virtual bool touchEvent(QTouchEvent* event);
258 
259  virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
260  virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
261  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
262  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
263 
264  bool mouseFlickEvent(QGestureEvent* event);
265  bool pinchEvent(QGestureEvent* event);
266  bool mouseSingleClickEvent(QGestureEvent* singleClick);
267  bool coversScreenFully() const;
268  void enableFullScreen();
269  void disableFullScreen();
270  virtual void fullScreenEnabled(bool val);
272 
273  // loading animation methods
274  void startLoadingOverlay();
275  bool loadingAnimTimerTicked();
276 
277  // window timeout methods
278  void startLoadingTimer(int duration);
279  void stopLoadingTimer();
280  bool hasLoadingTimer() const { return m_loadingTimerId != 0; }
281  static gboolean loadingTimeout(gpointer data);
282 
283  virtual void onEnableTouchEvents(bool enableTouchEvents);
284 
285  virtual void mapCoordinates(qreal& x, qreal& y);
286  virtual void mapFlickVelocities(qreal& x, qreal& y);
287  virtual void onSetAppFixedOrientation(int orientation, bool isPortrait);
288  virtual void onSetAppOrientation(int orientation) {}
289  virtual void onSetAppFreeOrientation(bool free) {}
290  virtual void refreshAdjustmentAngle();
291 
292  virtual void initializeRoundedCornerStage();
293 
294  bool isInValidOrientation();
295 
296 protected:
297 
302  };
303 
306  CapturedPen = 1 << 0,
307  CapturedGesture = 1 << 1,
308  CapturedInvalid = 1 << 31
309  };
310 
317 
318  //hack to tell the loading anime that it is big
320 
321  Event::Orientation m_appFixedOrientation;
322  Event::Orientation m_appPendingFixedOrientation;
326 
327 
328  // used for asynchronous resizing (flip)
336 
338  bool m_focused;
340 
342 
344 
345  WindowProperties m_winProps;
346 
349 
351 
352  QPainterPath m_paintPath;
353  QPainter::CompositionMode m_compMode;
354 
356 
357  // reference to card group
358  QPointer<CardGroup> m_group;
360 
362 
363  CardRoundedCornerShaderStage* m_roundedCornerShaderStage;
364 
365  QPropertyAnimation* m_activeAnimation;
366  float m_dimming;
367 
368  virtual void customEvent ( QEvent* event );
369 
378  };
379 
380  // This struct holds all the necessary information about the position of the modal window
391 
393  m_originalY = 0;
397  m_cardMoveDelta = 0;
399  m_IsAnimating = false;
401  m_centerModalWindow = false;
402  }
403 
406  }
407 
408  void setCardMoveDelta(int val) {
409  if(val != m_cardMoveDelta) {
410  m_cardMoveDelta = val;
412  }
413  }
414 
415  void reset()
416  {
417  m_originalY = 0;
421  m_cardMoveDelta = 0;
423  m_IsAnimating = false;
425  }
426  };
427 
432  };
433 
435  Unknown = 0,
438  };
439 
443 
449 
454 
455  QPropertyAnimation* m_ModalPositionAnimation;
456 
457 private:
458  CardWindow* m_modalChild;
459  CardWindow* m_modalParent;
460 
461  QPointF positionModalWindowWrpParent(int spaceAvailableAbove, int windowHeight);
462  void positionModalForMorePositiveSpace(int availablePosSpace, int newPositiveSpace);
463  void positionModalForLessPositiveSpace(int availablePosSpace, int newPositiveSpace);
464 
465  void increaseHeightAndPositionModalCard(int availablePosSpace, int newPositiveSpace);
466  void decreaseHeightAndPositionModalCard(int availablePosSpace, int newPositiveSpace);
467 
468  void resetModalWindowPositionInfo();
469  void startModalAnimation();
470  void resizeModalCard();
471  void centerModal(int availablePositiveSpace);
472  bool canPositionModalAtY(int yLoc, bool increasePositiveSpace, int& correctYLoc);
473 
474  int forwardToModal();
475 
476 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
477  void handleTouchBegin(QTouchEvent *te);
478  void handleTouchEnd(QTouchEvent *te);
479  void handleTouchUpdate(QTouchEvent *te);
480 #endif
481 };
482 
483 QDebug operator<<(QDebug, const CardWindow::Position &);
484 
485 QVariant positionInterpolator(const CardWindow::Position &start, const CardWindow::Position &end, qreal progress);
486 
487 Q_DECLARE_METATYPE(CardWindow*)
488 
489 #endif /* CARDWINDOW_H */