]> rtime.felk.cvut.cz Git - coffee/qtwebbrowser.git/commitdiff
Add search drop-down menu with suggestions
authorAndras Becsi <andras.becsi@theqtcompany.com>
Thu, 6 Aug 2015 18:32:25 +0000 (20:32 +0200)
committerAndras Becsi <andras.becsi@theqtcompany.com>
Wed, 12 Aug 2015 15:22:04 +0000 (17:22 +0200)
This is still missing persistent history and a
QSortFilterProxyModel implementation to seach in
that history.

src/engine.cpp
src/engine.h
src/qml/BrowserWindow.qml
src/qml/HomeScreen.qml
src/qml/NavigationBar.qml
src/qml/PageView.qml

index b6db85c2fd8379fd8ac9d002162177afaa0839e8..5768b5e348a6ebb9cd73b9aff4d80f00d7d76e3e 100644 (file)
@@ -60,6 +60,17 @@ QUrl Engine::fromUserInput(const QString& userInput)
     return QUrl::fromUserInput(userInput);
 }
 
+bool Engine::isUrl(const QString& userInput)
+{
+    if (userInput.startsWith(QStringLiteral("www."))
+            || userInput.startsWith(QStringLiteral("http"))
+            || userInput.startsWith(QStringLiteral("ftp"))
+            || userInput.contains(QStringLiteral("://"))
+            || userInput.endsWith(QStringLiteral(".com")))
+        return true;
+    return false;
+}
+
 QString Engine::domainFromString(const QString& urlString)
 {
     return QUrl::fromUserInput(urlString).host();
index 777dd74a0017e4b66f53e044b4eaeb1049c13007..49cbe249f0d2a20de18c3eac4b022ec26445224b 100644 (file)
@@ -89,6 +89,7 @@ public:
     }
     QString settingsPath();
 
+    Q_INVOKABLE bool isUrl(const QString& userInput);
     Q_INVOKABLE QUrl fromUserInput(const QString& userInput);
     Q_INVOKABLE QString domainFromString(const QString& urlString);
     Q_INVOKABLE QString fallbackColor();
index 233d2dcbbef23aba80c32cb260dafbdfde066f1b..5b3f5671c3cfc023e18b42dc09732b8600ebfea1 100644 (file)
@@ -55,6 +55,8 @@ Item {
         return tabView.get(tabView.currentIndex) ? tabView.get(tabView.currentIndex).item.webView : null
     }
 
+    property string googleSearchQuery: "https://www.google.com/search?sourceid=qtbrowser&ie=UTF-8&q="
+
     property int toolBarSize: 80
     property string uiColor: settingsView.privateBrowsingEnabled ? "#26282a" : "#46a2da"
     property string uiSeparatorColor: settingsView.privateBrowsingEnabled ? "#717273" : "#7ebee5"
