Unity 8
TopLevelSurfaceRepeater.qml
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  topmostDelegate.focus = true;
31  }
32  }
33 
34  onItemAdded: {
35  if (startingUp) {
36  checkIfStillStartingUp();
37  }
38  }
39 
40  function checkIfStillStartingUp() {
41  var i = 0;
42  var missingDelegate = false;
43  for (i = 0; i < model.count && !missingDelegate; ++i) {
44  if (!itemAt(i)) {
45  missingDelegate = true;
46  }
47  }
48  if (!missingDelegate) {
49  startingUp = false;
50  }
51  }
52 }