File indexing completed on 2024-12-08 04:34:09

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #pragma once
0007 
0008 #include "libruqolawidgets_private_export.h"
0009 #include "misc/messagelistdelegatebase.h"
0010 class QTextDocument;
0011 class RocketChatAccount;
0012 class LIBRUQOLAWIDGETS_TESTS_EXPORT BannerInfoListViewDelegate : public MessageListDelegateBase
0013 {
0014     Q_OBJECT
0015 public:
0016     explicit BannerInfoListViewDelegate(QListView *view, RocketChatAccount *account, QObject *parent = nullptr);
0017     ~BannerInfoListViewDelegate() override;
0018 
0019     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0020     [[nodiscard]] QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0021 
0022     bool helpEvent(QHelpEvent *helpEvent, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) override;
0023 
0024     [[nodiscard]] bool mouseEvent(QEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index);
0025 
0026     [[nodiscard]] bool maybeStartDrag(QMouseEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index);
0027 
0028 protected:
0029     [[nodiscard]] RocketChatAccount *rocketChatAccount(const QModelIndex &index) const override;
0030 
0031 private:
0032     struct Layout {
0033         // Text message
0034         QRect textRect;
0035         qreal baseLine; // used to draw sender/timestamp
0036     };
0037     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT BannerInfoListViewDelegate::Layout doLayout(const QStyleOptionViewItem &option, const QModelIndex &index) const;
0038     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QTextDocument *documentForModelIndex(const QModelIndex &index, int width) const override;
0039     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QPoint adaptMousePosition(const QPoint &pos, QRect textRect, const QStyleOptionViewItem &option);
0040     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QString cacheIdentifier(const QModelIndex &index) const;
0041 
0042     RocketChatAccount *const mRocketChatAccount;
0043 };