2021-02-21 18:40:21 +01:00
|
|
|
import QtQuick 2.9
|
|
|
|
import QtQuick.Controls 2.3
|
|
|
|
import im.nheko 1.0
|
|
|
|
|
|
|
|
Popup {
|
2021-02-22 18:38:42 +01:00
|
|
|
id: quickSwitcher
|
2021-02-23 17:06:21 +01:00
|
|
|
|
2021-03-14 01:24:26 +01:00
|
|
|
property int textHeight: Math.round(Qt.application.font.pixelSize * 2.4)
|
|
|
|
property int textMargin: Math.round(textHeight / 8)
|
2021-02-23 17:06:21 +01:00
|
|
|
|
2021-03-14 01:24:26 +01:00
|
|
|
function delay(delayTime, cb) {
|
|
|
|
timer.interval = delayTime;
|
|
|
|
timer.repeat = false;
|
|
|
|
timer.triggered.connect(cb);
|
|
|
|
timer.start();
|
|
|
|
}
|
|
|
|
|
2021-03-14 02:42:41 +01:00
|
|
|
background: null
|
2021-03-14 01:24:26 +01:00
|
|
|
width: Math.round(parent.width / 2)
|
|
|
|
x: Math.round(parent.width / 2 - width / 2)
|
|
|
|
y: Math.round(parent.height / 4 - height / 2)
|
2021-02-21 18:40:21 +01:00
|
|
|
modal: true
|
|
|
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
|
|
|
parent: Overlay.overlay
|
2021-02-23 17:37:45 +01:00
|
|
|
palette: colors
|
2021-03-14 01:24:26 +01:00
|
|
|
onOpened: {
|
|
|
|
completerPopup.open();
|
|
|
|
delay(200, function() {
|
|
|
|
roomTextInput.forceActiveFocus();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
onClosed: {
|
|
|
|
completerPopup.close();
|
2021-02-22 19:48:31 +01:00
|
|
|
}
|
|
|
|
|
2021-02-23 17:06:21 +01:00
|
|
|
MatrixTextField {
|
2021-02-21 18:40:21 +01:00
|
|
|
id: roomTextInput
|
|
|
|
|
2021-02-21 19:31:50 +01:00
|
|
|
anchors.fill: parent
|
2021-03-13 23:52:46 +01:00
|
|
|
font.pixelSize: Math.ceil(quickSwitcher.textHeight * 0.6)
|
2021-02-24 15:02:13 +01:00
|
|
|
padding: textMargin
|
2021-02-23 17:37:45 +01:00
|
|
|
color: colors.text
|
2021-02-21 18:40:21 +01:00
|
|
|
onTextEdited: {
|
2021-03-14 01:24:26 +01:00
|
|
|
completerPopup.completer.searchString = text;
|
2021-02-21 18:40:21 +01:00
|
|
|
}
|
2021-02-22 18:38:42 +01:00
|
|
|
Keys.onPressed: {
|
|
|
|
if (event.key == Qt.Key_Up && completerPopup.opened) {
|
|
|
|
event.accepted = true;
|
|
|
|
completerPopup.up();
|
|
|
|
} else if (event.key == Qt.Key_Down && completerPopup.opened) {
|
|
|
|
event.accepted = true;
|
|
|
|
completerPopup.down();
|
2021-02-22 19:48:31 +01:00
|
|
|
} else if (event.matches(StandardKey.InsertParagraphSeparator)) {
|
2021-03-14 01:24:26 +01:00
|
|
|
completerPopup.finishCompletion();
|
2021-02-22 19:48:31 +01:00
|
|
|
event.accepted = true;
|
2021-02-22 18:38:42 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-21 18:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Completer {
|
|
|
|
id: completerPopup
|
|
|
|
|
2021-03-06 19:48:24 +01:00
|
|
|
x: roomTextInput.x
|
2021-03-14 01:24:26 +01:00
|
|
|
y: roomTextInput.y + quickSwitcher.textHeight + quickSwitcher.textMargin
|
|
|
|
visible: roomTextInput.length > 0
|
2021-03-06 19:48:24 +01:00
|
|
|
width: parent.width
|
2021-02-21 18:40:21 +01:00
|
|
|
completerName: "room"
|
2021-02-26 07:09:51 +01:00
|
|
|
bottomToTop: false
|
2021-02-21 19:31:50 +01:00
|
|
|
fullWidth: true
|
2021-03-14 01:24:26 +01:00
|
|
|
avatarHeight: quickSwitcher.textHeight
|
|
|
|
avatarWidth: quickSwitcher.textHeight
|
2021-02-24 09:08:01 +01:00
|
|
|
centerRowContent: false
|
2021-03-14 01:24:26 +01:00
|
|
|
rowMargin: Math.round(quickSwitcher.textMargin / 2)
|
|
|
|
rowSpacing: quickSwitcher.textMargin
|
2021-02-21 19:31:50 +01:00
|
|
|
closePolicy: Popup.NoAutoClose
|
2021-02-21 18:40:21 +01:00
|
|
|
}
|
|
|
|
|
2021-02-22 18:38:42 +01:00
|
|
|
Connections {
|
|
|
|
onCompletionSelected: {
|
2021-03-14 01:24:26 +01:00
|
|
|
TimelineManager.setHistoryView(id);
|
|
|
|
TimelineManager.highlightRoom(id);
|
|
|
|
quickSwitcher.close();
|
|
|
|
}
|
|
|
|
onCountChanged: {
|
|
|
|
if (completerPopup.count > 0 && (completerPopup.currentIndex < 0 || completerPopup.currentIndex >= completerPopup.count))
|
|
|
|
completerPopup.currentIndex = 0;
|
|
|
|
|
2021-02-22 18:38:42 +01:00
|
|
|
}
|
|
|
|
target: completerPopup
|
|
|
|
}
|
2021-02-23 17:06:21 +01:00
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
}
|
|
|
|
|
2021-03-14 01:24:26 +01:00
|
|
|
Overlay.modal: Rectangle {
|
|
|
|
color: "#aa1E1E1E"
|
2021-02-23 17:06:21 +01:00
|
|
|
}
|
2021-03-14 01:24:26 +01:00
|
|
|
|
2021-03-13 23:52:46 +01:00
|
|
|
}
|