2 * Copyright 2016 Canonical Ltd.
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.
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.
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/>.
20 property Item itemView: null
21 property bool hasOverflow: false
23 signal select(int index)
26 function selectNext(currentIndex) {
29 if (currentIndex === -1 && itemView.count > 0) {
30 while (itemView.count > newIndex) {
31 menu = itemView.itemAt(newIndex);
32 if (!!menu["enabled"]) {
38 if (hasOverflow && newIndex === itemView.count) {
43 } else if (currentIndex !== -1 && itemView.count > 1) {
44 var startIndex = (currentIndex + 1) % itemView.count;
45 newIndex = startIndex;
47 menu = itemView.itemAt(newIndex);
48 if (!!menu["enabled"]) {
53 if (hasOverflow && newIndex + 1 === itemView.count) {
58 newIndex = (newIndex + 1) % itemView.count;
59 } while (newIndex !== startIndex)
63 function selectPrevious(currentIndex) {
65 var newIndex = itemView.count-1;
66 if (currentIndex === -1 && itemView.count > 0) {
67 while (itemView.count > newIndex) {
68 menu = itemView.itemAt(newIndex);
69 if (!!menu["enabled"]) {
75 if (hasOverflow && newIndex < 0 ) {
80 } else if (currentIndex !== -1 && itemView.count > 1) {
81 var startIndex = currentIndex - 1;
82 newIndex = startIndex;
89 newIndex = itemView.count - 1;
91 menu = itemView.itemAt(newIndex);
92 if (!!menu["enabled"]) {
98 } while (newIndex !== startIndex)