File indexing completed on 2024-06-09 04:59:24
0001 /* 0002 SPDX-FileCopyrightText: 2020 David Faure <faure@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/pixmapcache.h" 0011 #include "runninganimatedimage.h" 0012 0013 #include "messages/reaction.h" 0014 #include <QFont> 0015 #include <QRectF> 0016 #include <QSize> 0017 0018 #include <vector> 0019 0020 class QHelpEvent; 0021 class QPainter; 0022 class QRect; 0023 class QModelIndex; 0024 class QMouseEvent; 0025 class QStyleOptionViewItem; 0026 class Message; 0027 class RocketChatAccount; 0028 0029 class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageDelegateHelperReactions 0030 { 0031 public: 0032 explicit MessageDelegateHelperReactions(RocketChatAccount *account); 0033 void draw(QPainter *painter, QRect reactionsRect, const QModelIndex &index, const QStyleOptionViewItem &option) const; 0034 [[nodiscard]] QSize sizeHint(const QModelIndex &index, int maxWidth, const QStyleOptionViewItem &option) const; 0035 [[nodiscard]] bool handleMouseEvent(QMouseEvent *mouseEvent, QRect reactionsRect, const QStyleOptionViewItem &option, const Message *message); 0036 [[nodiscard]] bool handleHelpEvent(QHelpEvent *helpEvent, QWidget *view, QRect reactionsRect, const QStyleOptionViewItem &option, const Message *message); 0037 0038 void setRocketChatAccount(RocketChatAccount *newRocketChatAccount); 0039 0040 private: 0041 Q_DISABLE_COPY(MessageDelegateHelperReactions) 0042 struct ReactionLayout { 0043 QRectF reactionRect; 0044 QRectF countRect; 0045 QString emojiString; // for unicode emojis 0046 QString emojiImagePath; // for custom emojis (pixmaps) 0047 QString countStr; 0048 qreal emojiOffset; 0049 Reaction reaction; 0050 bool useEmojiFont; 0051 }; 0052 0053 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT std::vector<RunningAnimatedImage>::iterator findRunningAnimatedImage(const QModelIndex &index) const; 0054 LIBRUQOLAWIDGETS_NO_EXPORT void removeRunningAnimatedImage(const QModelIndex &index) const; 0055 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QVector<ReactionLayout> 0056 layoutReactions(const QVector<Reaction> &reactions, QRect reactionsRect, const QStyleOptionViewItem &option) const; 0057 const QFont mEmojiFont; 0058 mutable std::vector<RunningAnimatedImage> mRunningAnimatedImages; // not a hash or map, since QPersistentModelIndex changes value 0059 mutable PixmapCache mPixmapCache; 0060 RocketChatAccount *mRocketChatAccount = nullptr; 0061 };