~mhall119/webbrowser-app/alt-num-shortcut

« back to all changes in this revision

Viewing changes to src/app/webbrowser/TabItem.qml

  • Committer: CI Train Bot
  • Author(s): Ugo Riboni
  • Date: 2015-09-22 01:27:19 UTC
  • mfrom: (1145.4.24 tabs-visual-refresh)
  • Revision ID: ci-train-bot@canonical.com-20150922012719-p4us0pya5pc4wmbq
Implement the visual refresh for the tabs in all screen modes.
Approved by: PS Jenkins bot, Olivier Tilloy

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 Canonical Ltd.
 
3
 *
 
4
 * This file is part of webbrowser-app.
 
5
 *
 
6
 * webbrowser-app is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * webbrowser-app is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.4
 
20
import Ubuntu.Components 1.3
 
21
import ".."
 
22
 
 
23
Item {
 
24
    id: tabItem
 
25
 
 
26
    property bool incognito: false
 
27
    property bool active: false
 
28
    property bool hoverable: true
 
29
    property int rightMargin: tabImage.anchors.rightMargin
 
30
 
 
31
    property alias title: label.text
 
32
    property alias icon: favicon.source
 
33
 
 
34
    signal selected()
 
35
    signal closed()
 
36
 
 
37
    BorderImage {
 
38
        id: tabImage
 
39
        anchors.fill: parent
 
40
        anchors.rightMargin: tabItem.rightMargin
 
41
        source: "assets/tab-%1%2.sci".arg((active) ? "active" :
 
42
                                          (hoverArea.containsMouse ? "hover" : "non-active"))
 
43
                                     .arg(formFactor == "desktop" ? "-desktop" : "")
 
44
 
 
45
        Favicon {
 
46
            id: favicon
 
47
            anchors.verticalCenter: parent.verticalCenter
 
48
            anchors.left: parent.left
 
49
            anchors.leftMargin: units.gu(2)
 
50
            shouldCache: !incognito
 
51
        }
 
52
 
 
53
        Item {
 
54
            anchors.left: favicon.right
 
55
            anchors.leftMargin: units.gu(1)
 
56
            anchors.top: parent.top
 
57
            anchors.bottom: parent.bottom
 
58
            anchors.right: closeButton.left
 
59
            anchors.rightMargin: units.gu(1)
 
60
 
 
61
            Label {
 
62
                id: label
 
63
                anchors.fill: parent
 
64
                verticalAlignment: Text.AlignVCenter
 
65
                clip: true
 
66
                fontSize: "small"
 
67
            }
 
68
 
 
69
            Rectangle {
 
70
                anchors.centerIn: parent
 
71
                width: label.paintedHeight
 
72
                height: label.width + units.gu(0.25)
 
73
                rotation: 90
 
74
                gradient: Gradient {
 
75
                    GradientStop {
 
76
                        position: 0.0;
 
77
                        color: active ? "#f8f8f8" :
 
78
                               (hoverArea.containsMouse ? "#cecece" : "#dedede")
 
79
                    }
 
80
                    GradientStop { position: 0.33; color: "transparent" }
 
81
                }
 
82
            }
 
83
        }
 
84
 
 
85
        MouseArea {
 
86
            anchors.left: parent.left
 
87
            anchors.top: parent.top
 
88
            anchors.bottom: parent.bottom
 
89
            anchors.right: closeButton.left
 
90
            onClicked: tabItem.selected()
 
91
        }
 
92
 
 
93
        AbstractButton {
 
94
            id: closeButton
 
95
            objectName: "closeButton"
 
96
 
 
97
            anchors.top: parent.top
 
98
            anchors.bottom: parent.bottom
 
99
            anchors.right: parent.right
 
100
            width: units.gu(2)
 
101
 
 
102
            Icon {
 
103
                height: units.gu(1.5)
 
104
                width: height
 
105
                anchors.right: parent.right
 
106
                anchors.rightMargin: units.gu(1)
 
107
                anchors.verticalCenter: parent.verticalCenter
 
108
                name: "close"
 
109
            }
 
110
 
 
111
            onTriggered: closed()
 
112
        }
 
113
 
 
114
        MouseArea {
 
115
            id: hoverArea
 
116
            anchors.fill: parent
 
117
            hoverEnabled: !tabItem.active && tabItem.hoverable
 
118
            propagateComposedEvents: true
 
119
            acceptedButtons: Qt.MiddleButton
 
120
            onClicked: tabItem.closed()
 
121
        }
 
122
    }
 
123
}
 
124