Allow search with unicode names

This commit is contained in:
BulbyVR 2022-04-22 12:49:57 -04:00
parent dabde88e1c
commit 79ed520d59
6 changed files with 3674 additions and 10246 deletions

View file

@ -4,3 +4,4 @@ cd $ROOT
cat resources/provider-header.txt > src/emoji/Provider.cpp cat resources/provider-header.txt > src/emoji/Provider.cpp
scripts/emoji_codegen.py resources/emoji-test.txt resources/shortcodes.txt >> src/emoji/Provider.cpp scripts/emoji_codegen.py resources/emoji-test.txt resources/shortcodes.txt >> src/emoji/Provider.cpp
cd - > /dev/null

View file

@ -7,9 +7,10 @@ from jinja2 import Template
class Emoji(object): class Emoji(object):
def __init__(self, code, shortname): def __init__(self, code, shortname, unicodename):
self.code = ''.join(['\\U'+c.rjust(8, '0') for c in code.strip().split(' ')]) self.code = ''.join(['\\U'+c.rjust(8, '0') for c in code.strip().split(' ')])
self.shortname = shortname self.shortname = shortname
self.unicodename = unicodename
def generate_qml_list(**kwargs): def generate_qml_list(**kwargs):
tmpl = Template(''' tmpl = Template('''
@ -17,7 +18,7 @@ const QVector<Emoji> emoji::Provider::emoji = {
{%- for c in kwargs.items() %} {%- for c in kwargs.items() %}
// {{ c[0].capitalize() }} // {{ c[0].capitalize() }}
{%- for e in c[1] %} {%- for e in c[1] %}
Emoji{QStringLiteral(u"{{ e.code }}"), QStringLiteral(u"{{ e.shortname }}"), emoji::Emoji::Category::{{ c[0].capitalize() }}}, Emoji{QStringLiteral(u"{{ e.code }}"), QStringLiteral(u"{{ e.shortname }}"), QStringLiteral(u"{{ e.unicodename }}"), emoji::Emoji::Category::{{ c[0].capitalize() }}},
{%- endfor %} {%- endfor %}
{%- endfor %} {%- endfor %}
}; };
@ -78,29 +79,31 @@ if __name__ == '__main__':
char, name = re.match(r'^(\S+) E\d+\.\d+ (.*)$', charAndName).groups() char, name = re.match(r'^(\S+) E\d+\.\d+ (.*)$', charAndName).groups()
#TODO: Handle skintone modifiers in a sane way shortname = name
if name in shortcodeDict:
# TODO: this duplicates emoji
categories[current_category].append(Emoji(code, shortcodeDict[name]))
if name.endswith(' face'): #TODO: Handle skintone modifiers in a sane way
name = name[:-5] if shortname in shortcodeDict:
elif name.endswith(' button'): shortname = shortcodeDict[shortname]
name = name[:-7]
else: else:
matchobj = re.match(r'^flag: (.*)$', name) if shortname.endswith(' face'):
if matchobj: shortname = shortname[:-5]
country, = matchobj.groups() elif shortname.endswith(' button'):
name = country + " flag" shortname = shortname[:-7]
name = name.replace(" ", "_") else:
name = name.replace("", "") # FIXME: Is there a better way to do this?
name = name.replace("", "") matchobj = re.match(r'^flag: (.*)$', shortname)
name = name.replace(":", "") if matchobj:
name = name.replace("-", "_") country, = matchobj.groups()
name = re.sub(r'_{2,}', '_', name) shortname = country + " flag"
name = name.lower() shortname = shortname.replace(" ", "_")
name = unidecode(name) shortname = shortname.replace("", "")
categories[current_category].append(Emoji(code, name)) shortname = shortname.replace("", "")
shortname = shortname.replace(":", "")
shortname = shortname.replace("-", "_")
shortname = re.sub(r'_{2,}', '_', shortname)
shortname = shortname.lower()
shortname = unidecode(shortname)
categories[current_category].append(Emoji(code, shortname, name))
# Use xclip to pipe the output to clipboard. # Use xclip to pipe the output to clipboard.
# e.g ./codegen.py emoji.json | xclip -sel clip # e.g ./codegen.py emoji.json | xclip -sel clip

View file

@ -31,11 +31,12 @@ EmojiModel::roleNames() const
static QHash<int, QByteArray> roles; static QHash<int, QByteArray> roles;
if (roles.isEmpty()) { if (roles.isEmpty()) {
roles = QAbstractListModel::roleNames(); roles = QAbstractListModel::roleNames();
roles[static_cast<int>(EmojiModel::Roles::Unicode)] = QByteArrayLiteral("unicode"); roles[static_cast<int>(EmojiModel::Roles::Unicode)] = QByteArrayLiteral("unicode");
roles[static_cast<int>(EmojiModel::Roles::ShortName)] = QByteArrayLiteral("shortName"); roles[static_cast<int>(EmojiModel::Roles::ShortName)] = QByteArrayLiteral("shortName");
roles[static_cast<int>(EmojiModel::Roles::Category)] = QByteArrayLiteral("category"); roles[static_cast<int>(EmojiModel::Roles::UnicodeName)] = QByteArrayLiteral("unicodeName");
roles[static_cast<int>(EmojiModel::Roles::Emoji)] = QByteArrayLiteral("emoji"); roles[static_cast<int>(EmojiModel::Roles::Category)] = QByteArrayLiteral("category");
roles[static_cast<int>(EmojiModel::Roles::Emoji)] = QByteArrayLiteral("emoji");
} }
return roles; return roles;
@ -59,9 +60,11 @@ EmojiModel::data(const QModelIndex &index, int role) const
case Qt::ToolTipRole: case Qt::ToolTipRole:
case CompletionModel::SearchRole: case CompletionModel::SearchRole:
case static_cast<int>(EmojiModel::Roles::UnicodeName):
return Provider::emoji[index.row()].unicodeName;
case CompletionModel::SearchRole2:
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;
case static_cast<int>(EmojiModel::Roles::Category): case static_cast<int>(EmojiModel::Roles::Category):
return QVariant::fromValue(Provider::emoji[index.row()].category); return QVariant::fromValue(Provider::emoji[index.row()].category);

View file

@ -26,6 +26,7 @@ public:
Unicode = Qt::UserRole, // unicode of emoji Unicode = Qt::UserRole, // unicode of emoji
Category, // category of emoji Category, // category of emoji
ShortName, // shortext of the emoji ShortName, // shortext of the emoji
UnicodeName, // true unicode name of the emoji
Emoji, // Contains everything from the Emoji Emoji, // Contains everything from the Emoji
}; };

File diff suppressed because it is too large Load diff

View file

@ -35,11 +35,13 @@ public:
Q_PROPERTY(const QString &unicode MEMBER unicode) Q_PROPERTY(const QString &unicode MEMBER unicode)
Q_PROPERTY(const QString &shortName MEMBER shortName) Q_PROPERTY(const QString &shortName MEMBER shortName)
Q_PROPERTY(const QString &unicodeName MEMBER unicodeName)
Q_PROPERTY(emoji::Emoji::Category category MEMBER category) Q_PROPERTY(emoji::Emoji::Category category MEMBER category)
public: public:
QString unicode; QString unicode;
QString shortName; QString shortName;
QString unicodeName;
Category category; Category category;
}; };