aboutsummaryrefslogtreecommitdiff
path: root/src/corelib/scene/mscenemanager_p.h
blob: ed6a7998e2b90a5dee58799b132e49f495ddb8aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#ifndef MSCENEMANAGER_P_H
#define MSCENEMANAGER_P_H

#include <QList>
#include <QPointer>

#include "mnamespace.h"
#include "mscenemanager.h"
#include "mscenewindow.h"
#include <mscenewindowevent_p.h>
#include "mpageswitchanimation.h"

class MScene;
class MSceneWindow;
class MSceneLayerEffect;
class MSceneManager;
class MNavigationBar;
class MOrientationAnimation;
class MPageSwitchAnimation;
class MWindow;

class QAbstractAnimation;
class QGraphicsWidget;
class QTimeLine;
class QPointF;

class MSceneWindowTransition {
    public:
        QPointer<MSceneWindow> sceneWindow;

        enum TransitionType {
            AppearTransition,
            DisappearTransition
        } type;

        // Makes sense only for AppearTransition types.
        MSceneWindow::DeletionPolicy policy;

        bool animated;
};

class MSceneManagerPrivate
{
    Q_DECLARE_PUBLIC(MSceneManager)

public:

    void init(MScene *scene);
    virtual ~MSceneManagerPrivate();

    enum WindowTypeZ {
        PlainSceneWindow = 0,
        ApplicationPage = PlainSceneWindow,          // MApplicationPage
        ApplicationMenu = 500,                    // MApplicationMenu
        NavigationBar = 1000,                        // MNavigationBar
        DockWidget = NavigationBar,                  // MDockWidget
        EscapeButtonPanel = 2000,                    // MEscapeButtonPanel
        Dialog = 3000,                               // MDialog
        MessageBox = Dialog,                         // MMessageBox
        ModalSceneWindow = Dialog,                   // MModalSceneWindow
        PopupList = 4000,                            // MPopupList
        Overlay = 6000,                              // MOverlay
        Completer = Overlay,                         // MCompleter
        HomeButtonPanel = 7000,                      // MHomeButtonPanel
        ObjectMenu = 7500,
        NotificationInformation = 8000,              // MNotification - Information
        NotificationEvent = NotificationInformation, // MNotification - Event
        StatusBar = 9000                             // MStatusBar
    };

    void initOrientationAngles();
    int zForWindowType(MSceneWindow::WindowType windowType);
    MSceneLayerEffect *createLayerEffectForWindow(MSceneWindow *window);

    M::Orientation orientation(M::OrientationAngle angle) const;

    QPointF calculateSceneWindowPosition(MSceneWindow *window);
    void setSceneWindowGeometry(MSceneWindow *window);
    void setSceneWindowGeometries();
    void notifyWidgetsAboutOrientationChange();
    void rotateToAngle(M::OrientationAngle newAngle);
    void setOrientationAngleWithoutAnimation(M::OrientationAngle newAngle);

    void addSceneWindow(MSceneWindow *sceneWindow);
    void removeSceneWindow(MSceneWindow *sceneWindow);
    void addUnmanagedSceneWindow(MSceneWindow *sceneWindow);

    bool onApplicationPage(QGraphicsItem *item);
    MSceneWindow *parentSceneWindow(QGraphicsItem *item);
    void moveSceneWindow(MSceneWindow *window, int adjustment, int visibleHeight);
    int scrollPageContents(MSceneWindow *window, int adjustment) const;

    bool isOnDisplay();
    void produceMustBeResolvedDisplayEvent(MSceneWindow *sceneWindow);
    void produceFullyOffDisplayEvents(QGraphicsItem *item);
    void produceSceneWindowEvent(QEvent::Type type, MSceneWindow *sceneWindow,
                                 bool animatedTransition);

    void freezeUIForAnimationDuration(QAbstractAnimation *animation);

    void pushPage(MSceneWindow *page, bool animatedTransition);
    void popPage(bool animatedTransition);

    void prepareWindowShow(MSceneWindow *window);

    void appearSceneWindow(MSceneWindow *window,
                      MSceneWindow::DeletionPolicy policy,
                      bool animatedTransition);

    void prepareWindowHide(MSceneWindow *window);

    void disappearSceneWindow(MSceneWindow *window,
                         bool animatedTransition);

    void startPageSwitchAnimation(MSceneWindow *newPage,
                                  MSceneWindow *oldPage,
                                  MPageSwitchAnimation::PageTransitionDirection direction);

