File indexing completed on 2024-05-26 05:05:28

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.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 "misc/messagelistdelegatebase.h"
0012 class QListView;
0013 class RocketChatAccount;
0014 
0015 class LIBRUQOLAWIDGETS_TESTS_EXPORT ModerationReportInfoDelegate : public MessageListDelegateBase
0016 {
0017     Q_OBJECT
0018 public:
0019     explicit ModerationReportInfoDelegate(RocketChatAccount *account, QListView *view, QObject *parent = nullptr);
0020     ~ModerationReportInfoDelegate() override;
0021 
0022     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0023 
0024     [[nodiscard]] bool helpEvent(QHelpEvent *helpEvent, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) override;
0025 
0026     [[nodiscard]] bool mouseEvent(QEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index);
0027 
0028     [[nodiscard]] bool maybeStartDrag(QMouseEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index);
0029 
0030 protected:
0031     [[nodiscard]] QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0032 
0033     [[nodiscard]] RocketChatAccount *rocketChatAccount(const QModelIndex &index) const override;
0034 
0035 private:
0036     [[nodiscard]] QTextDocument *documentForModelIndex(const QModelIndex &index, int width) const override;
0037 
0038     struct Layout {
0039         // Sender
0040         QString senderText;
0041         QFont senderFont;
0042         QRectF senderRect;
0043 
0044         // Avatar pixmap
0045         QPixmap avatarPixmap;
0046         QPointF avatarPos;
0047 
0048         // Text message
0049         QRect textRect;
0050         qreal baseLine; // used to draw sender/timestamp
0051 
0052         QString timeStampText;
0053         QPoint timeStampPos;
0054     };
0055     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT ModerationReportInfoDelegate::Layout doLayout(const QStyleOptionViewItem &option, const QModelIndex &index) const;
0056     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QPoint adaptMousePosition(const QPoint &pos, QRect textRect, const QStyleOptionViewItem &option);
0057     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QString cacheIdentifier(const QModelIndex &index) const;
0058     RocketChatAccount *const mRocketChatAccount;
0059 };