Moved SearchBar to its own qml file
authorLuciano Montanaro <mikelima@cirulla.net>
Wed, 20 Jul 2011 00:52:05 +0000 (02:52 +0200)
committerLuciano Montanaro <mikelima@cirulla.net>
Tue, 27 Dec 2011 22:16:45 +0000 (23:16 +0100)
...cleaned up layout and improved match highlighting

application/application.pro
application/resources/harmattan/qml/SearchBar.qml [new file with mode: 0644]
application/resources/harmattan/qml/StationListPage.qml
application/resources/harmattan/qml/StationPage.qml
application/stationlistproxymodel.cpp

index 6367cf8..76d0282 100644 (file)
@@ -106,7 +106,8 @@ OTHER_FILES += \
     resources/stations/generateunclassifiedlist.xq \
     resources/harmattan/qml/main.qml \
     resources/harmattan/qml/StationListPage.qml \
-    resources/harmattan/qml/StationPage.qml
+    resources/harmattan/qml/StationPage.qml \
+    resources/harmattan/qml/SearchBar.qml
 
 unix {
     isEmpty(PREFIX) {
diff --git a/application/resources/harmattan/qml/SearchBar.qml b/application/resources/harmattan/qml/SearchBar.qml
new file mode 100644 (file)
index 0000000..a3f583d
--- /dev/null
@@ -0,0 +1,49 @@
+import QtQuick 1.0
+import com.nokia.meego 1.0
+
+Item {
+    property alias text: searchField.text
+    width: parent.width
+    height: 48
+
+    TextField {
+        id: searchField
+        width: parent.width
+        anchors.margins: 16
+        anchors.centerIn: parent
+        placeholderText: qsTr("Search")
+        inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
+        platformStyle: TextFieldStyle { paddingRight: clearButton.width }
+        onTextChanged: {
+            if (searchField.text.length == 0) {
+                searchButton.visible = true
+                clearButton.visible = false
+            } else {
+                searchButton.visible = false
+                clearButton.visible = true
+            }
+        }
+        Image {
+            id: searchButton
+            visible: true
+            smooth: true
+            anchors.right: parent.right
+            anchors.verticalCenter: parent.verticalCenter
+            source: "image://theme/icon-m-common-search"
+        }
+        Image {
+            id: clearButton
+            visible: false
+            anchors.right: parent.right
+            anchors.verticalCenter: parent.verticalCenter
+            source: "image://theme/icon-m-input-clear"
+            MouseArea {
+                anchors.fill: parent
+                onClicked: {
+                    inputContext.reset()
+                    searchField.text = ""
+                }
+            }
+        }
+    }
+}
index d607862..ee62845 100644 (file)
@@ -27,37 +27,31 @@ Page {
 
     function highlightSearch(s)
     {
-        return s.replace(searchField.text,
-                         '<span style="text-decoration:underline">' +
-                         searchField.text + '</span>')
+        // TODO compile RegExp on change, or find a way to cleanly use
+        // stationListProxyModel.filterRegExp
+        if (searchField.text.length) {
+            var r = new RegExp(searchField.text, 'i')
+            var match = r.exec(s)
+            return s.replace(r, '<span style="text-decoration:underline">' +
+                             match + '</span>')
+        } else {
+            return s
+        }
     }
 
     Column {
-        width: parent.width
+        x: 16
+        y: 16
+        width: parent.width - 32
         height: parent.height
-        TextField {
+        spacing: 16
+        SearchBar {
             id: searchField
-            width: parent.width
-            placeholderText: "Search..."
-            platformStyle: TextFieldStyle { paddingRight: clearButton.width }
-            onTextChanged: {
-            }
-            Image {
-                id: clearButton
-                anchors.right: parent.right
-                anchors.verticalCenter: parent.verticalCenter
-                source: "image://theme/icon-m-input-clear"
-                MouseArea {
-                    anchors.fill: parent
-                    onClicked: {
-                        inputContext.reset()
-                        searchField.text = ""
-                    }
-                }
-            }
         }
-        Rectangle {
-            height: 16
+        Binding {
+            target: stationListProxyModel
+            property: "searchPattern"
+            value: searchField.text
         }
         ListView {
             id: stationListView
index 238fbfa..9a992af 100644 (file)
@@ -1,6 +1,7 @@
 import QtQuick 1.1
 import com.nokia.meego 1.0
 import QtWebKit 1.0
+import QtQuick 1.0
 
 Page {
     property alias html: view.html
@@ -21,4 +22,4 @@ Page {
         settings.defaultFixedFontSize: labelStyle.fontPixelSize
         settings.standardFontFamily: labelStyle.fontFamily
     }
-}
+ }
index a85cbc1..823036a 100644 (file)
@@ -76,6 +76,7 @@ void StationListProxyModel::setSearchPattern(const QString &pattern)
 {
     m_searchPattern = pattern;
     setFilterFixedString(m_searchPattern);
+    qDebug() << "set Search pattern to" << pattern;
 }
 
 StationListProxyModel::SortingMode StationListProxyModel::sortingMode()