| 1 |
/* |
| 2 |
* Copyright 2016 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.3 |
| 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 |
| 32 |
? theme.palette.normal.background |
| 33 |
: theme.palette.normal.overlay |
| 34 |
|
| 35 |
property point target |
| 36 |
property string direction: "down" |
| 37 |
property bool clipContent: false |
| 38 |
default property alias children: content.children |
| 39 |
|
| 40 |
implicitWidth: units.gu(10) |
| 41 |
implicitHeight: units.gu(8) |
| 42 |
|
| 43 |
signal showCompleted() |
| 44 |
signal hideCompleted() |
| 45 |
|
| 46 |
opacity: 0.0 |
| 47 |
|
| 48 |
function show() { |
| 49 |
hideAnimation.stop(); |
| 50 |
showAnimation.start(); |
| 51 |
} |
| 52 |
|
| 53 |
function hide() { |
| 54 |
showAnimation.stop(); |
| 55 |
hideAnimation.start(); |
| 56 |
} |
| 57 |
|
| 58 |
ParallelAnimation { |
| 59 |
id: showAnimation |
| 60 |
|
| 61 |
NumberAnimation { |
| 62 |
target: bubbleShape |
| 63 |
property: "opacity" |
| 64 |
from: 0.0 |
| 65 |
to: 1.0 |
| 66 |
duration: LomiriAnimation.FastDuration |
| 67 |
easing: LomiriAnimation.StandardEasing |
| 68 |
} |
| 69 |
NumberAnimation { |
| 70 |
target: scaleTransform |
| 71 |
property: (direction === "up" || direction === "down") ? "yScale" : "xScale" |
| 72 |
from: 0.91 |
| 73 |
to: 1.0 |
| 74 |
duration: LomiriAnimation.FastDuration |
| 75 |
easing: LomiriAnimation.StandardEasing |
| 76 |
} |
| 77 |
onStopped: showCompleted() |
| 78 |
} |
| 79 |
|
| 80 |
NumberAnimation { |
| 81 |
id: hideAnimation |
| 82 |
target: bubbleShape |
| 83 |
property: "opacity" |
| 84 |
from: 1.0 |
| 85 |
to: 0.0 |
| 86 |
duration: LomiriAnimation.FastDuration |
| 87 |
easing: LomiriAnimation.StandardEasing |
| 88 |
onStopped: hideCompleted() |
| 89 |
} |
| 90 |
|
| 91 |
transform: Scale { |
| 92 |
id: scaleTransform |
| 93 |
origin.x: direction === "right" ? bubbleShape.width : |
| 94 |
direction === "left" ? 0 : |
| 95 |
bubbleShape.width/2.0 |
| 96 |
origin.y: direction === "up" ? 0 : |
| 97 |
direction === "down" ? bubbleShape.height : |
| 98 |
bubbleShape.height/2.0 |
| 99 |
} |
| 100 |
|
| 101 |
BorderImage { |
| 102 |
id: shadow |
| 103 |
anchors.fill: parent |
| 104 |
anchors.margins: square ? -units.gu(1) : -units.dp(2) |
| 105 |
anchors.topMargin: square ? 0 : anchors.margins |
| 106 |
source: !square ? Qt.resolvedUrl("../artwork/bubble_shadow.sci") : Qt.resolvedUrl("../artwork/header_overflow_dropshadow.sci") |
| 107 |
opacity: 0.8 |
| 108 |
} |
| 109 |
|
| 110 |
LomiriShape { |
| 111 |
anchors.fill: parent |
| 112 |
aspect: LomiriShape.Flat |
| 113 |
backgroundColor: bubbleShape.color |
| 114 |
source: bubbleShape.clipContent ? shapeSource : null |
| 115 |
visible: !square |
| 116 |
} |
| 117 |
|
| 118 |
ShaderEffectSource { |
| 119 |
id: shapeSource |
| 120 |
visible: bubbleShape.clipContent |
| 121 |
sourceItem: bubbleShape.clipContent ? content : null |
| 122 |
hideSource: !square |
| 123 |
// FIXME: visible: false prevents rendering so make it a nearly |
| 124 |
// transparent 1x1 pixel instead |
| 125 |
opacity: 0.01 |
| 126 |
width: 1 |
| 127 |
height: 1 |
| 128 |
} |
| 129 |
|
| 130 |
Item { |
| 131 |
id: content |
| 132 |
anchors.fill: parent |
| 133 |
|
| 134 |
Rectangle { |
| 135 |
id: colorRect |
| 136 |
anchors.fill: parent |
| 137 |
color: bubbleShape.color |
| 138 |
visible: bubbleShape.clipContent |
| 139 |
} |
| 140 |
} |
| 141 |
} |