From cd220a213060b6211330699ec6a3830593945a24 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Fri, 2 Dec 2011 20:31:12 +0100 Subject: moving some resources to the filesystem --- metawatch/qml/MWListView.qml | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 metawatch/qml/MWListView.qml (limited to 'metawatch/qml/MWListView.qml') diff --git a/metawatch/qml/MWListView.qml b/metawatch/qml/MWListView.qml new file mode 100644 index 0000000..e49905b --- /dev/null +++ b/metawatch/qml/MWListView.qml @@ -0,0 +1,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); + } + } +} -- cgit v1.2.3