    QRectF calculateAvailableSceneRect(MSceneWindow *window);

    void createOrientationAnimation();

    void createAppearanceAnimationForSceneWindow(MSceneWindow *sceneWindow);
    void createDisappearanceAnimationForSceneWindow(MSceneWindow *sceneWindow);

    bool verifySceneWindowStateBeforeAppear(
            MSceneWindow *sceneWindow,
            MSceneWindow::DeletionPolicy policy,
            bool animatedTransition);

    bool verifySceneWindowStateBeforeDisappear(
            MSceneWindow *sceneWindow,
            bool animatedTransition);

    void applySceneWindowTransition(MSceneWindowTransition *transition);
    void applySceneWindowTransitionsFromPageSwitchQueue();
    void removeSceneWindowFromTransitionQueue(MSceneWindow *sceneWindow,
            QList<MSceneWindowTransition> &transitionQueue);

    void setSceneWindowState(MSceneWindow *sceneWindow,
            MSceneWindow::SceneWindowState newState);

    void onSceneWindowEnteringAppearingState(MSceneWindow *sceneWindow);
    void onSceneWindowEnteringAppearedState(MSceneWindow *sceneWindow);
    void onSceneWindowEnteringDisappearingState(MSceneWindow *sceneWindow);
    void onSceneWindowEnteringDisappearedState(MSceneWindow *sceneWindow);

    void fastForwardSceneWindowTransitionAnimation(MSceneWindow *sceneWindow);

    void _q_setSenderGeometry();
    void _q_changeGlobalOrientationAngle();
    void _q_emitOrientationChangeFinished();
    void _q_pageShowAnimationFinished();
    void _q_onSceneWindowAppearanceAnimationFinished();
    void _q_onSceneWindowDisappearanceAnimationFinished();
    void _q_onPageSwitchAnimationFinished();
    void _q_restoreSceneWindow();
    void _q_relocateWindowByInputPanel(const QRect &inputPanelRect);

    //! Prepares current window for SIP.
    void _q_inputPanelOpened();

    //! Restores the current window state after SIP is closed.
    void _q_inputPanelClosed();

    void _q_unFreezeUI();

    void _q_applySceneWindowTransitionsQueuedDueToOrientationAnimation();

    void _q_triggerAsyncPendingOrientationChange();

    void _q_applyPendingOrientationChange();

public:

    MScene *scene;

    QGraphicsWidget *rootElement;
    MOrientationAnimation *orientationAnimation;
    MPageSwitchAnimation *pageSwitchAnimation;

    QList<MSceneWindow *> windows;
    QList< QPointer<MSceneWindow> > pageHistory;

    M::OrientationAngle angle;
    M::OrientationAngle newAngle;

    MNavigationBar *navBar;
    MSceneWindow *escapeButtonPanel;
    QPointer<MSceneWindow> currentPage;
    bool navBarHidden;
    bool escapeButtonHidden;

    QPointer<QGraphicsWidget> focusedInputWidget;

    QPointer<MSceneWindow> alteredSceneWindow;
    QPoint sceneWindowTranslation;

    bool pendingSIPClose;

    QPointer<MSceneWindow> statusBar;

    // Queued scene window transitions to be applied after an ongoing orientation
    // animation finishes.
    QList<MSceneWindowTransition> queuedTransitionsOrientationAnimation;

    // Queue of page transitions to be applied after an ongoing page switch
    // animation finishes. Usually only one is picked after each page switch
    // animation since it will probably result in anoter page switch animation.
    QList<MSceneWindowTransition> queuedTransitionsPageSwitchAnimation;

    // If an animation gets started by MSceneManager::setOrientationAngle() while
    // another orientation change transition is running, the orientation change
    // request gets remembered as a pending one:
    struct Rotation {
        M::OrientationAngle angle;
        MSceneManager::TransitionMode mode;
    };
    Rotation* pendingRotation;

    QPointer<QObject> debugInterface;

    MSceneManager *q_ptr;
};

class MSceneManagerTestInterface : public QObject
{
    Q_OBJECT
public:
    MSceneManagerTestInterface(MSceneManagerPrivate *d, QObject *parent = 0);
public Q_SLOTS:
    void fastForwardPageSwitchAnimation();
    void fastForwardSceneWindowTransitionAnimation(MSceneWindow *sceneWindow);
    void addSceneWindow(MSceneWindow *sceneWindow);
    void removeSceneWindow(MSceneWindow *sceneWindow);

public:
    MSceneManagerPrivate *d;
};

#endif