mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 06:08:48 +03:00
Merge branch 'quickswitcher_qml' of git://github.com/Jedi18/nheko into Jedi18-quickswitcher_qml
This commit is contained in:
commit
7a356f3832
18 changed files with 323 additions and 272 deletions
|
@ -316,7 +316,6 @@ set(SRC_FILES
|
||||||
src/MatrixClient.cpp
|
src/MatrixClient.cpp
|
||||||
src/MxcImageProvider.cpp
|
src/MxcImageProvider.cpp
|
||||||
src/Olm.cpp
|
src/Olm.cpp
|
||||||
src/QuickSwitcher.cpp
|
|
||||||
src/RegisterPage.cpp
|
src/RegisterPage.cpp
|
||||||
src/RoomInfoListItem.cpp
|
src/RoomInfoListItem.cpp
|
||||||
src/RoomList.cpp
|
src/RoomList.cpp
|
||||||
|
@ -532,7 +531,6 @@ qt5_wrap_cpp(MOC_HEADERS
|
||||||
src/LoginPage.h
|
src/LoginPage.h
|
||||||
src/MainWindow.h
|
src/MainWindow.h
|
||||||
src/MxcImageProvider.h
|
src/MxcImageProvider.h
|
||||||
src/QuickSwitcher.h
|
|
||||||
src/RegisterPage.h
|
src/RegisterPage.h
|
||||||
src/RoomInfoListItem.h
|
src/RoomInfoListItem.h
|
||||||
src/RoomList.h
|
src/RoomList.h
|
||||||
|
|
|
@ -15,9 +15,16 @@ Popup {
|
||||||
property string completerName
|
property string completerName
|
||||||
property var completer
|
property var completer
|
||||||
property bool bottomToTop: true
|
property bool bottomToTop: true
|
||||||
|
property bool fullWidth: false
|
||||||
|
property bool centerRowContent: true
|
||||||
|
property int avatarHeight: 24
|
||||||
|
property int avatarWidth: 24
|
||||||
|
property int rowMargin: 0
|
||||||
|
property int rowSpacing: 5
|
||||||
property alias count: listView.count
|
property alias count: listView.count
|
||||||
|
|
||||||
signal completionClicked(string completion)
|
signal completionClicked(string completion)
|
||||||
|
signal completionSelected(string id)
|
||||||
|
|
||||||
function up() {
|
function up() {
|
||||||
if (bottomToTop)
|
if (bottomToTop)
|
||||||
|
@ -54,9 +61,19 @@ Popup {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function finishCompletion() {
|
||||||
|
if(popup.completerName == "room") {
|
||||||
|
popup.completionSelected(listView.itemAtIndex(currentIndex).modelData.roomid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onCompleterNameChanged: {
|
onCompleterNameChanged: {
|
||||||
if (completerName) {
|
if (completerName) {
|
||||||
completer = TimelineManager.timeline.input.completerFor(completerName);
|
if (completerName == "user") {
|
||||||
|
completer = TimelineManager.completerFor(completerName, TimelineManager.timeline.roomId());
|
||||||
|
} else {
|
||||||
|
completer = TimelineManager.completerFor(completerName);
|
||||||
|
}
|
||||||
completer.setSearchString("");
|
completer.setSearchString("");
|
||||||
} else {
|
} else {
|
||||||
completer = undefined;
|
completer = undefined;
|
||||||
|
@ -75,14 +92,17 @@ Popup {
|
||||||
id: listView
|
id: listView
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
implicitWidth: contentItem.childrenRect.width
|
implicitWidth: fullWidth ? parent.width : contentItem.childrenRect.width
|
||||||
model: completer
|
model: completer
|
||||||
verticalLayoutDirection: popup.bottomToTop ? ListView.BottomToTop : ListView.TopToBottom
|
verticalLayoutDirection: popup.bottomToTop ? ListView.BottomToTop : ListView.TopToBottom
|
||||||
|
spacing: rowSpacing
|
||||||
|
pixelAligned: true
|
||||||
|
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
color: model.index == popup.currentIndex ? colors.highlight : colors.base
|
color: model.index == popup.currentIndex ? colors.highlight : colors.base
|
||||||
height: chooser.childrenRect.height + 4
|
height: chooser.childrenRect.height + 2 * popup.rowMargin
|
||||||
implicitWidth: chooser.childrenRect.width + 4
|
implicitWidth: fullWidth ? popup.width : chooser.childrenRect.width + 4
|
||||||
|
property variant modelData: model
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: mouseArea
|
id: mouseArea
|
||||||
|
@ -90,7 +110,12 @@ Popup {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onPositionChanged: popup.currentIndex = model.index
|
onPositionChanged: popup.currentIndex = model.index
|
||||||
onClicked: popup.completionClicked(completer.completionAt(model.index))
|
onClicked: {
|
||||||
|
popup.completionClicked(completer.completionAt(model.index))
|
||||||
|
if(popup.completerName == "room") {
|
||||||
|
popup.completionSelected(model.roomid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ripple {
|
Ripple {
|
||||||
rippleTarget: mouseArea
|
rippleTarget: mouseArea
|
||||||
|
@ -103,7 +128,8 @@ Popup {
|
||||||
id: chooser
|
id: chooser
|
||||||
|
|
||||||
roleValue: popup.completerName
|
roleValue: popup.completerName
|
||||||
anchors.centerIn: parent
|
anchors.fill: parent
|
||||||
|
anchors.margins: popup.rowMargin
|
||||||
|
|
||||||
DelegateChoice {
|
DelegateChoice {
|
||||||
roleValue: "user"
|
roleValue: "user"
|
||||||
|
@ -112,10 +138,11 @@ Popup {
|
||||||
id: del
|
id: del
|
||||||
|
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
spacing: rowSpacing
|
||||||
|
|
||||||
Avatar {
|
Avatar {
|
||||||
height: 24
|
height: popup.avatarHeight
|
||||||
width: 24
|
width: popup.avatarWidth
|
||||||
displayName: model.displayName
|
displayName: model.displayName
|
||||||
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
|
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
|
||||||
onClicked: popup.completionClicked(completer.completionAt(model.index))
|
onClicked: popup.completionClicked(completer.completionAt(model.index))
|
||||||
|
@ -142,6 +169,7 @@ Popup {
|
||||||
id: del
|
id: del
|
||||||
|
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
spacing: rowSpacing
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: model.unicode
|
text: model.unicode
|
||||||
|
@ -164,11 +192,41 @@ Popup {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: del
|
id: del
|
||||||
|
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: centerRowContent ? parent : undefined
|
||||||
|
spacing: rowSpacing
|
||||||
|
|
||||||
Avatar {
|
Avatar {
|
||||||
height: 24
|
height: popup.avatarHeight
|
||||||
width: 24
|
width: popup.avatarWidth
|
||||||
|
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
|
||||||
|
onClicked: {
|
||||||
|
popup.completionClicked(completer.completionAt(model.index))
|
||||||
|
popup.completionSelected(model.roomid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: model.roomName
|
||||||
|
font.pixelSize: popup.avatarHeight * 0.5
|
||||||
|
color: model.index == popup.currentIndex ? colors.highlightedText : colors.text
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DelegateChoice {
|
||||||
|
roleValue: "roomAliases"
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: del
|
||||||
|
|
||||||
|
anchors.centerIn: parent
|
||||||
|
spacing: rowSpacing
|
||||||
|
|
||||||
|
Avatar {
|
||||||
|
height: popup.avatarHeight
|
||||||
|
width: popup.avatarWidth
|
||||||
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
|
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
|
||||||
onClicked: popup.completionClicked(completer.completionAt(model.index))
|
onClicked: popup.completionClicked(completer.completionAt(model.index))
|
||||||
}
|
}
|
||||||
|
|
56
resources/qml/MatrixTextField.qml
Normal file
56
resources/qml/MatrixTextField.qml
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import QtQuick 2.13
|
||||||
|
import QtQuick.Layouts 1.13
|
||||||
|
import QtQuick.Controls 2.13
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id: input
|
||||||
|
palette: colors
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
color: colors.base
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: blueBar
|
||||||
|
|
||||||
|
anchors.top: parent.bottom
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
|
||||||
|
color: colors.highlight
|
||||||
|
height: 1
|
||||||
|
width: parent.width
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: blackBar
|
||||||
|
|
||||||
|
anchors.verticalCenter: blueBar.verticalCenter
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
|
||||||
|
height: parent.height+1
|
||||||
|
width: 0
|
||||||
|
color: colors.text
|
||||||
|
|
||||||
|
states: State {
|
||||||
|
name: "focused"; when: input.activeFocus == true
|
||||||
|
PropertyChanges {
|
||||||
|
target: blackBar
|
||||||
|
width: blueBar.width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
transitions: Transition {
|
||||||
|
from: ""
|
||||||
|
to: "focused"
|
||||||
|
reversible: true
|
||||||
|
|
||||||
|
NumberAnimation {
|
||||||
|
target: blackBar
|
||||||
|
properties: "width"
|
||||||
|
duration: 500
|
||||||
|
easing.type: Easing.InOutQuad
|
||||||
|
alwaysRunToEnd: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -161,7 +161,7 @@ Rectangle {
|
||||||
messageInput.openCompleter(cursorPosition, "emoji");
|
messageInput.openCompleter(cursorPosition, "emoji");
|
||||||
popup.open();
|
popup.open();
|
||||||
} else if (event.key == Qt.Key_NumberSign) {
|
} else if (event.key == Qt.Key_NumberSign) {
|
||||||
messageInput.openCompleter(cursorPosition, "room");
|
messageInput.openCompleter(cursorPosition, "roomAliases");
|
||||||
popup.open();
|
popup.open();
|
||||||
} else if (event.key == Qt.Key_Escape && popup.opened) {
|
} else if (event.key == Qt.Key_Escape && popup.opened) {
|
||||||
completerTriggeredAt = -1;
|
completerTriggeredAt = -1;
|
||||||
|
|
97
resources/qml/QuickSwitcher.qml
Normal file
97
resources/qml/QuickSwitcher.qml
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
import QtQuick 2.9
|
||||||
|
import QtQuick.Controls 2.3
|
||||||
|
import im.nheko 1.0
|
||||||
|
|
||||||
|
Popup {
|
||||||
|
id: quickSwitcher
|
||||||
|
|
||||||
|
property int textHeight: 32
|
||||||
|
property int textMargin: 8
|
||||||
|
|
||||||
|
x: parent.width / 2 - width / 2
|
||||||
|
y: parent.height / 4 - height / 2
|
||||||
|
width: parent.width / 2
|
||||||
|
modal: true
|
||||||
|
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||||
|
parent: Overlay.overlay
|
||||||
|
palette: colors
|
||||||
|
|
||||||
|
Overlay.modal: Rectangle {
|
||||||
|
color: "#aa1E1E1E"
|
||||||
|
}
|
||||||
|
|
||||||
|
MatrixTextField {
|
||||||
|
id: roomTextInput
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
font.pixelSize: quickSwitcher.textHeight * 0.6
|
||||||
|
padding: textMargin
|
||||||
|
color: colors.text
|
||||||
|
|
||||||
|
onTextEdited: {
|
||||||
|
completerPopup.completer.setSearchString(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
} else if (event.matches(StandardKey.InsertParagraphSeparator)) {
|
||||||
|
completerPopup.finishCompletion()
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Completer {
|
||||||
|
id: completerPopup
|
||||||
|
|
||||||
|
x: roomTextInput.x
|
||||||
|
y: roomTextInput.y + roomTextInput.height + textMargin
|
||||||
|
width: parent.width
|
||||||
|
completerName: "room"
|
||||||
|
bottomToTop: false
|
||||||
|
fullWidth: true
|
||||||
|
avatarHeight: textHeight
|
||||||
|
avatarWidth: textHeight
|
||||||
|
centerRowContent: false
|
||||||
|
rowMargin: 8
|
||||||
|
rowSpacing: 6
|
||||||
|
|
||||||
|
closePolicy: Popup.NoAutoClose
|
||||||
|
}
|
||||||
|
|
||||||
|
onOpened: {
|
||||||
|
completerPopup.open()
|
||||||
|
delay(200, function() {
|
||||||
|
roomTextInput.forceActiveFocus()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onClosed: {
|
||||||
|
completerPopup.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
onCompletionSelected: {
|
||||||
|
TimelineManager.setHistoryView(id)
|
||||||
|
TimelineManager.highlightRoom(id)
|
||||||
|
quickSwitcher.close()
|
||||||
|
}
|
||||||
|
target: completerPopup
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: timer
|
||||||
|
}
|
||||||
|
|
||||||
|
function delay(delayTime, cb) {
|
||||||
|
timer.interval = delayTime;
|
||||||
|
timer.repeat = false;
|
||||||
|
timer.triggered.connect(cb);
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,6 +72,22 @@ Page {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: quickSwitcherComponent
|
||||||
|
|
||||||
|
QuickSwitcher {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Shortcut {
|
||||||
|
sequence: "Ctrl+K"
|
||||||
|
onActivated: {
|
||||||
|
var quickSwitch = quickSwitcherComponent.createObject(timelineRoot);
|
||||||
|
TimelineManager.focusTimeline()
|
||||||
|
quickSwitch.open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Menu {
|
Menu {
|
||||||
id: messageContextMenu
|
id: messageContextMenu
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,7 @@
|
||||||
<file>qml/EncryptionIndicator.qml</file>
|
<file>qml/EncryptionIndicator.qml</file>
|
||||||
<file>qml/ImageButton.qml</file>
|
<file>qml/ImageButton.qml</file>
|
||||||
<file>qml/MatrixText.qml</file>
|
<file>qml/MatrixText.qml</file>
|
||||||
|
<file>qml/MatrixTextField.qml</file>
|
||||||
<file>qml/ToggleButton.qml</file>
|
<file>qml/ToggleButton.qml</file>
|
||||||
<file>qml/MessageInput.qml</file>
|
<file>qml/MessageInput.qml</file>
|
||||||
<file>qml/MessageView.qml</file>
|
<file>qml/MessageView.qml</file>
|
||||||
|
@ -140,6 +141,7 @@
|
||||||
<file>qml/StatusIndicator.qml</file>
|
<file>qml/StatusIndicator.qml</file>
|
||||||
<file>qml/TimelineRow.qml</file>
|
<file>qml/TimelineRow.qml</file>
|
||||||
<file>qml/TopBar.qml</file>
|
<file>qml/TopBar.qml</file>
|
||||||
|
<file>qml/QuickSwitcher.qml</file>
|
||||||
<file>qml/TypingIndicator.qml</file>
|
<file>qml/TypingIndicator.qml</file>
|
||||||
<file>qml/RoomSettings.qml</file>
|
<file>qml/RoomSettings.qml</file>
|
||||||
<file>qml/emoji/EmojiButton.qml</file>
|
<file>qml/emoji/EmojiButton.qml</file>
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "Olm.h"
|
#include "Olm.h"
|
||||||
#include "QuickSwitcher.h"
|
|
||||||
#include "RoomList.h"
|
#include "RoomList.h"
|
||||||
#include "SideBarActions.h"
|
#include "SideBarActions.h"
|
||||||
#include "Splitter.h"
|
#include "Splitter.h"
|
||||||
|
@ -589,18 +588,6 @@ ChatPage::loadStateFromCache()
|
||||||
emit trySyncCb();
|
emit trySyncCb();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
ChatPage::showQuickSwitcher()
|
|
||||||
{
|
|
||||||
auto dialog = new QuickSwitcher(this);
|
|
||||||
|
|
||||||
connect(dialog, &QuickSwitcher::roomSelected, room_list_, &RoomList::highlightSelectedRoom);
|
|
||||||
connect(
|
|
||||||
dialog, &QuickSwitcher::closing, this, []() { MainWindow::instance()->hideOverlay(); });
|
|
||||||
|
|
||||||
MainWindow::instance()->showTransparentOverlayModal(dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ChatPage::removeRoom(const QString &room_id)
|
ChatPage::removeRoom(const QString &room_id)
|
||||||
{
|
{
|
||||||
|
@ -1456,3 +1443,9 @@ ChatPage::handleMatrixUri(const QUrl &uri)
|
||||||
{
|
{
|
||||||
handleMatrixUri(uri.toString(QUrl::ComponentFormattingOption::FullyEncoded).toUtf8());
|
handleMatrixUri(uri.toString(QUrl::ComponentFormattingOption::FullyEncoded).toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatPage::highlightRoom(const QString &room_id)
|
||||||
|
{
|
||||||
|
room_list_->highlightSelectedRoom(room_id);
|
||||||
|
}
|
|
@ -31,7 +31,6 @@
|
||||||
#include "notifications/Manager.h"
|
#include "notifications/Manager.h"
|
||||||
|
|
||||||
class OverlayModal;
|
class OverlayModal;
|
||||||
class QuickSwitcher;
|
|
||||||
class RoomList;
|
class RoomList;
|
||||||
class SideBarActions;
|
class SideBarActions;
|
||||||
class Splitter;
|
class Splitter;
|
||||||
|
@ -72,7 +71,6 @@ public:
|
||||||
|
|
||||||
// Initialize all the components of the UI.
|
// Initialize all the components of the UI.
|
||||||
void bootstrap(QString userid, QString homeserver, QString token);
|
void bootstrap(QString userid, QString homeserver, QString token);
|
||||||
void showQuickSwitcher();
|
|
||||||
QString currentRoom() const { return current_room_; }
|
QString currentRoom() const { return current_room_; }
|
||||||
|
|
||||||
static ChatPage *instance() { return instance_; }
|
static ChatPage *instance() { return instance_; }
|
||||||
|
@ -104,6 +102,7 @@ public slots:
|
||||||
void startChat(QString userid);
|
void startChat(QString userid);
|
||||||
void leaveRoom(const QString &room_id);
|
void leaveRoom(const QString &room_id);
|
||||||
void createRoom(const mtx::requests::CreateRoom &req);
|
void createRoom(const mtx::requests::CreateRoom &req);
|
||||||
|
void highlightRoom(const QString &room_id);
|
||||||
void joinRoom(const QString &room);
|
void joinRoom(const QString &room);
|
||||||
void joinRoomVia(const std::string &room_id,
|
void joinRoomVia(const std::string &room_id,
|
||||||
const std::vector<std::string> &via,
|
const std::vector<std::string> &via,
|
||||||
|
|
|
@ -10,8 +10,11 @@
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model, QObject *parent)
|
CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
|
||||||
|
int max_mistakes,
|
||||||
|
QObject *parent)
|
||||||
: QAbstractProxyModel(parent)
|
: QAbstractProxyModel(parent)
|
||||||
|
, maxMistakes_(max_mistakes)
|
||||||
{
|
{
|
||||||
setSourceModel(model);
|
setSourceModel(model);
|
||||||
QRegularExpression splitPoints("\\s+|-");
|
QRegularExpression splitPoints("\\s+|-");
|
||||||
|
@ -63,7 +66,7 @@ CompletionProxyModel::invalidate()
|
||||||
{
|
{
|
||||||
auto key = searchString.toUcs4();
|
auto key = searchString.toUcs4();
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
mapping = trie_.search(key, 7);
|
mapping = trie_.search(key, 7, maxMistakes_);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
||||||
std::string temp;
|
std::string temp;
|
||||||
|
|
|
@ -58,19 +58,19 @@ struct trie
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Value> search(const QVector<Key> &keys, //< TODO(Nico): replace this with a span
|
std::vector<Value> search(const QVector<Key> &keys, //< TODO(Nico): replace this with a span
|
||||||
size_t limit,
|
size_t result_count_limit,
|
||||||
size_t max_distance = 2) const
|
size_t max_edit_distance = 2) const
|
||||||
{
|
{
|
||||||
std::vector<Value> ret;
|
std::vector<Value> ret;
|
||||||
if (!limit)
|
if (!result_count_limit)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (keys.isEmpty())
|
if (keys.isEmpty())
|
||||||
return valuesAndSubvalues(limit);
|
return valuesAndSubvalues(result_count_limit);
|
||||||
|
|
||||||
auto append = [&ret, limit](std::vector<Value> &&in) {
|
auto append = [&ret, result_count_limit](std::vector<Value> &&in) {
|
||||||
for (auto &&v : in) {
|
for (auto &&v : in) {
|
||||||
if (ret.size() >= limit)
|
if (ret.size() >= result_count_limit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (std::find(ret.begin(), ret.end(), v) == ret.end()) {
|
if (std::find(ret.begin(), ret.end(), v) == ret.end()) {
|
||||||
|
@ -80,11 +80,12 @@ struct trie
|
||||||
};
|
};
|
||||||
|
|
||||||
if (auto e = this->next.find(keys[0]); e != this->next.end()) {
|
if (auto e = this->next.find(keys[0]); e != this->next.end()) {
|
||||||
append(e->second.search(keys.mid(1), limit, max_distance));
|
append(
|
||||||
|
e->second.search(keys.mid(1), result_count_limit, max_edit_distance));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max_distance && ret.size() < limit) {
|
if (max_edit_distance && ret.size() < result_count_limit) {
|
||||||
max_distance -= 1;
|
max_edit_distance -= 1;
|
||||||
|
|
||||||
// swap chars case
|
// swap chars case
|
||||||
if (keys.size() >= 2) {
|
if (keys.size() >= 2) {
|
||||||
|
@ -99,27 +100,31 @@ struct trie
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t) {
|
if (t) {
|
||||||
append(t->search(
|
append(t->search(keys.mid(2),
|
||||||
keys.mid(2), (limit - ret.size()) * 2, max_distance));
|
(result_count_limit - ret.size()) * 2,
|
||||||
|
max_edit_distance));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete character case
|
// delete character case
|
||||||
append(this->search(keys.mid(1), (limit - ret.size()) * 2, max_distance));
|
append(this->search(
|
||||||
|
keys.mid(1), (result_count_limit - ret.size()) * 2, max_edit_distance));
|
||||||
|
|
||||||
// substitute and insert cases
|
// substitute and insert cases
|
||||||
for (const auto &[k, t] : this->next) {
|
for (const auto &[k, t] : this->next) {
|
||||||
if (k == keys[0] || ret.size() >= limit)
|
if (k == keys[0] || ret.size() >= result_count_limit)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// substitute
|
// substitute
|
||||||
append(t.search(keys.mid(1), limit - ret.size(), max_distance));
|
append(t.search(
|
||||||
|
keys.mid(1), result_count_limit - ret.size(), max_edit_distance));
|
||||||
|
|
||||||
if (ret.size() >= limit)
|
if (ret.size() >= result_count_limit)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// insert
|
// insert
|
||||||
append(t.search(keys, limit - ret.size(), max_distance));
|
append(t.search(
|
||||||
|
keys, result_count_limit - ret.size(), max_edit_distance));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +137,9 @@ class CompletionProxyModel : public QAbstractProxyModel
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CompletionProxyModel(QAbstractItemModel *model, QObject *parent = nullptr);
|
CompletionProxyModel(QAbstractItemModel *model,
|
||||||
|
int max_mistakes = 2,
|
||||||
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
void invalidate();
|
void invalidate();
|
||||||
|
|
||||||
|
@ -160,4 +167,5 @@ private:
|
||||||
QString searchString;
|
QString searchString;
|
||||||
trie<uint, int> trie_;
|
trie<uint, int> trie_;
|
||||||
std::vector<int> mapping;
|
std::vector<int> mapping;
|
||||||
|
int maxMistakes_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -135,12 +135,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
QShortcut *quitShortcut = new QShortcut(QKeySequence::Quit, this);
|
QShortcut *quitShortcut = new QShortcut(QKeySequence::Quit, this);
|
||||||
connect(quitShortcut, &QShortcut::activated, this, QApplication::quit);
|
connect(quitShortcut, &QShortcut::activated, this, QApplication::quit);
|
||||||
|
|
||||||
QShortcut *quickSwitchShortcut = new QShortcut(QKeySequence("Ctrl+K"), this);
|
|
||||||
connect(quickSwitchShortcut, &QShortcut::activated, this, [this]() {
|
|
||||||
if (chat_page_->isVisible() && !hasActiveDialogs())
|
|
||||||
chat_page_->showQuickSwitcher();
|
|
||||||
});
|
|
||||||
|
|
||||||
trayIcon_->setVisible(userSettings_->tray());
|
trayIcon_->setVisible(userSettings_->tray());
|
||||||
|
|
||||||
if (hasActiveUser()) {
|
if (hasActiveUser()) {
|
||||||
|
|
|
@ -1,129 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2017 Konstantinos Sideris <siderisk@auth.gr>
|
|
||||||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
#include <QCompleter>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QStringListModel>
|
|
||||||
#include <QStyleOption>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QtConcurrent>
|
|
||||||
|
|
||||||
#include "Cache.h"
|
|
||||||
#include "QuickSwitcher.h"
|
|
||||||
#include "popups/SuggestionsPopup.h"
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(std::vector<RoomSearchResult>)
|
|
||||||
|
|
||||||
RoomSearchInput::RoomSearchInput(QWidget *parent)
|
|
||||||
: TextField(parent)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void
|
|
||||||
RoomSearchInput::keyPressEvent(QKeyEvent *event)
|
|
||||||
{
|
|
||||||
switch (event->key()) {
|
|
||||||
case Qt::Key_Tab:
|
|
||||||
case Qt::Key_Down: {
|
|
||||||
emit selectNextCompletion();
|
|
||||||
event->accept();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Qt::Key_Backtab:
|
|
||||||
case Qt::Key_Up: {
|
|
||||||
emit selectPreviousCompletion();
|
|
||||||
event->accept();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
TextField::keyPressEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
RoomSearchInput::hideEvent(QHideEvent *event)
|
|
||||||
{
|
|
||||||
emit hiding();
|
|
||||||
TextField::hideEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
QuickSwitcher::QuickSwitcher(QWidget *parent)
|
|
||||||
: QWidget(parent)
|
|
||||||
{
|
|
||||||
qRegisterMetaType<std::vector<RoomSearchResult>>();
|
|
||||||
setMaximumWidth(450);
|
|
||||||
|
|
||||||
QFont font;
|
|
||||||
font.setPointSizeF(font.pointSizeF() * 1.5);
|
|
||||||
|
|
||||||
roomSearch_ = new RoomSearchInput(this);
|
|
||||||
roomSearch_->setFont(font);
|
|
||||||
roomSearch_->setPlaceholderText(tr("Search for a room..."));
|
|
||||||
|
|
||||||
topLayout_ = new QVBoxLayout(this);
|
|
||||||
topLayout_->addWidget(roomSearch_);
|
|
||||||
|
|
||||||
connect(this,
|
|
||||||
&QuickSwitcher::queryResults,
|
|
||||||
this,
|
|
||||||
[this](const std::vector<RoomSearchResult> &rooms) {
|
|
||||||
auto pos = mapToGlobal(roomSearch_->geometry().bottomLeft());
|
|
||||||
|
|
||||||
popup_.setFixedWidth(width());
|
|
||||||
popup_.addRooms(rooms);
|
|
||||||
popup_.move(pos.x() - topLayout_->margin(), pos.y() + topLayout_->margin());
|
|
||||||
popup_.show();
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(roomSearch_, &QLineEdit::textEdited, this, [this](const QString &query) {
|
|
||||||
if (query.isEmpty()) {
|
|
||||||
popup_.hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QtConcurrent::run([this, query = query.toLower()]() {
|
|
||||||
try {
|
|
||||||
emit queryResults(cache::searchRooms(query.toStdString()));
|
|
||||||
} catch (const lmdb::error &e) {
|
|
||||||
qWarning() << "room search failed:" << e.what();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(roomSearch_,
|
|
||||||
&RoomSearchInput::selectNextCompletion,
|
|
||||||
&popup_,
|
|
||||||
&SuggestionsPopup::selectNextSuggestion);
|
|
||||||
connect(roomSearch_,
|
|
||||||
&RoomSearchInput::selectPreviousCompletion,
|
|
||||||
&popup_,
|
|
||||||
&SuggestionsPopup::selectPreviousSuggestion);
|
|
||||||
connect(&popup_, &SuggestionsPopup::itemSelected, this, [this](const QString &room_id) {
|
|
||||||
reset();
|
|
||||||
emit roomSelected(room_id);
|
|
||||||
});
|
|
||||||
connect(roomSearch_, &RoomSearchInput::hiding, this, [this]() { popup_.hide(); });
|
|
||||||
connect(roomSearch_, &QLineEdit::returnPressed, this, [this]() {
|
|
||||||
reset();
|
|
||||||
popup_.selectHoveredSuggestion();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
QuickSwitcher::paintEvent(QPaintEvent *)
|
|
||||||
{
|
|
||||||
QStyleOption opt;
|
|
||||||
opt.init(this);
|
|
||||||
QPainter p(this);
|
|
||||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
QuickSwitcher::keyPressEvent(QKeyEvent *event)
|
|
||||||
{
|
|
||||||
if (event->key() == Qt::Key_Escape) {
|
|
||||||
event->accept();
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,65 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2017 Konstantinos Sideris <siderisk@auth.gr>
|
|
||||||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QAbstractItemView>
|
|
||||||
#include <QKeyEvent>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
#include "popups/SuggestionsPopup.h"
|
|
||||||
#include "ui/TextField.h"
|
|
||||||
|
|
||||||
class RoomSearchInput : public TextField
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit RoomSearchInput(QWidget *parent = nullptr);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void selectNextCompletion();
|
|
||||||
void selectPreviousCompletion();
|
|
||||||
void hiding();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void keyPressEvent(QKeyEvent *event) override;
|
|
||||||
void hideEvent(QHideEvent *event) override;
|
|
||||||
bool focusNextPrevChild(bool) override { return false; };
|
|
||||||
};
|
|
||||||
|
|
||||||
class QuickSwitcher : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
QuickSwitcher(QWidget *parent = nullptr);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void closing();
|
|
||||||
void roomSelected(const QString &roomid);
|
|
||||||
void queryResults(const std::vector<RoomSearchResult> &rooms);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void keyPressEvent(QKeyEvent *event) override;
|
|
||||||
void showEvent(QShowEvent *) override { roomSearch_->setFocus(); }
|
|
||||||
void paintEvent(QPaintEvent *event) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void reset()
|
|
||||||
{
|
|
||||||
emit closing();
|
|
||||||
roomSearch_->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Current highlighted selection from the completer.
|
|
||||||
int selection_ = -1;
|
|
||||||
|
|
||||||
QVBoxLayout *topLayout_;
|
|
||||||
RoomSearchInput *roomSearch_;
|
|
||||||
|
|
||||||
//! Autocomplete popup box with the room suggestions.
|
|
||||||
SuggestionsPopup popup_;
|
|
||||||
};
|
|
|
@ -192,28 +192,6 @@ InputBar::nextText()
|
||||||
return text();
|
return text();
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *
|
|
||||||
InputBar::completerFor(QString completerName)
|
|
||||||
{
|
|
||||||
if (completerName == "user") {
|
|
||||||
auto userModel = new UsersModel(room->roomId().toStdString());
|
|
||||||
auto proxy = new CompletionProxyModel(userModel);
|
|
||||||
userModel->setParent(proxy);
|
|
||||||
return proxy;
|
|
||||||
} else if (completerName == "emoji") {
|
|
||||||
auto emojiModel = new emoji::EmojiModel();
|
|
||||||
auto proxy = new CompletionProxyModel(emojiModel);
|
|
||||||
emojiModel->setParent(proxy);
|
|
||||||
return proxy;
|
|
||||||
} else if (completerName == "room") {
|
|
||||||
auto roomModel = new RoomsModel(true);
|
|
||||||
auto proxy = new CompletionProxyModel(roomModel);
|
|
||||||
roomModel->setParent(proxy);
|
|
||||||
return proxy;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InputBar::send()
|
InputBar::send()
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,8 +55,6 @@ public slots:
|
||||||
bool uploading() const { return uploading_; }
|
bool uploading() const { return uploading_; }
|
||||||
void message(QString body, MarkdownOverride useMarkdown = MarkdownOverride::NOT_SPECIFIED);
|
void message(QString body, MarkdownOverride useMarkdown = MarkdownOverride::NOT_SPECIFIED);
|
||||||
|
|
||||||
QObject *completerFor(QString completerName);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void startTyping();
|
void startTyping();
|
||||||
void stopTyping();
|
void stopTyping();
|
||||||
|
|
|
@ -15,13 +15,16 @@
|
||||||
#include "BlurhashProvider.h"
|
#include "BlurhashProvider.h"
|
||||||
#include "ChatPage.h"
|
#include "ChatPage.h"
|
||||||
#include "ColorImageProvider.h"
|
#include "ColorImageProvider.h"
|
||||||
|
#include "CompletionProxyModel.h"
|
||||||
#include "DelegateChooser.h"
|
#include "DelegateChooser.h"
|
||||||
#include "DeviceVerificationFlow.h"
|
#include "DeviceVerificationFlow.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "MxcImageProvider.h"
|
#include "MxcImageProvider.h"
|
||||||
|
#include "RoomsModel.h"
|
||||||
#include "UserSettingsPage.h"
|
#include "UserSettingsPage.h"
|
||||||
|
#include "UsersModel.h"
|
||||||
#include "dialogs/ImageOverlay.h"
|
#include "dialogs/ImageOverlay.h"
|
||||||
#include "emoji/EmojiModel.h"
|
#include "emoji/EmojiModel.h"
|
||||||
#include "emoji/Provider.h"
|
#include "emoji/Provider.h"
|
||||||
|
@ -334,6 +337,12 @@ TimelineViewManager::setHistoryView(const QString &room_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TimelineViewManager::highlightRoom(const QString &room_id)
|
||||||
|
{
|
||||||
|
ChatPage::instance()->highlightRoom(room_id);
|
||||||
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
TimelineViewManager::escapeEmoji(QString str) const
|
TimelineViewManager::escapeEmoji(QString str) const
|
||||||
{
|
{
|
||||||
|
@ -556,3 +565,36 @@ TimelineViewManager::focusMessageInput()
|
||||||
{
|
{
|
||||||
emit focusInput();
|
emit focusInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QObject *
|
||||||
|
TimelineViewManager::completerFor(QString completerName, QString roomId)
|
||||||
|
{
|
||||||
|
if (completerName == "user") {
|
||||||
|
auto userModel = new UsersModel(roomId.toStdString());
|
||||||
|
auto proxy = new CompletionProxyModel(userModel);
|
||||||
|
userModel->setParent(proxy);
|
||||||
|
return proxy;
|
||||||
|
} else if (completerName == "emoji") {
|
||||||
|
auto emojiModel = new emoji::EmojiModel();
|
||||||
|
auto proxy = new CompletionProxyModel(emojiModel);
|
||||||
|
emojiModel->setParent(proxy);
|
||||||
|
return proxy;
|
||||||
|
} else if (completerName == "room") {
|
||||||
|
auto roomModel = new RoomsModel(false);
|
||||||
|
auto proxy = new CompletionProxyModel(roomModel, 4);
|
||||||
|
roomModel->setParent(proxy);
|
||||||
|
return proxy;
|
||||||
|
} else if (completerName == "roomAliases") {
|
||||||
|
auto roomModel = new RoomsModel(true);
|
||||||
|
auto proxy = new CompletionProxyModel(roomModel);
|
||||||
|
roomModel->setParent(proxy);
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TimelineViewManager::focusTimeline()
|
||||||
|
{
|
||||||
|
getWidget()->setFocus();
|
||||||
|
}
|
|
@ -104,6 +104,8 @@ public slots:
|
||||||
}
|
}
|
||||||
|
|
||||||
void setHistoryView(const QString &room_id);
|
void setHistoryView(const QString &room_id);
|
||||||
|
void highlightRoom(const QString &room_id);
|
||||||
|
void focusTimeline();
|
||||||
TimelineModel *getHistoryView(const QString &room_id)
|
TimelineModel *getHistoryView(const QString &room_id)
|
||||||
{
|
{
|
||||||
auto room = models.find(room_id);
|
auto room = models.find(room_id);
|
||||||
|
@ -142,6 +144,7 @@ public slots:
|
||||||
}
|
}
|
||||||
|
|
||||||
void backToRooms() { emit showRoomList(); }
|
void backToRooms() { emit showRoomList(); }
|
||||||
|
QObject *completerFor(QString completerName, QString roomId = "");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef USE_QUICK_VIEW
|
#ifdef USE_QUICK_VIEW
|
||||||
|
|
Loading…
Reference in a new issue