Created
February 22, 2013 09:21
-
-
Save chenzx/5012007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.0 | |
import QtWebKit 3.0 | |
import QtQuick.XmlListModel 2.0 | |
Rectangle { | |
id: container | |
width: 1024 | |
height: 768 | |
property string initialUrl: "http://127.0.0.1/" | |
Rectangle { | |
id: thumbnailContainer | |
color: "black" | |
anchors.bottom: container.bottom | |
width: container.width | |
height: 100 | |
gradient: Gradient { | |
GradientStop { position: 0.0; color: "gray" } | |
GradientStop { position: 0.33; color: "black" } | |
} | |
Text { | |
id: info | |
color: "white" | |
anchors.horizontalCenter: thumbnailContainer.horizontalCenter | |
text: webView.title | |
} | |
ListView { | |
id: listView | |
orientation: "Horizontal" | |
anchors { | |
topMargin: 20 | |
fill: parent | |
} | |
model: model | |
delegate: Component { | |
Image { | |
source: thumbnail | |
MouseArea { | |
anchors.fill: parent | |
onClicked: webView.url = link + "/lightbox" | |
} | |
} | |
} | |
focus: true | |
spacing: 10 | |
visible: model.status == XmlListModel.Ready | |
} | |
Rectangle { | |
id: updateInfo | |
property real distance: -(listView.contentWidth - listView.contentX - thumbnailContainer.width) | |
property real threshold: Math.max(2.5 * listView.height, thumbnailContainer.width - listView.contentWidth + 2 * listView.height) | |
property bool triggerUpdate: false | |
opacity: 0.8 | |
x: thumbnailContainer.width - distance | |
width: listView.height | |
color: "transparent" | |
anchors { | |
top: thumbnailContainer.top | |
bottom: thumbnailContainer.bottom | |
} | |
Timer { | |
interval: 200; running: updateInfo.state == "update"; repeat: false | |
onTriggered: { model.reload(); updateInfo.triggerUpdate = false; } | |
} | |
states: [ | |
State { | |
name: "pull" | |
when: updateInfo.distance <= updateInfo.threshold && listView.dragging | |
PropertyChanges { target: message; text: "Pull\nto\nupdate" } | |
}, | |
State { | |
name: "release" | |
when: updateInfo.distance > updateInfo.threshold && listView.dragging | |
PropertyChanges { target: message; text: "Release\nto\nupdate" } | |
}, | |
State { | |
name: "update" | |
when: updateInfo.triggerUpdate && listView.atXEnd && !listView.dragging | |
PropertyChanges { target: message; text: "Updating" } | |
} | |
] | |
onStateChanged: { | |
if (state == "release") | |
triggerUpdate = true | |
if (state == "pull") | |
triggerUpdate = false | |
} | |
Rectangle { | |
id: icon | |
width: 30 | |
color: "transparent" | |
anchors { | |
topMargin: 10 | |
top: parent.top | |
bottom: parent.bottom | |
left: parent.left | |
} | |
Image { | |
source: "" | |
width: 30 | |
height: 30 | |
visible: updateInfo.state != "update" | |
rotation: updateInfo.state == "release" ? 180 : 0 | |
Behavior on rotation { NumberAnimation { duration: 100} } | |
SequentialAnimation on x { | |
running: listView.atXEnd && !listView.dragging | |
loops: Animation.Infinite | |
PropertyAnimation { to: 5; duration: 250 } | |
PropertyAnimation { to: 0; duration: 250 } | |
} | |
anchors { | |
verticalCenter: parent.verticalCenter | |
} | |
} | |
} | |
Text { | |
id: message | |
horizontalAlignment: Text.AlignHCenter | |
verticalAlignment: Text.AlignVCenter | |
font.family: "Monospace" | |
color: "white" | |
anchors { | |
top: parent.top | |
bottom: parent.bottom | |
right: parent.right | |
left: icon.right | |
} | |
} | |
} | |
} | |
Rectangle { | |
id: content | |
width: container.width | |
color: "black" | |
anchors { | |
top: container.top | |
bottom: thumbnailContainer.top | |
} | |
WebView { | |
id: webView | |
anchors.fill: parent | |
opacity: 0 | |
url: container.initialUrl | |
Behavior on opacity { | |
NumberAnimation { duration: 200 } | |
} | |
/* | |
onLoadingChanged: { | |
switch (loadRequest.status) | |
{ | |
case WebView.LoadSucceededStatus: | |
opacity = 1 | |
break | |
default: | |
opacity = 0 | |
break | |
} | |
} | |
onNavigationRequested: { | |
switch (request.navigationType) | |
{ | |
case WebView.LinkClickedNavigation: | |
case WebView.FormSubmittedNavigation: | |
case WebView.BackForwardNavigation: | |
case WebView.ReloadNavigation: | |
case WebView.FormResubmittedNavigation: | |
case WebView.OtherNavigation: | |
if (/^(https|http):\/\/(www\.flickr\.com|login\.yahoo\.com)/.test(request.url)) { | |
request.action = WebView.AcceptRequest | |
return | |
} | |
} | |
// Disallow navigating outside of flickr.com | |
request.action = WebView.IgnoreRequest | |
} | |
*/ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment