Tabs.qml 5.98 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 as Controls
24
import QtGraphicalEffects 1.0
25
26
27
28
29

//import QtWebEngine 1.0

import QtQuick.Layouts 1.0

30
import org.kde.kirigami 2.7 as Kirigami
31
32
33
34
// import org.kde.plasma.components 2.0 as PlasmaComponents
// import org.kde.plasma.extras 2.0 as PlasmaExtras


35
Kirigami.ScrollablePage {
36
    id: tabsRoot
37
    title: i18n("Tabs")
38

39
    Kirigami.ColumnView.fillWidth: false
40

41
42
43
44
45
46
47
48
49
50
    actions.main: Kirigami.Action {
        icon.name: "list-add"
        text: i18n("New")
        onTriggered: {
            tabs.newTab(browserManager.homepage)
            tabs.currentIndex = tabs.count - 1;
            pageStack.pop()
        }
    }

51
    property int itemHeight: Math.round(itemWidth/ 3 * 2)
52
    property int itemWidth: Kirigami.Units.gridUnit * 9
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

    //Rectangle { anchors.fill: parent; color: "brown"; opacity: 0.5; }

    GridView {
        anchors.fill: parent
        model: tabs.model
        cellWidth: itemWidth
        cellHeight: itemHeight

        delegate: Item {
            id: tabItem
            width: itemWidth
            height: itemHeight
            ShaderEffectSource {
                id: shaderItem

                //live: true
                anchors.fill: parent

                sourceRect: Qt.rect(0, 0, width * 2, height * 2)

                sourceItem: {
Rinigus Saar's avatar
Rinigus Saar committed
75
                    tabs.itemAt(index);
76
77
78
79
80
81
82
83
84
85
86
87
                }
                //opacity: tabs.currentIndex == index ? 1 : 0.0


                Behavior on height {
                    SequentialAnimation {
                        ScriptAction {
                            script: {
                                print("Animation start");
                                // switch to tabs
                            }
                        }
88
89
                        NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad }
                        NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad; target: contentView; property: opacity }
90
91
92
93
94
95
96
97
98
99
                        ScriptAction {
                            script: {
                                print("Animation done");
                                contentView.state = "hidden"
                            }
                        }
                    }
                }

                Behavior on width {
100
                    NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad}
101
102
103

                }

104
105
106
107
108
109
110
111
112
113
114
115
116
                LinearGradient {
                    id: grad
                    anchors.fill: parent
                    cached: true
                    start: Qt.point(0,0)
                    end: Qt.point(0,height)
                    gradient: Gradient {
                        GradientStop { position: 0.0; color: "transparent"; }
                        GradientStop { position: Math.max(0.25, (grad.height - label.x * 4) / grad.height); color: "transparent"; }
                        GradientStop { position: Math.max(0.25, (grad.height - (label.x + label.height) / 2) / grad.height); color: Kirigami.Theme.backgroundColor; }
                        GradientStop { position: 1; color: Kirigami.Theme.backgroundColor; }
                    }
                }
117
118
119
120
121
122
123
            }
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    print("Switch from " + tabs.currentIndex + "  to tab " + index);

                    tabs.currentIndex = index;
Rinigus Saar's avatar
Rinigus Saar committed
124
                    //tabs.positionViewAtIndex(index, ListView.Beginning);
125
                    //tabs.positionViewAtEnd();
126
                    pageStack.pop()
127
128
                }
            }
129
130
131

            Controls.ToolButton {
                icon.name: "window-close"
Jonah Brüchert's avatar
Jonah Brüchert committed
132
133
                height: Kirigami.gridUnit
                width: height
134
                anchors.right: parent.right
Jonah Brüchert's avatar
Jonah Brüchert committed
135
                anchors.rightMargin: Kirigami.Units.smallSpacing
136
                anchors.top: parent.top
Jonah Brüchert's avatar
Jonah Brüchert committed
137
                anchors.topMargin: Kirigami.Units.smallSpacing
138
139
                onClicked: tabs.closeTab(index)
            }
Jonah Brüchert's avatar
Jonah Brüchert committed
140
141

            Controls.Label {
142
                id: label
Jonah Brüchert's avatar
Jonah Brüchert committed
143
144
145
146
147
148
149
150
                anchors {
                    left: tabItem.left
                    right: tabItem.right
                    bottom: tabItem.bottom
                    margins: Kirigami.Units.gridUnit * 0.5
                }
                width: itemWidth

151
                text: tabs.itemAt(index) != null ? tabs.itemAt(index).title : ""
Jonah Brüchert's avatar
Jonah Brüchert committed
152
153
154
                elide: Qt.ElideRight

            }
155
156
157
        }
    }
}