File indexing completed on 2024-12-22 04:46:04

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 #include <QFont>
0009 #include <QPixmap>
0010 #include <QPoint>
0011 #include <QRect>
0012 #include <QString>
0013 #include <QStyleOptionViewItem>
0014 #include <QVector>
0015 
0016 class RocketChatAccount;
0017 class MessageListDelegate;
0018 class Message;
0019 class MessageListLayoutBase
0020 {
0021 public:
0022     explicit MessageListLayoutBase(MessageListDelegate *delegate);
0023     virtual ~MessageListLayoutBase();
0024 
0025     struct Layout {
0026         // Sender
0027         QString senderText;
0028         QFont senderFont;
0029         QRectF senderRect;
0030 
0031         // Avatar pixmap
0032         QPixmap avatarPixmap;
0033         QPointF avatarPos;
0034 
0035         // Roles icon
0036         QRect rolesIconRect;
0037 
0038         // Edited icon
0039         QRect editedIconRect;
0040 
0041         // Favorite icon
0042         QRect favoriteIconRect;
0043 
0044         // Pinned icon
0045         QRect pinIconRect;
0046 
0047         // Pinned icon
0048         QRect followingIconRect;
0049 
0050         // Translated icon
0051         QRect translatedIconRect;
0052 
0053         // Show Ignore Message icon
0054         QRect showIgnoredMessageIconRect;
0055 
0056         // add-reaction button and timestamp
0057         QRect addReactionRect;
0058         QString timeStampText;
0059         QPoint timeStampPos;
0060         QRect timeStampRect;
0061 
0062         QRect usableRect; // rect for everything except the date header (at the top) and the sender (on the left)
0063 
0064         // Text message
0065         QRect textRect;
0066         qreal baseLine; // used to draw sender/timestamp
0067 
0068         // Attachments
0069         QRect attachmentsRect;
0070         QVector<QRect> attachmentsRectList;
0071 
0072         // Blocks
0073         QRect blocksRect;
0074         QVector<QRect> blocksRectList;
0075 
0076         // MessageUrl preview
0077         QRect messageUrlsRect;
0078         QVector<QRect> messageUrlsRectList;
0079 
0080         // Reactions
0081         qreal reactionsY = 0;
0082         qreal reactionsHeight = 0;
0083 
0084         // Replies
0085         qreal repliesY = 0;
0086         qreal repliesHeight = 0;
0087 
0088         // Discussions
0089         qreal discussionsHeight = 0;
0090 
0091         // Last See
0092         qreal displayLastSeenMessageY = 0;
0093 
0094         // showIgnoreMessage
0095         bool showIgnoreMessage = false;
0096         bool sameSenderAsPreviousMessage = false;
0097         bool messageIsFollowing = false;
0098     };
0099 
0100     [[nodiscard]] virtual MessageListLayoutBase::Layout doLayout(const QStyleOptionViewItem &option, const QModelIndex &index) const = 0;
0101 
0102     [[nodiscard]] virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const = 0;
0103 
0104     [[nodiscard]] RocketChatAccount *rocketChatAccount() const;
0105     void setRocketChatAccount(RocketChatAccount *newRocketChatAccount);
0106 
0107 protected:
0108     void generateSenderInfo(Layout &layout, const Message *message, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0109     void generateAttachmentBlockAndUrlPreviewLayout(MessageListDelegate *delegate,
0110                                                     Layout &layout,
0111                                                     const Message *message,
0112                                                     int attachmentsY,
0113                                                     int textLeft,
0114                                                     int maxWidth,
0115                                                     const QStyleOptionViewItem &option,
0116                                                     const QModelIndex &index) const;
0117     [[nodiscard]] bool sameSenderAsPreviousMessage(const QModelIndex &index, const Message *message) const;
0118     [[nodiscard]] QString senderText(const Message *message) const;
0119     RocketChatAccount *mRocketChatAccount = nullptr;
0120     MessageListDelegate *mDelegate = nullptr;
0121 };