summary refs log tree commit diff
path: root/src/emoji/Provider.h
blob: 5d8000a4855cefbf608f7fe221432c736883c6ec (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QObject>
#include <array>

namespace emoji {
Q_NAMESPACE

struct Emoji
{
    Q_GADGET
public:
    enum class Category
    {
        People,
        Nature,
        Food,
        Activity,
        Travel,
        Objects,
        Symbols,
        Flags,
        Search
    };
    Q_ENUM(Category)

    Q_PROPERTY(QString unicode READ unicode CONSTANT)
    Q_PROPERTY(QString shortName READ shortName CONSTANT)
    Q_PROPERTY(QString unicodeName READ unicodeName CONSTANT)
    Q_PROPERTY(emoji::Emoji::Category category MEMBER category)

public:
    constexpr Emoji(std::u16string_view unicode,
                    std::u16string_view shortName,
                    std::u16string_view unicodeName,
                    Category cat)
      : unicode_(unicode)
      , shortName_(shortName)
      , unicodeName_(unicodeName)
      , category(cat)
    {
    }

    constexpr Emoji()
      : unicode_(u"", 0)
      , shortName_(u"", 0)
      , unicodeName_(u"", 0)
      , category(Category::Search)
    {
    }

    constexpr Emoji(const Emoji &) = default;
    constexpr Emoji(Emoji &&)      = default;

    constexpr Emoji &operator=(const Emoji &) = default;
    constexpr Emoji &operator=(Emoji &&)      = default;

    QString unicode() const
    {
        return QString::fromRawData(reinterpret_cast<const QChar *>(unicode_.data()),
                                    unicode_.size());
    }
    QString shortName() const
    {
        return QString::fromRawData(reinterpret_cast<const QChar *>(shortName_.data()),
                                    shortName_.size());
    }
    QString unicodeName() const
    {
        return QString::fromRawData(reinterpret_cast<const QChar *>(unicodeName_.data()),
                                    unicodeName_.size());
    }

private:
    std::u16string_view unicode_;
    std::u16string_view shortName_;
    std::u16string_view unicodeName_;

public:
    Category category;
};

class Provider
{
public:
    // all emoji for QML purposes
    static const std::array<Emoji, 3681> emoji;
};

QString
categoryToName(emoji::Emoji::Category cat);
} // namespace emoji
Q_DECLARE_METATYPE(emoji::Emoji)