Verified Commit 10613736 authored by Rinigus Saar's avatar Rinigus Saar Committed by Jonah Brüchert
Browse files

use snapshot images in tab selectors

parent fdfd06d9
......@@ -51,8 +51,8 @@ Repeater {
property bool showView: index === tabs.currentIndex
x: showView ? 0 : -width
z: showView ? 1 : 0
visible: showView
x: 0
onShowViewChanged: if (showView) tabs.currentItem = wv
}
......
......@@ -84,42 +84,13 @@ Kirigami.ScrollablePage {
anchors.centerIn: parent
width: itemWidth
height: itemHeight
ShaderEffectSource {
id: shaderItem
//live: true
Image {
anchors.fill: parent
sourceRect: Qt.rect(0, 0, width, height)
sourceItem: {
tabs.itemAt(index);
}
//opacity: tabs.currentIndex == index ? 1 : 0.0
Behavior on height {
SequentialAnimation {
ScriptAction {
script: {
print("Animation start");
// switch to tabs
}
}
NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad }
NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad; target: contentView; property: opacity }
ScriptAction {
script: {
print("Animation done");
contentView.state = "hidden"
}
}
}
}
Behavior on width {
NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad}
}
clip: true
fillMode: Image.PreserveAspectCrop
source: tabs.itemAt(index).thumb.source
verticalAlignment: Image.AlignTop
LinearGradient {
id: grad
......@@ -134,6 +105,59 @@ Kirigami.ScrollablePage {
}
}
// ShaderEffectSource requires that corresponding WebEngineView is
// visible. Which is probably not the best practice as it seems to keep
// all the views active.
// ShaderEffectSource {
// id: shaderItem
// //live: true
// anchors.fill: parent
// sourceRect: Qt.rect(0, 0, width, height)
// sourceItem: {
// tabs.itemAt(index);
// }
// //opacity: tabs.currentIndex == index ? 1 : 0.0
// Behavior on height {
// SequentialAnimation {
// ScriptAction {
// script: {
// print("Animation start");
// // switch to tabs
// }
// }
// NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad }
// NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad; target: contentView; property: opacity }
// ScriptAction {
// script: {
// print("Animation done");
// contentView.state = "hidden"
// }
// }
// }
// }
// Behavior on width {
// NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad}
// }
// LinearGradient {
// id: grad
// anchors.fill: parent
// cached: true
// start: Qt.point(0,0)
// end: Qt.point(0,height)
// gradient: Gradient {
// GradientStop { position: Math.max(0.25, 1 - 1.5*(1-label.y/itemHeight)); color: "transparent"; }
// GradientStop { position: Math.max(0.25, label.y/itemHeight); color: Kirigami.Theme.backgroundColor; }
// }
// }
// }
Rectangle {
// border around a tile
anchors.fill: parent;
......
......@@ -36,12 +36,28 @@ WebEngineView {
property string errorString: ""
property alias userAgent: userAgent
property alias thumb: thumb
UserAgentGenerator {
id: userAgent
isMobile: Kirigami.Settings.isMobile
}
Image {
id: thumb
visible: false
}
Timer {
id: snaphotTimer
interval: 1000
repeat: false
onTriggered: {
if (webEngineView.visible)
grabThumb();
}
}
profile {
offTheRecord: rootPage.privateMode
......@@ -135,15 +151,20 @@ WebEngineView {
*/
var ec = "";
var es = "";
if (loadRequest.status === WebEngineView.LoadStartedStatus) {
thumb.source = "";
}
if (loadRequest.status === WebEngineView.LoadSucceededStatus) {
if (!rootPage.privateMode) {
addHistoryEntry();
}
grabThumb();
}
if (loadRequest.status === WebEngineView.LoadFailedStatus) {
print("Load failed: " + loadRequest.errorCode + " " + loadRequest.errorString);
ec = loadRequest.errorCode;
es = loadRequest.errorString;
thumb.source = "";
}
errorCode = ec;
errorString = es;
......@@ -171,6 +192,8 @@ WebEngineView {
}
}
onUrlChanged: thumb.source = ""
onFullScreenRequested: {
request.accept()
if (webBrowser.visibility !== Window.FullScreen)
......@@ -204,8 +227,18 @@ WebEngineView {
onVisibleChanged: {
// set user agent to the current displayed tab
// this ensures that we follow mobile preference
// of the current webview
if (visible)
profile.httpUserAgent = Qt.binding(function() { return userAgent.userAgent; })
// of the current webview. also update the current
// snapshot image with short delay to be sure that
// all kirigami pages have moved into place
if (visible) {
profile.httpUserAgent = Qt.binding(function() { return userAgent.userAgent; });
snaphotTimer.start();
}
}
function grabThumb() {
webEngineView.grabToImage(function(result) {
webEngineView.thumb.source = result.url;
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment