88 lines
2.3 KiB
C++
88 lines
2.3 KiB
C++
// SPDX-FileCopyrightText: 2018 Black Hat <bhat@encom.eu.org>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QSettings>
|
|
|
|
struct Emoji {
|
|
Emoji(QString u, QString s, bool isCustom = false)
|
|
: unicode(std::move(std::move(u)))
|
|
, shortname(std::move(std::move(s)))
|
|
, isCustom(isCustom)
|
|
{
|
|
}
|
|
Emoji() = default;
|
|
|
|
friend QDataStream &operator<<(QDataStream &arch, const Emoji &object)
|
|
{
|
|
arch << object.unicode;
|
|
arch << object.shortname;
|
|
return arch;
|
|
}
|
|
|
|
friend QDataStream &operator>>(QDataStream &arch, Emoji &object)
|
|
{
|
|
arch >> object.unicode;
|
|
arch >> object.shortname;
|
|
object.isCustom = object.unicode.startsWith("image://");
|
|
return arch;
|
|
}
|
|
|
|
QString unicode;
|
|
QString shortname;
|
|
bool isCustom = false;
|
|
|
|
Q_GADGET
|
|
Q_PROPERTY(QString unicode MEMBER unicode)
|
|
Q_PROPERTY(QString shortname MEMBER shortname)
|
|
Q_PROPERTY(bool isCustom MEMBER isCustom)
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(Emoji)
|
|
|
|
class EmojiModel : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QVariantList history READ history NOTIFY historyChanged)
|
|
|
|
Q_PROPERTY(QVariantList people MEMBER people CONSTANT)
|
|
Q_PROPERTY(QVariantList nature MEMBER nature CONSTANT)
|
|
Q_PROPERTY(QVariantList food MEMBER food CONSTANT)
|
|
Q_PROPERTY(QVariantList activity MEMBER activity CONSTANT)
|
|
Q_PROPERTY(QVariantList travel MEMBER travel CONSTANT)
|
|
Q_PROPERTY(QVariantList objects MEMBER objects CONSTANT)
|
|
Q_PROPERTY(QVariantList symbols MEMBER symbols CONSTANT)
|
|
Q_PROPERTY(QVariantList flags MEMBER flags CONSTANT)
|
|
|
|
public:
|
|
explicit EmojiModel(QObject *parent = nullptr)
|
|
: QObject(parent)
|
|
{
|
|
}
|
|
|
|
Q_INVOKABLE QVariantList history();
|
|
Q_INVOKABLE static QVariantList filterModel(const QString &filter);
|
|
|
|
Q_SIGNALS:
|
|
void historyChanged();
|
|
|
|
public Q_SLOTS:
|
|
void emojiUsed(const QVariant &modelData);
|
|
|
|
private:
|
|
static const QVariantList people;
|
|
static const QVariantList nature;
|
|
static const QVariantList food;
|
|
static const QVariantList activity;
|
|
static const QVariantList travel;
|
|
static const QVariantList objects;
|
|
static const QVariantList symbols;
|
|
static const QVariantList flags;
|
|
|
|
// TODO: Port away from QSettings
|
|
QSettings m_settings;
|
|
};
|