From d5b5cfc83e1247ebc18ef2024f07bdd37d41164b Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Fri, 2 Dec 2011 23:02:51 +0100 Subject: provide a set of metawatch common qml elements --- .../javispedro/sowatch/metawatch/MWListView.qml | 56 ++++++++++++++++++++++ .../com/javispedro/sowatch/metawatch/MWTitle.qml | 16 +++++++ .../qml/com/javispedro/sowatch/metawatch/qmldir | 2 + 3 files changed, 74 insertions(+) create mode 100644 metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml create mode 100644 metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml create mode 100644 metawatch/qml/com/javispedro/sowatch/metawatch/qmldir (limited to 'metawatch/qml/com') 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; + } + } + } +} diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml b/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml new file mode 100644 index 0000000..8aa494c --- /dev/null +++ b/metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml @@ -0,0 +1,16 @@ +import QtQuick 1.0 + +Rectangle { + width: 96 + height: 16 + + property alias text: label.text + + Row { + anchors.fill: parent + Text { + id: label + font.bold: true + } + } +} diff --git a/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir b/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir new file mode 100644 index 0000000..02221c3 --- /dev/null +++ b/metawatch/qml/com/javispedro/sowatch/metawatch/qmldir @@ -0,0 +1,2 @@ +MWTitle 1.0 MWTitle.qml +MWListView 1.0 MWListView.qml -- cgit v1.2.3