Lomiri
Loading...
Searching...
No Matches
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
17import QtQuick 2.12
18import Lomiri.Components 1.3
19import Lomiri.Components.Themes 1.3
20import "../Components"
21
22import Lomiri.Components.Themes.Ambiance 1.3 as Ambiance
23
24Item {
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: header.title
33 property alias showHeader: header.visible
34
35 // Set clip to prevent drawing outside the window rectangle
36 clip: true
37
38 Ambiance.Palette {
39 id: ambiancePalette
40 }
41
42 QtObject {
43 id: d
44
45 // As specified in qtmir, it will set the color value to this for fields left undefined
46 // This is also the default value of a color property in QML.
47 readonly property color undefinedColor: "#00000000"
48
49 readonly property color defaultBackgroundColor: header.visible ? ambiancePalette.normal.background : "black"
50
51 // Splash screen that shows the application icon and splashTitle
52 readonly property bool showIcon: overlaidImage.status == Image.Null && !root.showHeader
53 }
54
55 StyledItem {
56 id: styledItem
57 anchors.fill: parent
58
59 // mimic API of toolkit's MainView component required by MainViewStyle
60 property color backgroundColor: Qt.colorEqual(root.backgroundColor, d.undefinedColor) ? d.defaultBackgroundColor
61 : root.backgroundColor
62 property color headerColor: Qt.colorEqual(root.headerColor, d.undefinedColor) ? styledItem.backgroundColor
63 : root.headerColor
64 property color footerColor: Qt.colorEqual(root.footerColor, d.undefinedColor) ? styledItem.backgroundColor
65 : root.footerColor
66
67 // FIXME: fake a Theme object as to expose the Palette corresponding to the backgroundColor (see MainViewStyle.qml)
68 readonly property var fakeTheme: QtObject {
69 property string name
70 property Palette palette: Qt.createQmlObject("import QtQuick 2.12;\
71 import Lomiri.Components.Themes.%1 1.3;\
72 Palette {}".arg(styledItem.fakeTheme.name),
73 styledItem, "dynamicPalette");
74 }
75
76 // FIXME: should instead use future toolkit API:
77 // style: theme.createStyleComponent("MainViewStyle.qml", styledItem)
78 style: Component { MainViewStyle {theme: styledItem.fakeTheme} }
79 }
80
81 PageHeader {
82 id: header
83 anchors { left: parent.left; right: parent.right }
84 StyleHints {
85 foregroundColor: styledItem.fakeTheme.palette.normal.backgroundText
86 backgroundColor: "transparent"
87 dividerColor: styledItem.fakeTheme.palette.normal.base
88 }
89 }
90
91 Image {
92 id: overlaidImage
93 anchors.centerIn: parent
94 anchors.verticalCenterOffset: header.visible ? header.height / 2 : 0
95 asynchronous: true
96 cache: false
97 clip: true
98 }
99
100 LomiriShape {
101 id: iconShape
102 anchors.horizontalCenter: parent.horizontalCenter
103 anchors.verticalCenter: parent.verticalCenter
104 anchors.verticalCenterOffset: -units.gu(4)
105 width: units.gu(8)
106 height: units.gu(7.5)
107
108 visible: d.showIcon
109
110 radius: "medium"
111 aspect: LomiriShape.Flat
112 sourceFillMode: Image.PreserveAspectCrop
113 source: Image {
114 id: iconImage
115 sourceSize.width: iconShape.width
116 sourceSize.height: iconShape.height
117 source: d.showIcon ? root.icon : ""
118 }
119 }
120
121 Label {
122 id: titleLabel
123 text: root.title
124 anchors.horizontalCenter: parent.horizontalCenter
125 anchors.top: iconShape.bottom
126 anchors.topMargin: units.gu(2)
127 fontSize: "large"
128
129 color: styledItem.fakeTheme.palette.normal.backgroundText
130 visible: d.showIcon
131 }
132
133 Timer {
134 interval: 2000
135 onTriggered: spinner.running = true
136 running: true
137 }
138
139 ActivityIndicator {
140 id: spinner
141 anchors.centerIn: parent
142 anchors.verticalCenterOffset: header.visible ? header.height / 2 : Math.max(titleLabel.y / 2, units.gu(8))
143 }
144
145 MouseArea {
146 anchors.fill: parent
147 enabled: parent.visible
148 // absorb all mouse events
149 }
150}