| 1 |
/* |
| 2 |
* Copyright 2013-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 Lomiri.Components 1.2 |
| 19 |
|
| 20 |
Item { |
| 21 |
id: bubbleShape |
| 22 |
|
| 23 |
/*! |
| 24 |
Do not use an LomiriShape but a Rectangle as the background of the BubbleShape. |
| 25 |
*/ |
| 26 |
property bool square: false |
| 27 |
|
| 28 |
/*! |
| 29 |
The background color of the bubble. |
| 30 |
*/ |
| 31 |
property color color: square ? Theme.palette.normal.background : Theme.palette.normal.overlay |
| 32 |
|
| 33 |
property point target |
| 34 |
property string direction: "down" |
| 35 |
property bool clipContent: false |
| 36 |
default property alias children: content.children |
| 37 |
// FIXME: This should not be necessary. See |
| 38 |
// https://bugs.launchpad.net/lomiri-ui-toolkit/+bug/1214978 |
| 39 |
property alias arrowSource: arrow.source |
| 40 |
|
| 41 |
implicitWidth: units.gu(10) |
| 42 |
implicitHeight: units.gu(8) |
| 43 |
|
| 44 |
signal showCompleted() |
| 45 |
signal hideCompleted() |
| 46 |
|
| 47 |
opacity: 0.0 |
| 48 |
|
| 49 |
function show() { |
| 50 |
hideAnimation.stop(); |
| 51 |
showAnimation.start(); |
| 52 |
} |
| 53 |
|
| 54 |
function hide() { |
| 55 |
showAnimation.stop(); |
| 56 |
hideAnimation.start(); |
| 57 |
} |
| 58 |
|
| 59 |
ParallelAnimation { |
| 60 |
id: showAnimation |
| 61 |
|
| 62 |
NumberAnimation { |
| 63 |
target: bubbleShape |
| 64 |
property: "opacity" |
| 65 |
from: 0.0 |
| 66 |
to: 1.0 |
| 67 |
duration: LomiriAnimation.FastDuration |
| 68 |
easing: LomiriAnimation.StandardEasing |
| 69 |
} |
| 70 |
NumberAnimation { |
| 71 |
target: scaleTransform |
| 72 |
property: (direction === "up" || direction === "down") ? "yScale" : "xScale" |
| 73 |
from: 0.91 |
| 74 |
to: 1.0 |
| 75 |
duration: LomiriAnimation.FastDuration |
| 76 |
easing: LomiriAnimation.StandardEasing |
| 77 |
} |
| 78 |
onStopped: showCompleted() |
| 79 |
} |
| 80 |
|
| 81 |
NumberAnimation { |
| 82 |
id: hideAnimation |
| 83 |
target: bubbleShape |
| 84 |
property: "opacity" |
| 85 |
from: 1.0 |
| 86 |
to: 0.0 |
| 87 |
duration: LomiriAnimation.FastDuration |
| 88 |
easing: LomiriAnimation.StandardEasing |
| 89 |
onStopped: hideCompleted() |
| 90 |
} |
| 91 |
|
| 92 |
transform: Scale { |
| 93 |
id: scaleTransform |
| 94 |
origin.x: direction === "right" ? bubbleShape.width : |
| 95 |
direction === "left" ? 0 : |
| 96 |
bubbleShape.width/2.0 |
| 97 |
origin.y: direction === "up" ? 0 : |
| 98 |
direction === "down" ? bubbleShape.height : |
| 99 |
bubbleShape.height/2.0 |
| 100 |
} |
| 101 |
|
| 102 |
BorderImage { |
| 103 |
id: shadow |
| 104 |
anchors.fill: parent |
| 105 |
anchors.margins: square ? -units.gu(1) : -units.dp(2) |
| 106 |
anchors.topMargin: square ? 0 : anchors.margins |
| 107 |
source: !square ? Qt.resolvedUrl("../artwork/bubble_shadow.sci") : Qt.resolvedUrl("../artwork/header_overflow_dropshadow.sci") |
| 108 |
opacity: 0.8 |
| 109 |
} |
| 110 |
|
| 111 |
LomiriShape { |
| 112 |
anchors.fill: parent |
| 113 |
borderSource: "none" |
| 114 |
color: Theme.palette.normal.overlay |
| 115 |
image: bubbleShape.clipContent ? shapeSource : null |
| 116 |
visible: !square |
| 117 |
} |
| 118 |
|
| 119 |
ShaderEffectSource { |
| 120 |
id: shapeSource |
| 121 |
visible: bubbleShape.clipContent |
| 122 |
sourceItem: bubbleShape.clipContent ? content : null |
| 123 |
hideSource: !square |
| 124 |
// FIXME: visible: false prevents rendering so make it a nearly |
| 125 |
// transparent 1x1 pixel instead |
| 126 |
opacity: 0.01 |
| 127 |
width: 1 |
| 128 |
height: 1 |
| 129 |
} |
| 130 |
|
| 131 |
Item { |
| 132 |
id: content |
| 133 |
anchors.fill: parent |
| 134 |
|
| 135 |
Rectangle { |
| 136 |
id: colorRect |
| 137 |
anchors.fill: parent |
| 138 |
color: bubbleShape.color |
| 139 |
visible: bubbleShape.clipContent |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
Item { |
| 144 |
x: target.x |
| 145 |
y: target.y |
| 146 |
|
| 147 |
Image { |
| 148 |
id: arrow |
| 149 |
|
| 150 |
visible: !square && bubbleShape.direction != "none" |
| 151 |
|
| 152 |
function directionToRotation(direction) { |
| 153 |
switch (direction) { |
| 154 |
case "up": |
| 155 |
return 180; |
| 156 |
case "left": |
| 157 |
return 90; |
| 158 |
case "right": |
| 159 |
return -90; |
| 160 |
default: // "down" or "none" |
| 161 |
return 0; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
x: -width / 2.0 |
| 166 |
y: -height |
| 167 |
transformOrigin: Item.Bottom |
| 168 |
rotation: directionToRotation(bubbleShape.direction) |
| 169 |
source: Qt.resolvedUrl("../artwork/bubble_arrow.png") |
| 170 |
} |
| 171 |
} |
| 172 |
} |