File indexing completed on 2024-05-12 09:38:00
0001 /* 0002 SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QAbstractItemModel> 0010 #include <QQmlExtensionPlugin> 0011 #include <QSortFilterProxyModel> 0012 0013 #include <qqmlregistration.h> 0014 0015 #include "emojidict.h" 0016 #include "emojiersettings.h" 0017 0018 class AbstractEmojiModel : public QAbstractListModel 0019 { 0020 Q_OBJECT 0021 public: 0022 enum EmojiRole { CategoryRole = Qt::UserRole + 1, AnnotationsRole }; 0023 0024 int rowCount(const QModelIndex &parent = {}) const override; 0025 0026 QVariant data(const QModelIndex &index, int role) const override; 0027 0028 protected: 0029 QList<Emoji> m_emoji; 0030 }; 0031 0032 class EmojiModel : public AbstractEmojiModel 0033 { 0034 Q_OBJECT 0035 QML_ELEMENT 0036 Q_PROPERTY(QStringList categories MEMBER m_categories CONSTANT) 0037 public: 0038 enum EmojiRole { CategoryRole = Qt::UserRole + 1 }; 0039 0040 EmojiModel(); 0041 0042 Q_SCRIPTABLE QString findFirstEmojiForCategory(const QString &category); 0043 0044 private: 0045 QStringList m_categories; 0046 }; 0047 0048 class RecentEmojiModel : public AbstractEmojiModel 0049 { 0050 Q_OBJECT 0051 QML_ELEMENT 0052 Q_PROPERTY(int count READ rowCount CONSTANT) 0053 public: 0054 RecentEmojiModel(); 0055 0056 Q_SCRIPTABLE void includeRecent(const QString &emoji, const QString &emojiDescription); 0057 0058 Q_INVOKABLE void clearHistory(); 0059 0060 private: 0061 void refresh(); 0062 0063 EmojierSettings m_settings; 0064 }; 0065 0066 class CategoryModelFilter : public QSortFilterProxyModel 0067 { 0068 Q_OBJECT 0069 QML_ELEMENT 0070 Q_PROPERTY(QString category READ category WRITE setCategory) 0071 public: 0072 QString category() const; 0073 0074 void setCategory(const QString &category); 0075 0076 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; 0077 0078 private: 0079 QString m_category; 0080 }; 0081 0082 class SearchModelFilter : public QSortFilterProxyModel 0083 { 0084 Q_OBJECT 0085 QML_ELEMENT 0086 Q_PROPERTY(QString search READ search WRITE setSearch) 0087 public: 0088 QString search() const; 0089 0090 void setSearch(const QString &search); 0091 0092 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; 0093 0094 private: 0095 QString m_search; 0096 }; 0097 0098 class CopyHelperPrivate : public QObject 0099 { 0100 Q_OBJECT 0101 QML_ELEMENT 0102 QML_NAMED_ELEMENT(CopyHelper) 0103 QML_SINGLETON 0104 public: 0105 Q_INVOKABLE static void copyTextToClipboard(const QString &text); 0106 };