#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;
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
tabView.createEmptyTab()
navigation.addressBar.forceActiveFocus();
navigation.addressBar.selectAll();
- tabView.currentIndex = tabView.count - 1
+ tabView.makeCurrent(tabView.count - 1)
}
}
Action {
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
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"
return -1;
}
- function select(index) {
- gridView.positionViewAtIndex(index, GridView.Contain)
- gridView.draggingChanged()
- }
-
states: [
State {
name: "enabled"
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
contentX = 0
}
+ onDraggingChanged: snapToPage()
+
+ anchors {
+ topMargin: toolBarSize
+ leftMargin: (parent.width - 4 * gridView.cellWidth + homeScreen.padding) / 2
+ }
+
delegate: Rectangle {
id: square
property string iconColor: "white"
}
homeScreen.state = "edit"
}
- onPressed: {
+ onClicked: {
console.log("index="+ index +" | title=" + title + " | url=" + url + " | iconUrl=" + iconUrl + " | fallbackColor=" + fallbackColor)
- // TODO: open bookmark
+ navigation.load(url)
}
}
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
+ }
+ }
}
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
}
}
+ 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 {
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 {
****************************************************************************/
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
settings.errorPageEnabled: appSettings.errorPageEnabled
settings.pluginsEnabled: appSettings.pluginsEnabled
*/
+ onLoadingChanged: {
+ if (loading)
+ navigation.state = "enabled"
+ }
+
onCertificateError: {
if (!acceptedCertificates.shouldAutoAccept(error)){
error.defer()
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 {
}
function makeCurrent(index) {
+ viewState = "list"
pathView.positionViewAtIndex(index, PathView.Center)
+ viewState = "page"
}
function createEmptyTab() {
TouchTracker::TouchTracker(QQuickItem *parent)
: QQuickItem(parent)
, m_blockEvents(false)
+ , m_diff(0)
+ , m_previousY(0)
, m_target(0)
, m_delegate(0)
{
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();
void touchBegin();
void touchEnd();
void velocityChanged();
+ void scrollDirectionChanged();
protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
bool m_blockEvents;
+ int m_diff;
+ int m_previousY;
PositionInfo m_startPoint;
PositionInfo m_currentPoint;
QQuickItem *m_target;