matrixion/src/CombinedImagePackModel.h

49 lines
1.2 KiB
C
Raw Normal View History

2021-07-15 21:37:52 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <QAbstractListModel>
#include <mtx/events/mscs/image_packs.hpp>
2021-07-21 02:03:38 +03:00
class CombinedImagePackModel : public QAbstractListModel
2021-07-15 21:37:52 +03:00
{
Q_OBJECT
public:
enum Roles
{
Url = Qt::UserRole,
ShortCode,
Body,
PackName,
OriginalRow,
};
2021-07-21 02:03:38 +03:00
CombinedImagePackModel(const std::string &roomId, bool stickers, QObject *parent = nullptr);
2021-07-15 21:37:52 +03:00
QHash<int, QByteArray> roleNames() const override;
2021-07-19 13:43:16 +03:00
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
2021-07-15 21:37:52 +03:00
QVariant data(const QModelIndex &index, int role) const override;
mtx::events::msc2545::PackImage imageAt(int row)
{
if (row < 0 || static_cast<size_t>(row) >= images.size())
return {};
return images.at(static_cast<size_t>(row)).image;
}
private:
std::string room_id;
struct ImageDesc
{
QString shortcode;
QString packname;
mtx::events::msc2545::PackImage image;
};
std::vector<ImageDesc> images;
};