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

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