2 * Copyright (C) 2013,2014 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3
19 import "../Components"
24 // This is the header displayed, like "Right edge"
25 property alias title: titleLabel.text
27 // This is the block of text displayed below the header
28 property alias text: textLabel.text
30 // Whether animations are paused
33 // Whether to give the text the full width that the title has
34 property bool fullTextWidth
36 // Whether whole page (background + foreground) or just the foreground fades in
37 property bool backgroundFadesIn: false
39 // Whether whole page (background + foreground) or just the foreground fades out
40 property bool backgroundFadesOut: false
42 // The foreground Item, add children to it that you want to fade in
43 property alias foreground: foregroundExtra
45 // The text label bottom, so you can position elements relative to it
46 readonly property real textBottom: Math.max(textLabel.y + textLabel.height, errorTextLabel.y + errorTextLabel.height)
48 // The MouseArea that eats events (so you can adjust size as you will)
49 property alias mouseArea: mouseArea
51 // X/Y offsets for text
52 property real textXOffset: 0
53 property real textYOffset: 0
55 // Foreground text opacity
56 property real textOpacity: 1
60 function showError() {
69 property real _foregroundHideOpacity
71 showAnimation: StandardAnimation {
72 property: root.backgroundFadesIn ? "opacity" : "_foregroundHideOpacity"
75 duration: root.backgroundFadesIn ? UbuntuAnimation.SleepyDuration : UbuntuAnimation.BriskDuration
76 onStarted: root.visible = true
79 hideAnimation: StandardAnimation {
80 property: root.backgroundFadesOut ? "opacity" : "_foregroundHideOpacity"
82 duration: UbuntuAnimation.BriskDuration
92 readonly property real sideMargin: units.gu(5.5)
93 readonly property real verticalOffset: -units.gu(9)
94 readonly property real textXOffset: Math.max(0, root.textXOffset - sideMargin + units.gu(2))
96 property real fadeInOffset: {
97 if (showAnimation.running) {
98 var opacity = root[root.showAnimation.property]
99 return (1 - opacity) * units.gu(3);
111 MouseArea { // eat any errant presses
125 opacity: root._foregroundHideOpacity
129 opacity: root.textOpacity
134 top: parent.verticalCenter
135 topMargin: d.verticalOffset + root.textYOffset
137 leftMargin: d.sideMargin + d.textXOffset
139 width: parent.width - d.sideMargin * 2
140 horizontalAlignment: Text.AlignLeft
142 font.weight: Font.Light
143 font.pixelSize: units.gu(3.5)
149 top: titleLabel.bottom
150 topMargin: units.gu(2)
152 leftMargin: d.sideMargin + d.textXOffset
154 width: (parent.width - d.sideMargin * 2) * (fullTextWidth ? 1 : 0.66)
155 horizontalAlignment: Text.AlignLeft
157 font.weight: Font.Light
158 font.pixelSize: units.gu(2.5)
161 // We use two separate labels like this rather than just changing
162 // the text of the above labels because we want to know where to place
163 // sliders (via root.textBottom) without having that place change
164 // as the text changes length.
167 objectName: "errorTitleLabel"
170 left: titleLabel.left
172 width: titleLabel.width
173 horizontalAlignment: titleLabel.horizontalAlignment
174 wrapMode: titleLabel.wrapMode
175 font.weight: titleLabel.font.weight
176 font.pixelSize: titleLabel.font.pixelSize
178 text: i18n.tr("You almost got it!")
183 objectName: "errorTextLabel"
185 top: errorTitleLabel.bottom
186 topMargin: textLabel.anchors.topMargin
189 width: textLabel.width
190 horizontalAlignment: textLabel.horizontalAlignment
191 wrapMode: textLabel.wrapMode
192 font.weight: textLabel.font.weight
193 font.pixelSize: textLabel.font.pixelSize
195 text: i18n.tr("Try again.")
199 // A place for subclasses to add extra widgets
208 when: errorTimer.running
209 PropertyChanges { target: titleLabel; opacity: 0 }
210 PropertyChanges { target: textLabel; opacity: 0 }
211 PropertyChanges { target: errorTitleLabel; opacity: 1 }
212 PropertyChanges { target: errorTextLabel; opacity: 1 }
215 transitions: Transition {
218 SequentialAnimation {
223 duration: UbuntuAnimation.BriskDuration
228 duration: UbuntuAnimation.BriskDuration
233 target: errorTitleLabel
235 duration: UbuntuAnimation.BriskDuration
238 target: errorTextLabel
240 duration: UbuntuAnimation.BriskDuration