LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WindowServer.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 WINDOWSERVER_H
23 #define WINDOWSERVER_H
24 
25 #include "Common.h"
26 
27 #include <list>
28 #include <string>
29 
30 #include "DisplayManager.h"
31 #include "InputManager.h"
32 #include "CustomEvents.h"
33 #include "VariantAnimation.h"
34 #include "HostWindow.h"
35 #include "ProgressAnimation.h"
36 #include "TouchPlot.h"
37 
38 #include <QGraphicsView>
39 #include <QGraphicsObject>
40 #include <QTouchEvent>
41 #include <QObject>
42 #include <QQueue>
43 #include <QTime>
44 #include <QTimer>
45 #include <QPixmap>
46 #ifdef DEBUG_RECORD_PAINT
47 #include <QTextStream>
48 #include <QFile>
49 #endif
50 
51 #include <QMultiMap>
52 #include <QPointer>
53 
54 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
55 #include <QGesture>
56 #endif
57 
58 class Window;
59 struct WindowProperties;
60 class WindowManagerBase;
61 class MetaKeyManager;
62 class CoreNaviManager;
63 class ReticleItem;
64 class QDeclarativeEngine;
66 
68 public:
71  QRectF boundingRect() const;
72 
73  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
74 
75  void setPixmap(QPixmap* img);
76  void setInternalRotation(qreal rotation) { m_rotation = rotation; }
77  qreal internalRotation() { return m_rotation; }
78 
79  QPixmap* getPixmap() const { return m_pixmap; }
80 
81  QPixmap* m_pixmap;
82  QPainter::CompositionMode m_compMode;
84  qreal m_rotation;
85 };
86 
87 class UiRootItem : public QGraphicsItem {
88 public:
90  setHandlesChildEvents(false);
91  setFlag(QGraphicsItem::ItemHasNoContents, true);
92  m_bounds = QRectF(0, 0, 0, 0);
93  }
94 
96  QRectF boundingRect() const { return m_bounds; }
97  void setBoundingRect(QRectF bounds) { prepareGeometryChange(); m_bounds = bounds; }
98 
99  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { }
100 
101  QRectF m_bounds;
102 };
103 
104 class Runtime : public QObject
105 {
106  Q_OBJECT
107  Q_PROPERTY(int orientation READ orientation NOTIFY orientationChanged)
109 
110 public:
111  static Runtime* instance();
112 
113  enum Orientation { // these values are used in the DockModeTime QML app.
118  };
119 
120  void setOrientation (OrientationEvent::Orientation orient);
121 
122  Q_INVOKABLE QString getLocalizedString(QString text);
123  Q_INVOKABLE QString getLocalizedDay();
124  Q_INVOKABLE QString getLocalizedMonth();
125  Q_INVOKABLE QString getLocalizedAMPM();
126 
127  Q_INVOKABLE int orientation() { return m_orientation; }
128  Q_INVOKABLE bool twelveHourClock() { return m_twelveHourClock; }
129 
130 Q_SIGNALS:
131  void orientationChanged();
132  void clockFormatChanged();
133 
134 public Q_SLOTS:
135  void slotTimeFormatChanged(const char*);
136 
137 private:
138  Runtime(QObject *parent=0);
139 
140  int m_orientation;
141  bool m_twelveHourClock;
142 };
143 
144 typedef struct CardFlipRequest {
145  QPointer<HostWindow> windowPtr;
147  bool sync;
149 
150 
151 
153 {
154  Q_OBJECT
155 
156 public:
157 
158  static WindowServer* instance();
159  virtual ~WindowServer();
160 
161  static void registerWindow(Window* win);
162  static void unregisterWindow(Window* win);
163  static bool windowIsRegistered(Window* win);
164 
165  virtual void addWindow(Window* win);
166  virtual void removeWindow(Window* win);
167  virtual void focusWindow(Window* win);
168  virtual void unfocusWindow(Window* win);
169  virtual void windowUpdated(Window* win);
170  virtual void prepareAddWindow(Window* win);
171  virtual void addWindowTimedOut(Window* win);
172 
173  void bootupFinished();
174 
176  void stopProgressAnimation();
177  bool progressRunning() const { return m_runningProgress; }
178 
179  virtual void startDrag(int x, int y, void* imgRef, const std::string& lpid);
180  virtual void endDrag(int x, int y, const std::string& lpid, bool handled);
181 
182  virtual void applyLaunchFeedback(int centerX, int centerY);
184 
185  // following are not thread-safe
189 
190  bool takeScreenShot(const char* path);
191  virtual QPixmap* takeScreenShot();
192 
193  OrientationEvent::Orientation getOrientation() const { return m_orientation; }
194  OrientationEvent::Orientation getUiOrientation() const { return m_currentUiOrientation; }
195 
196  void setPaintingDisabled(bool val);
197 
198  virtual void cancelVibrations();
199 
200  static void markBootStart();
201  static void markBootFinish();
202 
203  void shutdown();
204 
205  void setWindowProperties (Window* win, const WindowProperties& props);
206 
208 
209  virtual WindowManagerBase* getWindowManagerByClassName(const QString& undecoratedClassName) const;
210  virtual WindowManagerBase* windowManagerForWindow(Window* wm) const = 0;
211 
212  static void enableFpsCounter(bool enable);
213  static void dumpFpsHistory();
214  static void resetFpsBuffer(int newBufSize);
215 
216  static void enableTouchPlotOption(TouchPlot::TouchPlotOption_t type, bool enable);
217 
218  virtual void resizeWindowManagers(int width, int height);
219 
220  virtual bool okToResizeUi(bool ignorePendingRequests=false) { return true; }
221 
223 
224  virtual QDeclarativeEngine* declarativeEngine() { return NULL; }
225 
226  // maps a rect given in item's coordinate space into
227  virtual QRectF mapRectToRoot(const QGraphicsItem* item, const QRectF& rect) const;
228 
229  // during a UI resize, offscreen cards are queued up for resizing (flip event) after the animation is complete
230  virtual bool enqueueWindowForFlip(Window* window, QRect& windowScreenBoundaries, bool sync);
231  virtual bool removeWindowFromFlipQueue(Window* window);
241  };
242 
243  void setUiRotationMode(RotationMode uiRotationMode, bool cardMaximizing = false, bool skipAnimation = false);
244 
245  bool touchOnScreen() const { return m_fingerDownOnScreen; }
246 
248 
249 protected:
250 
255  };
256 
257  WindowServer();
258 
259  virtual bool handleEvent(QEvent* event);
260  virtual bool viewportEvent(QEvent* event);
261  virtual bool sysmgrEventFilters(QEvent* event) = 0;
262  virtual bool eventFilter(QObject *, QEvent *);
263 
264  virtual bool processSystemShortcut( QEvent* event );
265 
266  void setOrientation(OrientationEvent::Orientation newOrient);
267  int angleForOrientation(OrientationEvent::Orientation orient);
268 
269  virtual bool isOrientationAllowed(OrientationEvent::Orientation newOrient);
270 
271  void setUiOrientation(OrientationEvent::Orientation newOrient, UiRotationAnimationType animation = Rotation_RotateAndCrossFade);
272  void rotateUi(OrientationEvent::Orientation newOrientation, UiRotationAnimationType animation = Rotation_RotateAndCrossFade, bool forceResize = false);
273  virtual void rotatePendingWindows();
274  virtual void cancelPendingWindowRotations();
275  virtual void updateWallpaperForRotation(OrientationEvent::Orientation) { }
276 
277  // begin/end methods for caching and 'restoring' the QGraphicsScenes' currently focused
278  // QGraphicsItem. These are meant to wrap calls of setVisible(false) on WindowManagerBase's
279  // and the root ui item.
280  // NOTE: a call to cacheFocusedItem MUST finish with a call restoreCachedFocusItem!
281  void cacheFocusedItem();
282  void restoreCachedFocusItem();
283 
284 protected:
285 
290 
292 
293  uint32_t m_screenWidth;
294  uint32_t m_screenHeight;
296 
299 
301 
303 
306 
308 
310 
312  OrientationEvent::Orientation m_orientation;
313  OrientationEvent::Orientation m_currentUiOrientation;
314  OrientationEvent::Orientation m_pendingOrientation;
317  QQueue<t_cardFlipRequest> m_pendingFlipRequests;
318 
319 
320  //key: QMetaObject class name .. see getWindowManagerByClassName()
321  // multi-map in case we decide to extend the system to support multiple window managers of the same type
322  // in the system at the same time
323  typedef QMap<QString,QPointer<WindowManagerBase> >::const_iterator WindowManagerMapConstIter;
324  typedef QMap<QString,QPointer<WindowManagerBase> >::iterator WindowManagerMapIter;
325  QMultiMap<QString,QPointer<WindowManagerBase> > m_windowManagerMap;
326 
327 Q_SIGNALS:
328 
331  void signalTookScreenShot();
332  void signalUiRotated();
334 
335 private Q_SLOTS:
336 
337  void slotResizePendingTimerTicked();
338  void slotRotationLockChanged(OrientationEvent::Orientation rotationLock);
339  void slotProgressAnimationCompleted();
340  void slotRotationAnimFinished();
341  void rotationValueChanged(const QVariant& value);
342  void slotDeferredNewOrientation();
343 
344 private:
345 
346  void showReticle(const QPoint& pos);
347  void gestureEvent(QGestureEvent* event);
348  void paintBootupScreen();
349  void enableOverlay(const QString& str);
350  void disableOverlay();
351  void takeAndSaveScreenShot();
352  QImage getScreenShotImage();
353  QImage getScreenShotImageFromFb();
354  OrientationEvent::Orientation getInitialDeviceOrientation();
355 
356  bool m_screenShotImagesValid;
357  QGraphicsPixmapObject *m_beforePixItem, *m_afterPixItem;
358  QPixmap *m_rotationImageBeforePtr, *m_rotationImageAfterPtr;
359  VariantAnimation<WindowServer>* m_rotationAnim;
360  QTimer m_resizePendingTimer;
361  QGraphicsItem* m_cachedFocusedItem;
362 
363  QTimer m_unaliasPaintEvent;
364  QTime m_timeSinceLastPaint;
365  QPixmap m_bootupScreen;
366 
367  OrientationEvent::Orientation m_deferredNewOrientation;
368  QTimer m_deferredNewOrientationTimer;
369 
370 #ifdef DEBUG_RECORD_PAINT
371  void tracePaint(qreal durationMs);
372 
373  QTextStream *m_paintTrace;
374  QFile m_paintTraceFile;
375 #endif
376 };
377 
378 
379 #endif /* WINDOWSERVER_H */