summary refs log tree commit diff
path: root/src/emoji/EmojiModel.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/emoji/EmojiModel.h')
-rw-r--r--src/emoji/EmojiModel.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/emoji/EmojiModel.h b/src/emoji/EmojiModel.h
new file mode 100644
index 00000000..8d43e000
--- /dev/null
+++ b/src/emoji/EmojiModel.h
@@ -0,0 +1,64 @@
+#pragma once
+
+#include <QAbstractListModel>
+#include <QSet>
+#include <QSortFilterProxyModel>
+#include <QVector>
+
+#include "Provider.h"
+
+namespace emoji {
+
+/*
+ * Provides access to the emojis in Provider.h to QML
+ */
+class EmojiModel : public QAbstractListModel
+{
+        Q_OBJECT
+public:
+        enum Roles
+        {
+                Unicode = Qt::UserRole, // unicode of emoji
+                Category,               // category of emoji
+                ShortName,              // shortext of the emoji
+                Emoji,                  // Contains everything from the Emoji
+        };
+
+        using QAbstractListModel::QAbstractListModel;
+
+        QHash<int, QByteArray> roleNames() const override;
+        int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+        QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+};
+
+class EmojiProxyModel : public QSortFilterProxyModel
+{
+        Q_OBJECT
+
+        Q_PROPERTY(
+          emoji::EmojiCategory category READ category WRITE setCategory NOTIFY categoryChanged)
+        Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
+
+public:
+        explicit EmojiProxyModel(QObject *parent = nullptr);
+        ~EmojiProxyModel() override;
+
+        EmojiCategory category() const;
+        void setCategory(EmojiCategory cat);
+
+        QString filter() const;
+        void setFilter(const QString &filter);
+
+signals:
+        void categoryChanged();
+        void filterChanged();
+
+protected:
+        bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
+
+private:
+        EmojiCategory category_ = EmojiCategory::Search;
+        emoji::Provider emoji_provider_;
+};
+
+}
\ No newline at end of file