Commit 521d039d authored by Rinigus Saar's avatar Rinigus Saar Committed by Jonah Brüchert
Browse files

Show tabs using ShaderEffectSource

parent 7c0c9b00
......@@ -61,10 +61,12 @@ Repeater {
userAgent.isMobile: model.isMobile
width: tabs.width
property bool readyForSnapshot: false
property bool showView: index === tabs.currentIndex
visible: showView && tabs.activeTabs
x: 0
visible: (showView || readyForSnapshot || loadingActive) && tabs.activeTabs
x: showView && tabs.activeTabs ? 0 : -width
z: showView && tabs.activeTabs ? 0 : -1
onShowViewChanged: {
if (showView) {
......
......@@ -191,7 +191,7 @@ Item {
Kirigami.Theme.inherit: true
onClicked: currentWebView.loading ? currentWebView.stop() : currentWebView.reload()
onClicked: currentWebView.loading ? currentWebView.stopLoading() : currentWebView.reload()
}
......
......@@ -84,12 +84,22 @@ Kirigami.ScrollablePage {
width: itemWidth
height: itemHeight
Image {
// ShaderEffectSource requires that corresponding WebEngineView is
// visible. Here, visibility is enabled while snapshot is taken and
// removed as soon as it is ready.
ShaderEffectSource {
id: shaderItem
live: false
anchors.fill: parent
clip: true
fillMode: Image.PreserveAspectCrop
source: tabs.itemAt(index) ? tabs.itemAt(index).thumb.source : ""
verticalAlignment: Image.AlignTop
sourceRect: Qt.rect(0, 0, sourceItem.width, height/width * sourceItem.width)
sourceItem: tabs.itemAt(index)
Component.onCompleted: {
sourceItem.readyForSnapshot = true;
scheduleUpdate();
}
onScheduledUpdateCompleted: sourceItem.readyForSnapshot = false
LinearGradient {
id: grad
......@@ -104,59 +114,6 @@ 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;
......
......@@ -38,7 +38,18 @@ WebEngineView {
property bool privateMode: false
property alias userAgent: userAgent
property alias thumb: thumb
// loadingActive property is set to true when loading is started
// and turned to false only after succesful or failed loading. It
// is possible to set it to false by calling stopLoading method.
//
// The property was introduced as it triggers visibility of the webEngineView
// in the other parts of the code. When using loading that is linked
// to visibility, stop/start loading was observed in some conditions. It looked as if
// there is an internal optimization of webengine in the case of parallel
// loading of several pages that could use visibility as one of the decision
// making parameters.
property bool loadingActive: false
property bool reloadOnVisible: true
......@@ -52,21 +63,6 @@ WebEngineView {
onUserAgentChanged: webEngineView.reload()
}
Image {
id: thumb
visible: false
}
Timer {
id: snaphotTimer
interval: 1000
repeat: false
onTriggered: {
if (webEngineView.visible)
grabThumb();
}
}
profile {
offTheRecord: privateMode
......@@ -168,7 +164,7 @@ WebEngineView {
var ec = "";
var es = "";
if (loadRequest.status === WebEngineView.LoadStartedStatus) {
thumb.source = "";
loadingActive = true;
}
if (loadRequest.status === WebEngineView.LoadSucceededStatus) {
if (!privateMode) {
......@@ -179,14 +175,14 @@ WebEngineView {
BrowserManager.addToHistory(request);
BrowserManager.updateLastVisited(currentWebView.url);
}
grabThumb();
loadingActive = false;
}
if (loadRequest.status === WebEngineView.LoadFailedStatus) {
print("Load failed: " + loadRequest.errorCode + " " + loadRequest.errorString);
print("Load failed url: " + loadRequest.url + " " + url);
ec = loadRequest.errorCode;
es = loadRequest.errorString;
thumb.source = "";
loadingActive = false;
// update requested URL only after its clear that it fails.
// Otherwise, its updated as a part of url property update.
......@@ -223,7 +219,6 @@ WebEngineView {
if (requestedUrl !== url) {
requestedUrl = url;
}
thumb.source = "";
}
onFullScreenRequested: {
......@@ -271,7 +266,6 @@ WebEngineView {
// all kirigami pages have moved into place
if (visible) {
profile.httpUserAgent = Qt.binding(function() { return userAgent.userAgent; });
snaphotTimer.start();
if (reloadOnVisible) {
reloadOnVisible = false;
reload();
......@@ -279,9 +273,8 @@ WebEngineView {
}
}
function grabThumb() {
webEngineView.grabToImage(function(result) {
webEngineView.thumb.source = result.url;
});
function stopLoading() {
loadingActive = false;
stop();
}
}
......@@ -250,7 +250,7 @@ Kirigami.ApplicationWindow {
icon.name: currentWebView.loading ? "process-stop" : "view-refresh"
text: currentWebView.loading ? i18n("Stop loading") : i18n("Refresh")
onTriggered: {
currentWebView.loading ? currentWebView.stop() : currentWebView.reload()
currentWebView.loading ? currentWebView.stopLoading() : currentWebView.reload()
}
},
Kirigami.Action {
......
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