~unity-team/unity8/dash-only

« back to all changes in this revision

Viewing changes to qml/Stages/TopLevelSurfaceRepeater.qml

  • Committer: Kevin Gunn
  • Date: 2016-10-24 19:51:33 UTC
  • Revision ID: kevin.gunn@canonical.com-20161024195133-61lwdzzdwsnue1mn
shave some more

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2016 Canonical, Ltd.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; version 3.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 */
16
 
 
17
 
import QtQuick 2.4
18
 
 
19
 
Repeater {
20
 
    id: root
21
 
    // FIXME: This is a hack around us not knowing whether the Repeater has finished creating its
22
 
    // delegates on start up.
23
 
    // This is a problem when the stage gets a TopLevelSurfaceList already populated with several
24
 
    // rows.
25
 
    property bool startingUp: true
26
 
    onStartingUpChanged: {
27
 
        if (!startingUp) {
28
 
            // the top-most surface must be the focused one.
29
 
            var topmostDelegate = itemAt(0);
30
 
            if (topmostDelegate.focus) {
31
 
                // Delegate got focused while we were still starting up. Not good.
32
 
                // Force signal handler to run again
33
 
                topmostDelegate.onFocusChanged(true);
34
 
            } else {
35
 
                topmostDelegate.focus = true;
36
 
            }
37
 
        }
38
 
    }
39
 
 
40
 
    onItemAdded: {
41
 
        if (startingUp) {
42
 
            checkIfStillStartingUp();
43
 
        }
44
 
    }
45
 
 
46
 
    function checkIfStillStartingUp() {
47
 
        var i = 0;
48
 
        var missingDelegate = false;
49
 
        for (i = 0; i < model.count && !missingDelegate; ++i) {
50
 
            if (!itemAt(i)) {
51
 
                missingDelegate = true;
52
 
            }
53
 
        }
54
 
        if (!missingDelegate) {
55
 
            startingUp = false;
56
 
        }
57
 
    }
58
 
}