Unity 8
PreviewOverlay.qml
1 /*
2  * Copyright (C) 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 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 1.1
19 import "../../Components"
20 
21 Rectangle {
22  id: overlay
23  objectName: "overlay"
24 
25  readonly property real scaleProgress: (scale - initialScale) / (1.0 - initialScale)
26 
27  property alias delegate: loader.sourceComponent
28  property alias delegateItem: loader.item
29  property alias headerShown: overlayHeader.shown
30  property bool shown: false
31  property bool opening: false
32  property real initialX: 0
33  property real initialY: 0
34  property real initialScale: 0
35 
36  visible: scale > initialScale
37  clip: visible && scale < 1.0
38  scale: shown ? 1.0 : initialScale
39  transformOrigin: Item.TopLeft
40  transform: Translate {
41  x: overlay.initialX - overlay.initialX * overlay.scaleProgress
42  y: overlay.initialY - overlay.initialY * overlay.scaleProgress
43  }
44  color: Qt.rgba(0, 0, 0, scaleProgress)
45  radius: units.gu(1) - units.gu(1) * scaleProgress
46 
47  function show() {
48  opening = true;
49  shown = true;
50  }
51 
52  function hide() {
53  opening = false;
54  shown = false;
55  }
56 
57  Behavior on scale {
58  UbuntuNumberAnimation {
59  duration: overlay.opening ? UbuntuAnimation.FastDuration :
60  UbuntuAnimation.FastDuration / 2
61  }
62  }
63 
64  Loader {
65  id: loader
66  anchors.fill: parent
67  }
68 
69  Rectangle {
70  id: overlayHeader
71 
72  property bool shown: true
73 
74  anchors {
75  left: parent.left
76  right: parent.right
77  }
78  height: units.gu(7)
79  visible: opacity > 0
80  opacity: overlay.scaleProgress > 0.6 && shown ? 0.8 : 0
81  color: "black"
82 
83  Behavior on opacity {
84  UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration }
85  }
86 
87  AbstractButton {
88  id: overlayCloseButton
89  objectName: "overlayCloseButton"
90  anchors {
91  top: parent.top
92  bottom: parent.bottom
93  }
94  width: units.gu(8)
95  height: width
96 
97  onClicked: overlay.hide()
98 
99  Rectangle {
100  anchors.fill: parent
101  color: Qt.rgba(1.0, 1.0, 1.0, 0.3)
102  visible: overlayCloseButton.pressed
103  }
104 
105  Icon {
106  id: icon
107  anchors.centerIn: parent
108  width: units.gu(2.5)
109  height: width
110  color: Theme.palette.normal.foregroundText
111  name: "close"
112  }
113  }
114  }
115 }