File indexing completed on 2024-12-22 04:45:56
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "libruqolawidgets_private_export.h" 0010 #include "misc/messagelistdelegatebase.h" 0011 class QTextDocument; 0012 class RocketChatAccount; 0013 class AvatarCacheManager; 0014 class LIBRUQOLAWIDGETS_TESTS_EXPORT ListDiscussionDelegate : public MessageListDelegateBase 0015 { 0016 Q_OBJECT 0017 public: 0018 explicit ListDiscussionDelegate(QListView *view, RocketChatAccount *account, QObject *parent = nullptr); 0019 ~ListDiscussionDelegate() override; 0020 0021 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0022 [[nodiscard]] QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0023 0024 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 Q_SIGNALS: 0031 void openDiscussion(const QString &discussionRoomId); 0032 0033 protected: 0034 [[nodiscard]] RocketChatAccount *rocketChatAccount(const QModelIndex &index) const override; 0035 0036 private: 0037 struct Layout { 0038 // Sender 0039 QString senderText; 0040 QFont senderFont; 0041 QRectF senderRect; 0042 0043 // TimeStamp 0044 QString lastMessageTimeText; 0045 qreal lastMessageTimeY = 0; 0046 0047 // Number of message 0048 int numberOfMessages = 0; 0049 0050 // OpenDiscussionText 0051 QString openDiscussionText; 0052 qreal openDiscussionTextY = 0; 0053 qreal openDiscussionTextHeight = 0; 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 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT ListDiscussionDelegate::Layout doLayout(const QStyleOptionViewItem &option, const QModelIndex &index) const; 0064 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QTextDocument *documentForModelIndex(const QModelIndex &index, int width) const override; 0065 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QPixmap makeAvatarPixmap(const QWidget *widget, const QModelIndex &index, int maxHeight) const; 0066 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QPoint adaptMousePosition(const QPoint &pos, QRect textRect, const QStyleOptionViewItem &option); 0067 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QString cacheIdentifier(const QModelIndex &index) const; 0068 0069 RocketChatAccount *const mRocketChatAccount; 0070 AvatarCacheManager *const mAvatarCacheManager; 0071 };