Tabs.qml 6.35 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
    Kirigami.ColumnView.fillWidth: false
39

40
    property int itemHeight: Math.round(itemWidth/ 3 * 2)
41
    property int itemWidth: Kirigami.Units.gridUnit * 9
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

    //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
64
                    tabs.itemAt(index);
65
66
67
68
69
70
71
72
73
74
75
76
                }
                //opacity: tabs.currentIndex == index ? 1 : 0.0


                Behavior on height {
                    SequentialAnimation {
                        ScriptAction {
                            script: {
                                print("Animation start");
                                // switch to tabs
                            }
                        }
77
78
                        NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad }
                        NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad; target: contentView; property: opacity }
79
80
81
82
83
84
85
86
87
88
                        ScriptAction {
                            script: {
                                print("Animation done");
                                contentView.state = "hidden"
                            }
                        }
                    }
                }

                Behavior on width {
89
                    NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad}
90
91
92

                }

93
94
95
96
97
98
99
100
101
102
103
104
105
                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; }
                    }
                }
106
107
108
109
110
111
112
            }
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    print("Switch from " + tabs.currentIndex + "  to tab " + index);

                    tabs.currentIndex = index;
Rinigus Saar's avatar
Rinigus Saar committed
113
                    //tabs.positionViewAtIndex(index, ListView.Beginning);
114
                    //tabs.positionViewAtEnd();
115
                    pageStack.pop()
116
117
                }
            }
118
119
120

            Controls.ToolButton {
                icon.name: "window-close"
Jonah Brüchert's avatar
Jonah Brüchert committed
121
122
                height: Kirigami.gridUnit
                width: height
123
                anchors.right: parent.right
Jonah Brüchert's avatar
Jonah Brüchert committed
124
                anchors.rightMargin: Kirigami.Units.smallSpacing
125
                anchors.top: parent.top
Jonah Brüchert's avatar
Jonah Brüchert committed
126
                anchors.topMargin: Kirigami.Units.smallSpacing
127
128
                onClicked: tabs.closeTab(index)
            }
Jonah Brüchert's avatar
Jonah Brüchert committed
129
130

            Controls.Label {
131
                id: label
Jonah Brüchert's avatar
Jonah Brüchert committed
132
133
134
135
136
137
138
139
                anchors {
                    left: tabItem.left
                    right: tabItem.right
                    bottom: tabItem.bottom
                    margins: Kirigami.Units.gridUnit * 0.5
                }
                width: itemWidth

140
                text: tabs.itemAt(index) != null ? tabs.itemAt(index).title : ""
Jonah Brüchert's avatar
Jonah Brüchert committed
141
142
143
                elide: Qt.ElideRight

            }
144
145
        }

146
        footer: Item {
147
148
            width: itemWidth
            height: itemHeight
Jonah Brüchert's avatar
Jonah Brüchert committed
149
            Kirigami.Icon {
150
151
152
153
154
155
156
                anchors.fill: parent
                anchors.margins: Math.round(itemHeight / 4)
                source: "list-add"
            }
            MouseArea {
                anchors.fill: parent
                onClicked: {
157
                    tabs.newTab(browserManager.homepage)
158
159
160
                    //addressBar.forceActiveFocus();
                    //addressBar.selectAll();
                    tabs.currentIndex = tabs.count - 1;
161
                    pageStack.pop()
162
163
164
165
166
                }
            }
        }
    }
}