summary refs log tree commit diff
path: root/src/emoji
diff options
context:
space:
mode:
authorJussi Kuokkanen <jussi.kuokkanen@protonmail.com>2020-08-28 23:32:23 +0300
committerJussi Kuokkanen <jussi.kuokkanen@protonmail.com>2020-08-28 23:32:23 +0300
commita173d964f7e555da263dcbc1b4c81df9a8d3f811 (patch)
tree54a93262e06ea12853320d950380b6ad67186d5c /src/emoji
parentMerge pull request #237 from trilene/voip (diff)
downloadnheko-a173d964f7e555da263dcbc1b4c81df9a8d3f811.tar.xz
add emoji completer to text input
Diffstat (limited to 'src/emoji')
-rw-r--r--src/emoji/EmojiSearchModel.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/emoji/EmojiSearchModel.h b/src/emoji/EmojiSearchModel.h
new file mode 100644

index 00000000..bce96998 --- /dev/null +++ b/src/emoji/EmojiSearchModel.h
@@ -0,0 +1,37 @@ +#pragma once + +#include "EmojiModel.h" + +#include <QDebug> +#include <QEvent> +#include <QSortFilterProxyModel> +#include <qabstractitemmodel.h> +#include <qsortfilterproxymodel.h> + +namespace emoji { + +// Map emoji data to searchable data +class EmojiSearchModel : public QSortFilterProxyModel { +public: + EmojiSearchModel(QObject *parent = nullptr) : QSortFilterProxyModel(parent) { + setSourceModel(new EmojiModel(this)); + } + QVariant data(const QModelIndex &index, int role = Qt::UserRole + 1) const override { + if (role == Qt::DisplayRole) { + auto emoji = QSortFilterProxyModel::data(index, role).toString(); + return emoji + " :" + toShortcode(data(index, EmojiModel::ShortName).toString()) + + ":"; + } + return QSortFilterProxyModel::data(index, role); + } + /*int rowCount(const QModelIndex &parent) const override { + auto row_count = QSortFilterProxyModel::rowCount(parent); + return (row_count < 7) ? row_count : 7; + }*/ +private: + QString toShortcode(QString shortname) const { + return shortname.replace(" ", "-").replace(":", "-").replace("--", "-").toLower(); + } +}; + +}