summary refs log tree commit diff
path: root/src/emoji/EmojiModel.h
blob: 938db46d179be41e13af2a8b7b21e1a24922f477 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#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::Emoji::Category 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;

        Emoji::Category category() const;
        void setCategory(Emoji::Category 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:
        Emoji::Category category_ = Emoji::Category::Search;
        emoji::Provider emoji_provider_;
};
}