on e1659ca help sign in
unity8/qml/ApplicationMenus/MenuNavigator.qml
78 lines 2.6 kB history raw
1/*
2 * Copyright 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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.4
19QtObject {
20 property Item itemView: null
22 signal select(int index)
24 function selectNext(currentIndex) {
25 var menu;
26 var newIndex = 0;
27 if (currentIndex === -1 && itemView.count > 0) {
28 while (itemView.count > newIndex) {
29 menu = itemView.itemAt(newIndex);
30 if (!!menu["enabled"]) {
31 select(newIndex);
32 break;
33 }
34 newIndex++;
35 }
36 } else if (currentIndex !== -1 && itemView.count > 1) {
37 var startIndex = (currentIndex + 1) % itemView.count;
38 newIndex = startIndex;
39 do {
40 menu = itemView.itemAt(newIndex);
41 if (!!menu["enabled"]) {
42 select(newIndex);
43 break;
44 }
45 newIndex = (newIndex + 1) % itemView.count;
46 } while (newIndex !== startIndex)
47 }
48 }
50 function selectPrevious(currentIndex) {
51 var menu;
52 var newIndex = itemView.count-1;
53 if (currentIndex === -1 && itemView.count > 0) {
54 while (itemView.count > newIndex) {
55 menu = itemView.itemAt(newIndex);
56 if (!!menu["enabled"]) {
57 select(newIndex);
58 break;
59 }
60 newIndex--;
61 }
62 } else if (currentIndex !== -1 && itemView.count > 1) {
63 var startIndex = currentIndex - 1;
64 newIndex = startIndex;
65 do {
66 if (newIndex < 0) {
67 newIndex = itemView.count - 1;
68 }
69 menu = itemView.itemAt(newIndex);
70 if (!!menu["enabled"]) {
71 select(newIndex);
72 break;
73 }
74 newIndex--;
75 } while (newIndex !== startIndex)
76 }
77 }