| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import "./delegates/" |
| 6 |
import QtQuick 2.9 |
| 7 |
import QtQuick.Controls 2.3 |
| 8 |
import im.nheko 1.0 |
| 9 |
|
| 10 |
Popup { |
| 11 |
id: forwardMessagePopup |
| 12 |
|
| 13 |
property string mid: "" |
| 14 |
|
| 15 |
function setMessageEventId(mid_in) { |
| 16 |
mid = mid_in; |
| 17 |
} |
| 18 |
|
| 19 |
leftPadding: 10 |
| 20 |
modal: true |
| 21 |
|
| 22 |
// Workaround palettes not inheriting for popups |
| 23 |
palette: timelineRoot.palette |
| 24 |
parent: Overlay.overlay |
| 25 |
rightPadding: 10 |
| 26 |
width: timelineRoot.width * 0.8 |
| 27 |
x: Math.round(parent.width / 2 - width / 2) |
| 28 |
y: Math.round(parent.height / 4) |
| 29 |
|
| 30 |
Overlay.modal: Rectangle { |
| 31 |
color: Qt.rgba(palette.window.r, palette.window.g, palette.window.b, 0.7) |
| 32 |
} |
| 33 |
background: Rectangle { |
| 34 |
color: palette.window |
| 35 |
} |
| 36 |
|
| 37 |
onOpened: { |
| 38 |
roomTextInput.forceActiveFocus(); |
| 39 |
} |
| 40 |
|
| 41 |
contentItem: Column { |
| 42 |
id: forwardColumn |
| 43 |
|
| 44 |
spacing: 5 |
| 45 |
|
| 46 |
Label { |
| 47 |
id: titleLabel |
| 48 |
|
| 49 |
bottomPadding: 10 |
| 50 |
color: palette.text |
| 51 |
font.bold: true |
| 52 |
text: qsTr("Forward Message") |
| 53 |
} |
| 54 |
Reply { |
| 55 |
id: replyPreview |
| 56 |
|
| 57 |
eventId: mid |
| 58 |
userColor: TimelineManager.userColor(replyPreview.userId, palette.window) |
| 59 |
maxWidth: parent.width |
| 60 |
} |
| 61 |
MatrixTextField { |
| 62 |
id: roomTextInput |
| 63 |
|
| 64 |
color: palette.text |
| 65 |
width: forwardMessagePopup.width - forwardMessagePopup.leftPadding * 2 |
| 66 |
|
| 67 |
Keys.onPressed: (event) => { |
| 68 |
if (event.key == Qt.Key_Up || event.key == Qt.Key_Backtab) { |
| 69 |
event.accepted = true; |
| 70 |
completerPopup.up(); |
| 71 |
} else if (event.key == Qt.Key_Down || event.key == Qt.Key_Tab) { |
| 72 |
event.accepted = true; |
| 73 |
if (event.key == Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier)) |
| 74 |
completerPopup.up(); |
| 75 |
else |
| 76 |
completerPopup.down(); |
| 77 |
} else if (event.matches(StandardKey.InsertParagraphSeparator)) { |
| 78 |
completerPopup.finishCompletion(); |
| 79 |
event.accepted = true; |
| 80 |
} |
| 81 |
} |
| 82 |
onTextEdited: { |
| 83 |
completerPopup.completer.searchString = text; |
| 84 |
} |
| 85 |
} |
| 86 |
Completer { |
| 87 |
id: completerPopup |
| 88 |
|
| 89 |
avatarHeight: 24 |
| 90 |
avatarWidth: 24 |
| 91 |
bottomToTop: false |
| 92 |
centerRowContent: false |
| 93 |
completerName: "room" |
| 94 |
fullWidth: true |
| 95 |
width: forwardMessagePopup.width - forwardMessagePopup.leftPadding * 2 |
| 96 |
} |
| 97 |
} |
| 98 |
Connections { |
| 99 |
function onCompletionSelected(id) { |
| 100 |
room.forwardMessage(forwardMessagePopup.mid, id); |
| 101 |
forwardMessagePopup.close(); |
| 102 |
} |
| 103 |
function onCountChanged() { |
| 104 |
if (completerPopup.count > 0 && (completerPopup.currentIndex < 0 || completerPopup.currentIndex >= completerPopup.count)) |
| 105 |
completerPopup.currentIndex = 0; |
| 106 |
} |
| 107 |
|
| 108 |
target: completerPopup |
| 109 |
} |
| 110 |
} |