2020-05-13 07:35:26 +03:00
|
|
|
#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(
|
2021-01-23 04:07:23 +03:00
|
|
|
emoji::Emoji::Category category READ category WRITE setCategory NOTIFY categoryChanged)
|
2020-05-13 07:35:26 +03:00
|
|
|
Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit EmojiProxyModel(QObject *parent = nullptr);
|
|
|
|
~EmojiProxyModel() override;
|
|
|
|
|
2021-01-23 04:07:23 +03:00
|
|
|
Emoji::Category category() const;
|
|
|
|
void setCategory(Emoji::Category cat);
|
2020-05-13 07:35:26 +03:00
|
|
|
|
|
|
|
QString filter() const;
|
|
|
|
void setFilter(const QString &filter);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void categoryChanged();
|
|
|
|
void filterChanged();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
|
|
|
|
|
|
|
private:
|
2021-01-23 04:07:23 +03:00
|
|
|
Emoji::Category category_ = Emoji::Category::Search;
|
2020-05-13 07:35:26 +03:00
|
|
|
emoji::Provider emoji_provider_;
|
|
|
|
};
|
2021-01-23 04:07:23 +03:00
|
|
|
}
|