8import QtQuick.Controls as QQC2
10import org.kde.kirigami as Kirigami
22 readonly property int maximumNotificationWidth: {
23 if (Kirigami.Settings.isMobile) {
24 return applicationWindow().width - Kirigami.Units.largeSpacing * 4
26 return Math.min(Kirigami.Units.gridUnit * 25, applicationWindow().width / 1.5)
30 readonly property int maximumNotificationCount: 4
32 function showNotification(message, timeout, actionText, callBack) {
39 if (timeout ===
"short") {
41 }
else if (timeout ===
"long") {
43 }
else if (timeout > 0) {
48 const callBackWrapperObj = callBackWrapper.createObject(listView, { callBack })
51 notificationsModel.append({
53 actionButtonText: actionText ||
"",
54 closeInterval: interval,
55 callBackWrapper: callBackWrapperObj
58 if (notificationsModel.count === maximumNotificationCount) {
59 if (listView.itemAtIndex(0).hovered ===
true) {
70 function hideNotification(index = 0) {
71 if (index >= 0 && notificationsModel.count > index) {
72 const callBackWrapperObj = notificationsModel.get(index).callBackWrapper
73 if (callBackWrapperObj) {
74 callBackWrapperObj.destroy()
76 notificationsModel.remove(index)
81 height: Math.min(applicationWindow().height, Kirigami.Units.gridUnit * 10)
83 implicitHeight: listView.implicitHeight
84 implicitWidth: listView.implicitWidth
86 Kirigami.Theme.inherit:
false
87 Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
90 id: notificationsModel
97 anchors.bottomMargin: Kirigami.Units.largeSpacing
99 implicitWidth: root.maximumNotificationWidth
100 spacing: Kirigami.Units.smallSpacing
101 model: notificationsModel
102 verticalLayoutDirection: ListView.BottomToTop
103 keyNavigationEnabled:
false
116 duration: Kirigami.Units.longDuration
117 easing.type: Easing.OutCubic
121 from: addAnimation.ViewTransition.destination.y - Kirigami.Units.gridUnit * 3
122 duration: Kirigami.Units.longDuration
123 easing.type: Easing.OutCubic
127 displaced: Transition {
132 duration: Kirigami.Units.longDuration
133 easing.type: Easing.InOutCubic
149 duration: Kirigami.Units.longDuration
150 easing.type: Easing.InCubic
154 to: Kirigami.Units.gridUnit * 3
155 duration: Kirigami.Units.longDuration
156 easing.type: Easing.InCubic
159 property:
"transformOrigin"
166 duration: Kirigami.Units.longDuration
167 easing.type: Easing.InCubic
171 delegate: QQC2.Control {
176 anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined
177 width: Math.min(implicitWidth, maximumNotificationWidth)
180 void contentItem.implicitHeight;
181 return Math.max(implicitBackgroundHeight + topInset + bottomInset,
182 implicitContentHeight + topPadding + bottomPadding);
185 if (delegate.hovered) {
187 }
else if (delegate.index === 0) {
194 leftPadding: Kirigami.Units.largeSpacing
195 rightPadding: Kirigami.Units.largeSpacing
196 topPadding: Kirigami.Units.largeSpacing
197 bottomPadding: Kirigami.Units.largeSpacing
199 contentItem: RowLayout {
202 Kirigami.Theme.inherit:
false
203 Kirigami.Theme.colorSet: root.Kirigami.Theme.colorSet
205 spacing: Kirigami.Units.mediumSpacing
208 acceptedButtons:
Qt.LeftButton
209 onTapped: eventPoint => hideNotification(index)
213 interval: model.closeInterval
214 running: !delegate.hovered
215 onTriggered: hideNotification(index)
221 elide: Text.ElideRight
223 Layout.fillWidth:
true
224 Layout.alignment:
Qt.AlignVCenter
229 text: model.actionButtonText
230 visible: text.length > 0
231 Layout.alignment:
Qt.AlignVCenter
233 const callBack = model.callBackWrapper.callBack
234 hideNotification(index)
235 if (callBack && (typeof callBack ===
"function")) {
241 background: Kirigami.ShadowedRectangle {
242 Kirigami.Theme.inherit:
false
243 Kirigami.Theme.colorSet: root.Kirigami.Theme.colorSet
245 size: Kirigami.Units.gridUnit/2
246 color:
Qt.rgba(0, 0, 0, 0.4)
249 radius: Kirigami.Units.cornerRadius
250 color: Kirigami.Theme.backgroundColor
258 property var callBack
QString label(StandardShortcut id)