File indexing completed on 2024-12-01 04:36:51

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "delegateutils/textselection.h"
0010 #include "libruqolawidgets_private_export.h"
0011 #include "messagelisttextui.h"
0012 #include <QItemDelegate>
0013 class QTextDocument;
0014 class RocketChatAccount;
0015 class QListView;
0016 class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageListDelegateBase : public QItemDelegate, public DocumentFactoryInterface, public MessageListTextUi
0017 {
0018     Q_OBJECT
0019 public:
0020     explicit MessageListDelegateBase(QListView *view, QObject *parent = nullptr);
0021     ~MessageListDelegateBase() override;
0022 
0023     void clearCache() override;
0024     void clearSizeHintCache();
0025 
0026     [[nodiscard]] bool maybeStartDrag(QMouseEvent *mouseEvent, QRect messageRect, const QStyleOptionViewItem &option, const QModelIndex &index);
0027 
0028     [[nodiscard]] bool handleMouseEvent(QMouseEvent *mouseEvent, QRect messageRect, const QStyleOptionViewItem &option, const QModelIndex &index);
0029     void selectAll(const QStyleOptionViewItem &option, const QModelIndex &index);
0030 
0031     [[nodiscard]] const QString &searchText() const;
0032     void setSearchText(const QString &newSearchText);
0033 
0034     [[nodiscard]] QString selectedText() const;
0035 
0036     [[nodiscard]] bool hasSelection() const;
0037 
0038 Q_SIGNALS:
0039     void updateView(const QModelIndex &index);
0040 
0041 protected:
0042     [[nodiscard]] QTextDocument *documentForIndex(const QModelIndex &index) const override;
0043     [[nodiscard]] QSize textSizeHint(const QModelIndex &index, int maxWidth, const QStyleOptionViewItem &option, qreal *pBaseLine) const;
0044 
0045     virtual QTextDocument *documentForModelIndex(const QModelIndex &index, int width) const = 0;
0046     [[nodiscard]] virtual RocketChatAccount *rocketChatAccount(const QModelIndex &index) const = 0;
0047     [[nodiscard]] QTextDocument *documentForDelegate(RocketChatAccount *rcAccount, const QString &messageId, const QString &messageStr, int width) const;
0048 
0049     QString mSearchText;
0050 };