@@ -116,7 +118,6 @@ Item {
             if (!tab)
                 return
 
-            navigation.addressBar.forceActiveFocus();
             navigation.addressBar.selectAll();
             tabView.makeCurrent(tabView.count - 1)
             navigation.addressBar.forceActiveFocus()
@@ -159,7 +160,6 @@ Item {
 
         onDoneClicked: {
             settingsView.state = "disabled"
-            tabView.interactive = true
         }
     }
 
@@ -174,8 +174,11 @@ Item {
 
     PageView {
         id: tabView
-        interactive: !sslDialog.visible && homeScreen.state == "disabled"
-
+        interactive: {
+            if (sslDialog.visible || homeScreen.state != "disabled" || urlDropDown.state == "enabled" || settingsView.state == "enabled")
+                return false
+            return true
+        }
         height: parent.height
 
         anchors {
@@ -248,6 +251,158 @@ Item {
         }
     }
 
+    Rectangle {
+        id: urlDropDown
+        color: "white"
+        visible: navigation.visible
+        anchors {
+            left: parent.left
+            right: parent.right
+            top: navigation.bottom
+        }
+
+        state: "disabled"
+
+        states: [
+            State {
+                name: "enabled"
+                PropertyChanges {
+                    target: homeScreen
+                    state: "disabled"
+                }
+                PropertyChanges {
+                    target: urlDropDown
+                    height: Math.min(3 * toolBarSize, historyList.childrenRect.height)
+                }
+            },
+            State {
+                name: "disabled"
+                PropertyChanges {
+                    target: urlDropDown
+                    height: 0
+                }
+            }
+        ]
+
+        ListView {
+            id: historyList
+            model: navigation.webView.navigationHistory.items
+            clip: true
+            visible: urlDropDown.state == "enabled"
+            footerPositioning: ListView.OverlayFooter
+            anchors {
+                top: parent.top
+                left: parent.left
+                right: parent.right
+            }
+            height: Math.min(childrenRect.height, parent.height)
+            delegate: Rectangle {
+                id: wrapper
+                width: historyList.width
+                height: toolBarSize
+
+                MouseArea {
+                    anchors.fill: parent
+                    onClicked: {
+                        if (!url)
+                            return
+                        navigation.addressBar.text = url
+                        navigation.addressBar.accepted()
+                    }
+                }
+
+                Column {
+                    width: parent.width - 60
+                    height: parent.height
+                    anchors {
+                        verticalCenter: parent.verticalCenter
+                        horizontalCenter: parent.horizontalCenter
+                    }
+                    Text {
+                        height: wrapper.height / 2
+                        width: parent.width
+                        elide: Text.ElideRight
+                        verticalAlignment: Text.AlignBottom
+                        anchors{
+                            leftMargin: 30
+                            rightMargin: 30
+                        }
+                        id: titleLabel
+                        font.family: defaultFontFamily
+                        font.pixelSize: 23
+                        color: "black"
+                        text: title ? title : ""
+                    }
+                    Text {
+                        height: wrapper.height / 2 - 1
+                        width: parent.width
+                        elide: Text.ElideRight
+                        verticalAlignment: Text.AlignTop
+                        font.family: defaultFontFamily
+                        font.pixelSize: 23
+                        color: uiColor
+                        text: url ? url : ""
+                    }
+                    Rectangle {
+                        anchors.horizontalCenter: parent.horizontalCenter
+                        width: historyList.width
+                        height: 1
+                        color: iconStrokeColor
+                    }
+                }
+            }
+            footer: Rectangle {
+                z: 5
+                width: historyList.width
+                height: toolBarSize
+                border.color: iconStrokeColor
+                MouseArea {
+                    anchors.fill: parent
+                    onClicked: {
+                        var string = searchText.text
+                        var constructedUrl = ""
+                        if (engine.isUrl(string)) {
+                            constructedUrl = engine.fromUserInput(string)
+                        } else {
+                            constructedUrl = engine.fromUserInput(googleSearchQuery + string)
+                        }
+                        navigation.addressBar.text = constructedUrl
+                        navigation.addressBar.accepted()
+                    }
+                }
+                Row {
+                    height: parent.height
+                    Rectangle {
+                        id: searchIcon
+                        height: parent.height
+                        width: height
+                        color: "transparent"
+                        Image {
+                            anchors.centerIn: parent
+                            source: "qrc:///search"
+                        }
+                    }
+                    Text {
+                        id: searchText
+                        height: parent.height
+                        width: historyList.width - searchIcon.width - 30
+                        elide: Text.ElideRight
+                        text: navigation.addressBar.text
+                        verticalAlignment: Text.AlignVCenter
+                        font.family: defaultFontFamily
+                        font.pixelSize: 23
+                        color: "black"
+                    }
+                }
+            }
+        }
+
+
+        transitions: Transition {
+            PropertyAnimation { property: "height"; duration: animationDuration; easing.type : Easing.InSine }
+        }
+    }
+
     HomeScreen {
         id: homeScreen
         height: parent.height - toolBarSize
index 793589eb894ac7e1b8ff3fa0cd6b99026394e785..580a3ef6e0310540a0feb00b7db181fc3f2e5f02 100644 (file)
@@ -93,10 +93,6 @@ Rectangle {
     states: [
         State {
             name: "enabled"
-            PropertyChanges {
-                target: tabView
-                interactive: false
-            }
             AnchorChanges {
                 target: homeScreen
                 anchors.top: navigation.bottom
@@ -111,10 +107,6 @@ Rectangle {
         },
         State {
             name: "edit"
-            PropertyChanges {
-                target: tabView
-                interactive: false
-            }
         }
     ]
 
index d926b6771678d20c1b7d62a874c59c51239892a2..9071eadcb2c983e12f9a503f6db987ad71c7ab32 100644 (file)
@@ -167,15 +167,38 @@ ToolBar {
             placeholderText: qsTr("Search or type a URL")
 
             onActiveFocusChanged: {
-                if (activeFocus)
+                if (activeFocus) {
+                    urlBar.selectAll()
                     root.state = "enabled"
-                else
+                    urlDropDown.state = "enabled"
+                } else {
+                    urlDropDown.state = "disabled"
                     root.state = "tracking"
+                }
             }
 
             UIButton {
                 id: reloadButton
-                source: webView && webView.loading ? "qrc:///stop" : "qrc:///refresh"
+                state: cancelButton.visible ? "edit" : "load"
+                states: [
+                    State {
+                        name: "load"
+                        PropertyChanges {
+                            target: reloadButton
+                            source: webView && webView.loading ? "qrc:///stop" : "qrc:///refresh"
+                            height: 54
+                        }
+                    },
+                    State {
+                        name: "edit"
+                        PropertyChanges {
+                            target: reloadButton
+                            source: "qrc:///stop"
+                            height: 45
+                            visible: urlBar.text != ""
+                        }
+                    }
+                ]
                 height: 54
                 width: height
                 color: "transparent"
@@ -186,7 +209,14 @@ ToolBar {
                     right: parent.right
                     verticalCenter: addressBar.verticalCenter;
                 }
-                onClicked: { webView.loading ? webView.stop() : webView.reload() }
+                onClicked: {
+                    if (state == "load") {
+                        webView.loading ? webView.stop() : webView.reload()
+                        return
+                    }
+                    urlBar.selectAll()
+                    urlBar.remove(urlBar.selectionStart, urlBar.selectionEnd)
+                }
             }
             style: TextFieldStyle {
                 textColor: "black"
@@ -213,18 +243,13 @@ ToolBar {
             }
 
             onTextChanged: refresh()
-            onEditingFinished: selectAll()
-            onFocusChanged: {
-                if (focus) {
-                    forceActiveFocus()
-                    selectAll()
-                } else {
-                    urlBar.cursorPosition = 0
-                    deselect()
-                }
+            onEditingFinished: {
+                selectAll()
+                webView.forceActiveFocus()
             }
         }
         Rectangle {
+            visible: !cancelButton.visible
             Layout.fillWidth: true
             implicitWidth: 10
             anchors {
@@ -233,6 +258,25 @@ ToolBar {
             }
             color: uiColor
         }
+
+        UIButton {
+            id: cancelButton
+            color: uiColor
+            visible: urlDropDown.state === "enabled"
+            highlightColor: buttonPressedColor
+            Text {
+                color: "white"
+                anchors.centerIn: parent
+                text: "Cancel"
+                font.family: defaultFontFamily
+                font.pixelSize: 28
+            }
+            implicitWidth: 120
+            onClicked: {
+                urlDropDown.state = "disabled"
+                webView.forceActiveFocus()
+            }
+        }
         Rectangle {
             width: 1
             anchors {
@@ -334,7 +378,6 @@ ToolBar {
             color: uiColor
             highlightColor: buttonPressedColor
             onClicked: {
-                tabView.interactive = false
                 settingsView.state = "enabled"
             }
         }
index 279f9d803fc6881fce58a844684bd5c649153cea..fb6ac12ffbf07a4dd1e4ab9cd79ba662bba5cb73 100644 (file)
@@ -594,7 +594,7 @@ Rectangle {
 
         dragMargin: itemHeight
 
-        focus: interactive
+        focus: pathView.interactive
 
         property real offset: 30