mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Qml emoji completer
This commit is contained in:
parent
67dcc74c79
commit
094c0b09ab
4 changed files with 62 additions and 12 deletions
|
@ -56,8 +56,17 @@ Popup {
|
||||||
|
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
color: model.index == popup.currentIndex ? colors.window : colors.base
|
color: model.index == popup.currentIndex ? colors.window : colors.base
|
||||||
height: del.implicitHeight + 4
|
height: chooser.childrenRect.height + 4
|
||||||
width: del.implicitWidth + 4
|
width: chooser.childrenRect.width + 4
|
||||||
|
|
||||||
|
DelegateChooser {
|
||||||
|
id: chooser
|
||||||
|
|
||||||
|
roleValue: popup.completerName
|
||||||
|
anchors.centerIn: parent
|
||||||
|
|
||||||
|
DelegateChoice {
|
||||||
|
roleValue: "user"
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: del
|
id: del
|
||||||
|
@ -80,6 +89,33 @@ Popup {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DelegateChoice {
|
||||||
|
roleValue: "emoji"
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: del
|
||||||
|
|
||||||
|
anchors.centerIn: parent
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: model.unicode
|
||||||
|
color: colors.text
|
||||||
|
font: Settings.emojiFont
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: model.shortName
|
||||||
|
color: colors.text
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,10 @@ Rectangle {
|
||||||
completerTriggeredAt = cursorPosition;
|
completerTriggeredAt = cursorPosition;
|
||||||
popup.completerName = "user";
|
popup.completerName = "user";
|
||||||
popup.open();
|
popup.open();
|
||||||
|
} else if (event.key == Qt.Key_Colon) {
|
||||||
|
completerTriggeredAt = cursorPosition;
|
||||||
|
popup.completerName = "emoji";
|
||||||
|
popup.open();
|
||||||
} else if (event.key == Qt.Key_Escape && popup.opened) {
|
} else if (event.key == Qt.Key_Escape && popup.opened) {
|
||||||
completerTriggeredAt = -1;
|
completerTriggeredAt = -1;
|
||||||
popup.completerName = "";
|
popup.completerName = "";
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <Cache.h>
|
#include <Cache.h>
|
||||||
#include <MatrixClient.h>
|
#include <MatrixClient.h>
|
||||||
|
|
||||||
|
#include "CompletionModelRoles.h"
|
||||||
|
|
||||||
using namespace emoji;
|
using namespace emoji;
|
||||||
|
|
||||||
QHash<int, QByteArray>
|
QHash<int, QByteArray>
|
||||||
|
@ -35,10 +37,12 @@ EmojiModel::data(const QModelIndex &index, int role) const
|
||||||
if (hasIndex(index.row(), index.column(), index.parent())) {
|
if (hasIndex(index.row(), index.column(), index.parent())) {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
|
case CompletionModel::CompletionRole:
|
||||||
case static_cast<int>(EmojiModel::Roles::Unicode):
|
case static_cast<int>(EmojiModel::Roles::Unicode):
|
||||||
return Provider::emoji[index.row()].unicode;
|
return Provider::emoji[index.row()].unicode;
|
||||||
|
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
|
case CompletionModel::SearchRole:
|
||||||
case static_cast<int>(EmojiModel::Roles::ShortName):
|
case static_cast<int>(EmojiModel::Roles::ShortName):
|
||||||
return Provider::emoji[index.row()].shortName;
|
return Provider::emoji[index.row()].shortName;
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "dialogs/PlaceCall.h"
|
#include "dialogs/PlaceCall.h"
|
||||||
#include "dialogs/PreviewUploadOverlay.h"
|
#include "dialogs/PreviewUploadOverlay.h"
|
||||||
|
#include "emoji/EmojiModel.h"
|
||||||
|
|
||||||
#include "blurhash.hpp"
|
#include "blurhash.hpp"
|
||||||
|
|
||||||
|
@ -173,6 +174,11 @@ InputBar::completerFor(QString completerName)
|
||||||
auto proxy = new CompletionProxyModel(userModel);
|
auto proxy = new CompletionProxyModel(userModel);
|
||||||
userModel->setParent(proxy);
|
userModel->setParent(proxy);
|
||||||
return proxy;
|
return proxy;
|
||||||
|
} else if (completerName == "emoji") {
|
||||||
|
auto emojiModel = new emoji::EmojiModel();
|
||||||
|
auto proxy = new CompletionProxyModel(emojiModel);
|
||||||
|
emojiModel->setParent(proxy);
|
||||||
|
return proxy;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue