summaryrefslogtreecommitdiff
path: root/metawatch/qml
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2011-12-02 23:02:51 +0100
committerJavier S. Pedro <maemo@javispedro.com>2011-12-02 23:02:51 +0100
commitd5b5cfc83e1247ebc18ef2024f07bdd37d41164b (patch)
treed6c44ffe944c730f4bb16a3e5a412db78027f324 /metawatch/qml
parent1abf33ab7bcbf73ebb9eeb6c388c3c1c4abef445 (diff)
downloadsowatch-d5b5cfc83e1247ebc18ef2024f07bdd37d41164b.tar.gz
sowatch-d5b5cfc83e1247ebc18ef2024f07bdd37d41164b.zip
provide a set of metawatch common qml elements
Diffstat (limited to 'metawatch/qml')
-rw-r--r--metawatch/qml/MWTitle.qml6
-rw-r--r--metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml (renamed from metawatch/qml/MWListView.qml)63
-rw-r--r--metawatch/qml/com/javispedro/sowatch/metawatch/MWTitle.qml16
-rw-r--r--metawatch/qml/com/javispedro/sowatch/metawatch/qmldir2
4 files changed, 48 insertions, 39 deletions
diff --git a/metawatch/qml/MWTitle.qml b/metawatch/qml/MWTitle.qml
deleted file mode 100644
index 44f4f70..0000000
--- a/metawatch/qml/MWTitle.qml
+++ /dev/null
@@ -1,6 +0,0 @@
-import QtQuick 1.0
-
-Rectangle {
- width: 100
- height: 62
-}
diff --git a/metawatch/qml/MWListView.qml b/metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml
index e49905b..3e445fb 100644
--- a/metawatch/qml/MWListView.qml
+++ b/metawatch/qml/com/javispedro/sowatch/metawatch/MWListView.qml
@@ -5,55 +5,52 @@ ListView {
property bool selectable: true
- //interactive: false
+ interactive: false
highlightFollowsCurrentItem: false
boundsBehavior: Flickable.StopAtBounds
- property real currentItemTop: currentItem.y - contentY
- property real currentItemBottom: currentItemTop + currentItem.height
+ property real currentItemTop: currentItem !== null ? currentItem.y - contentY : 0
+ property real currentItemBottom: currentItem !== null ? currentItemTop + currentItem.height : 0
- function _scrollSelectable(dir) {
- var maxy = contentHeight - height;
- if (maxy < 0) maxy = 0;
-
- console.log(contentHeight);
-
- var newy = contentY;
-
- if (dir > 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
- list.incrementCurrentIndex();
+ incrementCurrentIndex();
}
if (currentItemBottom >= height) {
// If the next item now is still not visible, scroll
- newy += 96/3;
+ 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;
}
- } else {
if (currentIndex >= 0 && currentItemTop > 0) {
// If the previous item is visible, highlight it
- list.decrementCurrentIndex();
+ decrementCurrentIndex();
}
if (currentItemTop <= 0) {
// If the previous item now is still not visible, scroll
- newy -= 96/3;
+ contentY -= 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);
- }
}
}
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