| 1 |
// SPDX-FileCopyrightText: 2018 James Turner |
| 2 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 3 |
|
| 4 |
import QtQuick 2.4 |
| 5 |
import QtQml 2.4 |
| 6 |
|
| 7 |
import FlightGear.Launcher 1.0 |
| 8 |
import FlightGear 1.0 |
| 9 |
|
| 10 |
Item { |
| 11 |
id: root |
| 12 |
width: 500 |
| 13 |
|
| 14 |
readonly property int ourMargin: Style.margin * 2 |
| 15 |
|
| 16 |
|
| 17 |
Component { |
| 18 |
id: notificationBox |
| 19 |
|
| 20 |
Rectangle { |
| 21 |
id: boxRoot |
| 22 |
|
| 23 |
property alias content: contentLoader.sourceComponent |
| 24 |
|
| 25 |
width: notificationsColumn.width |
| 26 |
height: contentLoader.height + (ourMargin * 2) |
| 27 |
|
| 28 |
clip: true |
| 29 |
color: Style.themeColor |
| 30 |
border.width: 1 |
| 31 |
border.color: Qt.darker(Style.themeColor) |
| 32 |
|
| 33 |
Rectangle { |
| 34 |
id: background |
| 35 |
anchors.fill: parent |
| 36 |
z: -1 |
| 37 |
opacity: Style.panelOpacity |
| 38 |
color: "white" |
| 39 |
} |
| 40 |
|
| 41 |
// capture mouse events |
| 42 |
MouseArea { |
| 43 |
anchors.fill: parent |
| 44 |
hoverEnabled: true |
| 45 |
} |
| 46 |
|
| 47 |
Loader { |
| 48 |
// height is not anchored, can float |
| 49 |
anchors { |
| 50 |
top: parent.top |
| 51 |
left: parent.left |
| 52 |
right: closeButton.left |
| 53 |
margins: ourMargin |
| 54 |
} |
| 55 |
|
| 56 |
id: contentLoader |
| 57 |
source: model.source |
| 58 |
|
| 59 |
// don't set height, comes from content |
| 60 |
} |
| 61 |
|
| 62 |
Connections { |
| 63 |
target: contentLoader.item |
| 64 |
function onDismiss() { |
| 65 |
_notifications.dismissIndex(model.index) |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
Image { |
| 70 |
id: closeButton |
| 71 |
source: "image://colored-icon/cross?themeContrast" |
| 72 |
|
| 73 |
anchors { |
| 74 |
verticalCenter: parent.verticalCenter |
| 75 |
right: parent.right |
| 76 |
margins: ourMargin |
| 77 |
} |
| 78 |
|
| 79 |
MouseArea { |
| 80 |
anchors.fill: parent |
| 81 |
cursorShape: Qt.PointingHandCursor |
| 82 |
|
| 83 |
onClicked: { |
| 84 |
if (contentLoader.item.dismissed) { |
| 85 |
contentLoader.item.dismissed(); |
| 86 |
} |
| 87 |
|
| 88 |
_notifications.dismissIndex(model.index) |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
} // of notification box |
| 93 |
} |
| 94 |
|
| 95 |
// ensure clicks 'near' the notifications don't go to other UI |
| 96 |
MouseArea { |
| 97 |
width: parent.width |
| 98 |
height: notificationsColumn.height |
| 99 |
} |
| 100 |
|
| 101 |
Column { |
| 102 |
id: notificationsColumn |
| 103 |
// height of this is determined by content. This is important |
| 104 |
// so the mouse area above only blocks clicks near active |
| 105 |
// notifications |
| 106 |
|
| 107 |
anchors { |
| 108 |
right: parent.right |
| 109 |
top: parent.top |
| 110 |
left: parent.left |
| 111 |
margins: Style.strutSize |
| 112 |
} |
| 113 |
|
| 114 |
spacing: Style.strutSize |
| 115 |
|
| 116 |
Repeater { |
| 117 |
model: _notifications.active |
| 118 |
delegate: notificationBox |
| 119 |
} |
| 120 |
} // of boxes column |
| 121 |
|
| 122 |
} |