File indexing completed on 2024-05-05 05:01:22

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