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
|
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <QAbstractListModel>
#include <QMultiMap>
#include <QObject>
#include <QString>
#include <mtx/events/mscs/image_packs.hpp>
#include "CompletionProxyModel.h"
struct StickerImage
{
Q_GADGET
Q_PROPERTY(QString url MEMBER url CONSTANT)
Q_PROPERTY(QString shortcode MEMBER shortcode CONSTANT)
Q_PROPERTY(QString body MEMBER body CONSTANT)
Q_PROPERTY(QStringList descriptor READ descriptor CONSTANT)
public:
QStringList descriptor() const
{
if (descriptor_.size() == 3)
return QStringList{
QString::fromStdString(descriptor_[0]),
QString::fromStdString(descriptor_[1]),
QString::fromStdString(descriptor_[2]),
};
else
return {};
}
QString url;
QString shortcode;
QString body;
std::vector<std::string> descriptor_; // roomid, statekey, shortcode
};
class GridImagePackModel final : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(QString searchString READ searchString WRITE setSearchString NOTIFY newSearchString)
public:
enum Roles
{
PackName = Qt::UserRole,
Row,
};
GridImagePackModel(const std::string &roomId, bool stickers, QObject *parent = nullptr);
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QString searchString() const { return searchString_; }
void setSearchString(QString newValue);
signals:
void newSearchString();
private:
std::string room_id;
struct PackDesc
{
QString packname;
QString packavatar;
std::string room_id, state_key;
std::vector<std::pair<mtx::events::msc2545::PackImage, QString>> images;
std::size_t firstRow;
};
std::vector<PackDesc> packs;
std::vector<size_t> rowToPack;
int columns = 3;
QString searchString_;
trie<uint, std::pair<std::uint32_t, std::uint32_t>> trie_;
std::vector<std::pair<std::uint32_t, std::uint32_t>> currentSearchResult;
std::vector<std::size_t> rowToFirstRowEntryFromSearch;
};
|