File indexing completed on 2024-05-26 05:06:02
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 "messageattachmentdelegatehelperbase.h" 0010 #include "misc/pixmapcache.h" 0011 #include "runninganimatedimage.h" 0012 0013 #include <QModelIndex> 0014 #include <QPixmap> 0015 #include <vector> 0016 class RocketChatAccount; 0017 class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageAttachmentDelegateHelperImage : public MessageAttachmentDelegateHelperBase 0018 { 0019 public: 0020 explicit MessageAttachmentDelegateHelperImage(RocketChatAccount *account, QListView *view, TextSelectionImpl *textSelectionImpl); 0021 ~MessageAttachmentDelegateHelperImage() override = default; 0022 void 0023 draw(const MessageAttachment &msgAttach, QPainter *painter, QRect messageRect, const QModelIndex &index, const QStyleOptionViewItem &option) const override; 0024 [[nodiscard]] QSize sizeHint(const MessageAttachment &msgAttach, const QModelIndex &index, int maxWidth, const QStyleOptionViewItem &option) const override; 0025 [[nodiscard]] bool handleMouseEvent(const MessageAttachment &msgAttach, 0026 QMouseEvent *mouseEvent, 0027 QRect attachmentsRect, 0028 const QStyleOptionViewItem &option, 0029 const QModelIndex &index) override; 0030 0031 private: 0032 Q_DISABLE_COPY(MessageAttachmentDelegateHelperImage) 0033 friend class MessageDelegateHelperImageTest; 0034 0035 struct ImageLayout { 0036 QPixmap pixmap; 0037 QString imagePreviewPath; 0038 QString imageBigPath; 0039 QString title; 0040 QSize titleSize; 0041 QSize imageSize; 0042 QSize descriptionSize; 0043 QRect hideShowButtonRect; 0044 QRect downloadButtonRect; 0045 bool isShown = true; 0046 bool isAnimatedImage = false; 0047 bool hasDescription = false; 0048 }; 0049 [[nodiscard]] ImageLayout 0050 layoutImage(const MessageAttachment &msgAttach, const QStyleOptionViewItem &option, int attachmentsWidth, int attachmentsHeight) const; 0051 0052 [[nodiscard]] std::vector<RunningAnimatedImage>::iterator findRunningAnimatedImage(const QModelIndex &index) const; 0053 void removeRunningAnimatedImage(const QModelIndex &index) const; 0054 [[nodiscard]] bool contextMenu(const QPoint &pos, 0055 const QPoint &globalPos, 0056 const MessageAttachment &msgAttach, 0057 QRect attachmentsRect, 0058 const QStyleOptionViewItem &option, 0059 QMenu *menu) override; 0060 0061 private: 0062 [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QPoint adaptMousePosition(const QPoint &pos, 0063 const MessageAttachment &msgAttach, 0064 QRect attachmentsRect, 0065 const QStyleOptionViewItem &option) override; 0066 mutable PixmapCache mPixmapCache; 0067 mutable std::vector<RunningAnimatedImage> mRunningAnimatedImages; // not a hash or map, since QPersistentModelIndex changes value 0068 };