~seb128/ubuntu-ui-toolkit/correct-translation-quoting

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Components/PageStack.qml

  • Committer: Tarmac
  • Author(s): Tim Peeters
  • Date: 2014-09-30 19:33:09 UTC
  • mfrom: (1240.1.28 10-gc)
  • Revision ID: tarmac-20140930193309-e8oyl6d8i4p3djjr
Implement header animations in PageHeadStyle and prepare PageStack for enabling the animations.

Approved by PS Jenkins bot, Zsombor Egri.

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
      The pushed page may be an Item, Component or URL.
162
162
     */
163
163
    function push(page, properties) {
164
 
        if (internal.stack.size() > 0) internal.stack.top().active = false;
165
 
        internal.stack.push(internal.createWrapper(page, properties));
166
 
        internal.stackUpdated();
 
164
        internal.finishPreviousAction();
 
165
        internal.pageToPush = page;
 
166
        internal.propertiesToPush = properties;
 
167
        if (internal.animateHeader && internal.stack.size() > 0) {
 
168
            internal.headStyle.animateOutFinished.connect(internal.createAndPush);
 
169
            internal.headStyle.animateOut();
 
170
        } else {
 
171
            internal.createAndPush();
 
172
        }
167
173
    }
168
174
 
169
175
    /*!
172
178
      Do not do anything if 0 or 1 items are on the stack.
173
179
     */
174
180
    function pop() {
 
181
        internal.finishPreviousAction();
175
182
        if (internal.stack.size() < 1) {
176
183
            print("WARNING: Trying to pop an empty PageStack. Ignoring.");
177
184
            return;
178
185
        }
179
 
        internal.stack.top().active = false;
180
 
        if (internal.stack.top().canDestroy) internal.stack.top().destroyObject();
181
 
        internal.stack.pop();
182
 
        internal.stackUpdated();
 
186
        // do not animate if there is no page to animate back in after popping
 
187
        if (internal.animateHeader && internal.stack.size() > 1) {
 
188
            internal.headStyle.animateOutFinished.connect(internal.popAndDestroy);
 
189
            internal.headStyle.animateOut();
 
190
        } else {
 
191
            internal.popAndDestroy();
 
192
        }
183
193
    }
184
194
 
185
195
    /*!
197
207
 
198
208
    QtObject {
199
209
        id: internal
 
210
        property Item headStyle: (pageStack.__propagated
 
211
                                      && pageStack.__propagated.header
 
212
                                      && pageStack.__propagated.header.__styleInstance)
 
213
                                    ? pageStack.__propagated.header.__styleInstance
 
214
                                    : null
 
215
 
 
216
        function headerCanAnimate() {
 
217
            if (!headStyle) return false;
 
218
            if (!headStyle.hasOwnProperty("animateIn")) return false;
 
219
            if (!headStyle.hasOwnProperty("animateOut")) return false;
 
220
            if (!headStyle.hasOwnProperty("animateInFinished")) return false;
 
221
            if (!headStyle.hasOwnProperty("animateOutFinished")) return false;
 
222
            return true;
 
223
        }
 
224
 
 
225
        // FIXME: Replace false by headerCanAnimate() below to enable
 
226
        //  header animations.
 
227
        property bool animateHeader: false
 
228
 
 
229
        // Call this function before pushing or popping to ensure correct order
 
230
        // of pushes/pops on the stack. This terminates any currently running
 
231
        // header transition.
 
232
        function finishPreviousAction() {
 
233
            // no action required when animating IN because the PageStack was
 
234
            // already updated before that transition started.
 
235
            if (internal.animateHeader && internal.headStyle.state == "OUT") {
 
236
                // force instant update of the PageStack without waiting for
 
237
                // the OUT animation to finish:
 
238
                internal.headStyle.animateOutFinished();
 
239
            }
 
240
        }
 
241
 
 
242
        // The page and properties to push on the stack when the OUT animation
 
243
        // finishes.
 
244
        property var pageToPush
 
245
        property var propertiesToPush
 
246
 
 
247
        // Called when the header animate OUT transition finishes for push() or instantly
 
248
        // when header animations are disabled.
 
249
        function createAndPush() {
 
250
            if (internal.animateHeader) {
 
251
                headStyle.animateOutFinished.disconnect(internal.createAndPush);
 
252
            }
 
253
            if (internal.stack.size() > 0) internal.stack.top().active = false;
 
254
            internal.stack.push(internal.createWrapper(pageToPush, propertiesToPush));
 
255
            internal.stackUpdated();
 
256
        }
 
257
 
 
258
        // Called when header animate OUT transition finishes for pop() or instantly
 
259
        // when header animations are disabled.
 
260
        function popAndDestroy() {
 
261
            if (internal.animateHeader) {
 
262
                headStyle.animateOutFinished.disconnect(internal.popAndDestroy);
 
263
            }
 
264
            internal.stack.top().active = false;
 
265
            if (internal.stack.top().canDestroy) internal.stack.top().destroyObject();
 
266
            internal.stack.pop();
 
267
            internal.stackUpdated();
 
268
        }
200
269
 
201
270
        /*!
202
271
          The instance of the stack from javascript
212
281
            return wrapperObject;
213
282
        }
214
283
 
 
284
        // Update depth and makes the Item on top of the stack active, and
 
285
        // then animates IN the new header contents if header animations are enabled.
215
286
        function stackUpdated() {
216
287
            pageStack.depth = stack.size();
217
288
            if (pageStack.depth > 0) {
218
289
                internal.stack.top().active = true;
219
290
                currentPage = stack.top().object;
 
291
 
 
292
                if (internal.animateHeader) {
 
293
                    headStyle.animateIn();
 
294
                }
220
295
            } else {
221
296
                currentPage = null;
222
297
            }