File indexing completed on 2024-05-12 05:04:18
0001 // SPDX-FileCopyrightText: 2018 Black Hat <bhat@encom.eu.org> 0002 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> 0003 // SPDX-License-Identifier: GPL-3.0-only 0004 0005 #pragma once 0006 0007 #include <QtQml> 0008 0009 /** 0010 * @class Emoji 0011 * 0012 * Defines the structure of a typical Unicode emoji. 0013 */ 0014 struct Emoji { 0015 Emoji(QString unicode, QString shortname, bool isCustom = false) 0016 : unicode(std::move(unicode)) 0017 , shortName(std::move(shortname)) 0018 , isCustom(isCustom) 0019 { 0020 } 0021 Emoji(QString unicode, QString shortname, QString description) 0022 : unicode(std::move(unicode)) 0023 , shortName(std::move(shortname)) 0024 , description(std::move(description)) 0025 { 0026 } 0027 Emoji() = default; 0028 0029 QString unicode; 0030 QString shortName; 0031 QString description; 0032 bool isCustom = false; 0033 0034 Q_GADGET 0035 0036 Q_PROPERTY(QString unicode MEMBER unicode) 0037 Q_PROPERTY(QString shortName MEMBER shortName) 0038 Q_PROPERTY(QString description MEMBER description) 0039 Q_PROPERTY(bool isCustom MEMBER isCustom) 0040 }; 0041 0042 class AbstractAccount; 0043 0044 /** 0045 * @class EmojiModel 0046 * 0047 * This class defines the model for visualising a list of emojis. 0048 */ 0049 class EmojiModel : public QObject 0050 { 0051 Q_OBJECT 0052 QML_ELEMENT 0053 QML_SINGLETON 0054 0055 /** 0056 * @brief Return a list of emoji categories. 0057 */ 0058 Q_PROPERTY(QVariantList categories READ categories CONSTANT) 0059 0060 public: 0061 explicit EmojiModel(QObject *parent = nullptr); 0062 0063 /** 0064 * @brief Defines the potential categories an emoji can be placed in. 0065 */ 0066 enum Category { 0067 Custom, /**< A custom user emoji. */ 0068 Search, /**< The results of a filter. */ 0069 History, /**< Recently used emojis. */ 0070 Smileys, /**< Smileys & emotion emojis. */ 0071 People, /**< People & Body emojis. */ 0072 Nature, /**< Animals & Nature emojis. */ 0073 Food, /**< Food & Drink emojis. */ 0074 Activities, /**< Activities emojis. */ 0075 Travel, /**< Travel & Places emojis. */ 0076 Objects, /**< Objects emojis. */ 0077 Symbols, /**< Symbols emojis. */ 0078 Flags, /**< Flags emojis. */ 0079 Component, /**< ??? */ 0080 }; 0081 Q_ENUM(Category) 0082 0083 /** 0084 * @brief Return a filtered list of emojis. 0085 * 0086 * @note This includes custom emojis, use filterModelNoCustom to return a result 0087 * without custom emojis. 0088 * 0089 * @sa filterModelNoCustom 0090 */ 0091 Q_INVOKABLE static QVariantList filterModel(AbstractAccount *account, const QString &filter); 0092 0093 /** 0094 * @brief Return a list of emojis for the given category. 0095 */ 0096 Q_INVOKABLE QVariantList emojis(AbstractAccount *account, Category category) const; 0097 0098 /** 0099 * @brief Return a list of emoji tones for the given base emoji. 0100 */ 0101 Q_INVOKABLE QVariantList tones(const QString &baseEmoji) const; 0102 0103 /** 0104 * @brief Return a list of emoji that were recently used. 0105 */ 0106 Q_INVOKABLE QStringList history(AbstractAccount *account) const; 0107 0108 Q_SIGNALS: 0109 void historyChanged(); 0110 0111 public Q_SLOTS: 0112 void emojiUsed(AbstractAccount *account, const QString &shortcode); 0113 0114 private: 0115 static QHash<Category, QVariantList> _emojis; 0116 0117 QVariantList categories() const; 0118 0119 static QVariantList filterModelNoCustom(const QString &filter); 0120 static QVariantList filterCustomModel(AbstractAccount *account, const QString &filter); 0121 };