~unity-team/+junk/dashboard-playground

« back to all changes in this revision

Viewing changes to Notifications/Notification.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import Ubuntu.Components 0.1
 
19
 
 
20
UbuntuShape {
 
21
    id: notification
 
22
 
 
23
    property string type
 
24
    property alias iconSource: avatarIcon.source
 
25
    property alias secondaryIconSource: secondaryIcon.source
 
26
    property alias summary: summaryLabel.text
 
27
    property alias body: bodyLabel.text
 
28
    property var actions
 
29
 
 
30
    signal actionInvoked(string buttonId)
 
31
 
 
32
    implicitHeight: childrenRect.height
 
33
    color: Qt.rgba(0, 0, 0, 0.85)
 
34
    opacity: 0
 
35
 
 
36
    MouseArea {
 
37
        id: interactiveArea
 
38
 
 
39
        anchors.fill: contentColumn
 
40
        objectName: "interactiveArea"
 
41
        enabled: notification.type == "Notifications.Type.Interactive"
 
42
        onClicked: notification.actionInvoked(actions.get(0).id)
 
43
    }
 
44
 
 
45
    Column {
 
46
        id: contentColumn
 
47
 
 
48
        anchors {
 
49
            left: parent.left
 
50
            right: parent.right
 
51
            top: parent.top
 
52
            margins: spacing
 
53
        }
 
54
        height: childrenRect.height + spacing
 
55
        spacing: units.gu(1)
 
56
 
 
57
        Row {
 
58
            id: topRow
 
59
 
 
60
            spacing: contentColumn.spacing
 
61
            anchors {
 
62
                left: parent.left
 
63
                right: parent.right
 
64
            }
 
65
 
 
66
            UbuntuShape {
 
67
                id: icon
 
68
 
 
69
                objectName: "icon"
 
70
                width: units.gu(6)
 
71
                height: units.gu(6)
 
72
                visible: iconSource !== undefined && iconSource != ""
 
73
                image: Image {
 
74
                    id: avatarIcon
 
75
 
 
76
                    fillMode: Image.PreserveAspectCrop
 
77
                }
 
78
            }
 
79
 
 
80
            Image {
 
81
                id: secondaryIcon
 
82
 
 
83
                objectName: "secondaryIcon"
 
84
                width: units.gu(2)
 
85
                height: units.gu(2)
 
86
                visible: source !== undefined && source != ""
 
87
                fillMode: Image.PreserveAspectCrop
 
88
            }
 
89
 
 
90
            Column {
 
91
                id: labelColumn
 
92
                width: parent.width - x
 
93
 
 
94
                Label {
 
95
                    id: summaryLabel
 
96
 
 
97
                    objectName: "summaryLabel"
 
98
                    anchors {
 
99
                        left: parent.left
 
100
                        right: parent.right
 
101
                    }
 
102
                    fontSize: "medium"
 
103
                    font.bold: true
 
104
                    color: "#f3f3e7"
 
105
                    elide: Text.ElideRight
 
106
                }
 
107
 
 
108
                Label {
 
109
                    id: bodyLabel
 
110
 
 
111
                    objectName: "bodyLabel"
 
112
                    anchors {
 
113
                        left: parent.left
 
114
                        right: parent.right
 
115
                    }
 
116
                    visible: body != ""
 
117
                    fontSize: "small"
 
118
                    color: "#f3f3e7"
 
119
                    opacity: 0.6
 
120
                    wrapMode: Text.WordWrap
 
121
                    maximumLineCount: 10
 
122
                    elide: Text.ElideRight
 
123
                }
 
124
            }
 
125
        }
 
126
 
 
127
        Row {
 
128
            id: buttonRow
 
129
 
 
130
            objectName: "buttonRow"
 
131
            spacing: contentColumn.spacing
 
132
            layoutDirection: Qt.RightToLeft
 
133
            visible: notification.type == "Notifications.Type.SnapDecision"
 
134
            anchors {
 
135
                left: parent.left
 
136
                right: parent.right
 
137
            }
 
138
 
 
139
            Repeater {
 
140
                model: notification.actions
 
141
 
 
142
                Button {
 
143
                    objectName: "button" + index
 
144
                    color: Positioner.isFirstItem ? "#d85317" : "#cdcdcb"
 
145
                    width: (buttonRow.width - buttonRow.spacing) / 2
 
146
                    height: units.gu(4)
 
147
                    text: label
 
148
                    onClicked: notification.actionInvoked(id)
 
149
                }
 
150
            }
 
151
        }
 
152
    }
 
153
}