summaryrefslogtreecommitdiff
path: root/metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml
diff options
context:
space:
mode:
Diffstat (limited to 'metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml')
-rw-r--r--metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml56
1 files changed, 56 insertions, 0 deletions
diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml b/metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml
new file mode 100644
index 0000000..3e445fb
--- /dev/null
+++ b/metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml
@@ -0,0 +1,56 @@
+import QtQuick 1.0
+
+ListView {
+ id: list
+
+ property bool selectable: true
+
+ interactive: false
+ highlightFollowsCurrentItem: false
+ boundsBehavior: Flickable.StopAtBounds
+
+ property real currentItemTop: currentItem !== null ? currentItem.y - contentY : 0
+ property real currentItemBottom: currentItem !== null ? currentItemTop + currentItem.height : 0
+
+ function scrollDown() {
+ if (count == 0) {
+ return; // No items
+ }
+ if (selectable) {
+ if (currentIndex == -1) {
+ // If no item is selected, select the first one.
+ currentItem = 0;
+ return;
+ }
+ if (currentIndex < count && currentItemBottom < height) {
+ // If the next item is visible, highlight it
+ incrementCurrentIndex();
+ }
+ if (currentItemBottom >= height) {
+ // If the next item now is still not visible, scroll
+ contentY += 96/3;
+ }
+ }
+ }
+
+ function scrollUp() {
+ if (count == 0) {
+ return; // No items
+ }
+ if (selectable) {
+ if (currentIndex == -1) {
+ // If no item is selected, select the last one.
+ currentIndex = count - 1;
+ return;
+ }
+ if (currentIndex >= 0 && currentItemTop > 0) {
+ // If the previous item is visible, highlight it
+ decrementCurrentIndex();
+ }
+ if (currentItemTop <= 0) {
+ // If the previous item now is still not visible, scroll
+ contentY -= 96/3;
+ }
+ }
+ }
+}