File indexing completed on 2024-05-05 16:58:37

0001 // SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <QSortFilterProxyModel>
0007 
0008 /**
0009  * @class EmoticonFilterModel
0010  *
0011  * This class creates a custom QSortFilterProxyModel for filtering a emoticon by type
0012  * (Sticker or Emoji).
0013  */
0014 class EmoticonFilterModel : public QSortFilterProxyModel
0015 {
0016     Q_OBJECT
0017 
0018     /**
0019      * @brief Whether stickers should be shown
0020      */
0021     Q_PROPERTY(bool showStickers READ showStickers WRITE setShowStickers NOTIFY showStickersChanged)
0022 
0023     /**
0024      * @brief Whether emojis show be shown
0025      */
0026     Q_PROPERTY(bool showEmojis READ showEmojis WRITE setShowEmojis NOTIFY showEmojisChanged)
0027 
0028 public:
0029     explicit EmoticonFilterModel(QObject *parent = nullptr);
0030 
0031     /**
0032      * @brief Custom filter function checking the type of emoticon
0033      *
0034      * @note The filter cannot be modified and will always use the same filter properties.
0035      */
0036     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
0037 
0038     [[nodiscard]] bool showStickers() const;
0039     void setShowStickers(bool showStickers);
0040 
0041     [[nodiscard]] bool showEmojis() const;
0042     void setShowEmojis(bool showEmojis);
0043 
0044 Q_SIGNALS:
0045     void showStickersChanged();
0046     void showEmojisChanged();
0047 
0048 private:
0049     bool m_showStickers = false;
0050     bool m_showEmojis = false;
0051     int m_stickerRole = 0;
0052     int m_emojiRole = 0;
0053 };