2021-12-22 23:29:00 +00:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
|
|
|
|
|
* SPDX-FileCopyrightText: 2018-2019 Kai Uwe Broulik <kde@privat.broulik.de>
|
2024-07-27 03:47:44 +00:00
|
|
|
*
|
2021-12-22 23:29:00 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import QtQuick 2.15
|
|
|
|
|
import QtQuick.Layouts 1.1
|
|
|
|
|
|
2023-07-25 01:13:52 +00:00
|
|
|
import org.kde.kirigami 2.20 as Kirigami
|
2021-12-22 23:29:00 +00:00
|
|
|
import org.kde.plasma.components 3.0 as PlasmaComponents
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: actionContainer
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
required property BaseNotificationItem notification
|
2024-11-07 16:13:06 +00:00
|
|
|
property bool popupNotification: false
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
implicitHeight: Math.max(actionFlow.implicitHeight, replyLoader.height)
|
|
|
|
|
visible: actionRepeater.count > 0
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2024-11-07 16:13:06 +00:00
|
|
|
signal takeFocus()
|
|
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
Flow {
|
|
|
|
|
id: actionFlow
|
|
|
|
|
width: parent.width
|
2023-07-25 01:13:52 +00:00
|
|
|
spacing: Kirigami.Units.smallSpacing
|
2021-12-22 23:29:00 +00:00
|
|
|
layoutDirection: Qt.RightToLeft
|
|
|
|
|
enabled: !replyLoader.active
|
|
|
|
|
opacity: replyLoader.active ? 0 : 1
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
Behavior on opacity {
|
|
|
|
|
NumberAnimation {
|
2023-07-25 01:13:52 +00:00
|
|
|
duration: Kirigami.Units.longDuration
|
2021-12-22 23:29:00 +00:00
|
|
|
easing.type: Easing.InOutQuad
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// action buttons
|
|
|
|
|
Repeater {
|
|
|
|
|
id: actionRepeater
|
|
|
|
|
|
|
|
|
|
model: {
|
|
|
|
|
const buttons = [];
|
|
|
|
|
var actionNames = (notificationItem.actionNames || []);
|
|
|
|
|
var actionLabels = (notificationItem.actionLabels || []);
|
|
|
|
|
for (var i = actionNames.length - 1; i >= 0; --i) {
|
|
|
|
|
buttons.push({
|
|
|
|
|
actionName: actionNames[i],
|
|
|
|
|
label: actionLabels[i]
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
if (notificationItem.hasReplyAction) {
|
|
|
|
|
buttons.unshift({
|
|
|
|
|
actionName: "inline-reply",
|
|
|
|
|
label: notificationItem.replyActionLabel || i18nc("Reply to message", "Reply")
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
return buttons;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlasmaComponents.ToolButton {
|
|
|
|
|
flat: false
|
|
|
|
|
text: modelData.label || ""
|
|
|
|
|
|
2024-11-07 16:13:06 +00:00
|
|
|
visible: !(notificationItem.hasReplyAction && actionContainer.popupNotification)
|
|
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
onClicked: {
|
|
|
|
|
if (modelData.actionName === "inline-reply") {
|
|
|
|
|
replyLoader.beginReply();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
notificationItem.actionInvoked(modelData.actionName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
// inline reply field
|
|
|
|
|
Loader {
|
|
|
|
|
id: replyLoader
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: active ? item.implicitHeight : 0
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
// When there is only one action and it is a reply action, show text field right away
|
2024-11-07 16:13:06 +00:00
|
|
|
active: notificationItem.hasReplyAction && actionContainer.popupNotification
|
2021-12-22 23:29:00 +00:00
|
|
|
visible: active
|
|
|
|
|
opacity: active ? 1 : 0
|
|
|
|
|
x: active ? 0 : parent.width
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2024-11-07 16:13:06 +00:00
|
|
|
property bool replying: false
|
|
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
Behavior on x {
|
|
|
|
|
NumberAnimation {
|
2023-07-25 01:13:52 +00:00
|
|
|
duration: Kirigami.Units.longDuration
|
2021-12-22 23:29:00 +00:00
|
|
|
easing.type: Easing.InOutQuad
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Behavior on opacity {
|
|
|
|
|
NumberAnimation {
|
2023-07-25 01:13:52 +00:00
|
|
|
duration: Kirigami.Units.longDuration
|
2021-12-22 23:29:00 +00:00
|
|
|
easing.type: Easing.InOutQuad
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function beginReply() {
|
2024-11-07 16:13:06 +00:00
|
|
|
actionContainer.takeFocus();
|
|
|
|
|
active = true;
|
|
|
|
|
replying = true;
|
2021-12-22 23:29:00 +00:00
|
|
|
replyLoader.item.activate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sourceComponent: NotificationReplyField {
|
|
|
|
|
placeholderText: notificationItem.replyPlaceholderText
|
|
|
|
|
buttonIconName: notificationItem.replySubmitButtonIconName
|
|
|
|
|
buttonText: notificationItem.replySubmitButtonText
|
|
|
|
|
onReplied: notificationItem.replied(text)
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2024-11-07 16:13:06 +00:00
|
|
|
replying: replyLoader.replying
|
2021-12-22 23:29:00 +00:00
|
|
|
onBeginReplyRequested: replyLoader.beginReply()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|