File indexing completed on 2024-05-05 16:58:38
0001 // SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0003 0004 #pragma once 0005 0006 #include <QSortFilterProxyModel> 0007 0008 #include "models/collapsestateproxymodel.h" 0009 0010 /** 0011 * @class MediaMessageFilterModel 0012 * 0013 * This model filters a MessageEventModel for image and video messages. 0014 * 0015 * @sa MessageEventModel 0016 */ 0017 class MediaMessageFilterModel : public QSortFilterProxyModel 0018 { 0019 Q_OBJECT 0020 public: 0021 /** 0022 * @brief Defines the model roles. 0023 */ 0024 enum Roles { 0025 SourceRole = CollapseStateProxyModel::LastRole + 1, /**< The mxc source URL for the item. */ 0026 TempSourceRole, /**< Source for the temporary content (either blurhash or mxc URL). */ 0027 TypeRole, /**< The type of the media (image or video). */ 0028 CaptionRole, /**< The caption for the item. */ 0029 SourceWidthRole, /**< The width of the source item. */ 0030 SourceHeightRole, /**< The height of the source item. */ 0031 }; 0032 Q_ENUM(Roles) 0033 0034 explicit MediaMessageFilterModel(QObject *parent = nullptr); 0035 0036 /** 0037 * @brief Custom filter to show only image and video messages. 0038 */ 0039 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 0040 0041 /** 0042 * @brief Get the given role value at the given index. 0043 * 0044 * @sa QSortFilterProxyModel::data 0045 */ 0046 [[nodiscard]] QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override; 0047 0048 /** 0049 * @brief Returns a mapping from Role enum values to role names. 0050 * 0051 * @sa Roles, QAbstractProxyModel::roleNames() 0052 */ 0053 [[nodiscard]] QHash<int, QByteArray> roleNames() const override; 0054 0055 Q_INVOKABLE int getRowForSourceItem(int sourceRow) const; 0056 };