2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-05-13 07:35:26 +03:00
|
|
|
#include "EmojiModel.h"
|
|
|
|
|
|
|
|
#include <Cache.h>
|
|
|
|
#include <MatrixClient.h>
|
|
|
|
|
2020-11-20 06:33:11 +03:00
|
|
|
#include "CompletionModelRoles.h"
|
|
|
|
|
2020-05-13 07:35:26 +03:00
|
|
|
using namespace emoji;
|
|
|
|
|
2021-04-18 21:21:03 +03:00
|
|
|
int
|
|
|
|
EmojiModel::categoryToIndex(int category)
|
|
|
|
{
|
|
|
|
auto dist = std::distance(Provider::emoji.begin(),
|
|
|
|
std::lower_bound(Provider::emoji.begin(),
|
|
|
|
Provider::emoji.end(),
|
|
|
|
static_cast<Emoji::Category>(category),
|
|
|
|
[](const struct Emoji &e, Emoji::Category c) {
|
|
|
|
return e.category < c;
|
|
|
|
}));
|
|
|
|
|
|
|
|
return static_cast<int>(dist);
|
|
|
|
}
|
|
|
|
|
2020-05-13 07:35:26 +03:00
|
|
|
QHash<int, QByteArray>
|
|
|
|
EmojiModel::roleNames() const
|
|
|
|
{
|
|
|
|
static QHash<int, QByteArray> roles;
|
|
|
|
|
|
|
|
if (roles.isEmpty()) {
|
|
|
|
roles = QAbstractListModel::roleNames();
|
|
|
|
roles[static_cast<int>(EmojiModel::Roles::Unicode)] = QByteArrayLiteral("unicode");
|
|
|
|
roles[static_cast<int>(EmojiModel::Roles::ShortName)] =
|
|
|
|
QByteArrayLiteral("shortName");
|
|
|
|
roles[static_cast<int>(EmojiModel::Roles::Category)] =
|
|
|
|
QByteArrayLiteral("category");
|
|
|
|
roles[static_cast<int>(EmojiModel::Roles::Emoji)] = QByteArrayLiteral("emoji");
|
|
|
|
}
|
|
|
|
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
EmojiModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return parent == QModelIndex() ? Provider::emoji.count() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant
|
|
|
|
EmojiModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (hasIndex(index.row(), index.column(), index.parent())) {
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
2020-11-20 06:33:11 +03:00
|
|
|
case CompletionModel::CompletionRole:
|
2020-05-13 07:35:26 +03:00
|
|
|
case static_cast<int>(EmojiModel::Roles::Unicode):
|
2020-06-11 05:34:14 +03:00
|
|
|
return Provider::emoji[index.row()].unicode;
|
2020-05-13 07:35:26 +03:00
|
|
|
|
|
|
|
case Qt::ToolTipRole:
|
2020-11-20 06:33:11 +03:00
|
|
|
case CompletionModel::SearchRole:
|
2020-05-13 07:35:26 +03:00
|
|
|
case static_cast<int>(EmojiModel::Roles::ShortName):
|
2020-06-11 05:34:14 +03:00
|
|
|
return Provider::emoji[index.row()].shortName;
|
2020-05-13 07:35:26 +03:00
|
|
|
|
|
|
|
case static_cast<int>(EmojiModel::Roles::Category):
|
2020-06-11 05:34:14 +03:00
|
|
|
return QVariant::fromValue(Provider::emoji[index.row()].category);
|
2020-05-13 07:35:26 +03:00
|
|
|
|
|
|
|
case static_cast<int>(EmojiModel::Roles::Emoji):
|
|
|
|
return QVariant::fromValue(Provider::emoji[index.row()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|