Unity 8
Splash.qml
1 /*
2  * Copyright 2014 Canonical Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
17 import QtQuick 2.4
18 import Ubuntu.Components 1.3
19 import Ubuntu.Components.Themes 1.3
20 import "../Components"
21 
22 import Ubuntu.Components.Themes.Ambiance 1.3 as Ambiance
23 
24 Item {
25  id: root
26 
27  property color backgroundColor: d.undefinedColor
28  property color headerColor: d.undefinedColor
29  property color footerColor: d.undefinedColor
30  property alias imageSource: overlaidImage.source
31  property url icon
32  property alias title: headerConfig.title
33  property alias showHeader: header.visible
34 
35  Ambiance.Palette {
36  id: ambiancePalette
37  }
38 
39  QtObject {
40  id: d
41 
42  // As specified in qtmir, it will set the color value to this for fields left undefined
43  // This is also the default value of a color property in QML.
44  readonly property color undefinedColor: "#00000000"
45 
46  readonly property color defaultBackgroundColor: header.visible ? ambiancePalette.normal.background : "black"
47 
48  // Splash screen that shows the application icon and splashTitle
49  readonly property bool showIcon: overlaidImage.status == Image.Null && !root.showHeader
50  }
51 
52  StyledItem {
53  id: styledItem
54  anchors.fill: parent
55 
56  // mimic API of toolkit's MainView component required by MainViewStyle
57  property color backgroundColor: Qt.colorEqual(root.backgroundColor, d.undefinedColor) ? d.defaultBackgroundColor
58  : root.backgroundColor
59  property color headerColor: Qt.colorEqual(root.headerColor, d.undefinedColor) ? styledItem.backgroundColor
60  : root.headerColor
61  property color footerColor: Qt.colorEqual(root.footerColor, d.undefinedColor) ? styledItem.backgroundColor
62  : root.footerColor
63 
64  // FIXME: fake a Theme object as to expose the Palette corresponding to the backgroundColor (see MainViewStyle.qml)
65  readonly property var fakeTheme: QtObject {
66  property string name
67  property Palette palette: Qt.createQmlObject("import QtQuick 2.4;\
68  import Ubuntu.Components.Themes.%1 1.3;\
69  Palette {}".arg(styledItem.fakeTheme.name),
70  styledItem, "dynamicPalette");
71  }
72 
73  // FIXME: should instead use future toolkit API:
74  // style: theme.createStyleComponent("MainViewStyle.qml", styledItem)
75  style: Component { MainViewStyle {theme: styledItem.fakeTheme} }
76  }
77 
78  Ambiance.PageHeadStyle {
79  // FIXME: Replace PageHeadStyle by PageHeader from Ubuntu.Components 1.3.
80  id: header
81  anchors {
82  left: parent.left;
83  right: parent.right
84  }
85  property var styledItem: header
86  // FIXME Keep in sync with SDK's MainView.qml values of these two colors
87  property color dividerColor: Qt.darker(styledItem.backgroundColor, 1.1)
88  property color panelColor: Qt.lighter(styledItem.backgroundColor, 1.1)
89  panelForegroundColor: config.foregroundColor
90  backgroundColor: "transparent"
91  config: PageHeadConfiguration {
92  id: headerConfig
93  foregroundColor: styledItem.fakeTheme.palette.normal.backgroundText
94  }
95 
96  property var contents: null
97  }
98 
99  Image {
100  id: overlaidImage
101  anchors.centerIn: parent
102  anchors.verticalCenterOffset: header.visible ? header.height / 2 : 0
103  sourceSize {
104  width: root.width
105  height: root.height
106  }
107  asynchronous: true
108  cache: false
109  }
110 
111  UbuntuShape {
112  id: iconShape
113  anchors.horizontalCenter: parent.horizontalCenter
114  anchors.verticalCenter: parent.verticalCenter
115  anchors.verticalCenterOffset: -units.gu(4)
116  width: units.gu(8)
117  height: units.gu(7.5)
118 
119  visible: d.showIcon
120 
121  radius: "medium"
122  aspect: UbuntuShape.Flat
123  sourceFillMode: Image.PreserveAspectCrop
124  source: Image {
125  id: iconImage
126  sourceSize.width: iconShape.width
127  sourceSize.height: iconShape.height
128  source: d.showIcon ? root.icon : ""
129  }
130  }
131 
132  Label {
133  text: root.title
134  anchors.horizontalCenter: parent.horizontalCenter
135  anchors.top: iconShape.bottom
136  anchors.topMargin: units.gu(2)
137  fontSize: "large"
138 
139  color: styledItem.fakeTheme.palette.normal.backgroundText
140  visible: d.showIcon
141  }
142 
143  Timer {
144  interval: 2000
145  onTriggered: spinner.running = true
146  running: true
147  }
148 
149  ActivityIndicator {
150  id: spinner
151  anchors.centerIn: header.visible ? parent : undefined
152  anchors.verticalCenterOffset: header.visible ? header.height / 2 : 0
153 
154  anchors.horizontalCenter: header.visible ? undefined : parent.horizontalCenter
155  anchors.bottom: header.visible ? undefined : parent.bottom
156  anchors.bottomMargin: header.visible ? 0 : units.gu(12)
157  }
158 
159  MouseArea {
160  anchors.fill: parent
161  enabled: parent.visible
162  // absorb all mouse events
163  }
164 }