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/>.
16
* Author: Nick Dedekind <nick.dedekind@canonical.com>
23
// items to navigate through
24
property QtObject model
26
signal select(int index)
28
function selectNext(currentIndex) {
31
if (currentIndex === -1 && model.count > 0) {
32
while (model.count > newIndex) {
33
delegate = model.get(newIndex);
34
if (!!delegate["enabled"]) {
40
} else if (currentIndex !== -1 && model.count > 1) {
41
var startIndex = (currentIndex + 1) % model.count;
42
newIndex = startIndex;
44
delegate = model.get(newIndex);
45
if (!!delegate["enabled"]) {
49
newIndex = (newIndex + 1) % model.count;
50
} while (newIndex !== startIndex)
54
function selectPrevious(currentIndex) {
56
var newIndex = model.count-1;
57
if (currentIndex === -1 && model.count > 0) {
58
while (model.count > newIndex) {
59
delegate = model.get(newIndex);
60
if (!!delegate["enabled"]) {
66
} else if (currentIndex !== -1 && model.count > 1) {
67
var startIndex = currentIndex - 1;
68
newIndex = startIndex;
71
newIndex = model.count - 1;
73
delegate = model.get(newIndex);
74
if (!!delegate["enabled"]) {
79
} while (newIndex !== startIndex)