| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import QtQuick |
| 6 |
import QtQuick.Controls |
| 7 |
import im.nheko |
| 8 |
|
| 9 |
Popup { |
| 10 |
id: quickSwitcher |
| 11 |
|
| 12 |
property int textHeight: Math.round(Qt.application.font.pixelSize * 2.4) |
| 13 |
property int textMargin: Nheko.paddingSmall |
| 14 |
|
| 15 |
background: null |
| 16 |
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside |
| 17 |
modal: true |
| 18 |
|
| 19 |
// Workaround palettes not inheriting for popups |
| 20 |
palette: timelineRoot.palette |
| 21 |
parent: Overlay.overlay |
| 22 |
width: Math.min(Math.max(Math.round(parent.width / 2), 450), parent.width) // limiting width to parent.width/2 can be a bit narrow |
| 23 |
x: Math.round(parent.width / 2 - contentWidth / 2) |
| 24 |
y: Math.round(parent.height / 4) |
| 25 |
|
| 26 |
Overlay.modal: Rectangle { |
| 27 |
color: "#aa1E1E1E" |
| 28 |
} |
| 29 |
|
| 30 |
onClosed: TimelineManager.focusMessageInput() |
| 31 |
onOpened: { |
| 32 |
roomTextInput.forceActiveFocus(); |
| 33 |
} |
| 34 |
|
| 35 |
contentItem: Column { |
| 36 |
spacing: 1 |
| 37 |
|
| 38 |
MatrixTextField { |
| 39 |
id: roomTextInput |
| 40 |
|
| 41 |
color: palette.text |
| 42 |
font.pixelSize: Math.ceil(quickSwitcher.textHeight * 0.6) |
| 43 |
width: parent.width |
| 44 |
|
| 45 |
Keys.onPressed: event => { |
| 46 |
if (event.key == Qt.Key_Up || event.key == Qt.Key_Backtab) { |
| 47 |
event.accepted = true; |
| 48 |
completerPopup.up(); |
| 49 |
} else if (event.key == Qt.Key_Down || event.key == Qt.Key_Tab) { |
| 50 |
event.accepted = true; |
| 51 |
if (event.key == Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier)) |
| 52 |
completerPopup.up(); |
| 53 |
else |
| 54 |
completerPopup.down(); |
| 55 |
} else if (event.matches(StandardKey.InsertParagraphSeparator)) { |
| 56 |
completerPopup.finishCompletion(); |
| 57 |
event.accepted = true; |
| 58 |
} |
| 59 |
} |
| 60 |
onTextEdited: { |
| 61 |
completerPopup.completer.searchString = text; |
| 62 |
} |
| 63 |
} |
| 64 |
Completer { |
| 65 |
id: completerPopup |
| 66 |
|
| 67 |
avatarHeight: quickSwitcher.textHeight |
| 68 |
avatarWidth: quickSwitcher.textHeight |
| 69 |
bottomToTop: false |
| 70 |
centerRowContent: false |
| 71 |
completerName: "room" |
| 72 |
fullWidth: true |
| 73 |
rowMargin: Math.round(quickSwitcher.textMargin / 2) |
| 74 |
rowSpacing: quickSwitcher.textMargin |
| 75 |
visible: roomTextInput.text.length > 0 |
| 76 |
width: parent.width |
| 77 |
} |
| 78 |
} |
| 79 |
Connections { |
| 80 |
function onCompletionSelected(id) { |
| 81 |
Rooms.setCurrentRoom(id); |
| 82 |
quickSwitcher.close(); |
| 83 |
} |
| 84 |
function onCountChanged() { |
| 85 |
if (completerPopup.count > 0 && (completerPopup.currentIndex < 0 || completerPopup.currentIndex >= completerPopup.count)) |
| 86 |
completerPopup.currentIndex = 0; |
| 87 |
} |
| 88 |
|
| 89 |
target: completerPopup |
| 90 |
} |
| 91 |
} |