ListWebView.qml 2.75 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/***************************************************************************
 *                                                                         *
 *   Copyright 2014-2015 Sebastian Kügler <sebas@kde.org>                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 *                                                                         *
 ***************************************************************************/

import QtQuick 2.3
Jonah Brüchert's avatar
Jonah Brüchert committed
23
import QtQuick.Controls 2.0
24
25
26
import QtQuick.Controls.Styles 1.0
import QtQml.Models 2.1

Jonah Brüchert's avatar
Jonah Brüchert committed
27
import QtWebEngine 1.6
28
29
30
31
32
33
34
35
36
37
38
39


ListView {
    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

40
41
    property int pageHeight: height
    property int pageWidth: width
42
43
44
45
46
47
48

    property alias count: tabsModel.count

    orientation: Qt.Horizontal

    model: ListModel {
        id: tabsModel
49
        ListElement { pageurl: "https://plasma-mobile.org" }
50
51
52
53
54
55
56
57
58
59
60
61
62
    }

    delegate: WebView {
        url: pageurl;
    }

    function createEmptyTab() {
        var t = newTab("");
        return t;
    }

    function newTab(url) {
        tabsModel.append({pageurl: url});
63
        tabs.currentIndex = tabs.count - 1
64
    }
65

66
67
68
69
70
71
    function closeTab(index) {
        tabsModel.remove(index)
        if (tabs.count === 0)
            createEmptyTab()
    }

72
73
74
75
76
77
78
79
    Component.onCompleted: {
        if (initialUrl !== "") {
            load(initialUrl)
        } else {
            console.log("Using homepage")
            load(browserManager.homepage)
        }
    }
80
}