1// SPDX-FileCopyrightText: 2021 Nheko Contributors
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5import "./delegates/"
6import QtQuick 2.9
7import QtQuick.Controls 2.3
8import QtQuick.Layouts 1.2
9import im.nheko 1.0
10
11Rectangle {
12    id: replyPopup
13
14    Layout.fillWidth: true
15    visible: room && (room.reply || room.edit)
16    // Height of child, plus margins, plus border
17    implicitHeight: (room && room.reply ? replyPreview.height : closeEditButton.height) + 10
18    color: Nheko.colors.window
19    z: 3
20
21    Reply {
22        id: replyPreview
23
24        property var modelData: room ? room.getDump(room.reply, room.id) : {
25        }
26
27        visible: room && room.reply
28        anchors.left: parent.left
29        anchors.leftMargin: 2 * 22 + 3 * 16
30        anchors.right: closeReplyButton.left
31        anchors.rightMargin: 2 * 22 + 3 * 16
32        anchors.bottom: parent.bottom
33        userColor: TimelineManager.userColor(modelData.userId, Nheko.colors.window)
34        blurhash: modelData.blurhash ?? ""
35        body: modelData.body ?? ""
36        formattedBody: modelData.formattedBody ?? ""
37        eventId: modelData.eventId ?? ""
38        filename: modelData.filename ?? ""
39        filesize: modelData.filesize ?? ""
40        proportionalHeight: modelData.proportionalHeight ?? 1
41        type: modelData.type ?? MtxEvent.UnknownMessage
42        typeString: modelData.typeString ?? ""
43        url: modelData.url ?? ""
44        originalWidth: modelData.originalWidth ?? 0
45        isOnlyEmoji: modelData.isOnlyEmoji ?? false
46        userId: modelData.userId ?? ""
47        userName: modelData.userName ?? ""
48        encryptionError: modelData.encryptionError ?? ""
49    }
50
51    ImageButton {
52        id: closeReplyButton
53
54        visible: room && room.reply
55        anchors.right: parent.right
56        anchors.rightMargin: 16
57        anchors.top: replyPreview.top
58        hoverEnabled: true
59        width: 16
60        height: 16
61        image: ":/icons/icons/ui/dismiss.svg"
62        ToolTip.visible: closeReplyButton.hovered
63        ToolTip.text: qsTr("Close")
64        onClicked: room.reply = undefined
65    }
66
67    Button {
68        id: closeEditButton
69
70        visible: room && room.edit
71        anchors.left: parent.left
72        anchors.rightMargin: 16
73        anchors.topMargin: 10
74        anchors.top: parent.top
75        //height: 16
76        text: qsTr("Cancel edit")
77        onClicked: room.edit = undefined
78    }
79
80}
81