]> rtime.felk.cvut.cz Git - coffee/qtwebbrowser.git/commitdiff
Improve home screen
authorAndras Becsi <andras.becsi@theqtcompany.com>
Thu, 30 Jul 2015 18:31:26 +0000 (20:31 +0200)
committerAndras Becsi <andras.becsi@theqtcompany.com>
Wed, 12 Aug 2015 15:22:03 +0000 (17:22 +0200)
src/main.cpp
src/qml/BrowserWindow.qml
src/qml/HomeScreen.qml
src/qml/NavigationBar.qml
src/qml/PageView.qml
src/touchtracker.cpp
src/touchtracker.h

index f6645a2911003a479e85cacfade2c7c8fe6f81f1..d35578d74a50aa73bf312de993201f000f2ab726 100644 (file)
@@ -68,6 +68,10 @@ int main(int argc, char **argv)
 #endif
     QtWebEngine::initialize();
 
+    app.setOrganizationName("The Qt Company");
+    app.setOrganizationDomain("qt.io");
+    app.setApplicationName("qtbrowser");
+
     qmlRegisterType<TouchTracker>("io.qt.browser", 1, 0, "TouchTracker");
 
     BrowserWindow window;
index 7e6a5e4c3b5d226bedfc605a3478690e3be08a91..9dc7b2a9be2aad81bdbdbfd3051f752dd21ac32b 100644 (file)
@@ -69,7 +69,7 @@ Item {
     property string defaultFontFamily: "Open Sans"
 
     property int animationDuration: 200
-    property int velocityThreshold: 500
+    property int velocityThreshold: 400
     property int velocityY: 0
     property real touchY: 0
     property real touchReference: 0
@@ -116,7 +116,7 @@ Item {
             tabView.createEmptyTab()
             navigation.addressBar.forceActiveFocus();
             navigation.addressBar.selectAll();
-            tabView.currentIndex = tabView.count - 1
+            tabView.makeCurrent(tabView.count - 1)
         }
     }
     Action {
@@ -228,48 +228,6 @@ Item {
     NavigationBar {
         id: navigation
 
-        Behavior on y {
-            NumberAnimation { duration: animationDuration }
-        }
-
-        y: {
-            var diff = touchReference - touchY
-
-            if (velocityY > velocityThreshold) {
-                if (diff > 0)
-                    return -toolBarSize
-                else
-                    return 0
-            }
-
-            if (!touchGesture || diff == 0) {
-                if (y < -toolBarSize / 2)
-                    return -toolBarSize
-                else
-                    return 0
-            }
-
-            if (diff > toolBarSize)
-                return -toolBarSize
-
-            if (diff > 0) {
-                if (y == -toolBarSize)
-                    return -toolBarSize
-                return -diff
-            }
-
-            // diff < 0
-
-            if (y == 0)
-                return 0
-
-            diff = Math.abs(diff)
-            if (diff >= toolBarSize)
-                return 0
-
-            return -toolBarSize + diff
-        }
-
         anchors {
             left: parent.left
             right: parent.right
index 881fcb4027f64b1a1c19a6f633b012169f69cdd8..44d15f02bb76fc9a8b9ff1f56cd91bc7a1a2488e 100644 (file)
@@ -43,6 +43,13 @@ Rectangle {
 
     property int padding: 60
     property int cellSize: width / 5 - padding
+    property alias count: gridView.count
+    property alias currentIndex: gridView.currentIndex
+
+    function set(index) {
+        currentIndex = index
+        gridView.snapToPage()
+    }
 
     state: "disabled"
 
@@ -60,11 +67,6 @@ Rectangle {
         return -1;
     }
 
-    function select(index) {
-        gridView.positionViewAtIndex(index, GridView.Contain)
-        gridView.draggingChanged()
-    }
-
     states: [
         State {
             name: "enabled"
@@ -107,18 +109,13 @@ Rectangle {
         boundsBehavior: Flickable.StopAtBounds
         maximumFlickVelocity: 0
         contentHeight: parent.height
-        displayMarginEnd: 3 * page
         rightMargin: (parent.width - 4 * gridView.cellWidth - homeScreen.padding) / 2
 
         Behavior on contentX {
             NumberAnimation { duration: 1.5 * animationDuration; easing.type : Easing.InSine}
         }
 
-        anchors {
-            topMargin: toolBarSize
-            leftMargin: (parent.width - 4 * gridView.cellWidth + homeScreen.padding) / 2
-        }
-        onDraggingChanged: {
+        function snapToPage() {
             if (dragging) {
                 dragStart = contentX
                 return
@@ -144,6 +141,13 @@ Rectangle {
             contentX = 0
         }
 
+        onDraggingChanged: snapToPage()
+
+        anchors {
+            topMargin: toolBarSize
+            leftMargin: (parent.width - 4 * gridView.cellWidth + homeScreen.padding) / 2
+        }
+
         delegate: Rectangle {
             id: square
             property string iconColor: "white"
@@ -282,9 +286,9 @@ Rectangle {
                     }
                     homeScreen.state = "edit"
                 }
-                onPressed: {
+                onClicked: {
                     console.log("index="+ index +" | title=" + title + " | url=" + url + " | iconUrl=" + iconUrl + " | fallbackColor=" + fallbackColor)
-                    // TODO: open bookmark
+                    navigation.load(url)
                 }
             }
             Rectangle {
@@ -413,4 +417,20 @@ Rectangle {
             }
         }
     }
+    Rectangle {
+        visible: gridView.count == 0
+        color: "transparent"
+        anchors.centerIn: parent
+        width: 500
+        height: 100
+        Text {
+            anchors.centerIn: parent
+            color: placeholderColor
+            font.family: defaultFontFamily
+            font.pixelSize: 28
+            text: "No bookmarks have been saved so far."
+            verticalAlignment: Text.AlignVCenter
+            horizontalAlignment: Text.AlignHCenter
+        }
+    }
 }
index ce0b80bedb02d782388f41a5f0f42291560498cd..1089cd7aa92ea75f99c80310ed44713947bcb6cd 100644 (file)
@@ -15,6 +15,13 @@ ToolBar {
     visible: opacity != 0.0
     opacity: tabView.viewState == "page" ? 1.0 : 0.0
 
+    function load(url) {
+        webView.url = url
+        homeScreen.state = "disabled"
+    }
+
+    state: "enabled"
+
     style: ToolBarStyle {
         background: Rectangle {
             color: uiColor
@@ -28,6 +35,70 @@ ToolBar {
         }
     }
 
+    Behavior on y {
+        NumberAnimation { duration: animationDuration }
+    }
+
+    states: [
+        State {
+            name: "enabled"
+            PropertyChanges {
+                target: root
+                y: 0
+            }
+        },
+        State {
+            name: "tracking"
+            PropertyChanges {
+                target: root
+                y: {
+                    var diff = touchReference - touchY
+
+                    if (velocityY > velocityThreshold) {
+                        if (diff > 0)
+                            return -toolBarSize
+                        else
+                            return 0
+                    }
+
+                    if (!touchGesture || diff == 0) {
+                        if (y < -toolBarSize / 2)
+                            return -toolBarSize
+                        else
+                            return 0
+                    }
+
+                    if (diff > toolBarSize)
+                        return -toolBarSize
+
+                    if (diff > 0) {
+                        if (y == -toolBarSize)
+                            return -toolBarSize
+                        return -diff
+                    }
+
+                    // diff < 0
+
+                    if (y == 0)
+                        return 0
+
+                    diff = Math.abs(diff)
+                    if (diff >= toolBarSize)
+                        return 0
+
+                    return -toolBarSize + diff
+                }
+            }
+        },
+        State {
+            name: "disabled"
+            PropertyChanges {
+                target: root
+                y: -toolBarSize
+            }
+        }
+    ]
+
     RowLayout {
         height: toolBarSize - 2
         anchors {
@@ -209,10 +280,11 @@ ToolBar {
                 var idx = homeScreen.contains(webView.url.toString())
                 if (idx != -1) {
                     homeScreen.state = "enabled"
-                    homeScreen.select(idx)
+                    homeScreen.currentIndex = idx
                     return
                 }
-                homeScreen.add(webView.title, webView.url, webView.icon, engine.randomColor())
+                var icon = webView.loading ? "" : webView.icon
+                homeScreen.add(webView.title, webView.url, icon, engine.randomColor())
             }
         }
         Rectangle {
index 3552a0b319bb23f014f2d293e1909f89ccd24063..792de1939f3749f9e423826bfb9dfa82086fec01 100644 (file)
@@ -36,7 +36,7 @@
 ****************************************************************************/
 
 import QtQuick 2.5
-import QtWebEngine 1.3
+import QtWebEngine 1.2
 import QtWebEngine.experimental 1.0
 import QtQuick.Controls 1.4
 import QtQuick.Controls.Styles 1.4
@@ -140,6 +140,11 @@ Rectangle {
                 settings.errorPageEnabled: appSettings.errorPageEnabled
                 settings.pluginsEnabled: appSettings.pluginsEnabled
 */
+                onLoadingChanged: {
+                    if (loading)
+                        navigation.state = "enabled"
+                }
+
                 onCertificateError: {
                     if (!acceptedCertificates.shouldAutoAccept(error)){
                         error.defer()
@@ -210,11 +215,14 @@ Rectangle {
                     browserWindow.velocityY = yVelocity
                     browserWindow.touchReference = tracker.touchY
                     browserWindow.touchGesture = true
+                    navigation.state = "tracking"
                 }
                 onTouchEnd: {
                     browserWindow.velocityY = yVelocity
                     browserWindow.touchGesture = false
+                    navigation.state = "tracking"
                 }
+                onScrollDirectionChanged: browserWindow.touchReference = tracker.touchY
             }
 
             Rectangle {
@@ -268,7 +276,9 @@ Rectangle {
     }
 
     function makeCurrent(index) {
+        viewState = "list"
         pathView.positionViewAtIndex(index, PathView.Center)
+        viewState = "page"
     }
 
     function createEmptyTab() {
index 11cbb6e9a9d8a0a7130bba287c37f77d5e5b1f5b..81dba5c2375e58ea116c3f8dabdf778b273ace1f 100644 (file)
@@ -9,6 +9,8 @@ using namespace utils;
 TouchTracker::TouchTracker(QQuickItem *parent)
     : QQuickItem(parent)
     , m_blockEvents(false)
+    , m_diff(0)
+    , m_previousY(0)
     , m_target(0)
     , m_delegate(0)
 {
@@ -78,8 +80,15 @@ bool TouchTracker::eventFilter(QObject *obj, QEvent *event)
 
     const QTouchEvent *touch = static_cast<QTouchEvent*>(event);
     const QList<QTouchEvent::TouchPoint> &points = touch->touchPoints();
+    m_previousY = m_currentPoint.y();
     m_currentPoint.pos = m_target->mapToScene(points.at(0).pos());
     m_currentPoint.ts = QDateTime::currentMSecsSinceEpoch();
+    int currentDiff = m_previousY - m_currentPoint.y();
+
+    if ((currentDiff > 0 && m_diff < 0) || (currentDiff < 0 && m_diff > 0))
+        emit scrollDirectionChanged();
+
+    m_diff = currentDiff;
 
     emit touchChanged();
     emit velocityChanged();
index 9aa555a1d9b66b7f09792134cc8d9bf395422b45..8392e127bcf5568e17f4bae6845de9cccfbc76a8 100644 (file)
@@ -41,6 +41,7 @@ signals:
     void touchBegin();
     void touchEnd();
     void velocityChanged();
+    void scrollDirectionChanged();
 
 protected:
     bool eventFilter(QObject *obj, QEvent *event);
@@ -48,6 +49,8 @@ protected:
 
 private:
     bool m_blockEvents;
+    int m_diff;
+    int m_previousY;
     PositionInfo m_startPoint;
     PositionInfo m_currentPoint;
     QQuickItem *m_target;