Verified Commit 71bea350 authored by Rinigus Saar's avatar Rinigus Saar Committed by Jonah Brüchert

implement tabs using repeater

To avoid complications rising from ListView, position all
webviews to cover full page and make only one of them
visible
parent fc6ac8fe
......@@ -27,30 +27,33 @@ import QtQml.Models 2.1
import QtWebEngine 1.6
ListView {
Repeater {
id: tabs
// Make sure we don't delete and re-create tabs "randomly"
cacheBuffer: 10000
// Don't animate tab switching, this just feels slow
highlightMoveDuration: 0
// No horizontal swiping between tabs, disturbs page interaction
interactive: false
property int currentIndex: -1
property var currentItem: currentIndex >= 0 && currentIndex < tabsModel.count ? tabs.itemAt(currentIndex) : null
property int pageHeight: height
property int pageWidth: width
property alias count: tabsModel.count
orientation: Qt.Horizontal
model: ListModel {
id: tabsModel
ListElement { pageurl: "about:blank" }
}
delegate: WebView {
id: wv
anchors.fill: tabs
url: pageurl;
visible: index === tabs.currentIndex
Connections {
target: tabs
onCurrentIndexChanged: {
if (currentIndex===index)
tabs.currentItem = wv;
}
}
}
function createEmptyTab() {
......@@ -70,7 +73,8 @@ ListView {
}
Component.onCompleted: {
if (initialUrl !== "") {
newTab("about:blank");
if (initialUrl) {
load(initialUrl)
} else {
console.log("Using homepage")
......
......@@ -62,7 +62,7 @@ Kirigami.ScrollablePage {
sourceRect: Qt.rect(0, 0, width * 2, height * 2)
sourceItem: {
tabs.itemAt(tabs.pageWidth * index, 0);
tabs.itemAt(index);
}
//opacity: tabs.currentIndex == index ? 1 : 0.0
......@@ -106,7 +106,7 @@ Kirigami.ScrollablePage {
print("Switch from " + tabs.currentIndex + " to tab " + index);
tabs.currentIndex = index;
tabs.positionViewAtIndex(index, ListView.Beginning);
//tabs.positionViewAtIndex(index, ListView.Beginning);
//tabs.positionViewAtEnd();
pageStack.layers.pop()
}
......@@ -132,7 +132,7 @@ Kirigami.ScrollablePage {
}
width: itemWidth
text: tabs.itemAt(tabs.pageWidth * index, 0).title
text: tabs.itemAt(index).title
elide: Qt.ElideRight
}
......
......@@ -37,7 +37,7 @@ Kirigami.ApplicationWindow {
* Browser-level functionality should use this to refer to the current
* view, rather than looking up views in the mode, as far as possible.
*/
property Item currentWebView: tabs.currentIndex < tabs.count ? tabs.currentItem : null
property Item currentWebView: tabs.currentItem
onCurrentWebViewChanged: {
print("Current WebView is now : " + tabs.currentIndex);
......
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