summaryrefslogtreecommitdiff
path: root/metawatch/qml/MWListView.qml
blob: e49905bd2d8618dde98db3fa0ec556cc75f669b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import QtQuick 1.0

ListView {
	id: list

	property bool selectable: true

	//interactive: false
	highlightFollowsCurrentItem: false
	boundsBehavior: Flickable.StopAtBounds

	property real currentItemTop: currentItem.y - contentY
	property real currentItemBottom: currentItemTop + currentItem.height

	function _scrollSelectable(dir) {
		var maxy = contentHeight - height;
		if (maxy < 0) maxy = 0;

		console.log(contentHeight);

		var newy = contentY;

		if (dir > 0) {
			if (currentIndex < count && currentItemBottom < height) {
				// If the next item is visible, highlight it
				list.incrementCurrentIndex();
			}
			if (currentItemBottom >= height) {
				// If the next item now is still not visible, scroll
				newy += 96/3;
			}
		} else {
			if (currentIndex >= 0 && currentItemTop > 0) {
				// If the previous item is visible, highlight it
				list.decrementCurrentIndex();
			}
			if (currentItemTop <= 0) {
				// If the previous item now is still not visible, scroll
				newy -= 96/3;
			}
		}

		//if (newy < 0) newy = 0;
		//if (newy > maxy) newy = maxy;
		list.contentY = newy;
	}

	function scrollDown() {
		if (selectable) {
			_scrollSelectable(+1);
		}
	}

	function scrollUp() {
		if (selectable) {
			_scrollSelectable(-1);
		}
	}
}