| 1 |
import QtQuick 2.4 |
| 2 |
|
| 3 |
Item { |
| 4 |
id: root |
| 5 |
|
| 6 |
readonly property bool dismissOnClickOutside: activeOverlayLoader.item && activeOverlayLoader.item.hasOwnProperty("dismissOnClickOutside") ? |
| 7 |
activeOverlayLoader.item.dismissOnClickOutside : false |
| 8 |
|
| 9 |
property var __showPos: Qt.point(0,0) |
| 10 |
|
| 11 |
function showOverlay(comp) |
| 12 |
{ |
| 13 |
__showPos = Qt.point(0,0) |
| 14 |
activeOverlayLoader.sourceComponent = comp; |
| 15 |
activeOverlayLoader.visible = true; |
| 16 |
activeOverlayLoader.x = __showPos.x; |
| 17 |
activeOverlayLoader.y = __showPos.y; |
| 18 |
} |
| 19 |
|
| 20 |
function showOverlayAtItemOffset(comp, item, offset) |
| 21 |
{ |
| 22 |
__showPos = mapFromItem(item, offset.x, offset.y) |
| 23 |
|
| 24 |
activeOverlayLoader.sourceComponent = comp; |
| 25 |
activeOverlayLoader.visible = true; |
| 26 |
activeOverlayLoader.x = __showPos.x; |
| 27 |
activeOverlayLoader.y = __showPos.y; |
| 28 |
} |
| 29 |
|
| 30 |
function dismissOverlay() |
| 31 |
{ |
| 32 |
activeOverlayLoader.sourceComponent = null |
| 33 |
activeOverlayLoader.visible = false; |
| 34 |
} |
| 35 |
|
| 36 |
function verticalOverflowFor(itemHeight) |
| 37 |
{ |
| 38 |
// assumes we fill the whole window, so anything |
| 39 |
// extending past our bottom is overflowing |
| 40 |
var ov = (itemHeight + activeOverlayLoader.y) - root.height; |
| 41 |
return Math.max(ov, 0); |
| 42 |
} |
| 43 |
|
| 44 |
MouseArea { |
| 45 |
anchors.fill: parent |
| 46 |
hoverEnabled: true |
| 47 |
visible: activeOverlayLoader.visible && root.dismissOnClickOutside |
| 48 |
onClicked: root.dismissOverlay() |
| 49 |
} |
| 50 |
|
| 51 |
Loader |
| 52 |
{ |
| 53 |
id: activeOverlayLoader |
| 54 |
// no size, size to the component |
| 55 |
} |
| 56 |
} |