Allow search with unicode names

pull/1058/head
BulbyVR 3 years ago
parent dabde88e1c
commit 79ed520d59
  1. 1
      scripts/codegen.sh
  2. 45
      scripts/emoji_codegen.py
  3. 5
      src/emoji/EmojiModel.cpp
  4. 1
      src/emoji/EmojiModel.h
  5. 13836
      src/emoji/Provider.cpp
  6. 2
      src/emoji/Provider.h

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

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

@ -34,6 +34,7 @@ EmojiModel::roleNames() const
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::UnicodeName)] = QByteArrayLiteral("unicodeName");
roles[static_cast<int>(EmojiModel::Roles::Category)] = QByteArrayLiteral("category");
roles[static_cast<int>(EmojiModel::Roles::Emoji)] = QByteArrayLiteral("emoji");
}
@ -59,9 +60,11 @@ EmojiModel::data(const QModelIndex &index, int role) const
case Qt::ToolTipRole:
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):
return Provider::emoji[index.row()].shortName;
case static_cast<int>(EmojiModel::Roles::Category):
return QVariant::fromValue(Provider::emoji[index.row()].category);

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

File diff suppressed because it is too large Load Diff

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

Loading…
Cancel
Save